[vala/wip/transform-ast: 11/28] Move MethodCall transformation into the code transformer



commit 5dce6a018f3a99c428acdbea1904f0f9910740c8
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Aug 7 12:22:15 2011 +0200

    Move MethodCall transformation into the code transformer

 codegen/valaccodetransformer.vala | 21 +++++++++++++++++++++
 vala/valamethodcall.vala          | 36 ------------------------------------
 2 files changed, 21 insertions(+), 36 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 3599fc3c8..bbc3c84ad 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -68,4 +68,25 @@ public class Vala.CCodeTransformer : CodeTransformer {
 
                base.visit_expression (expr);
        }
+
+       public override void visit_method_call (MethodCall expr) {
+               if (expr.tree_can_fail) {
+                       if (expr.parent_node is LocalVariable || expr.parent_node is ExpressionStatement) {
+                               // simple statements, no side effects after method call
+                       } else if (!(context.analyzer.get_current_non_local_symbol (expr) is Block)) {
+                               // can't handle errors in field initializers
+                               expr.error = true;
+                               Report.error (expr.source_reference, "Field initializers must not throw 
errors");
+                       } else {
+                               var formal_target_type = copy_type (expr.target_type);
+                               var target_type = copy_type (expr.target_type);
+                               begin_replace_expression (expr);
+
+                               var local = b.add_temp_declaration (copy_type (expr.value_type), expr);
+                               var replacement = return_temp_access (local, expr.value_type, target_type, 
formal_target_type);
+
+                               end_replace_expression (replacement);
+                       }
+               }
+       }
 }
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 787fc99e5..c0a13fe10 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -651,42 +651,6 @@ public class Vala.MethodCall : Expression {
 
                value_type.check (context);
 
-               // FIXME code duplication in ObjectCreationExpression.check
-               if (tree_can_fail) {
-                       if (parent_node is LocalVariable || parent_node is ExpressionStatement) {
-                               // simple statements, no side effects after method call
-                       } else if (!(context.analyzer.get_current_non_local_symbol (this) is Block)) {
-                               // can't handle errors in field initializers
-                               error = true;
-                               Report.error (source_reference, "Field initializers must not throw errors");
-                       } else {
-                               // store parent_node as we need to replace the expression in the old parent 
node later on
-                               var old_parent_node = parent_node;
-
-                               var local = new LocalVariable (value_type.copy (), get_temp_name (), null, 
source_reference);
-                               var decl = new DeclarationStatement (local, source_reference);
-
-                               insert_statement (context.analyzer.get_insert_block (this), decl);
-
-                               var temp_access = SemanticAnalyzer.create_temp_access (local, target_type);
-                               temp_access.formal_target_type = formal_target_type;
-
-                               // don't set initializer earlier as this changes parent_node and 
parent_statement
-                               local.initializer = this;
-                               decl.check (context);
-
-                               // move temp variable to insert block to ensure the
-                               // variable is in the same block as the declaration
-                               // otherwise there will be scoping issues in the generated code
-                               var block = context.analyzer.get_current_block (this);
-                               block.remove_local_variable (local);
-                               context.analyzer.get_insert_block (this).add_local_variable (local);
-
-                               old_parent_node.replace_expression (this, temp_access);
-                               temp_access.check (context);
-                       }
-               }
-
                return !error;
        }
 


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