]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move MethodCall transformation into the CCodeTransformer
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 7 Aug 2011 10:22:15 +0000 (12:22 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 19 Apr 2019 13:25:24 +0000 (15:25 +0200)
codegen/valaccodetransformer.vala
vala/valaflowanalyzer.vala
vala/valamethodcall.vala

index 3599fc3c878858524a5fb167006b7c54b6db9d8f..fa24ae7ab00da2ba0d845dc25e0549cdb52b4427 100644 (file)
@@ -68,4 +68,27 @@ 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
+                               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);
+                               return;
+                       }
+               }
+
+               base.visit_method_call (expr);
+       }
 }
index dc7e471a324be8f7a512ea0e5cf36d40d6fedfba..48b85004555e6853ea47a55713d32d36b8aac0f1 100644 (file)
@@ -1093,6 +1093,14 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                }
        }
 
+       public override void visit_method_call (MethodCall expr) {
+               if (unreachable (expr)) {
+                       return;
+               }
+
+               handle_errors (expr);
+       }
+
        private bool unreachable (CodeNode node) {
                if (current_block == null) {
                        node.unreachable = true;
index 1b0916349f6541efb0a745e779033d3fd1e6cc88..433915f31394108b1bd489e1100057cc317a5295 100644 (file)
@@ -652,39 +652,6 @@ public class Vala.MethodCall : Expression {
 
                value_type.check (context);
 
-               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
-                               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);
-
-                               // 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;
        }