Commit bda9e0cf authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

allow construction methods to throw exceptions, fix issue with multiple

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
parent 08c26be7
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> 2007-07-12 Jürg Billeter <j@bitron.ch>
* vala/parser.y, vala/valacodenode.vala, vala/valaenum.vala, * vala/parser.y, vala/valacodenode.vala, vala/valaenum.vala,
......
...@@ -1568,9 +1568,9 @@ public class Vala.CodeGenerator : CodeVisitor { ...@@ -1568,9 +1568,9 @@ public class Vala.CodeGenerator : CodeVisitor {
var cfrag = new CCodeFragment (); var cfrag = new CCodeFragment ();
cfrag.append (stmt.body.ccodenode); cfrag.append (stmt.body.ccodenode);
cfrag.append (new CCodeGotoStatement ("__finally%d".printf (next_try_id)));
foreach (CatchClause clause in stmt.get_catch_clauses ()) { foreach (CatchClause clause in stmt.get_catch_clauses ()) {
cfrag.append (new CCodeGotoStatement ("__finally%d".printf (next_try_id)));
cfrag.append (clause.ccodenode); cfrag.append (clause.ccodenode);
} }
...@@ -2111,6 +2111,12 @@ public class Vala.CodeGenerator : CodeVisitor { ...@@ -2111,6 +2111,12 @@ public class Vala.CodeGenerator : CodeVisitor {
params_it = params_it.next; 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) { if (ellipsis) {
// ensure variable argument list ends with NULL // ensure variable argument list ends with NULL
ccall.add_argument (new CCodeConstant ("NULL")); ccall.add_argument (new CCodeConstant ("NULL"));
......
...@@ -2640,7 +2640,7 @@ method_header ...@@ -2640,7 +2640,7 @@ method_header
g_object_unref ($5); g_object_unref ($5);
g_free ($6); 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; GList *l;
...@@ -2662,6 +2662,14 @@ method_header ...@@ -2662,6 +2662,14 @@ method_header
} }
g_list_free ($8); 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);
}
} }
; ;
......
...@@ -1645,6 +1645,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor { ...@@ -1645,6 +1645,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
if (expr.symbol_reference != null && expr.symbol_reference.node is Method) { if (expr.symbol_reference != null && expr.symbol_reference.node is Method) {
var m = (Method) expr.symbol_reference.node; var m = (Method) expr.symbol_reference.node;
check_arguments (expr, m.symbol, m.get_parameters (), expr.get_argument_list ()); 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) { } else if (type is Enum) {
if (expr.get_argument_list ().length () == 0) { if (expr.get_argument_list ().length () == 0) {
expr.error = true; expr.error = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment