Skip to content

Commit

Permalink
cgen: add asm to c_reserved, fixes compilation of `struct Abc { @asm
Browse files Browse the repository at this point in the history
…int }` (#22340)
  • Loading branch information
spytheman authored Sep 28, 2024
1 parent 4a01b2c commit 2e0fa12
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
14 changes: 7 additions & 7 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
26 changes: 26 additions & 0 deletions vlib/v/tests/reserved_keyword_asm_test.v
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 2e0fa12

Please sign in to comment.