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



commit c22128e590668773d9e85604c10a5810a1e4dd7c
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      |    6 +++---
 vala/valaelementaccess.vala            |    2 +-
 vala/valamethodcall.vala               |    2 +-
 vala/valaobjectcreationexpression.vala |    2 +-
 vala/valatemplate.vala                 |   19 +++++++++++++++++++
 6 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e61077c..cd9ac8c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2291,7 +2291,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 626c5a7..ed870ad 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -73,7 +73,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
                if (m.body == null) {
                        return;
                }
-               
+
                m.accept_children (this);
        }
 
@@ -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 437c382..94082bc 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 884429e..08e0563 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -101,7 +101,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 400e1a8..a1aafa1 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 f346e90..ce458bd 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]