[vala] Improve handling of reserved identifiers



commit 74cb5c7d6d1df95f7779f84b58f31ceeab5417ad
Author: Jürg Billeter <j bitron ch>
Date:   Fri Apr 10 10:27:11 2009 +0200

    Improve handling of reserved identifiers
    
    Avoid conflicts between reserved identifiers and generated code
    for local variables and formal parameters. Fixes bug 469335 and
    bug 515225.
---
 gobject/valaccodearraymodule.vala        |    8 +-
 gobject/valaccodeassignmentmodule.vala   |    2 +-
 gobject/valaccodebasemodule.vala         |  101 ++++++++++++++++--------------
 gobject/valaccodedelegatemodule.vala     |   20 +++---
 gobject/valaccodememberaccessmodule.vala |    4 +-
 gobject/valaccodemethodcallmodule.vala   |    2 +-
 gobject/valaccodemethodmodule.vala       |   18 +++---
 gobject/valadbusmodule.vala              |   42 ++++++------
 gobject/valagerrormodule.vala            |   14 ++--
 gobject/valagobjectmodule.vala           |    6 +-
 gobject/valagtypemodule.vala             |    4 +-
 11 files changed, 113 insertions(+), 108 deletions(-)

diff --git a/gobject/valaccodearraymodule.vala b/gobject/valaccodearraymodule.vala
index f161c88..f1a9ba8 100644
--- a/gobject/valaccodearraymodule.vala
+++ b/gobject/valaccodearraymodule.vala
@@ -705,7 +705,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			ctypename += "*";
 		}
 
-		param.ccodenode = new CCodeFormalParameter (param.name, ctypename);
+		param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
 
 		var array_type = (ArrayType) param.parameter_type;
 
@@ -713,7 +713,7 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
 		if (carg_map != null) {
-			carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
+			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
 		}
 
 		if (!param.no_array_length) {
@@ -723,10 +723,10 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			}
 			
 			for (int dim = 1; dim <= array_type.rank; dim++) {
-				var cparam = new CCodeFormalParameter (head.get_array_length_cname (param.name, dim), length_ctype);
+				var cparam = new CCodeFormalParameter (head.get_array_length_cname (get_variable_cname (param.name), dim), length_ctype);
 				cparam_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), new CCodeIdentifier (cparam.name));
+					carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_variable_cexpression (param.name));
 				}
 			}
 		}
diff --git a/gobject/valaccodeassignmentmodule.vala b/gobject/valaccodeassignmentmodule.vala
index eef4f9a..fa64ccc 100644
--- a/gobject/valaccodeassignmentmodule.vala
+++ b/gobject/valaccodeassignmentmodule.vala
@@ -133,7 +133,7 @@ internal class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 				outer_ccomma = new CCodeCommaExpression ();
 
 				var lhs_value_type = assignment.left.value_type.copy ();
-				string lhs_temp_name = "_tmp%d".printf (next_temp_var_id++);
+				string lhs_temp_name = "_tmp%d_".printf (next_temp_var_id++);
 				var lhs_temp = new LocalVariable (lhs_value_type, "*" + lhs_temp_name);
 				temp_vars.insert (0, lhs_temp);
 				outer_ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs)));
diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala
index b083409..e11eece 100644
--- a/gobject/valaccodebasemodule.vala
+++ b/gobject/valaccodebasemodule.vala
@@ -71,8 +71,8 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 	public Gee.Set<string> user_marshal_set;
 	/* (constant) hash table with all predefined marshallers */
 	public Gee.Set<string> predefined_marshal_set;
-	/* (constant) hash table with all C keywords */
-	public Gee.Set<string> c_keywords;
+	/* (constant) hash table with all reserved identifiers in the generated code */
+	Gee.Set<string> reserved_identifiers;
 	
 	public int next_temp_var_id = 0;
 	public bool in_creation_method = false;
@@ -158,49 +158,54 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 		predefined_marshal_set.add ("VOID:UINT,POINTER");
 		predefined_marshal_set.add ("BOOLEAN:FLAGS");
 
