mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-05-02 06:46:26 -04:00
Reject identifiers reserved in C++
C reserves all identifiers with leading underscores in file scope, and reservers identifiers with two leading underscores or an underscore followed by a capital letter in any context. C++ also reserves identifiers with two consecutive underscores in any context. Ensure that code generated by wayland-scanner obeys these restrictions. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
parent
7cdc20cee6
commit
ee7141ef88
1 changed files with 7 additions and 0 deletions
|
|
@ -653,6 +653,7 @@ validate_identifier(struct location *loc,
|
||||||
enum identifier_role role)
|
enum identifier_role role)
|
||||||
{
|
{
|
||||||
const char *scan;
|
const char *scan;
|
||||||
|
bool last_was_underscore = true;
|
||||||
|
|
||||||
if (!*str) {
|
if (!*str) {
|
||||||
fail(loc, "element name is empty");
|
fail(loc, "element name is empty");
|
||||||
|
|
@ -665,6 +666,12 @@ validate_identifier(struct location *loc,
|
||||||
bool is_alpha = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
bool is_alpha = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||||
bool is_digit = c >= '0' && c <= '9';
|
bool is_digit = c >= '0' && c <= '9';
|
||||||
bool leading_char = (scan == str) && role == STANDALONE_IDENT;
|
bool leading_char = (scan == str) && role == STANDALONE_IDENT;
|
||||||
|
if (c == '_' && last_was_underscore)
|
||||||
|
fail(loc,
|
||||||
|
"'%s' is not a valid identifier: identifiers must "
|
||||||
|
"not start with an underscore or have consecutive "
|
||||||
|
"underscores", str);
|
||||||
|
last_was_underscore = c == '_';
|
||||||
|
|
||||||
if (is_alpha || c == '_' || (!leading_char && is_digit))
|
if (is_alpha || c == '_' || (!leading_char && is_digit))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue