[vala/wip/issue/1329: 1/2] codegen: Split reserved identifiers for C and Vala
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/1329: 1/2] codegen: Split reserved identifiers for C and Vala
- Date: Sat, 11 Jun 2022 11:38:55 +0000 (UTC)
commit 4d9c0d031278cb9eaccbd52d4fcf01535ea85f25
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jun 11 13:28:11 2022 +0200
codegen: Split reserved identifiers for C and Vala
codegen/valaccodeattribute.vala | 4 ++--
codegen/valaccodebasemodule.vala | 11 +++++++----
2 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 3c3b18ef4..a996480d7 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -787,7 +787,7 @@ public class Vala.CCodeAttribute : AttributeCache {
return Symbol.camel_case_to_lower_case (sym.name).replace ("_", "-");;
} else if (sym is LocalVariable) {
unowned string name = sym.name;
- if (CCodeBaseModule.reserved_identifiers.contains (name)) {
+ if (CCodeBaseModule.reserved_identifiers.contains (name) ||
CCodeBaseModule.reserved_vala_identifiers.contains (name)) {
return "_%s_".printf (name);
} else {
return name;
@@ -798,7 +798,7 @@ public class Vala.CCodeAttribute : AttributeCache {
return "...";
}
unowned string name = sym.name;
- if (CCodeBaseModule.reserved_identifiers.contains (name)) {
+ if (CCodeBaseModule.reserved_identifiers.contains (name) ||
CCodeBaseModule.reserved_vala_identifiers.contains (name)) {
return "_%s_".printf (name);
} else {
return name;
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 121344373..fcdbe66c2 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -275,6 +275,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public Set<string> predefined_marshal_set;
/* (constant) hash table with all reserved identifiers in the generated code */
public static Set<string> reserved_identifiers;
+ public static Set<string> reserved_vala_identifiers;
public int next_temp_var_id {
get { return emit_context.next_temp_var_id; }
@@ -459,10 +460,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// MSVC keywords
reserved_identifiers.add ("cdecl");
+ reserved_vala_identifiers = new HashSet<string> (str_hash, str_equal);
+
// reserved for Vala/GObject naming conventions
- reserved_identifiers.add ("error");
- reserved_identifiers.add ("result");
- reserved_identifiers.add ("self");
+ reserved_vala_identifiers.add ("error");
+ reserved_vala_identifiers.add ("result");
+ reserved_vala_identifiers.add ("self");
}
public override void emit (CodeContext context) {
@@ -2713,7 +2716,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
next_temp_var_id++;
}
return variable_name_map.get (name);
- } else if (reserved_identifiers.contains (name)) {
+ } else if (reserved_identifiers.contains (name) || reserved_vala_identifiers.contains (name))
{
return "_%s_".printf (name);
} else {
return name;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]