-		c_keywords = new HashSet<string> (str_hash, str_equal);
+		reserved_identifiers = new HashSet<string> (str_hash, str_equal);
 
 		// C99 keywords
-		c_keywords.add ("_Bool");
-		c_keywords.add ("_Complex");
-		c_keywords.add ("_Imaginary");
-		c_keywords.add ("auto");
-		c_keywords.add ("break");
-		c_keywords.add ("case");
-		c_keywords.add ("char");
-		c_keywords.add ("const");
-		c_keywords.add ("continue");
-		c_keywords.add ("default");
-		c_keywords.add ("do");
-		c_keywords.add ("double");
-		c_keywords.add ("else");
-		c_keywords.add ("enum");
-		c_keywords.add ("extern");
-		c_keywords.add ("float");
-		c_keywords.add ("for");
-		c_keywords.add ("goto");
-		c_keywords.add ("if");
-		c_keywords.add ("inline");
-		c_keywords.add ("int");
-		c_keywords.add ("long");
-		c_keywords.add ("register");
-		c_keywords.add ("restrict");
-		c_keywords.add ("return");
-		c_keywords.add ("short");
-		c_keywords.add ("signed");
-		c_keywords.add ("sizeof");
-		c_keywords.add ("static");
-		c_keywords.add ("struct");
-		c_keywords.add ("switch");
-		c_keywords.add ("typedef");
-		c_keywords.add ("union");
-		c_keywords.add ("unsigned");
-		c_keywords.add ("void");
-		c_keywords.add ("volatile");
-		c_keywords.add ("while");
+		reserved_identifiers.add ("_Bool");
+		reserved_identifiers.add ("_Complex");
+		reserved_identifiers.add ("_Imaginary");
+		reserved_identifiers.add ("auto");
+		reserved_identifiers.add ("break");
+		reserved_identifiers.add ("case");
+		reserved_identifiers.add ("char");
+		reserved_identifiers.add ("const");
+		reserved_identifiers.add ("continue");
+		reserved_identifiers.add ("default");
+		reserved_identifiers.add ("do");
+		reserved_identifiers.add ("double");
+		reserved_identifiers.add ("else");
+		reserved_identifiers.add ("enum");
+		reserved_identifiers.add ("extern");
+		reserved_identifiers.add ("float");
+		reserved_identifiers.add ("for");
+		reserved_identifiers.add ("goto");
+		reserved_identifiers.add ("if");
+		reserved_identifiers.add ("inline");
+		reserved_identifiers.add ("int");
+		reserved_identifiers.add ("long");
+		reserved_identifiers.add ("register");
+		reserved_identifiers.add ("restrict");
+		reserved_identifiers.add ("return");
+		reserved_identifiers.add ("short");
+		reserved_identifiers.add ("signed");
+		reserved_identifiers.add ("sizeof");
+		reserved_identifiers.add ("static");
+		reserved_identifiers.add ("struct");
+		reserved_identifiers.add ("switch");
+		reserved_identifiers.add ("typedef");
+		reserved_identifiers.add ("union");
+		reserved_identifiers.add ("unsigned");
+		reserved_identifiers.add ("void");
+		reserved_identifiers.add ("volatile");
+		reserved_identifiers.add ("while");
 
 		// MSVC keywords
