1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: use a trie matcher for c_reserved checks as well

This commit is contained in:
Delyan Angelov 2022-07-29 20:58:45 +03:00
parent 8268df7e1d
commit a42eb3b947
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -26,7 +26,7 @@ const (
'short', 'signed', 'sizeof', 'static', 'string', 'struct', 'switch', 'typedef', 'typename', 'short', 'signed', 'sizeof', 'static', 'string', 'struct', 'switch', 'typedef', 'typename',
'union', 'unix', 'unsigned', 'void', 'volatile', 'while', 'template', 'true', 'small', 'union', 'unix', 'unsigned', 'void', 'volatile', 'while', 'template', 'true', 'small',
'stdout', 'stdin', 'stderr'] 'stdout', 'stdin', 'stderr']
c_reserved_map = string_array_to_map(c_reserved) c_reserved_chk = token.new_keywords_matcher_from_array_trie(c_reserved)
// 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
@ -5330,7 +5330,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
[inline] [inline]
fn c_name(name_ string) string { fn c_name(name_ string) string {
name := util.no_dots(name_) name := util.no_dots(name_)
if name in c.c_reserved_map { if -1 != c.c_reserved_chk.find(name) {
return '_v_$name' return '_v_$name'
} }
return name return name