summaryrefslogtreecommitdiff
path: root/codegen
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2022-06-11 13:04:00 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2022-06-14 15:46:39 +0200
commit27d55956ff1e5064ff7b44b24bb9f528f3862faa (patch)
tree225b2bb973b169ad932376167d0c5f391e4bb28d /codegen
parentecf55f6768005a50f4f84348a1991b3af7c1c71e (diff)
downloadvala-27d55956ff1e5064ff7b44b24bb9f528f3862faa.tar.gz
codegen: Check cname of fields and methods against reserved identfiers
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1329
Diffstat (limited to 'codegen')
-rw-r--r--codegen/valaccodeattribute.vala12
1 files changed, 9 insertions, 3 deletions
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index a996480d7..9b49fe9e1 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -734,7 +734,8 @@ public class Vala.CCodeAttribute : AttributeCache {
}
if (cname[0].isdigit ()) {
Report.error (node.source_reference, "Field name starts with a digit. Use the `cname' attribute to provide a valid C name if intended");
- return "";
+ } else if (CCodeBaseModule.reserved_identifiers.contains (cname)) {
+ Report.error (node.source_reference, "Field name `%s' collides with reserved identifier. Use the `cname' attribute to provide a valid C name if intended", cname);
}
return cname;
} else if (sym is CreationMethod) {
@@ -760,6 +761,7 @@ public class Vala.CCodeAttribute : AttributeCache {
if (m.signal_reference != null) {
return "%s%s".printf (get_ccode_lower_case_prefix (m.parent_symbol), get_ccode_lower_case_name (m.signal_reference));
}
+ string cname;
if (sym.name == "main" && sym.parent_symbol.name == null) {
// avoid conflict with generated main function
if (m.coroutine) {
@@ -768,10 +770,14 @@ public class Vala.CCodeAttribute : AttributeCache {
return "_vala_main";
}
} else if (sym.name.has_prefix ("_")) {
- return "_%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), sym.name.substring (1));
+ cname = "_%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), sym.name.substring (1));
} else {
- return "%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), sym.name);
+ cname = "%s%s".printf (get_ccode_lower_case_prefix (sym.parent_symbol), sym.name);
+ }
+ if (CCodeBaseModule.reserved_identifiers.contains (cname)) {
+ Report.error (node.source_reference, "Method name `%s' collides with reserved identifier. Use the `cname' attribute to provide a valid C name if intended", cname);
}
+ return cname;
} else if (sym is Property) {
return sym.name.replace ("_", "-");
} else if (sym is PropertyAccessor) {