support exception handling in constructors, avoid error when not using
authorJuerg Billeter <j@bitron.ch>
Thu, 12 Jul 2007 12:22:59 +0000 (12:22 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 12 Jul 2007 12:22:59 +0000 (12:22 +0000)
2007-07-12  Juerg Billeter  <j@bitron.ch>

* gobject/valacodegenerator.vala: support exception handling in
  constructors, avoid error when not using finally blocks

svn path=/trunk/; revision=351

ChangeLog
gobject/valacodegenerator.vala

index a17c859..1b44600 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2007-07-12  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valacodegenerator.vala: support exception handling in
+         constructors, avoid error when not using finally blocks
+
+2007-07-12  Jürg Billeter  <j@bitron.ch>
+
        * vala/parser.y: allow delegates to throw exceptions
 
 2007-07-12  Jürg Billeter  <j@bitron.ch>
index c6e3394..c239757 100644 (file)
@@ -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;