]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
allow construction methods to throw exceptions, fix issue with multiple
authorJuerg Billeter <j@bitron.ch>
Thu, 12 Jul 2007 09:16:14 +0000 (09:16 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 12 Jul 2007 09:16:14 +0000 (09:16 +0000)
2007-07-12  Juerg Billeter  <j@bitron.ch>

* vala/parser.y, vala/valasemanticanalyzer.vala,
  gobject/valacodegenerator.vala: allow construction methods to throw
  exceptions, fix issue with multiple catch clauses

svn path=/trunk/; revision=349

ChangeLog
gobject/valacodegenerator.vala
vala/parser.y
vala/valasemanticanalyzer.vala

index 052f217f825760c1d82df0f8628054576da0ceb7..c545f613ef8d9225f573daaa276fa7d05dbc0a34 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-07-12  Jürg Billeter  <j@bitron.ch>
+
+       * vala/parser.y, vala/valasemanticanalyzer.vala,
+         gobject/valacodegenerator.vala: allow construction methods to throw
+         exceptions, fix issue with multiple catch clauses
+
 2007-07-12  Jürg Billeter  <j@bitron.ch>
 
        * vala/parser.y, vala/valacodenode.vala, vala/valaenum.vala,
index 955c387aaf3428b445b452b29ed7be5cf2e576b3..c6e33949d16035591954991323e75535f8af2ded 100644 (file)
@@ -1568,9 +1568,9 @@ public class Vala.CodeGenerator : CodeVisitor {
                var cfrag = new CCodeFragment ();
                cfrag.append (stmt.body.ccodenode);
 
-               cfrag.append (new CCodeGotoStatement ("__finally%d".printf (next_try_id)));
-
                foreach (CatchClause clause in stmt.get_catch_clauses ()) {
+                       cfrag.append (new CCodeGotoStatement ("__finally%d".printf (next_try_id)));
+
                        cfrag.append (clause.ccodenode);
                }
 
@@ -2111,6 +2111,12 @@ public class Vala.CodeGenerator : CodeVisitor {
                                params_it = params_it.next;
                        }
 
+                       if (expr.can_fail) {
+                               // method can fail
+                               current_method_inner_error = true;
+                               ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error")));
+                       }
+
                        if (ellipsis) {
                                // ensure variable argument list ends with NULL
                                ccall.add_argument (new CCodeConstant ("NULL"));
index 49bfea40c0297441deda8aba5a1f7fd1ad353265..331a41b2d89c5b1840dec979ed6d2ad9693ce79a 100644 (file)
@@ -2640,7 +2640,7 @@ method_header
                g_object_unref ($5);
                g_free ($6);
          }
-       | comment opt_attributes opt_access_modifier opt_modifiers identifier opt_name_specifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+       | comment opt_attributes opt_access_modifier opt_modifiers identifier opt_name_specifier OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS opt_throws_declaration
          {
                GList *l;
                
@@ -2662,6 +2662,14 @@ method_header
                        }
                        g_list_free ($8);
                }
+
+               for (l = $10; l != NULL; l = l->next) {
+                       vala_method_add_error_domain ($$, l->data);
+                       g_object_unref (l->data);
+               }
+               if ($10 != NULL) {
+                       g_list_free ($10);
+               }
          }
        ;
 
index 802b1eb25aca511a11a6af499f74b9601c778f33..aea30a28a3c3a545d1a3af5741d16c89fd9b4354 100644 (file)
@@ -1645,6 +1645,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                if (expr.symbol_reference != null && expr.symbol_reference.node is Method) {
                        var m = (Method) expr.symbol_reference.node;
                        check_arguments (expr, m.symbol, m.get_parameters (), expr.get_argument_list ());
+
+                       expr.tree_can_fail = expr.can_fail = (m.get_error_domains ().length () > 0);
                } else if (type is Enum) {
                        if (expr.get_argument_list ().length () == 0) {
                                expr.error = true;