[vala/wip/transform: 139/214] Add more to_string() methods to expressions



commit c886d5a387d9f4892541a32b423d8e1ab3a1f4bb
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 ++++++++++++++
 7 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/vala/valaaddressofexpression.vala b/vala/valaaddressofexpression.vala
index b537174..8d0f026 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 a433157..f5d6062 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 52648b7..1847632 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 f9e3d30..76bef3c 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -93,6 +93,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 a7b761b..32cf5d4 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -116,6 +116,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 4fb44b8..2fe4b87 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 c1f97ca..8d05feb 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) {


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