From 6dcf72fe9b733019f163a580a61b7a33ea4ca081 Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Tue, 3 Aug 2021 02:17:22 +0200 Subject: [PATCH] cgen: dont generate function if its flag is false (#11021) --- vlib/v/ast/ast.v | 13 +++++++------ vlib/v/checker/checker.v | 2 +- vlib/v/gen/c/fn.v | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index b2e1e3bf8a..a34423e7df 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -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 diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index dd179c99c2..519b75159b 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) } } } diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index b0ed915c47..b87d8ea89a 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -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