-		c_keywords.add ("cdecl");
+		reserved_identifiers.add ("cdecl");
+
+		// reserved for Vala/GObject naming conventions
+		reserved_identifiers.add ("error");
+		reserved_identifiers.add ("result");
+		reserved_identifiers.add ("self");
 	}
 
 	public override void emit (CodeContext context) {
@@ -1302,7 +1307,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 			if (current_method_inner_error) {
 				var cdecl = new CCodeDeclaration ("GError *");
-				cdecl.add_declarator (new CCodeVariableDeclarator ("inner_error", new CCodeConstant ("NULL")));
+				cdecl.add_declarator (new CCodeVariableDeclarator ("_inner_error_", new CCodeConstant ("NULL")));
 				function.block.prepend_statement (cdecl);
 			}
 
@@ -1357,7 +1362,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 
 		if (current_method_inner_error) {
 			var cdecl = new CCodeDeclaration ("GError *");
-			cdecl.add_declarator (new CCodeVariableDeclarator ("inner_error", new CCodeConstant ("NULL")));
+			cdecl.add_declarator (new CCodeVariableDeclarator ("_inner_error_", new CCodeConstant ("NULL")));
 			cfrag.append (cdecl);
 		}
 
@@ -1454,12 +1459,12 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 		if (name[0] == '.') {
 			// compiler-internal variable
 			if (!variable_name_map.contains (name)) {
-				variable_name_map.set (name, "_tmp%d".printf (next_temp_var_id));
+				variable_name_map.set (name, "_tmp%d_".printf (next_temp_var_id));
 				next_temp_var_id++;
 			}
 			return variable_name_map.get (name);
-		} else if (c_keywords.contains (name)) {
-			return name + "_";
+		} else if (reserved_identifiers.contains (name)) {
+			return "_%s_".printf (name);
 		} else {
 			return name;
 		}
@@ -1640,7 +1645,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 	public LocalVariable get_temp_variable (DataType type, bool value_owned = true, CodeNode? node_reference = null) {
 		var var_type = type.copy ();
 		var_type.value_owned = value_owned;
-		var local = new LocalVariable (var_type, "_tmp%d".printf (next_temp_var_id));
+		var local = new LocalVariable (var_type, "_tmp%d_".printf (next_temp_var_id));
 
 		if (node_reference != null) {
 			local.source_reference = node_reference.source_reference;
@@ -2956,7 +2961,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 			if (expr.tree_can_fail) {
 				// method can fail
 				current_method_inner_error = true;
-				creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error")));
+				creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_inner_error_")));
 			}
 
 			if (ellipsis) {
diff --git a/gobject/valaccodedelegatemodule.vala b/gobject/valaccodedelegatemodule.vala
index 006b75c..d427e68 100644
--- a/gobject/valaccodedelegatemodule.vala
+++ b/gobject/valaccodedelegatemodule.vala
@@ -55,7 +55,7 @@ internal class Vala.CCodeDelegateModule : CCodeArrayModule {
 				}
 				
 				for (int dim = 1; dim <= array_type.rank; dim++) {
-					var cparam = new CCodeFormalParameter (head.get_array_length_cname (param.name, dim), length_ctype);
+					var cparam = new CCodeFormalParameter (head.get_array_length_cname (get_variable_cname (param.name), dim), length_ctype);
 					cfundecl.add_parameter (cparam);
 				}
 			}
@@ -124,7 +124,7 @@ internal class Vala.CCodeDelegateModule : CCodeArrayModule {
 		} else if (delegate_expr.symbol_reference != null) {
 			if (delegate_expr.symbol_reference is FormalParameter) {
 				var param = (FormalParameter) delegate_expr.symbol_reference;
-				CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (param.name));
+				CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (param.name)));
 				if (param.direction != ParameterDirection.IN) {
 					// accessing argument of out/ref param
 					target_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr);
@@ -405,11 +405,11 @@ internal class Vala.CCodeDelegateModule : CCodeArrayModule {
 			ctypename += "*";
 		}
 
-		param.ccodenode = new CCodeFormalParameter (param.name, ctypename);
+		param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
 
 		cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
 		if (carg_map != null) {
-			carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
+			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
 		}
 
 		if (param.parameter_type is DelegateType) {
@@ -419,24 +419,24 @@ internal class Vala.CCodeDelegateModule : CCodeArrayModule {
 			generate_delegate_declaration (d, decl_space);
 
 			if (d.has_target) {
-				var cparam = new CCodeFormalParameter (get_delegate_target_cname (param.name), "void*");
+				var cparam = new CCodeFormalParameter (get_delegate_target_cname (get_variable_cname (param.name)), "void*");
 				cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), new CCodeIdentifier (cparam.name));
+					carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (param.name));
 				}
 				if (deleg_type.value_owned) {
-					cparam = new CCodeFormalParameter (get_delegate_target_destroy_notify_cname (param.name), "GDestroyNotify");
+					cparam = new CCodeFormalParameter (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)), "GDestroyNotify");
 					cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), cparam);
 					if (carg_map != null) {
-						carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), new CCodeIdentifier (cparam.name));
+						carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), get_variable_cexpression (param.name));
 					}
 				}
 			}
 		} else if (param.parameter_type is MethodType) {
-			var cparam = new CCodeFormalParameter (get_delegate_target_cname (param.name), "void*");
+			var cparam = new CCodeFormalParameter (get_delegate_target_cname (get_variable_cname (param.name)), "void*");
 			cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
 			if (carg_map != null) {
-				carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), new CCodeIdentifier (cparam.name));
+				carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (param.name));
 			}
 		}
 	}
diff --git a/gobject/valaccodememberaccessmodule.vala b/gobject/valaccodememberaccessmodule.vala
index e842010..e257ed1 100644
--- a/gobject/valaccodememberaccessmodule.vala
+++ b/gobject/valaccodememberaccessmodule.vala
@@ -321,7 +321,7 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					var type_as_struct = p.parameter_type.data_type as Struct;
 					if (p.direction != ParameterDirection.IN
 					    || (type_as_struct != null && !type_as_struct.is_simple_type () && !p.parameter_type.nullable)) {
-						expr.ccodenode = new CCodeIdentifier ("(*%s)".printf (p.name));
+						expr.ccodenode = new CCodeIdentifier ("(*%s)".printf (get_variable_cname (p.name)));
 					} else {
 						// Property setters of non simple structs shall replace all occurences
 						// of the "value" formal parameter with a dereferencing version of that
@@ -332,7 +332,7 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 						    current_property_accessor.prop.property_type.is_real_struct_type ()) {
 							expr.ccodenode = new CCodeIdentifier ("(*value)");
 						} else {
-							expr.ccodenode = new CCodeIdentifier (p.name);
+							expr.ccodenode = get_variable_cexpression (p.name);
 						}
 					}
 				}
diff --git a/gobject/valaccodemethodcallmodule.vala b/gobject/valaccodemethodcallmodule.vala
index 4785120..4341b1a 100644
--- a/gobject/valaccodemethodcallmodule.vala
+++ b/gobject/valaccodemethodcallmodule.vala
@@ -483,7 +483,7 @@ internal class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			// method can fail
 			current_method_inner_error = true;
 			// add &inner_error before the ellipsis arguments
-			out_arg_map.set (get_param_pos (-1), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression ("inner_error")));
+			out_arg_map.set (get_param_pos (-1), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression ("_inner_error_")));
 		}
 
 		if (ellipsis) {
diff --git a/gobject/valaccodemethodmodule.vala b/gobject/valaccodemethodmodule.vala
index a584ebe..8e235a4 100644
--- a/gobject/valaccodemethodmodule.vala
+++ b/gobject/valaccodemethodmodule.vala
@@ -88,7 +88,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 				var cparam = new CCodeFormalParameter (head.get_array_length_cname ("result", dim), "int*");
 				cparam_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), new CCodeIdentifier (cparam.name));
+					carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), get_variable_cexpression (cparam.name));
 				}
 			}
 		} else if (m.return_type is DelegateType) {
@@ -99,7 +99,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 				var cparam = new CCodeFormalParameter (get_delegate_target_cname ("result"), "void*");
 				cparam_map.set (get_param_pos (m.cdelegate_target_parameter_position), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), new CCodeIdentifier (cparam.name));
+					carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
 				}
 			}
 		}
@@ -112,7 +112,7 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 			var cparam = new CCodeFormalParameter ("error", "GError**");
 			cparam_map.set (get_param_pos (-1), cparam);
 			if (carg_map != null) {
-				carg_map.set (get_param_pos (-1), new CCodeIdentifier (cparam.name));
+				carg_map.set (get_param_pos (-1), get_variable_cexpression (cparam.name));
 			}
 		}
 	}
