From: Luca Bruno Date: Fri, 22 Apr 2011 20:05:31 +0000 (+0200) Subject: codegen: Use CatchClause.error_variable instead of variable_name X-Git-Tag: 0.13.0~201 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3bf994eb14b355675afde2444a10bcfba2d6d2e;p=thirdparty%2Fvala.git codegen: Use CatchClause.error_variable instead of variable_name --- diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala index 70d335d56..75e9a78fb 100644 --- a/codegen/valagerrormodule.vala +++ b/codegen/valagerrormodule.vala @@ -345,20 +345,9 @@ public class Vala.GErrorModule : CCodeDelegateModule { ccode.open_block (); - string variable_name; - if (clause.variable_name != null) { - variable_name = get_variable_cname (clause.variable_name); - } else { - variable_name = "__err"; - } - - if (clause.variable_name != null) { - if (is_in_coroutine ()) { - closure_struct.add_field ("GError *", variable_name); - } else { - ccode.add_declaration ("GError *", new CCodeVariableDeclarator (variable_name)); - } - ccode.add_assignment (get_variable_cexpression (variable_name), get_variable_cexpression ("_inner_error_")); + if (clause.error_variable != null) { + visit_local_variable (clause.error_variable); + ccode.add_assignment (get_variable_cexpression (clause.error_variable.name), get_variable_cexpression ("_inner_error_")); } else { // error object is not used within catch statement, clear it var cclear = new CCodeFunctionCall (new CCodeIdentifier ("g_clear_error")); diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala index 72c9d8468..46b4e0fa2 100644 --- a/vala/valacatchclause.vala +++ b/vala/valacatchclause.vala @@ -117,12 +117,14 @@ public class Vala.CatchClause : CodeNode { checked = true; if (error_type != null) { - error_variable = new LocalVariable (error_type.copy (), variable_name); + if (variable_name != null) { + error_variable = new LocalVariable (error_type.copy (), variable_name); - body.scope.add (variable_name, error_variable); - body.add_local_variable (error_variable); + body.scope.add (variable_name, error_variable); + body.add_local_variable (error_variable); - error_variable.checked = true; + error_variable.checked = true; + } } else { // generic catch clause if (context.profile == Profile.GOBJECT) {