mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: fix - v fmt
transforms compile time options in some cases (#16351)
This commit is contained in:
parent
5f33585edf
commit
dc9997f58c
10
vlib/v/checker/constants/constants.v
Normal file
10
vlib/v/checker/constants/constants.v
Normal file
@ -0,0 +1,10 @@
|
||||
module constants
|
||||
|
||||
// TODO: move all constants from `checker` to here, and replace the hardcoded one with the computed one
|
||||
pub const valid_comptime_not_user_defined = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux',
|
||||
'gnu', 'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'termux',
|
||||
'solaris', 'haiku', 'serenity', 'vinix', 'gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus',
|
||||
'amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32', 'x64', 'x32', 'little_endian',
|
||||
'big_endian', 'apk', 'js', 'debug', 'prod', 'test', 'glibc', 'prealloc', 'no_bounds_checking',
|
||||
'freestanding', 'threads', 'js_node', 'js_browser', 'js_freestanding', 'interpreter', 'es5',
|
||||
'profile', 'wasm32_emscripten']
|
@ -7,6 +7,7 @@ import strings
|
||||
import v.ast
|
||||
import v.util
|
||||
import v.pref
|
||||
import v.checker.constants
|
||||
|
||||
const (
|
||||
bs = '\\'
|
||||
@ -1936,6 +1937,10 @@ pub fn (mut f Fmt) enum_val(node ast.EnumVal) {
|
||||
|
||||
pub fn (mut f Fmt) ident(node ast.Ident) {
|
||||
if node.info is ast.IdentVar {
|
||||
if node.comptime && node.name in constants.valid_comptime_not_user_defined {
|
||||
f.write(node.name)
|
||||
return
|
||||
}
|
||||
if node.info.is_mut {
|
||||
f.write(node.info.share.str() + ' ')
|
||||
}
|
||||
|
15
vlib/v/fmt/tests/conditional_compilation_keep_in_module.vv
Normal file
15
vlib/v/fmt/tests/conditional_compilation_keep_in_module.vv
Normal file
@ -0,0 +1,15 @@
|
||||
module log
|
||||
|
||||
const (
|
||||
debug = 'debug'
|
||||
prod = 'prod'
|
||||
)
|
||||
|
||||
fn log() {
|
||||
$if debug {
|
||||
println('debug')
|
||||
}
|
||||
$if !prod {
|
||||
println('prod')
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user