@@ -413,14 +413,14 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 					var t = param.parameter_type.data_type;
 					if (t != null && t.is_reference_type ()) {
 						if (param.direction != ParameterDirection.OUT) {
-							var type_check = create_method_type_check_statement (m, creturn_type, t, !param.parameter_type.nullable, param.name);
+							var type_check = create_method_type_check_statement (m, creturn_type, t, !param.parameter_type.nullable, get_variable_cname (param.name));
 							if (type_check != null) {
 								type_check.line = function.line;
 								cinit.append (type_check);
 							}
 						} else {
 							// ensure that the passed reference for output parameter is cleared
-							var a = new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), new CCodeConstant ("NULL"));
+							var a = new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (param.name)), new CCodeConstant ("NULL"));
 							cinit.append (new CCodeExpressionStatement (a));
 						}
 					}
@@ -431,12 +431,12 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 					 * as error may be set to NULL but we're always interested in inner errors
 					 */
 					if (m.coroutine) {
-						closure_struct.add_field ("GError *", "inner_error");
+						closure_struct.add_field ("GError *", "_inner_error_");
 
 						// no initialization necessary, closure struct is zeroed
 					} else {
 						var cdecl = new CCodeDeclaration ("GError *");
-						cdecl.add_declarator (new CCodeVariableDeclarator ("inner_error", new CCodeConstant ("NULL")));
+						cdecl.add_declarator (new CCodeVariableDeclarator ("_inner_error_", new CCodeConstant ("NULL")));
 						cinit.append (cdecl);
 					}
 				}
@@ -661,14 +661,14 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 				ctypename += "*";
 			}
 
-			param.ccodenode = new CCodeFormalParameter (param.name, ctypename);
+			param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
 		} else {
 			param.ccodenode = new CCodeFormalParameter.with_ellipsis ();
 		}
 
 		cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
 		if (carg_map != null && !param.ellipsis) {
-			carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
+			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
 		}
 	}
 
