]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
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 a17c85993639c08f6663f09c8cb9a5bc1c56ff02..1b446004e4dbee4f83103d3bd390a53217d325b3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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
index c6e33949d16035591954991323e75535f8af2ded..c23975754f182bde64360a652b909e6ad8d0da79 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;