support throw statements in try statements
authorJuerg Billeter <j@bitron.ch>
Fri, 29 Feb 2008 20:39:19 +0000 (20:39 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 29 Feb 2008 20:39:19 +0000 (20:39 +0000)
2008-02-29  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegenerator.vala: support throw statements in try
  statements

* tests/exceptions.vala: test throw statement in try statement with
  generic catch clause

svn path=/trunk/; revision=1064

ChangeLog
gobject/valaccodegenerator.vala
tests/exceptions.vala

index 84136c3..8aaeac4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-02-29  Jürg Billeter  <j@bitron.ch>
+
+       * gobject/valaccodegenerator.vala: support throw statements in try
+         statements
+
+       * tests/exceptions.vala: test throw statement in try statement with
+         generic catch clause
+
 2008-02-28  Jürg Billeter  <j@bitron.ch>
 
        * gobject/valaccodeassignmentbinding.vala,
index 071c3f9..c0f2373 100644 (file)
@@ -122,7 +122,6 @@ public class Vala.CCodeGenerator : CodeGenerator {
        private bool requires_array_free;
        private bool requires_array_move;
        private bool requires_strcmp0;
-       private bool inside_throws_statement;
 
        private Set<string> wrappers;
 
@@ -2096,16 +2095,19 @@ public class Vala.CCodeGenerator : CodeGenerator {
        }
 
        public override void visit_throw_statement (ThrowStatement! stmt) {
-               inside_throws_statement = true;
                stmt.accept_children (this);
-               inside_throws_statement = false;
 
                var cfrag = new CCodeFragment ();
 
                /* declare temporary objects */
                append_temp_decl (cfrag, temp_vars);
 
-               cfrag.append (new CCodeExpressionStatement ((CCodeExpression) stmt.error_expression.ccodenode));
+               // method will fail
+               current_method_inner_error = true;
+               var cassign = new CCodeAssignment (new CCodeIdentifier ("inner_error"), (CCodeExpression) stmt.error_expression.ccodenode);
+               cfrag.append (new CCodeExpressionStatement (cassign));
+
+               add_simple_check (stmt, cfrag);
 
                /* free temporary objects */
                foreach (VariableDeclarator decl in temp_ref_vars) {
@@ -2824,12 +2826,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
                        var ecode = (ErrorCode) expr.symbol_reference;
                        var edomain = (ErrorDomain) ecode.parent_symbol;
 
-                       if (inside_throws_statement) {
-                               creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_set_error"));
-                               creation_call.add_argument (new CCodeIdentifier ("error"));
-                       } else {
-                               creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_error_new"));
-                       }
+                       creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_error_new"));
                        creation_call.add_argument (new CCodeIdentifier (edomain.get_upper_case_cname ()));
                        creation_call.add_argument (new CCodeIdentifier (ecode.get_cname ()));
 
index d024bba..7d22192 100644 (file)
@@ -88,6 +88,16 @@ class Maman.Bar : Object {
                stdout.printf (" 14");
        }
 
+       static void test_generic_catch () {
+               try {
+                       throw new BarError.FOO ("error message");
+               } catch (Error e) {
+                       return;
+               }
+
+               assert_not_reached ();
+       }
+
        static int main (string[] args) {
                stdout.printf ("Exception Test: 1");
                
@@ -95,7 +105,9 @@ class Maman.Bar : Object {
                bar.run ();
 
                stdout.printf (" 15\n");
-               
+
+               test_generic_catch ();
+
                return 0;
        }
 }