cgen: add asm to c_reserved, fixes compilation of struct Abc { @asm int } (#22340)

This commit is contained in:
Delyan Angelov 2024-09-28 13:44:01 +03:00 committed by GitHub
parent 4a01b2cca8
commit 2e0fa12261
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 7 deletions

View File

@ -20,13 +20,13 @@ import sync.pool
// in C++, or have special meaning in V, thus need escaping too. `small`
// should not be needed, but see:
// https://stackoverflow.com/questions/5874215/what-is-rpcndr-h
const c_reserved = ['array', 'auto', 'bool', 'break', 'calloc', 'case', 'char', 'class', 'complex',
'const', 'continue', 'default', 'delete', 'do', 'double', 'else', 'enum', 'error', 'exit',
'export', 'extern', 'false', 'float', 'for', 'free', 'goto', 'if', 'inline', 'int', 'link',
'long', 'malloc', 'namespace', 'new', 'nil', 'panic', 'register', 'restrict', 'return', 'short',
'signed', 'sizeof', 'static', 'string', 'struct', 'switch', 'typedef', 'typename', 'union',
'unix', 'unsigned', 'void', 'volatile', 'while', 'template', 'true', 'small', 'stdout', 'stdin',
'stderr', 'far', 'near', 'huge', 'requires']
const c_reserved = ['asm', 'array', 'auto', 'bool', 'break', 'calloc', 'case', 'char', 'class',
'complex', 'const', 'continue', 'default', 'delete', 'do', 'double', 'else', 'enum', 'error',
'exit', 'export', 'extern', 'false', 'float', 'for', 'free', 'goto', 'if', 'inline', 'int',
'link', 'long', 'malloc', 'namespace', 'new', 'nil', 'panic', 'register', 'restrict', 'return',
'short', 'signed', 'sizeof', 'static', 'string', 'struct', 'switch', 'typedef', 'typename',
'union', 'unix', 'unsigned', 'void', 'volatile', 'while', 'template', 'true', 'small', 'stdout',
'stdin', 'stderr', 'far', 'near', 'huge', 'requires']
const c_reserved_chk = token.new_keywords_matcher_from_array_trie(c_reserved)
// same order as in token.Kind
const cmp_str = ['eq', 'ne', 'gt', 'lt', 'ge', 'le']

View File

@ -0,0 +1,26 @@
struct Abc {
@asm string
}
enum Enum {
@asm
end
}
fn test_struct() {
dump(Abc{})
assert true
}
fn test_local() {
@asm := 12
dump(@asm)
assert true
}
fn test_enum() {
dump(unsafe { Enum(0) })
dump(Enum.@asm)
dump(Enum.end)
assert true
}