diff --git a/gobject/valadbusmodule.vala b/gobject/valadbusmodule.vala
index d6f2b3c..5e7fe11 100644
--- a/gobject/valadbusmodule.vala
+++ b/gobject/valadbusmodule.vala
@@ -71,7 +71,7 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	CCodeExpression read_basic (CCodeFragment fragment, BasicTypeInfo basic_type, CCodeExpression iter_expr) {
-		string temp_name = "_tmp%d".printf (next_temp_var_id++);
+		string temp_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration (basic_type.cname);
 		cdecl.add_declarator (new CCodeVariableDeclarator (temp_name));
@@ -96,7 +96,7 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	CCodeExpression read_array (CCodeFragment fragment, ArrayType array_type, CCodeExpression iter_expr, CCodeExpression? expr) {
-		string temp_name = "_tmp%d".printf (next_temp_var_id++);
+		string temp_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var new_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new"));
 		new_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
@@ -128,7 +128,7 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	void read_array_dim (CCodeFragment fragment, ArrayType array_type, int dim, string temp_name, CCodeExpression iter_expr, CCodeExpression? expr) {
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration ("int");
 		cdecl.add_declarator (new CCodeVariableDeclarator ("%s_length%d".printf (temp_name, dim), new CCodeConstant ("0")));
@@ -190,8 +190,8 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	CCodeExpression read_struct (CCodeFragment fragment, Struct st, CCodeExpression iter_expr) {
-		string temp_name = "_tmp%d".printf (next_temp_var_id++);
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
+		string temp_name = "_tmp%d_".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration (st.get_cname ());
 		cdecl.add_declarator (new CCodeVariableDeclarator (temp_name));
@@ -219,8 +219,8 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	CCodeExpression read_value (CCodeFragment fragment, CCodeExpression iter_expr) {
-		string temp_name = "_tmp%d".printf (next_temp_var_id++);
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
+		string temp_name = "_tmp%d_".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		// 0-initialize struct with struct initializer { 0 }
 		var cvalinit = new CCodeInitializerList ();
@@ -275,9 +275,9 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	CCodeExpression read_hash_table (CCodeFragment fragment, ObjectType type, CCodeExpression iter_expr) {
-		string temp_name = "_tmp%d".printf (next_temp_var_id++);
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
-		string entryiter_name = "_tmp%d".printf (next_temp_var_id++);
+		string temp_name = "_tmp%d_".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
+		string entryiter_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var type_args = type.get_type_arguments ();
 		assert (type_args.size == 2);
@@ -402,7 +402,7 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	void write_basic (CCodeFragment fragment, BasicTypeInfo basic_type, CCodeExpression iter_expr, CCodeExpression expr) {
-		string temp_name = "_tmp%d".printf (next_temp_var_id++);
+		string temp_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration (basic_type.cname);
 		cdecl.add_declarator (new CCodeVariableDeclarator (temp_name));
@@ -418,7 +418,7 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	void write_array (CCodeFragment fragment, ArrayType array_type, CCodeExpression iter_expr, CCodeExpression array_expr) {
-		string array_iter_name = "_tmp%d".printf (next_temp_var_id++);
+		string array_iter_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration (array_type.get_cname ());
 		cdecl.add_declarator (new CCodeVariableDeclarator (array_iter_name));
@@ -430,8 +430,8 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	void write_array_dim (CCodeFragment fragment, ArrayType array_type, int dim, CCodeExpression iter_expr, CCodeExpression array_expr, CCodeExpression array_iter_expr) {
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
-		string index_name = "_tmp%d".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
+		string index_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration ("DBusMessageIter");
 		cdecl.add_declarator (new CCodeVariableDeclarator (subiter_name));
@@ -473,7 +473,7 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	void write_struct (CCodeFragment fragment, Struct st, CCodeExpression iter_expr, CCodeExpression struct_expr) {
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration ("DBusMessageIter");
 		cdecl.add_declarator (new CCodeVariableDeclarator (subiter_name));
@@ -501,7 +501,7 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	void write_value (CCodeFragment fragment, CCodeExpression iter_expr, CCodeExpression expr) {
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var cdecl = new CCodeDeclaration ("DBusMessageIter");
 		cdecl.add_declarator (new CCodeVariableDeclarator (subiter_name));
@@ -552,11 +552,11 @@ internal class Vala.DBusModule : GAsyncModule {
 	}
 
 	void write_hash_table (CCodeFragment fragment, ObjectType type, CCodeExpression iter_expr, CCodeExpression hash_table_expr) {
-		string subiter_name = "_tmp%d".printf (next_temp_var_id++);
-		string entryiter_name = "_tmp%d".printf (next_temp_var_id++);
-		string tableiter_name = "_tmp%d".printf (next_temp_var_id++);
-		string key_name = "_tmp%d".printf (next_temp_var_id++);
-		string value_name = "_tmp%d".printf (next_temp_var_id++);
+		string subiter_name = "_tmp%d_".printf (next_temp_var_id++);
+		string entryiter_name = "_tmp%d_".printf (next_temp_var_id++);
+		string tableiter_name = "_tmp%d_".printf (next_temp_var_id++);
+		string key_name = "_tmp%d_".printf (next_temp_var_id++);
+		string value_name = "_tmp%d_".printf (next_temp_var_id++);
 
 		var type_args = type.get_type_arguments ();
 		assert (type_args.size == 2);
diff --git a/gobject/valagerrormodule.vala b/gobject/valagerrormodule.vala
index 6fa5c73..5692cac 100644
--- a/gobject/valagerrormodule.vala
+++ b/gobject/valagerrormodule.vala
@@ -92,7 +92,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 
 		// method will fail
 		current_method_inner_error = true;
-		var cassign = new CCodeAssignment (get_variable_cexpression ("inner_error"), (CCodeExpression) stmt.error_expression.ccodenode);
+		var cassign = new CCodeAssignment (new CCodeIdentifier ("_inner_error_"), (CCodeExpression) stmt.error_expression.ccodenode);
 		cfrag.append (new CCodeExpressionStatement (cassign));
 
 		head.add_simple_check (stmt, cfrag);
@@ -105,7 +105,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 	public virtual CCodeStatement return_with_exception (CCodeExpression error_expr)
 	{
 		var cpropagate = new CCodeFunctionCall (new CCodeIdentifier ("g_propagate_error"));
-		cpropagate.add_argument (get_variable_cexpression ("error"));
+		cpropagate.add_argument (new CCodeIdentifier ("error"));
 		cpropagate.add_argument (error_expr);
 
 		var cerror_block = new CCodeBlock ();
@@ -163,7 +163,7 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 	public override void add_simple_check (CodeNode node, CCodeFragment cfrag) {
 		current_method_inner_error = true;
 
-		var inner_error = get_variable_cexpression ("inner_error");
+		var inner_error = get_variable_cexpression ("_inner_error_");
 
 		CCodeStatement cerror_handler = null;
 
@@ -319,20 +319,20 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
 
 		var cblock = new CCodeBlock ();
 
-		string variable_name = clause.variable_name;
+		string variable_name = get_variable_cname (clause.variable_name);
 		if (variable_name == null) {
 			variable_name = "__err";
 		}
 
 		if (current_method != null && current_method.coroutine) {
 			closure_struct.add_field ("GError *", variable_name);
-			cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (get_variable_cexpression (variable_name), get_variable_cexpression ("inner_error"))));
+			cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (get_variable_cexpression (variable_name), get_variable_cexpression ("_inner_error_"))));
 		} else {
 			var cdecl = new CCodeDeclaration ("GError *");
-			cdecl.add_declarator (new CCodeVariableDeclarator (variable_name, get_variable_cexpression ("inner_error")));
+			cdecl.add_declarator (new CCodeVariableDeclarator (variable_name, get_variable_cexpression ("_inner_error_")));
 			cblock.add_statement (cdecl);
 		}
-		cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (get_variable_cexpression ("inner_error"), new CCodeConstant ("NULL"))));
+		cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (get_variable_cexpression ("_inner_error_"), new CCodeConstant ("NULL"))));
 
 		cblock.add_statement (clause.body.ccodenode);
 
diff --git a/gobject/valagobjectmodule.vala b/gobject/valagobjectmodule.vala
index b48ffa5..dc198e4 100644
--- a/gobject/valagobjectmodule.vala
+++ b/gobject/valagobjectmodule.vala
@@ -488,7 +488,7 @@ internal class Vala.GObjectModule : GTypeModule {
 				 * as error may be set to NULL but we're always interested in inner errors
 				 */
 				cdecl = new CCodeDeclaration ("GError *");
-				cdecl.add_declarator (new CCodeVariableDeclarator ("inner_error", new CCodeConstant ("NULL")));
+				cdecl.add_declarator (new CCodeVariableDeclarator ("_inner_error_", new CCodeConstant ("NULL")));
 				cblock.add_statement (cdecl);
 			}
 
@@ -517,7 +517,7 @@ internal class Vala.GObjectModule : GTypeModule {
 				 * as error may be set to NULL but we're always interested in inner errors
 				 */
 				var cdecl = new CCodeDeclaration ("GError *");
-				cdecl.add_declarator (new CCodeVariableDeclarator ("inner_error", new CCodeConstant ("NULL")));
+				cdecl.add_declarator (new CCodeVariableDeclarator ("_inner_error_", new CCodeConstant ("NULL")));
 				base_init_fragment.append (cdecl);
 			}
 
@@ -537,7 +537,7 @@ internal class Vala.GObjectModule : GTypeModule {
 				 * as error may be set to NULL but we're always interested in inner errors
 				 */
 				var cdecl = new CCodeDeclaration ("GError *");
-				cdecl.add_declarator (new CCodeVariableDeclarator ("inner_error", new CCodeConstant ("NULL")));
+				cdecl.add_declarator (new CCodeVariableDeclarator ("_inner_error_", new CCodeConstant ("NULL")));
 				class_init_fragment.append (cdecl);
 			}
 
diff --git a/gobject/valagtypemodule.vala b/gobject/valagtypemodule.vala
index 5f748da..dd4421b 100644
--- a/gobject/valagtypemodule.vala
+++ b/gobject/valagtypemodule.vala
@@ -43,11 +43,11 @@ internal class Vala.GTypeModule : GErrorModule {
 			ctypename += "*";
 		}
 
-		param.ccodenode = new CCodeFormalParameter (param.name, ctypename);
+		param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
 
 		cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
 		if (carg_map != null) {
-			carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
+			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
 		}
 	}
 



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