[vala/wip/transform: 352/373] Use _ctmp%d_ for compiler variables since they are globally mapped. Fix templates



commit 8ca83eb98a343a5d52328e9fed651d1040347316
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Feb 1 18:26:35 2014 +0100

    Use _ctmp%d_ for compiler variables since they are globally mapped. Fix templates

 codegen/valaccodebasemodule.vala       |  2 +-
 codegen/valaccodetransformer.vala      |  4 ++--
 vala/valaelementaccess.vala            |  2 +-
 vala/valamethodcall.vala               |  2 +-
 vala/valaobjectcreationexpression.vala |  2 +-
 vala/valatemplate.vala                 | 19 +++++++++++++++++++
 6 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3398c0ed4..c449f0b64 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2352,7 +2352,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        }
                        // compiler-internal variable
                        if (!variable_name_map.contains (name)) {
-                               variable_name_map.set (name, "_tmp%d_".printf (next_temp_var_id));
+                               variable_name_map.set (name, "_ctmp%d_".printf (next_temp_var_id));
                                next_temp_var_id++;
                        }
                        return variable_name_map.get (name);
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 413b64a1a..4b8c68a0d 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -530,7 +530,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                if (expr.value_type.data_type != null && expr.value_type.data_type.is_subtype_of 
(context.analyzer.string_type.data_type)) {
                        return expr;
                } else {
-                       return expression (@"($expr).to_string ()");
+                       return expression (@"$expr.to_string ()");
                }
        }
 
@@ -545,7 +545,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                } else {
                        replacement = stringify (expression_list[0]);
                        if (expression_list.size > 1) {
-                               var concat = (MethodCall) expression (@"($replacement).concat()");
+                               var concat = (MethodCall) expression (@"$replacement.concat()");
                                for (int i = 1; i < expression_list.size; i++) {
                                        concat.add_argument (stringify (expression_list[i]));
                                }
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 154ffd5f0..59d5ab201 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -95,7 +95,7 @@ public class Vala.ElementAccess : Expression {
                }
 
                int index = indices.index_of (old_node);
-               if (index >= 0 && new_node.parent_node == null) {
+               if (index >= 0) {
                        indices[index] = new_node;
                        new_node.parent_node = this;
                }
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index e0ca7f320..80b00d9f4 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -103,7 +103,7 @@ public class Vala.MethodCall : Expression {
                }
 
                int index = argument_list.index_of (old_node);
-               if (index >= 0 && new_node.parent_node == null) {
+               if (index >= 0) {
                        argument_list[index] = new_node;
                        new_node.parent_node = this;
                }
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 9aa18a813..2ab0fb25f 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -138,7 +138,7 @@ public class Vala.ObjectCreationExpression : Expression {
 
        public override void replace_expression (Expression old_node, Expression new_node) {
                int index = argument_list.index_of (old_node);
-               if (index >= 0 && new_node.parent_node == null) {
+               if (index >= 0) {
                        argument_list[index] = new_node;
                        new_node.parent_node = this;
                }
diff --git a/vala/valatemplate.vala b/vala/valatemplate.vala
index f346e90f8..f60821508 100644
--- a/vala/valatemplate.vala
+++ b/vala/valatemplate.vala
@@ -51,6 +51,25 @@ public class Vala.Template : Expression {
                return false;
        }
 
+       public override string to_string () {
+               var b = new StringBuilder ();
+               b.append ("@\"");
+
+               foreach (var expr in expression_list) {
+                       if (expr is StringLiteral) {
+                               unowned string value = ((StringLiteral) expr).value;
+                               b.append (value.substring (1, (uint) (value.length - 2)));
+                       } else {
+                               b.append ("$(");
+                               b.append (expr.to_string ());
+                               b.append_c (')');
+                       }
+               }
+
+               b.append_c ('"');
+               return b.str;
+       }
+
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;


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