v.gen.c: ensure that @continue is escaped in the generated C code

pull/8989/head
Delyan Angelov 2021-02-26 10:22:35 +02:00
parent 995bd66970
commit 1a8ff9d7dd
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 13 additions and 7 deletions

View File

@ -12,14 +12,14 @@ import v.token
import v.util import v.util
import v.depgraph import v.depgraph
// NB: keywords after 'new' are reserved in C++
const ( const (
c_reserved = ['delete', 'exit', 'link', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic', // NB: some of the words in c_reserved, are not reserved in C,
'case', 'auto', 'char', 'default', 'do', 'double', 'extern', 'float', 'inline', 'int', // but are in C++, or have special meaning in V, thus need escaping too.
'long', 'register', 'restrict', 'short', 'signed', 'sizeof', 'static', 'switch', 'typedef', c_reserved = ['auto', 'break', 'calloc', 'case', 'char', 'class', 'const', 'continue', 'default',
'union', 'unsigned', 'void', 'volatile', 'while', 'new', 'namespace', 'class', 'typename', 'delete', 'do', 'double', 'else', 'enum', 'error', 'exit', 'export', 'extern', 'float',
'export', 'for', 'free', 'goto', 'if', 'inline', 'int', 'link', 'long', 'malloc', 'namespace', 'new',
] 'panic', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof', 'static', 'struct',
'switch', 'typedef', 'typename', 'union', 'unix', 'unsigned', 'void', 'volatile', 'while']
// same order as in token.Kind // same order as in token.Kind
cmp_str = ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] cmp_str = ['eq', 'ne', 'gt', 'lt', 'ge', 'le']
// when operands are switched // when operands are switched

View File

@ -0,0 +1,6 @@
fn test_reserved_keywords() {
@continue := 'abc'
@sizeof := 'def'
@union := 'xyz'
assert [@continue, @sizeof, @union] == ['abc', 'def', 'xyz']
}