[vala/wip/transform: 10/31] Add ConditionalExpression.replace_expression plus other fixes



commit c4590041e0a0d2dbe21435d9c89c278116d97a3a
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Dec 29 12:39:15 2011 +0100

    Add ConditionalExpression.replace_expression plus other fixes

 codegen/valagvarianttransformer.vala |    2 ++
 vala/valacodetransformer.vala        |    6 ++++++
 vala/valaconditionalexpression.vala  |   18 ++++++++++++++----
 3 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valagvarianttransformer.vala b/codegen/valagvarianttransformer.vala
index 3ead018..a0be0e8 100644
--- a/codegen/valagvarianttransformer.vala
+++ b/codegen/valagvarianttransformer.vala
@@ -244,6 +244,8 @@ public class Vala.GVariantTransformer : CodeTransformer {
 	}
 
 	public override void visit_expression (Expression expr) {
+		base.visit_expression (expr);
+
 		if (!(context.profile == Profile.GOBJECT && expr.target_type != null && expr.target_type.data_type == context.analyzer.gvariant_type.data_type && !(expr.value_type is NullType) && expr.value_type.data_type != context.analyzer.gvariant_type.data_type)) {
 			// no implicit gvariant boxing
 			return;
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index 5fa1922..857a663 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -200,6 +200,7 @@ public class Vala.CodeTransformer : CodeVisitor {
 		var loop = new Loop (stmt.body, stmt.source_reference);
 
 		var parent_block = (Block) stmt.parent_node;
+		context.analyzer.replaced_nodes.add (stmt);
 		parent_block.replace_statement (stmt, loop);
 
 		stmt.body.checked = false;
@@ -214,6 +215,7 @@ public class Vala.CodeTransformer : CodeVisitor {
 			var loop = new Loop (stmt.body, stmt.source_reference);
 
 			var parent_block = (Block) stmt.parent_node;
+			context.analyzer.replaced_nodes.add (stmt);
 			parent_block.replace_statement (stmt, loop);
 
 			check (loop);
@@ -241,6 +243,7 @@ public class Vala.CodeTransformer : CodeVisitor {
 		block.add_statement (new Loop (stmt.body, stmt.source_reference));
 
 		var parent_block = (Block) stmt.parent_node;
+		context.analyzer.replaced_nodes.add (stmt);
 		parent_block.replace_statement (stmt, block);
 
 		stmt.body.checked = false;
@@ -287,6 +290,7 @@ public class Vala.CodeTransformer : CodeVisitor {
 		block.add_statement (new Loop (stmt.body, stmt.source_reference));
 
 		var parent_block = (Block) stmt.parent_node;
+		context.analyzer.replaced_nodes.add (stmt);
 		parent_block.replace_statement (stmt, block);
 
 		stmt.body.checked = false;
@@ -375,6 +379,7 @@ public class Vala.CodeTransformer : CodeVisitor {
 				block.remove_local_variable (local);
 				context.analyzer.get_insert_block (expr).add_local_variable (local);
 
+				context.analyzer.replaced_nodes.add (expr);
 				old_parent_node.replace_expression (expr, temp_access);
 				check (temp_access);
 			}
@@ -405,6 +410,7 @@ public class Vala.CodeTransformer : CodeVisitor {
 		ma.formal_target_type = expr.formal_target_type;
 		ma.target_type = expr.target_type;
 
+		context.analyzer.replaced_nodes.add (expr);
 		expr.parent_node.replace_expression (expr, ma);
 		check (ma);
 	}
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 7ea39e4..486ecbd 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -85,11 +85,9 @@ public class Vala.ConditionalExpression : Expression {
 	}
 	
 	public override void accept (CodeVisitor visitor) {
-		// FIXME: temporary workaround to keep alive the object
-		var self = this;
-		visitor.visit_conditional_expression (self);
+		visitor.visit_conditional_expression (this);
 
-		visitor.visit_expression (self);
+		visitor.visit_expression (this);
 	}
 
 	public override void accept_children (CodeVisitor visitor) {
@@ -114,6 +112,18 @@ public class Vala.ConditionalExpression : Expression {
 		false_expression.get_used_variables (collection);
 	}
 
+	public override void replace_expression (Expression old_node, Expression new_node) {
+		if (condition == old_node) {
+			condition = new_node;
+		}
+		if (true_expression == old_node) {
+			true_expression = new_node;
+		}
+		if (false_expression == old_node) {
+			false_expression = new_node;
+		}
+	}
+
 	public override bool check (CodeContext context) {
 		if (checked) {
 			return !error;



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