]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Check reserved_identifiers in CCodeAttribute.get_default_name()
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 15 Jan 2019 12:35:52 +0000 (13:35 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 15 Jan 2019 12:38:48 +0000 (13:38 +0100)
This is a step for wider usage of get_ccode_name() on variables

codegen/valaccodeattribute.vala
codegen/valaccodebasemodule.vala

index 0dba3a99b639090f85d7f671c07e3cf67a85ab75..d6399e4595f9b40093299c0e959767238b1a166b 100644 (file)
@@ -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);
                        }
index fe2550ff1eff20ff60de909d4fc44a0d9f3ee06d..2e347362a8defe4e08e97405a1ab848f659f7905 100644 (file)
@@ -250,7 +250,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        /* (constant) hash table with all predefined marshallers */
        public Set<string> predefined_marshal_set;
        /* (constant) hash table with all reserved identifiers in the generated code */
-       Set<string> reserved_identifiers;
+       public static Set<string> reserved_identifiers;
 
        public int next_temp_var_id {
                get { return emit_context.next_temp_var_id; }