From: Rico Tzschichholz Date: Tue, 15 Jan 2019 12:35:52 +0000 (+0100) Subject: codegen: Check reserved_identifiers in CCodeAttribute.get_default_name() X-Git-Tag: 0.43.5~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a4254e7e01c4b4a07082283f7ca19eebf46f646;p=thirdparty%2Fvala.git codegen: Check reserved_identifiers in CCodeAttribute.get_default_name() This is a step for wider usage of get_ccode_name() on variables --- diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index 0dba3a99b..d6399e459 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -738,7 +738,12 @@ public class Vala.CCodeAttribute : AttributeCache { } else if (sym is Signal) { return Symbol.camel_case_to_lower_case (sym.name).replace ("_", "-");; } else if (sym is LocalVariable || sym is Parameter) { - return sym.name; + unowned string name = sym.name; + if (CCodeBaseModule.reserved_identifiers.contains (name)) { + return "_%s_".printf (name); + } else { + return name; + } } else { return "%s%s".printf (get_ccode_prefix (sym.parent_symbol), sym.name); } diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index fe2550ff1..2e347362a 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -250,7 +250,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { /* (constant) hash table with all predefined marshallers */ public Set predefined_marshal_set; /* (constant) hash table with all reserved identifiers in the generated code */ - Set reserved_identifiers; + public static Set reserved_identifiers; public int next_temp_var_id { get { return emit_context.next_temp_var_id; }