[vala/wip/transform: 39/74] Move ObjectCreationExpression transformation to the code transformer
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 39/74] Move ObjectCreationExpression transformation to the code transformer
- Date: Sun, 9 Jun 2013 19:44:15 +0000 (UTC)
commit 1e69a5861f881065d3b37d092870d205aa5db588
Author: Luca Bruno <lucabru src gnome org>
Date: Thu Jan 5 11:42:15 2012 +0100
Move ObjectCreationExpression transformation to the code transformer
codegen/valaccodetransformer.vala | 32 ++++++++++++++++++++++++---
vala/valaobjectcreationexpression.vala | 36 --------------------------------
2 files changed, 28 insertions(+), 40 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 829cc08..6511c40 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -381,10 +381,8 @@ public class Vala.CCodeTransformer : CodeTransformer {
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_symbol (expr) is Block)) {
- if (context.profile != Profile.DOVA) {
- // can't handle errors in field initializers
- Report.error (expr.source_reference, "Field initializers must not
throw errors");
- }
+ // can't handle errors in field initializers
+ Report.error (expr.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 = expr.parent_node;
@@ -491,4 +489,30 @@ 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_symbol (expr) is Block)) {
+ if (context.profile != Profile.DOVA) {
+ // 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));
+
+ 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);
+ }
+ }
+ }
}
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 6d2c469..73fdaf9 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -400,42 +400,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_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, get_temp_name (), null,
source_reference);
- // use floating variable to avoid unnecessary (and sometimes impossible)
copies
- local.floating = true;
- var decl = new DeclarationStatement (local, source_reference);
-
- insert_statement (context.analyzer.get_current_block (this), decl);
-
- Expression temp_access = new MemberAccess.simple (local.name,
source_reference);
- temp_access.target_type = 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
- // variable is in the same block as the declarat
- // otherwise there will be scoping issues in the
- 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]