cgen: dont generate function if its flag is false (#11021)

pull/11028/head
Leo Developer 2021-08-03 02:17:22 +02:00 committed by GitHub
parent 820669b011
commit 6dcf72fe9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -392,12 +392,13 @@ pub:
attrs []Attr
ctdefine_idx int = -1 // the index in fn.attrs of `[if xyz]`, when such attribute exists
pub mut:
params []Param
stmts []Stmt
defer_stmts []DeferStmt
return_type Type
return_type_pos token.Position // `string` in `fn (u User) name() string` position
has_return bool
params []Param
stmts []Stmt
defer_stmts []DeferStmt
return_type Type
return_type_pos token.Position // `string` in `fn (u User) name() string` position
has_return bool
should_be_skipped bool
//
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl

View File

@ -7983,7 +7983,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
} else {
for mut a in node.attrs {
if a.kind == .comptime_define {
c.evaluate_once_comptime_if_attribute(mut a)
node.should_be_skipped = c.evaluate_once_comptime_if_attribute(mut a)
}
}
}

View File

@ -31,6 +31,9 @@ fn (mut g Gen) process_fn_decl(node ast.FnDecl) {
if !g.is_used_by_main(node) {
return
}
if node.should_be_skipped {
return
}
if g.is_builtin_mod && g.pref.gc_mode == .boehm_leak && node.name == 'malloc' {
g.definitions.write_string('#define _v_malloc GC_MALLOC\n')
return