[vala] codegen: Use CatchClause.error_variable instead of variable_name



commit a3bf994eb14b355675afde2444a10bcfba2d6d2e
Author: Luca Bruno <lucabru src gnome org>
Date:   Fri Apr 22 22:05:31 2011 +0200

    codegen: Use CatchClause.error_variable instead of variable_name

 codegen/valagerrormodule.vala |   17 +++--------------
 vala/valacatchclause.vala     |   10 ++++++----
 2 files changed, 9 insertions(+), 18 deletions(-)
---
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 70d335d..75e9a78 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 72c9d84..46b4e0f 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) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]