[vala/staging] codegen: Check reserved_identifiers in CCodeAttribute.get_default_name()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Check reserved_identifiers in CCodeAttribute.get_default_name()
- Date: Tue, 15 Jan 2019 15:53:58 +0000 (UTC)
commit 6a4254e7e01c4b4a07082283f7ca19eebf46f646
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Jan 15 13:35:52 2019 +0100
codegen: Check reserved_identifiers in CCodeAttribute.get_default_name()
This is a step for wider usage of get_ccode_name() on variables
codegen/valaccodeattribute.vala | 7 ++++++-
codegen/valaccodebasemodule.vala | 2 +-
2 files changed, 7 insertions(+), 2 deletions(-)
---
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<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; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]