Commit 18eadfcb authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

free local variables before break and continue

2007-07-27  Juerg Billeter  <j@bitron.ch>

	* vala/valadostatement.vala, vala/valaforeachstatement.vala,
	  vala/valaforstatement.vala, vala/valawhilestatement.vala,
	  gobject/valacodegenerator.vala: free local variables before break and
	  continue

svn path=/trunk/; revision=398
parent ba731c8a
2007-07-27 Jürg Billeter <j@bitron.ch>
* vala/valadostatement.vala, vala/valaforeachstatement.vala,
vala/valaforstatement.vala, vala/valawhilestatement.vala,
gobject/valacodegenerator.vala: free local variables before break and
continue
2007-07-27 Jürg Billeter <j@bitron.ch>
* gobject/valacodegenerator.vala: fix freeing local variables of all
......
......@@ -1494,12 +1494,16 @@ public class Vala.CodeGenerator : CodeVisitor {
public override void visit_break_statement (BreakStatement! stmt) {
stmt.ccodenode = new CCodeBreakStatement ();
create_local_free (stmt, true);
}
public override void visit_continue_statement (ContinueStatement! stmt) {
stmt.ccodenode = new CCodeContinueStatement ();
create_local_free (stmt, true);
}
private void append_local_free (Symbol sym, CCodeFragment cfrag, bool stop_at_loop) {
var b = (Block) sym;
......@@ -1512,24 +1516,31 @@ public class Vala.CodeGenerator : CodeVisitor {
}
}
if (stop_at_loop) {
if (b.parent_node is DoStatement || b.parent_node is WhileStatement ||
b.parent_node is ForStatement || b.parent_node is ForeachStatement) {
return;
}
}
if (sym.parent_symbol is Block) {
append_local_free (sym.parent_symbol, cfrag, stop_at_loop);
}
}
private void create_local_free (CodeNode stmt) {
private void create_local_free (CodeNode stmt, bool stop_at_loop = false) {
if (!memory_management) {
return;
}
var cfrag = new CCodeFragment ();
append_local_free (current_symbol, cfrag, false);
append_local_free (current_symbol, cfrag, stop_at_loop);
cfrag.append (stmt.ccodenode);
stmt.ccodenode = cfrag;
}
private bool append_local_free_expr (Symbol sym, CCodeCommaExpression ccomma, bool stop_at_loop) {
var found = false;
......
......@@ -29,7 +29,15 @@ public class Vala.DoStatement : CodeNode, Statement {
/**
* Specifies the loop body.
*/
public Block body { get; set; }
public Block body {
get {
return _body;
}
set {
_body = value;
_body.parent_node = this;
}
}
/**
* Specifies the loop condition.
......@@ -45,6 +53,7 @@ public class Vala.DoStatement : CodeNode, Statement {
}
private Expression! _condition;
private Block _body;
/**
* Creates a new do statement.
......
......@@ -53,14 +53,23 @@ public class Vala.ForeachStatement : CodeNode, Statement {
/**
* Specifies the loop body.
*/
public Block body { get; set; }
public Block body {
get {
return _body;
}
set {
_body = value;
_body.parent_node = this;
}
}
/**
* Specifies the declarator for the generated element variable.
*/
public VariableDeclarator variable_declarator { get; set; }
private Expression! _collection;
private Block _body;
/**
* Creates a new foreach statement.
......
......@@ -42,12 +42,21 @@ public class Vala.ForStatement : CodeNode, Statement {
/**
* Specifies the loop body.
*/
public Block body { get; set; }
public Block body {
get {
return _body;
}
set {
_body = value;
_body.parent_node = this;
}
}
private List<Expression> initializer;
private List<Expression> iterator;
private Expression! _condition;
private Block _body;
/**
* Creates a new for statement.
......
......@@ -42,9 +42,18 @@ public class Vala.WhileStatement : CodeNode, Statement {
/**
* Specifies the loop body.
*/
public Block body { get; set; }
public Block body {
get {
return _body;
}
set {
_body = value;
_body.parent_node = this;
}
}
private Expression! _condition;
private Block _body;
/**
* Creates a new while statement.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment