From: Luca Bruno Date: Thu, 5 Jan 2012 10:42:15 +0000 (+0100) Subject: Move ObjectCreationExpression transformation to the CCodeTransformer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3d257b67923b7c8c394fd6920773d3962c10324;p=thirdparty%2Fvala.git Move ObjectCreationExpression transformation to the CCodeTransformer --- diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala index c9374d832..dddade94d 100644 --- a/codegen/valaccodetransformer.vala +++ b/codegen/valaccodetransformer.vala @@ -317,4 +317,27 @@ 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 target_type = copy_type (expr.target_type); + var formal_target_type = copy_type (expr.formal_target_type); + begin_replace_expression (expr); + + var local = b.add_temp_declaration (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_object_creation_expression (expr); + } } diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala index a063f0494..cd166bef0 100644 --- a/vala/valaflowanalyzer.vala +++ b/vala/valaflowanalyzer.vala @@ -1383,6 +1383,14 @@ public class Vala.FlowAnalyzer : CodeVisitor { } } + public override void visit_object_creation_expression (ObjectCreationExpression expr) { + if (unreachable (expr)) { + return; + } + + handle_errors (expr); + } + private bool unreachable (CodeNode node) { if (current_block == null) { node.unreachable = true; diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index 1739e9030..63f650254 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -491,38 +491,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; }