[vala/wip/transform: 298/373] Add more to_string() methods to expressions



commit e9c9d3f84c86731761621b8596170396646888bf
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jan 3 13:03:53 2012 +0100

    Add more to_string() methods to expressions

 vala/valaaddressofexpression.vala     |  4 ++++
 vala/valaarraycreationexpression.vala | 18 ++++++++++++++++++
 vala/valaassignment.vala              | 21 +++++++++++++++++++++
 vala/valacastexpression.vala          | 10 ++++++++++
 vala/valaconditionalexpression.vala   |  4 ++++
 vala/valaelementaccess.vala           | 14 ++++++++++++++
 vala/valainitializerlist.vala         | 14 ++++++++++++++
 vala/valanamespace.vala               |  8 ++++++++
 vala/valasymbol.vala                  |  4 ++++
 9 files changed, 97 insertions(+)
---
diff --git a/vala/valaaddressofexpression.vala b/vala/valaaddressofexpression.vala
index 029325264..4948a46c2 100644
--- a/vala/valaaddressofexpression.vala
+++ b/vala/valaaddressofexpression.vala
@@ -62,6 +62,10 @@ public class Vala.AddressofExpression : Expression {
                inner.accept (visitor);
        }
 
+       public override string to_string () {
+               return "&" + inner.to_string ();
+       }
+
        public override void replace_expression (Expression old_node, Expression new_node) {
                if (inner == old_node) {
                        inner = new_node;
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index 41b0f351b..43cb1e6af 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -127,6 +127,24 @@ public class Vala.ArrayCreationExpression : Expression {
                return true;
        }
 
+       public override string to_string () {
+               var builder = new StringBuilder ("new ");
+               builder.append_printf ("%s[", element_type.to_string ());
+               bool first = true;
+               foreach (var size in sizes) {
+                       if (first) {
+                               builder.append (size.to_string ());
+                               first = false;
+                       } else {
+                               builder.append_printf (", %s", size.to_string ());
+                       }
+               }
+               if (initializer_list != null) {
+                       builder.append (initializer_list.to_string ());
+               }
+               return builder.str;
+       }
+
        public override void replace_expression (Expression old_node, Expression new_node) {
                for (int i = 0; i < sizes.size; i++) {
                        if (sizes[i] == old_node) {
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 172ae5254..4ca167c3a 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -84,6 +84,27 @@ public class Vala.Assignment : Expression {
                right.accept (visitor);
        }
 
+       public string get_operator_string () {
+               switch (_operator) {
+               case AssignmentOperator.SIMPLE: return "=";
+               case AssignmentOperator.BITWISE_OR: return "|=";
+               case AssignmentOperator.BITWISE_AND: return "&=";
+               case AssignmentOperator.BITWISE_XOR: return "^=";
+               case AssignmentOperator.ADD: return "+=";
+               case AssignmentOperator.SUB: return "-=";
+               case AssignmentOperator.MUL: return "*=";
+               case AssignmentOperator.DIV: return "/=";
+               case AssignmentOperator.PERCENT: return "%=";
+               case AssignmentOperator.SHIFT_LEFT: return "<<=";
+               case AssignmentOperator.SHIFT_RIGHT: return ">>=";
+               default: assert_not_reached ();
+               }
+       }
+
+       public override string to_string () {
+               return left.to_string () + get_operator_string () + right.to_string ();
+       }
+
        public override void replace_expression (Expression old_node, Expression new_node) {
                if (left == old_node) {
                        left = new_node;
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index 18ed153b8..4bed12c86 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -102,6 +102,16 @@ public class Vala.CastExpression : Expression {
                }
        }
 
+       public override string to_string () {
+               if (is_non_null_cast) {
+                       return "(!)"+inner.to_string ();
+               } else if (is_silent_cast) {
+                       return "%s as %s".printf (inner.to_string (), type_reference.to_string ());
+               } else {
+                       return "(%s) %s".printf (type_reference.to_string (), inner.to_string ());
+               }
+       }
+
        public override void replace_expression (Expression old_node, Expression new_node) {
                if (inner == old_node) {
                        inner = new_node;
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 63de278ab..454f36de5 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -122,6 +122,10 @@ public class Vala.ConditionalExpression : Expression {
                false_expression.get_used_variables (collection);
        }
 
+       public override string to_string () {
+               return "%s ? %s : %s".printf (condition.to_string, true_expression.to_string (), 
false_expression.to_string ());
+       }
+
        public override void replace_expression (Expression old_node, Expression new_node) {
                if (condition == old_node) {
                        condition = new_node;
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 88c396ae1..dec200795 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -75,6 +75,20 @@ public class Vala.ElementAccess : Expression {
                }
        }
 
+       public override string to_string () {
+               var s = "%s[";
+               bool first = true;
+               foreach (var index in indices) {
+                       if (first) {
+                               s += index.to_string ();
+                               first = false;
+                       } else {
+                               s += ", %s".printf (index.to_string ());
+                       }
+               }
+               return s+"]";
+       }
+
        public override void replace_expression (Expression old_node, Expression new_node) {
                if (container == old_node) {
                        container = new_node;
diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala
index 8a601874e..a4f0f2486 100644
--- a/vala/valainitializerlist.vala
+++ b/vala/valainitializerlist.vala
@@ -106,6 +106,20 @@ public class Vala.InitializerList : Expression {
                return true;
        }
 
+       public override string to_string () {
+               var builder = new StringBuilder ("{");
+               bool first = true;
+               foreach (var initializer in initializers) {
+                       if (first) {
+                               builder.append (initializer.to_string ());
+                               first = false;
+                       } else {
+                               builder.append_printf (", %s", initializer.to_string ());
+                       }
+               }
+               return builder.str;
+       }
+
        public override void replace_expression (Expression old_node, Expression new_node) {
                for (int i = 0; i < initializers.size; i++) {
                        if (initializers[i] == old_node) {
diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala
index af062f85c..c53fda830 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -523,4 +523,12 @@ public class Vala.Namespace : Symbol {
 
                return !error;
        }
+
+       public override string to_string () {
+               if (name == null) {
+                       return "(root namespace)";
+               } else {
+                       return "namespace %s".printf (name);
+               }
+       }
 }
diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala
index 131969afb..e77f2da58 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -472,6 +472,10 @@ public abstract class Vala.Symbol : CodeNode {
        public virtual void add_destructor (Destructor d) {
                Report.error (d.source_reference, "unexpected declaration");
        }
+
+       public override string to_string () {
+               return get_full_name();
+       }
 }
 
 public enum Vala.SymbolAccessibility {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]