1
0
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:
Taegon Kim 2022-11-08 15:05:48 +09:00 committed by GitHub
parent 5f33585edf
commit dc9997f58c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View 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']

View File

@ -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() + ' ')
}

View File

@ -0,0 +1,15 @@
module log
const (
debug = 'debug'
prod = 'prod'
)
fn log() {
$if debug {
println('debug')
}
$if !prod {
println('prod')
}
}