mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
fix system defines and user defines. remove comment
This commit is contained in:
parent
dd5e653a8a
commit
b98a99649a
5 changed files with 23 additions and 28 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, is_comptime_option bool) !string {
|
||||
fn (mut c Checker) comptime_if_to_ifdef(name string) !string {
|
||||
match name {
|
||||
// platforms/os-es:
|
||||
'windows' {
|
||||
|
@ -964,15 +964,9 @@ fn (mut c Checker) comptime_if_to_ifdef(name string, is_comptime_option bool) !s
|
|||
// turned on by: `-cflags -ffast-math`
|
||||
return '__FAST_MATH__'
|
||||
}
|
||||
else {
|
||||
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
|
||||
}
|
||||
else {}
|
||||
}
|
||||
return error('none')
|
||||
return error('bad os ifdef name "${name}"')
|
||||
}
|
||||
|
||||
fn (mut c Checker) get_expr_type(cond ast.Expr) ast.Type {
|
||||
|
@ -1105,11 +1099,11 @@ 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
|
||||
ifdef := c.comptime_if_to_ifdef(cname, true) or {
|
||||
c.error(err.msg(), cond.pos)
|
||||
return false, false
|
||||
}
|
||||
sb.write_string('defined(${ifdef})')
|
||||
// ifdef := c.comptime_if_to_ifdef(cname, true) or {
|
||||
// c.error(err.msg(), cond.pos)
|
||||
// return false, false
|
||||
//}
|
||||
sb.write_string('defined(CUSTOM_DEFINE_${cname})')
|
||||
is_true = cname in c.pref.compile_defines
|
||||
return is_true, false
|
||||
}
|
||||
|
@ -1655,7 +1649,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, false) {
|
||||
if ifdef := c.comptime_if_to_ifdef(cname) {
|
||||
sb.write_string('defined(${ifdef})')
|
||||
} else {
|
||||
sb.write_string('${is_true}')
|
||||
|
|
|
@ -1029,16 +1029,16 @@ pub fn (mut g Gen) init() {
|
|||
if g.pref.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak] {
|
||||
g.comptime_definitions.writeln('#define _VGCBOEHM (1)')
|
||||
}
|
||||
if g.pref.is_debug || 'debug' in g.pref.compile_defines {
|
||||
if g.pref.is_debug {
|
||||
g.comptime_definitions.writeln('#define _VDEBUG (1)')
|
||||
}
|
||||
if g.pref.is_prod || 'prod' in g.pref.compile_defines {
|
||||
if g.pref.is_prod {
|
||||
g.comptime_definitions.writeln('#define _VPROD (1)')
|
||||
}
|
||||
if g.pref.is_test || 'test' in g.pref.compile_defines {
|
||||
if g.pref.is_test {
|
||||
g.comptime_definitions.writeln('#define _VTEST (1)')
|
||||
}
|
||||
if g.pref.is_prof || 'profile' in g.pref.compile_defines {
|
||||
if g.pref.is_prof {
|
||||
g.comptime_definitions.writeln('#define _VPROFILE (1)')
|
||||
}
|
||||
if g.pref.autofree {
|
||||
|
|
|
@ -430,7 +430,10 @@ fn (mut g Gen) comptime_if(node ast.IfExpr) {
|
|||
}
|
||||
// directly use `checker` evaluate results
|
||||
// for `cgen`, we can use `is_true.c_str` or `is_true.value` here
|
||||
g.writeln('${is_true.c_str}\t/* ${node.branches[i].cond} | generic=[${comptime_branch_context_str}] */')
|
||||
g.writeln('${is_true.c_str}')
|
||||
$if debug_comptime_branch_context ? {
|
||||
g.writeln('/* ${node.branches[i].cond} | generic=[${comptime_branch_context_str}] */')
|
||||
}
|
||||
} else {
|
||||
g.writeln('#else')
|
||||
}
|
||||
|
|
|
@ -44,15 +44,14 @@ fn (mut g JsGen) comptime_if(node ast.IfExpr) {
|
|||
if i == node.branches.len - 1 && node.has_else {
|
||||
g.writeln('else')
|
||||
} else {
|
||||
result := if is_true.val { '1' } else { '0' }
|
||||
if i == 0 {
|
||||
g.write('if (')
|
||||
g.writeln('if (${result})')
|
||||
} else {
|
||||
g.write('else if (')
|
||||
g.writeln('else if (${result})')
|
||||
}
|
||||
if is_true.val {
|
||||
g.writeln('1)\t// ${node.branches[i].cond} generic=[${comptime_branch_context_str}]')
|
||||
} else {
|
||||
g.writeln('0)\t// ${node.branches[i].cond} generic=[${comptime_branch_context_str}]')
|
||||
$if debug_comptime_branch_context ? {
|
||||
g.writeln('// ${node.branches[i].cond} generic=[${comptime_branch_context_str}]')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,5 @@ fn test_test_ident() {
|
|||
result += '0'
|
||||
}
|
||||
|
||||
// TODO: correct result should be '13689', it may fix for vtest or builder
|
||||
assert result == '3689'
|
||||
assert result == '23689'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue