From: Juerg Billeter Date: Thu, 12 Jul 2007 12:22:59 +0000 (+0000) Subject: support exception handling in constructors, avoid error when not using X-Git-Tag: VALA_0_1_1~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab1d99cd74f7dbdfd88bb92bc06fb7c747ec111b;p=thirdparty%2Fvala.git support exception handling in constructors, avoid error when not using 2007-07-12 Juerg Billeter * gobject/valacodegenerator.vala: support exception handling in constructors, avoid error when not using finally blocks svn path=/trunk/; revision=351 --- diff --git a/ChangeLog b/ChangeLog index a17c85993..1b446004e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-07-12 Jürg Billeter + + * gobject/valacodegenerator.vala: support exception handling in + constructors, avoid error when not using finally blocks + 2007-07-12 Jürg Billeter * vala/parser.y: allow delegates to throw exceptions diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index c6e33949d..c23975754 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -584,6 +584,8 @@ public class Vala.CodeGenerator : CodeVisitor { } public override void visit_constructor (Constructor! c) { + current_method_inner_error = false; + c.accept_children (this); var cl = (Class) c.symbol.parent_symbol.node; @@ -640,6 +642,15 @@ public class Vala.CodeGenerator : CodeVisitor { cblock.add_statement (cdecl); + if (current_method_inner_error) { + /* always separate error parameter and inner_error local variable + * as error may be set to NULL but we're always interested in inner errors + */ + var cdecl = new CCodeDeclaration ("GError *"); + cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("inner_error", new CCodeConstant ("NULL"))); + cblock.add_statement (cdecl); + } + cblock.add_statement (c.body.ccodenode); @@ -1577,6 +1588,9 @@ public class Vala.CodeGenerator : CodeVisitor { cfrag.append (new CCodeLabel ("__finally%d".printf (next_try_id))); if (stmt.finally_body != null) { cfrag.append (stmt.finally_body.ccodenode); + } else { + // avoid gcc error: label at end of compound statement + cfrag.append (new CCodeEmptyStatement ()); } stmt.ccodenode = cfrag;