mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
fix comptime ident
This commit is contained in:
parent
0129566b1d
commit
165185681a
1 changed files with 11 additions and 7 deletions
|
@ -784,7 +784,7 @@ fn (mut c Checker) evaluate_once_comptime_if_attribute(mut node ast.Attr) bool {
|
|||
return node.ct_skip
|
||||
}
|
||||
|
||||
fn (mut c Checker) comptime_if_to_ifdef(name string) !string {
|
||||
fn (mut c Checker) comptime_if_to_ifdef(name string, is_comptime_option bool) !string {
|
||||
match name {
|
||||
// platforms/os-es:
|
||||
'windows' {
|
||||
|
@ -965,9 +965,11 @@ fn (mut c Checker) comptime_if_to_ifdef(name string) !string {
|
|||
return '__FAST_MATH__'
|
||||
}
|
||||
else {
|
||||
if name in c.pref.compile_defines_all {
|
||||
if is_comptime_option
|
||||
|| (c.pref.compile_defines_all.len > 0 && name in c.pref.compile_defines_all) {
|
||||
return 'CUSTOM_DEFINE_${name}'
|
||||
}
|
||||
return error('bad os ifdef name "${name}"') // should never happen, caught in the checker
|
||||
}
|
||||
}
|
||||
return error('none')
|
||||
|
@ -1103,12 +1105,14 @@ fn (mut c Checker) comptime_if_cond(mut cond ast.Expr, mut sb strings.Builder) (
|
|||
should_record_ident = true
|
||||
is_user_ident = true
|
||||
ident_name = cname
|
||||
sb.write_string('defined(CUSTOM_DEFINE_${cname})')
|
||||
if cname in c.pref.compile_defines {
|
||||
return true, false
|
||||
}
|
||||
ifdef := c.comptime_if_to_ifdef(cname, true) or {
|
||||
c.error(err.msg(), cond.pos)
|
||||
return false, false
|
||||
}
|
||||
sb.write_string('defined(${ifdef})')
|
||||
is_true = cname in c.pref.compile_defines
|
||||
return is_true, false
|
||||
}
|
||||
ast.InfixExpr {
|
||||
match cond.op {
|
||||
.and, .logical_or {
|
||||
|
@ -1651,7 +1655,7 @@ fn (mut c Checker) comptime_if_cond(mut cond ast.Expr, mut sb strings.Builder) (
|
|||
c.error('invalid \$if condition: unknown indent `${cname}`', cond.pos)
|
||||
return false, false
|
||||
}
|
||||
if ifdef := c.comptime_if_to_ifdef(cname) {
|
||||
if ifdef := c.comptime_if_to_ifdef(cname, false) {
|
||||
sb.write_string('defined(${ifdef})')
|
||||
} else {
|
||||
sb.write_string('${is_true}')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue