v: fix `[if debug] fn abc(){} ... abc()`

pull/9254/head
Delyan Angelov 2021-03-07 11:09:17 +02:00
parent c15de57f0f
commit 64bc2fb40a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
5 changed files with 25 additions and 5 deletions

View File

@ -319,6 +319,7 @@ pub:
is_manualfree bool // true, when [manualfree] is used on a fn is_manualfree bool // true, when [manualfree] is used on a fn
is_main bool // true for `fn main()` is_main bool // true for `fn main()`
is_test bool // true for `fn test_abcde` is_test bool // true for `fn test_abcde`
is_conditional bool // true for `[if abc] fn abc(){}`
receiver Field receiver Field
receiver_pos token.Position // `(u User)` in `fn (u User) name()` position receiver_pos token.Position // `(u User)` in `fn (u User) name()` position
is_method bool is_method bool

View File

@ -171,6 +171,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
is_manualfree := p.is_manualfree || p.attrs.contains('manualfree') is_manualfree := p.is_manualfree || p.attrs.contains('manualfree')
is_deprecated := p.attrs.contains('deprecated') is_deprecated := p.attrs.contains('deprecated')
is_direct_arr := p.attrs.contains('direct_array_access') is_direct_arr := p.attrs.contains('direct_array_access')
is_conditional, conditional_ctdefine := p.attrs.has_comptime_define()
mut is_unsafe := p.attrs.contains('unsafe') mut is_unsafe := p.attrs.contains('unsafe')
is_pub := p.tok.kind == .key_pub is_pub := p.tok.kind == .key_pub
if is_pub { if is_pub {
@ -331,6 +332,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
is_unsafe: is_unsafe is_unsafe: is_unsafe
is_main: is_main is_main: is_main
is_test: is_test is_test: is_test
is_conditional: is_conditional
ctdefine: conditional_ctdefine
no_body: no_body no_body: no_body
mod: p.mod mod: p.mod
attrs: p.attrs attrs: p.attrs
@ -358,6 +361,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
is_unsafe: is_unsafe is_unsafe: is_unsafe
is_main: is_main is_main: is_main
is_test: is_test is_test: is_test
is_conditional: is_conditional
ctdefine: conditional_ctdefine
no_body: no_body no_body: no_body
mod: p.mod mod: p.mod
attrs: p.attrs attrs: p.attrs
@ -397,6 +402,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
is_variadic: is_variadic is_variadic: is_variadic
is_main: is_main is_main: is_main
is_test: is_test is_test: is_test
is_conditional: is_conditional
receiver: ast.Field{ receiver: ast.Field{
name: rec.name name: rec.name
typ: rec.typ typ: rec.typ

View File

@ -451,6 +451,9 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
} }
} }
} }
if res.is_debug {
parse_define(mut res, 'debug')
}
// res.use_cache = true // res.use_cache = true
if command != 'doc' && res.out_name.ends_with('.v') { if command != 'doc' && res.out_name.ends_with('.v') {
eprintln('Cannot save output binary in a .v file.') eprintln('Cannot save output binary in a .v file.')

View File

@ -47,3 +47,12 @@ pub fn (attrs []Attr) contains(str string) bool {
} }
return false return false
} }
pub fn (attrs []Attr) has_comptime_define() (bool, string) {
for a in attrs {
if a.is_comptime_define {
return true, a.name
}
}
return false, ''
}

View File

@ -32,12 +32,13 @@ pub:
language Language language Language
generic_names []string generic_names []string
is_pub bool is_pub bool
is_deprecated bool is_deprecated bool // `[deprecated] fn abc(){}`
is_unsafe bool is_unsafe bool // `[unsafe] fn abc(){}`
is_placeholder bool is_placeholder bool
is_main bool is_main bool // `fn main(){}`
is_test bool is_test bool // `fn test_abc(){}`
no_body bool is_conditional bool // `[if abc]fn(){}`
no_body bool // a pure declaration like `fn abc(x int)`; used in .vh files, C./JS. fns.
mod string mod string
ctdefine string // compile time define. "myflag", when [if myflag] tag ctdefine string // compile time define. "myflag", when [if myflag] tag
attrs []Attr attrs []Attr