From 18eadfcbf7509958ef147d1a001b14e65649491a Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Fri, 27 Jul 2007 06:51:03 +0000 Subject: [PATCH] free local variables before break and continue 2007-07-27 Juerg Billeter * 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 --- ChangeLog | 7 +++++++ gobject/valacodegenerator.vala | 19 +++++++++++++++---- vala/valadostatement.vala | 11 ++++++++++- vala/valaforeachstatement.vala | 13 +++++++++++-- vala/valaforstatement.vala | 11 ++++++++++- vala/valawhilestatement.vala | 11 ++++++++++- 6 files changed, 63 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90277a4..5d86403 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2007-07-27 Jürg Billeter + * 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 + * gobject/valacodegenerator.vala: fix freeing local variables of all blocks before returning from function diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index 72e1559..358c213 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -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; diff --git a/vala/valadostatement.vala b/vala/valadostatement.vala index f54a916..0a1e478 100644 --- a/vala/valadostatement.vala +++ b/vala/valadostatement.vala @@ -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. diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala index c973024..9ec4597 100644 --- a/vala/valaforeachstatement.vala +++ b/vala/valaforeachstatement.vala @@ -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. diff --git a/vala/valaforstatement.vala b/vala/valaforstatement.vala index 37bbd62..038a1e7 100644 --- a/vala/valaforstatement.vala +++ b/vala/valaforstatement.vala @@ -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 initializer; private List iterator; private Expression! _condition; + private Block _body; /** * Creates a new for statement. diff --git a/vala/valawhilestatement.vala b/vala/valawhilestatement.vala index 496038a..9fe10cf 100644 --- a/vala/valawhilestatement.vala +++ b/vala/valawhilestatement.vala @@ -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. -- 2.7.4