Fix error handling in catch and finally clauses, fixes bug 530212
authorJuerg Billeter <j@bitron.ch>
Fri, 2 May 2008 20:36:49 +0000 (20:36 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 2 May 2008 20:36:49 +0000 (20:36 +0000)
2008-05-02  Juerg Billeter  <j@bitron.ch>

* vala/valacatchclause.vala:
* gobject/valaccodegenerator.vala:

Fix error handling in catch and finally clauses, fixes bug 530212

svn path=/trunk/; revision=1334

ChangeLog
gobject/valaccodegenerator.vala
vala/valacatchclause.vala

index cb377c5..4939f6f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-05-02  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valacatchclause.vala:
+       * gobject/valaccodegenerator.vala:
+
+       Fix error handling in catch and finally clauses, fixes bug 530212
+
+2008-05-02  Jürg Billeter  <j@bitron.ch>
+
        * vapi/glib-2.0.vapi: fix g_rand*_int and g_rand*_double bindings,
        patch Ondrej Jirman, fixes bug 530207
 
index 5072fc8..061d5ec 100644 (file)
@@ -1488,7 +1488,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                        var cerror_block = new CCodeBlock ();
                        foreach (CatchClause clause in current_try.get_catch_clauses ()) {
                                // go to catch clause if error domain matches
-                               var cgoto_stmt = new CCodeGotoStatement ("__catch%d_%s".printf (current_try_id, clause.error_type.get_lower_case_cname ()));
+                               var cgoto_stmt = new CCodeGotoStatement (clause.clabel_name);
 
                                if (clause.error_type.equals (gerror_type)) {
                                        // general catch clause
@@ -2278,23 +2278,44 @@ public class Vala.CCodeGenerator : CodeGenerator {
        }
 
        public override void visit_try_statement (TryStatement stmt) {
+               int this_try_id = next_try_id++;
+
                var old_try = current_try;
                var old_try_id = current_try_id;
                current_try = stmt;
-               current_try_id = next_try_id++;
+               current_try_id = this_try_id;
 
-               stmt.accept_children (this);
+               foreach (CatchClause clause in stmt.get_catch_clauses ()) {
+                       clause.clabel_name = "__catch%d_%s".printf (this_try_id, clause.error_type.get_lower_case_cname ());
+               }
+
+               if (stmt.finally_body != null) {
+                       stmt.finally_body.accept (this);
+               }
+
+               stmt.body.accept (this);
+
+               current_try = old_try;
+               current_try_id = old_try_id;
+
+               foreach (CatchClause clause in stmt.get_catch_clauses ()) {
+                       clause.accept (this);
+               }
+
+               if (stmt.finally_body != null) {
+                       stmt.finally_body.accept (this);
+               }
 
                var cfrag = new CCodeFragment ();
                cfrag.append (stmt.body.ccodenode);
 
                foreach (CatchClause clause in stmt.get_catch_clauses ()) {
-                       cfrag.append (new CCodeGotoStatement ("__finally%d".printf (current_try_id)));
+                       cfrag.append (new CCodeGotoStatement ("__finally%d".printf (this_try_id)));
 
                        cfrag.append (clause.ccodenode);
                }
 
-               cfrag.append (new CCodeLabel ("__finally%d".printf (current_try_id)));
+               cfrag.append (new CCodeLabel ("__finally%d".printf (this_try_id)));
                if (stmt.finally_body != null) {
                        cfrag.append (stmt.finally_body.ccodenode);
                } else {
@@ -2303,9 +2324,6 @@ public class Vala.CCodeGenerator : CodeGenerator {
                }
 
                stmt.ccodenode = cfrag;
-
-               current_try = old_try;
-               current_try_id = old_try_id;
        }
 
        public override void visit_catch_clause (CatchClause clause) {
@@ -2314,7 +2332,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                clause.accept_children (this);
 
                var cfrag = new CCodeFragment ();
-               cfrag.append (new CCodeLabel ("__catch%d_%s".printf (current_try_id, clause.error_type.get_lower_case_cname ())));
+               cfrag.append (new CCodeLabel (clause.clabel_name));
 
                var cblock = new CCodeBlock ();
 
index ec43c9f..4d48945 100644 (file)
@@ -54,6 +54,11 @@ public class Vala.CatchClause : CodeNode {
         */
        public LocalVariable error_variable { get; set; }
 
+       /**
+        * Specifies the label used for this catch clause in the C code.
+        */
+       public string? clabel_name { get; set; }
+
        private DataType _data_type;
 
        /**