v.markused: support `./v -skip-unused -freestanding run vlib/os/bare/bare_example_linux.v` too

pull/10182/head
Delyan Angelov 2021-05-23 16:25:34 +03:00
parent 5efd8c62d0
commit bf3af40f13
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 24 additions and 0 deletions

View File

@ -367,6 +367,7 @@ pub:
is_main bool // true for `fn main()`
is_test bool // true for `fn test_abcde`
is_conditional bool // true for `[if abc] fn abc(){}`
is_exported bool // true for `[export: 'exact_C_name']`
is_keep_alive bool // passed memory must not be freed (by GC) before function returns
receiver StructField // TODO this is not a struct field
receiver_pos token.Position // `(u User)` in `fn (u User) name()` position

View File

@ -103,6 +103,18 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
'os.init_os_args',
'os.init_os_args_wide',
]
if pref.is_bare {
all_fn_root_names << [
'strlen',
'memcmp',
'memcpy',
'realloc',
'vsnprintf',
'vsprintf',
]
}
if pref.gc_mode in [.boehm_full_opt, .boehm_incr_opt] {
all_fn_root_names << [
'__new_array_noscan',
@ -232,6 +244,7 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
all_consts: all_consts
}
// println( all_fns.keys() )
walker.mark_exported_fns()
walker.mark_root_fns(all_fn_root_names)
if walker.n_asserts > 0 {

View File

@ -46,6 +46,14 @@ pub fn (mut w Walker) mark_root_fns(all_fn_root_names []string) {
}
}
pub fn (mut w Walker) mark_exported_fns() {
for _, mut func in w.all_fns {
if func.is_exported {
w.fn_decl(mut func)
}
}
}
pub fn (mut w Walker) stmt(node ast.Stmt) {
match mut node {
ast.EmptyStmt {}

View File

@ -180,6 +180,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
conditional_ctdefine := p.attrs.find_comptime_define() or { '' }
mut is_unsafe := p.attrs.contains('unsafe')
is_keep_alive := p.attrs.contains('keep_args_alive')
is_exported := p.attrs.contains('export')
is_pub := p.tok.kind == .key_pub
if is_pub {
p.next()
@ -423,6 +424,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
params: params
is_manualfree: is_manualfree
is_deprecated: is_deprecated
is_exported: is_exported
is_direct_arr: is_direct_arr
is_pub: is_pub
is_variadic: is_variadic