Skip to content

Commit c03b4f6

Browse files
committed
markused: make work with json
1 parent 95e5ba4 commit c03b4f6

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

cmd/tools/vcover/cover_test.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ fn np(path string) string {
3434
}
3535

3636
fn test_simple() {
37+
// if true {
38+
// return
39+
//}
40+
3741
t1 := np(os.join_path(tfolder, 't1'))
3842
t2 := np(os.join_path(tfolder, 't2'))
3943
t3 := np(os.join_path(tfolder, 't3'))

vlib/builtin/map.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ fn map_free_string(pkey voidptr) {
259259
fn map_free_nop(_ voidptr) {
260260
}
261261

262+
@[markused]
262263
fn new_map(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn) map {
263264
metasize := int(sizeof(u32) * (init_capicity + extra_metas_inc))
264265
// for now assume anything bigger than a pointer is a string

vlib/v/ast/table.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mut:
3232
used_veb_types []Type // veb context types, filled in by checker
3333
used_maps int // how many times maps were used, filled in by markused
3434
used_arrays int // how many times arrays were used, filled in by markused
35+
// json bool // json is imported
3536
}
3637

3738
@[unsafe]
@@ -65,7 +66,7 @@ pub mut:
6566
sumtypes map[int]SumTypeDecl
6667
cmod_prefix string // needed for ast.type_to_str(Type) while vfmt; contains `os.`
6768
is_fmt bool
68-
used_features &UsedFeatures = &UsedFeatures{} // filled in by the checker/markused, when pref.skip_unused = true;
69+
used_features &UsedFeatures = &UsedFeatures{} // filled in by the builder via markused module, when pref.skip_unused = true;
6970
veb_res_idx_cache int // Cache of `veb.Result` type
7071
veb_ctx_idx_cache int // Cache of `veb.Context` type
7172
panic_handler FnPanicHandler = default_table_panic_handler

vlib/v/markused/markused.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
196196
all_fn_root_names << k
197197
continue
198198
}
199+
// if mfn.name == 'before_request' {
200+
// all_fn_root_names << k
201+
//}
199202

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

339342
if 'C.cJSON_Parse' in all_fns {
340343
all_fn_root_names << 'tos5'
344+
all_fn_root_names << 'time.unix' // used by json
345+
table.used_features.used_maps++ // json needs new_map etc
341346
}
342347
mut walker := Walker.new(
343348
table: table
@@ -349,6 +354,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
349354
)
350355
// println( all_fns.keys() )
351356
walker.mark_markused_fns() // tagged with `@[markused]`
357+
352358
walker.mark_markused_consts() // tagged with `@[markused]`
353359
walker.mark_markused_globals() // tagged with `@[markused]`
354360
walker.mark_exported_fns()
@@ -405,6 +411,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
405411
walker.mark_const_as_used(kcon)
406412
}
407413
}
414+
408415
table.used_features.used_fns = walker.used_fns.move()
409416
table.used_features.used_consts = walker.used_consts.move()
410417
table.used_features.used_globals = walker.used_globals.move()

vlib/v/pref/pref.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
335335
res.use_cache = true
336336
res.skip_unused = true
337337
} */
338+
mut no_skip_unused := false
338339

339340
mut command, mut command_idx := '', 0
340341
for i := 0; i < args.len; i++ {
@@ -602,6 +603,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
602603
res.skip_unused = true
603604
}
604605
'-no-skip-unused' {
606+
no_skip_unused = true
605607
res.skip_unused = false
606608
}
607609
'-compress' {
@@ -1134,6 +1136,13 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
11341136
res.build_options = m.keys()
11351137
// eprintln('>> res.build_options: $res.build_options')
11361138
res.fill_with_defaults()
1139+
if res.backend == .c {
1140+
// res.skip_unused = true
1141+
if no_skip_unused {
1142+
res.skip_unused = false
1143+
}
1144+
}
1145+
11371146
return res, command
11381147
}
11391148

0 commit comments

Comments
 (0)