]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move ObjectCreationExpression transformation to the code transformer
authorLuca Bruno <lucabru@src.gnome.org>
Thu, 5 Jan 2012 10:42:15 +0000 (11:42 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 11 Mar 2019 12:52:38 +0000 (13:52 +0100)
codegen/valaccodetransformer.vala
vala/valaobjectcreationexpression.vala

index 6b2eac01b2dddbcaec34819ed8b517a9502534ea..ec811f230f75b8a47f532e3c0e15f424eb5d2525 100644 (file)
@@ -487,4 +487,29 @@ public class Vala.CCodeTransformer : CodeTransformer {
                        base.visit_binary_expression (expr);
                }
        }
+
+       public override void visit_object_creation_expression (ObjectCreationExpression 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 old_parent_node = expr.parent_node;
+                               var target_type = expr.target_type != null ? expr.target_type.copy () : null;
+                               push_builder (new CodeBuilder (context, expr.parent_statement, expr.source_reference));
+
+                               // FIXME: use create_temp_access behavior
+                               var replacement = expression (b.add_temp_declaration (expr.value_type, expr));
+
+                               replacement.target_type = target_type;
+                               context.analyzer.replaced_nodes.add (expr);
+                               old_parent_node.replace_expression (expr, replacement);
+                               b.check (this);
+                               pop_builder ();
+                               check (replacement);
+                       }
+               }
+       }
 }
index 2e8e4efacf91fefdb56a7293986658d9c52e4111..3d80dca38e513266301f0e7ad6e89df6947293fb 100644 (file)
@@ -482,38 +482,6 @@ public class Vala.ObjectCreationExpression : Expression {
                        context.analyzer.visit_member_initializer (init, type_reference);
                }
 
-               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_current_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_current_block (this).add_local_variable (local);
-
-                               old_parent_node.replace_expression (this, temp_access);
-                               temp_access.check (context);
-                       }
-               }
-
                return !error;
        }