Skip to content

Commit

Permalink
markused: make work with json
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Nov 25, 2024
1 parent 95e5ba4 commit c03b4f6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/tools/vcover/cover_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ fn np(path string) string {
}

fn test_simple() {
// if true {
// return
//}

t1 := np(os.join_path(tfolder, 't1'))
t2 := np(os.join_path(tfolder, 't2'))
t3 := np(os.join_path(tfolder, 't3'))
Expand Down
1 change: 1 addition & 0 deletions vlib/builtin/map.v
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ fn map_free_string(pkey voidptr) {
fn map_free_nop(_ voidptr) {
}

@[markused]
fn new_map(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn) map {
metasize := int(sizeof(u32) * (init_capicity + extra_metas_inc))
// for now assume anything bigger than a pointer is a string
Expand Down
3 changes: 2 additions & 1 deletion vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mut:
used_veb_types []Type // veb context types, filled in by checker
used_maps int // how many times maps were used, filled in by markused
used_arrays int // how many times arrays were used, filled in by markused
// json bool // json is imported
}

@[unsafe]
Expand Down Expand Up @@ -65,7 +66,7 @@ pub mut:
sumtypes map[int]SumTypeDecl
cmod_prefix string // needed for ast.type_to_str(Type) while vfmt; contains `os.`
is_fmt bool
used_features &UsedFeatures = &UsedFeatures{} // filled in by the checker/markused, when pref.skip_unused = true;
used_features &UsedFeatures = &UsedFeatures{} // filled in by the builder via markused module, when pref.skip_unused = true;
veb_res_idx_cache int // Cache of `veb.Result` type
veb_ctx_idx_cache int // Cache of `veb.Context` type
panic_handler FnPanicHandler = default_table_panic_handler
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/markused/markused.v
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
all_fn_root_names << k
continue
}
// if mfn.name == 'before_request' {
// all_fn_root_names << k
//}

// sync:
if k == 'sync.new_channel_st' {
Expand Down Expand Up @@ -338,6 +341,8 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a

if 'C.cJSON_Parse' in all_fns {
all_fn_root_names << 'tos5'
all_fn_root_names << 'time.unix' // used by json
table.used_features.used_maps++ // json needs new_map etc
}
mut walker := Walker.new(
table: table
Expand All @@ -349,6 +354,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
)
// println( all_fns.keys() )
walker.mark_markused_fns() // tagged with `@[markused]`

walker.mark_markused_consts() // tagged with `@[markused]`
walker.mark_markused_globals() // tagged with `@[markused]`
walker.mark_exported_fns()
Expand Down Expand Up @@ -405,6 +411,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
walker.mark_const_as_used(kcon)
}
}

table.used_features.used_fns = walker.used_fns.move()
table.used_features.used_consts = walker.used_consts.move()
table.used_features.used_globals = walker.used_globals.move()
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.use_cache = true
res.skip_unused = true
} */
mut no_skip_unused := false

mut command, mut command_idx := '', 0
for i := 0; i < args.len; i++ {
Expand Down Expand Up @@ -602,6 +603,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.skip_unused = true
}
'-no-skip-unused' {
no_skip_unused = true
res.skip_unused = false
}
'-compress' {
Expand Down Expand Up @@ -1134,6 +1136,13 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.build_options = m.keys()
// eprintln('>> res.build_options: $res.build_options')
res.fill_with_defaults()
if res.backend == .c {
// res.skip_unused = true
if no_skip_unused {
res.skip_unused = false
}
}

return res, command
}

Expand Down

0 comments on commit c03b4f6

Please sign in to comment.