[vala/emit: 2/5] Call emit for child statements in code generator



commit 775c856e1972fa34a2377a50dd3e58d7fdf6a3a2
Author: Jürg Billeter <j bitron ch>
Date:   Sun Aug 8 14:39:21 2010 +0200

    Call emit for child statements in code generator

 codegen/valaccodebasemodule.vala        |   20 ++++++++++----------
 codegen/valaccodecontrolflowmodule.vala |   15 +++++++++++++++
 codegen/valadovabasemodule.vala         |   20 ++++++++++----------
 codegen/valadovacontrolflowmodule.vala  |   11 +++++++++++
 codegen/valadovaerrormodule.vala        |    2 ++
 codegen/valagerrormodule.vala           |    2 ++
 vala/valablock.vala                     |    9 ---------
 vala/valacatchclause.vala               |    2 --
 vala/valacodegenerator.vala             |    2 --
 vala/valaforeachstatement.vala          |    4 ----
 vala/valaifstatement.vala               |    5 -----
 vala/valalockstatement.vala             |    3 ---
 vala/valaloop.vala                      |    2 --
 vala/valaswitchstatement.vala           |    4 ----
 14 files changed, 50 insertions(+), 51 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 76a0c4a..4c191e1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -30,16 +30,7 @@ public class Vala.CCodeBaseModule : CCodeModule {
 	public CodeContext context { get; set; }
 
 	public Symbol root_symbol;
-
-	public Symbol current_symbol {
-		get {
-			return codegen.current_symbol;
-		}
-		set {
-			codegen.current_symbol = value;
-		}
-	}
-
+	public Symbol current_symbol;
 	public TryStatement current_try;
 
 	public TypeSymbol? current_type_symbol {
@@ -1719,6 +1710,13 @@ public class Vala.CCodeBaseModule : CCodeModule {
 	}
 
 	public override void visit_block (Block b) {
+		var old_symbol = current_symbol;
+		current_symbol = b;
+
+		foreach (Statement stmt in b.get_statements ()) {
+			stmt.emit (codegen);
+		}
+
 		var local_vars = b.get_local_variables ();
 		foreach (LocalVariable local in local_vars) {
 			local.active = false;
@@ -1943,6 +1941,8 @@ public class Vala.CCodeBaseModule : CCodeModule {
 		}
 
 		b.ccodenode = cblock;
+
+		current_symbol = old_symbol;
 	}
 
 	public override void visit_empty_statement (EmptyStatement stmt) {
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index 641893d..b6d9ca5 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -30,6 +30,11 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule {
 	}
 
 	public override void visit_if_statement (IfStatement stmt) {
+		stmt.true_statement.emit (codegen);
+		if (stmt.false_statement != null) {
+			stmt.false_statement.emit (codegen);
+		}
+
 		if (stmt.false_statement != null) {
 			stmt.ccodenode = new CCodeIfStatement ((CCodeExpression) stmt.condition.ccodenode, (CCodeStatement) stmt.true_statement.ccodenode, (CCodeStatement) stmt.false_statement.ccodenode);
 		} else {
@@ -187,6 +192,10 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule {
 	}
 
 	public override void visit_switch_statement (SwitchStatement stmt) {
+		foreach (SwitchSection section in stmt.get_sections ()) {
+			section.emit (codegen);
+		}
+
 		if (stmt.expression.value_type.compatible (string_type)) {
 			visit_string_switch_statement (stmt);
 			return;
@@ -225,6 +234,8 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule {
 	}
 
 	public override void visit_loop (Loop stmt) {
+		stmt.body.emit (codegen);
+
 		if (context.profile == Profile.GOBJECT) {
 			stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("TRUE"), (CCodeStatement) stmt.body.ccodenode);
 		} else {
@@ -234,6 +245,10 @@ public class Vala.CCodeControlFlowModule : CCodeMethodModule {
 	}
 
 	public override void visit_foreach_statement (ForeachStatement stmt) {
+		stmt.body.emit (codegen);
+
+		visit_block (stmt);
+
 		var cblock = new CCodeBlock ();
 		// sets #line
 		stmt.ccodenode = cblock;
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 37cd42c..cbb85c6 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -29,16 +29,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
 	public CodeContext context { get; set; }
 
 	public Symbol root_symbol;
-
-	public Symbol current_symbol {
-		get {
-			return codegen.current_symbol;
-		}
-		set {
-			codegen.current_symbol = value;
-		}
-	}
-
+	public Symbol current_symbol;
 	public TryStatement current_try;
 
 	public TypeSymbol? current_type_symbol {
@@ -714,6 +705,13 @@ internal class Vala.DovaBaseModule : CCodeModule {
 	}
 
 	public override void visit_block (Block b) {
+		var old_symbol = current_symbol;
+		current_symbol = b;
+
+		foreach (Statement stmt in b.get_statements ()) {
+			stmt.emit (codegen);
+		}
+
 		var local_vars = b.get_local_variables ();
 		foreach (LocalVariable local in local_vars) {
 			local.active = false;
@@ -917,6 +915,8 @@ internal class Vala.DovaBaseModule : CCodeModule {
 		}
 
 		b.ccodenode = cblock;
+
+		current_symbol = old_symbol;
 	}
 
 	public override void visit_empty_statement (EmptyStatement stmt) {
diff --git a/codegen/valadovacontrolflowmodule.vala b/codegen/valadovacontrolflowmodule.vala
index cbf08d3..f75368c 100644
--- a/codegen/valadovacontrolflowmodule.vala
+++ b/codegen/valadovacontrolflowmodule.vala
@@ -26,6 +26,11 @@ internal class Vala.DovaControlFlowModule : DovaMethodModule {
 	}
 
 	public override void visit_if_statement (IfStatement stmt) {
+		stmt.true_statement.emit (codegen);
+		if (stmt.false_statement != null) {
+			stmt.false_statement.emit (codegen);
+		}
+
 		if (stmt.false_statement != null) {
 			stmt.ccodenode = new CCodeIfStatement ((CCodeExpression) stmt.condition.ccodenode, (CCodeStatement) stmt.true_statement.ccodenode, (CCodeStatement) stmt.false_statement.ccodenode);
 		} else {
@@ -36,6 +41,10 @@ internal class Vala.DovaControlFlowModule : DovaMethodModule {
 	}
 
 	public override void visit_switch_statement (SwitchStatement stmt) {
+		foreach (SwitchSection section in stmt.get_sections ()) {
+			section.emit (codegen);
+		}
+
 		var cswitch = new CCodeSwitchStatement ((CCodeExpression) stmt.expression.ccodenode);
 		stmt.ccodenode = cswitch;
 
@@ -73,6 +82,8 @@ internal class Vala.DovaControlFlowModule : DovaMethodModule {
 	}
 
 	public override void visit_loop (Loop stmt) {
+		stmt.body.emit (codegen);
+
 		stmt.ccodenode = new CCodeWhileStatement (new CCodeConstant ("true"), (CCodeStatement) stmt.body.ccodenode);
 	}
 
diff --git a/codegen/valadovaerrormodule.vala b/codegen/valadovaerrormodule.vala
index e122756..ecee398 100644
--- a/codegen/valadovaerrormodule.vala
+++ b/codegen/valadovaerrormodule.vala
@@ -278,6 +278,8 @@ internal class Vala.DovaErrorModule : DovaDelegateModule {
 	public override void visit_catch_clause (CatchClause clause) {
 		generate_type_declaration (clause.error_type, source_declarations);
 
+		clause.body.emit (codegen);
+
 		var cfrag = new CCodeFragment ();
 		cfrag.append (new CCodeLabel (clause.clabel_name));
 
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 3333c6c..deca24b 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -374,6 +374,8 @@ public class Vala.GErrorModule : CCodeDelegateModule {
 			generate_error_domain_declaration (error_type.error_domain, source_declarations);
 		}
 
+		clause.body.emit (codegen);
+
 		var cfrag = new CCodeFragment ();
 		cfrag.append (new CCodeLabel (clause.clabel_name));
 
diff --git a/vala/valablock.vala b/vala/valablock.vala
index a5effd8..64cbfaa 100644
--- a/vala/valablock.vala
+++ b/vala/valablock.vala
@@ -155,16 +155,7 @@ public class Vala.Block : Symbol, Statement {
 	}
 
 	public override void emit (CodeGenerator codegen) {
-		var old_symbol = codegen.current_symbol;
-		codegen.current_symbol = this;
-
-		foreach (Statement stmt in statement_list) {
-			stmt.emit (codegen);
-		}
-
 		codegen.visit_block (this);
-
-		codegen.current_symbol = old_symbol;
 	}
 
 	public void insert_before (Statement stmt, Statement new_stmt) {
diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala
index 094c8a2..b6d742e 100644
--- a/vala/valacatchclause.vala
+++ b/vala/valacatchclause.vala
@@ -144,8 +144,6 @@ public class Vala.CatchClause : CodeNode {
 			error_variable.active = true;
 		}
 
-		body.emit (codegen);
-
 		codegen.visit_catch_clause (this);
 	}
 
diff --git a/vala/valacodegenerator.vala b/vala/valacodegenerator.vala
index 1fdb497..39442ab 100644
--- a/vala/valacodegenerator.vala
+++ b/vala/valacodegenerator.vala
@@ -24,8 +24,6 @@
  * Abstract code visitor generating code.
  */
 public class Vala.CodeGenerator : CodeVisitor {
-	public Symbol current_symbol;
-
 	/**
 	 * Generate and emit C code for the specified code context.
 	 *
diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala
index 30f44af..bc0cf3d 100644
--- a/vala/valaforeachstatement.vala
+++ b/vala/valaforeachstatement.vala
@@ -363,10 +363,6 @@ public class Vala.ForeachStatement : Block {
 			iterator_variable.active = true;
 		}
 
-		base.emit (codegen);
-
-		body.emit (codegen);
-
 		codegen.visit_foreach_statement (this);
 	}
 
diff --git a/vala/valaifstatement.vala b/vala/valaifstatement.vala
index add70fb..8cb1bac 100644
--- a/vala/valaifstatement.vala
+++ b/vala/valaifstatement.vala
@@ -145,11 +145,6 @@ public class Vala.IfStatement : CodeNode, Statement {
 
 		codegen.visit_end_full_expression (condition);
 
-		true_statement.emit (codegen);
-		if (false_statement != null) {
-			false_statement.emit (codegen);
-		}
-
 		codegen.visit_if_statement (this);
 	}
 }
diff --git a/vala/valalockstatement.vala b/vala/valalockstatement.vala
index b70b6bf..39ad4e0 100644
--- a/vala/valalockstatement.vala
+++ b/vala/valalockstatement.vala
@@ -104,9 +104,6 @@ public class Vala.LockStatement : CodeNode, Statement {
 
 	public override void emit (CodeGenerator codegen) {
 		resource.emit (codegen);
-		if (body != null) {
-			body.emit (codegen);
-		}
 		codegen.visit_lock_statement (this);
 	}
 }
diff --git a/vala/valaloop.vala b/vala/valaloop.vala
index 091c579..e73174d 100644
--- a/vala/valaloop.vala
+++ b/vala/valaloop.vala
@@ -76,8 +76,6 @@ public class Vala.Loop : CodeNode, Statement {
 	}
 
 	public override void emit (CodeGenerator codegen) {
-		body.emit (codegen);
-
 		codegen.visit_loop (this);
 	}
 }
diff --git a/vala/valaswitchstatement.vala b/vala/valaswitchstatement.vala
index 9770d56..1fbcb16 100644
--- a/vala/valaswitchstatement.vala
+++ b/vala/valaswitchstatement.vala
@@ -146,10 +146,6 @@ public class Vala.SwitchStatement : CodeNode, Statement {
 
 		codegen.visit_end_full_expression (expression);
 
-		foreach (SwitchSection section in sections) {
-			section.emit (codegen);
-		}
-
 		codegen.visit_switch_statement (this);
 	}
 }



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