Skip to content

Commit bf3af40

Browse files
committed
v.markused: support ./v -skip-unused -freestanding run vlib/os/bare/bare_example_linux.v too
1 parent 5efd8c6 commit bf3af40

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

vlib/v/ast/ast.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ pub:
367367
is_main bool // true for `fn main()`
368368
is_test bool // true for `fn test_abcde`
369369
is_conditional bool // true for `[if abc] fn abc(){}`
370+
is_exported bool // true for `[export: 'exact_C_name']`
370371
is_keep_alive bool // passed memory must not be freed (by GC) before function returns
371372
receiver StructField // TODO this is not a struct field
372373
receiver_pos token.Position // `(u User)` in `fn (u User) name()` position

vlib/v/markused/markused.v

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
103103
'os.init_os_args',
104104
'os.init_os_args_wide',
105105
]
106+
107+
if pref.is_bare {
108+
all_fn_root_names << [
109+
'strlen',
110+
'memcmp',
111+
'memcpy',
112+
'realloc',
113+
'vsnprintf',
114+
'vsprintf',
115+
]
116+
}
117+
106118
if pref.gc_mode in [.boehm_full_opt, .boehm_incr_opt] {
107119
all_fn_root_names << [
108120
'__new_array_noscan',
@@ -232,6 +244,7 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
232244
all_consts: all_consts
233245
}
234246
// println( all_fns.keys() )
247+
walker.mark_exported_fns()
235248
walker.mark_root_fns(all_fn_root_names)
236249

237250
if walker.n_asserts > 0 {

vlib/v/markused/walker.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ pub fn (mut w Walker) mark_root_fns(all_fn_root_names []string) {
4646
}
4747
}
4848

49+
pub fn (mut w Walker) mark_exported_fns() {
50+
for _, mut func in w.all_fns {
51+
if func.is_exported {
52+
w.fn_decl(mut func)
53+
}
54+
}
55+
}
56+
4957
pub fn (mut w Walker) stmt(node ast.Stmt) {
5058
match mut node {
5159
ast.EmptyStmt {}

vlib/v/parser/fn.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
180180
conditional_ctdefine := p.attrs.find_comptime_define() or { '' }
181181
mut is_unsafe := p.attrs.contains('unsafe')
182182
is_keep_alive := p.attrs.contains('keep_args_alive')
183+
is_exported := p.attrs.contains('export')
183184
is_pub := p.tok.kind == .key_pub
184185
if is_pub {
185186
p.next()
@@ -423,6 +424,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
423424
params: params
424425
is_manualfree: is_manualfree
425426
is_deprecated: is_deprecated
427+
is_exported: is_exported
426428
is_direct_arr: is_direct_arr
427429
is_pub: is_pub
428430
is_variadic: is_variadic

0 commit comments

Comments
 (0)