2022-01-04 10:21:08 +01:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
2021-02-13 16:36:14 +01:00
|
|
|
// Use of this source code is governed by an MIT license that can be found in the LICENSE file.
|
|
|
|
module markused
|
2021-02-05 09:42:52 +01:00
|
|
|
|
|
|
|
import v.ast
|
2021-02-05 15:34:56 +01:00
|
|
|
import v.util
|
2021-02-13 16:36:14 +01:00
|
|
|
import v.pref
|
2021-02-05 09:42:52 +01:00
|
|
|
|
|
|
|
// mark_used walks the AST, starting at main() and marks all used fns transitively
|
2021-05-22 17:59:17 +02:00
|
|
|
pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.File) {
|
2021-07-28 07:11:55 +02:00
|
|
|
mut all_fns, all_consts, all_globals := all_fn_const_and_global(ast_files)
|
2021-02-05 15:41:55 +01:00
|
|
|
util.timing_start(@METHOD)
|
2021-02-13 16:36:14 +01:00
|
|
|
defer {
|
|
|
|
util.timing_measure(@METHOD)
|
2021-02-06 08:34:01 +01:00
|
|
|
}
|
2021-02-07 00:01:37 +01:00
|
|
|
mut all_fn_root_names := [
|
2021-02-06 08:34:01 +01:00
|
|
|
'main.main',
|
|
|
|
'__new_array',
|
2021-05-24 04:20:45 +02:00
|
|
|
'str_intp',
|
|
|
|
'format_sb',
|
2021-02-06 08:34:01 +01:00
|
|
|
'__new_array_with_default',
|
2021-02-13 14:47:09 +01:00
|
|
|
'__new_array_with_array_default',
|
2021-05-19 09:35:56 +02:00
|
|
|
'v_realloc' /* needed for _STR */,
|
2021-06-13 05:26:43 +02:00
|
|
|
'malloc',
|
|
|
|
'malloc_noscan',
|
|
|
|
'vcalloc',
|
|
|
|
'vcalloc_noscan',
|
2021-02-06 08:34:01 +01:00
|
|
|
'new_array_from_c_array',
|
2021-02-22 13:54:24 +01:00
|
|
|
'v_fixed_index',
|
2021-02-06 08:34:01 +01:00
|
|
|
'memdup',
|
|
|
|
'vstrlen',
|
2021-02-13 15:08:44 +01:00
|
|
|
'__as_cast',
|
2021-02-06 08:34:01 +01:00
|
|
|
'tos',
|
2021-02-07 00:01:37 +01:00
|
|
|
'tos2',
|
|
|
|
'tos3',
|
2021-02-06 08:34:01 +01:00
|
|
|
'isnil',
|
2021-03-14 01:54:46 +01:00
|
|
|
'opt_ok',
|
|
|
|
'error',
|
2021-02-26 08:01:03 +01:00
|
|
|
// utf8_str_visible_length is used by c/str.v
|
2021-02-06 08:34:01 +01:00
|
|
|
'utf8_str_visible_length',
|
2021-02-13 14:47:09 +01:00
|
|
|
'compare_ints',
|
|
|
|
'compare_u64s',
|
|
|
|
'compare_strings',
|
|
|
|
'compare_ints_reverse',
|
|
|
|
'compare_u64s_reverse',
|
|
|
|
'compare_strings_reverse',
|
2021-02-06 08:34:01 +01:00
|
|
|
'builtin_init',
|
2021-02-26 08:01:03 +01:00
|
|
|
// byteptr and charptr
|
2021-02-06 08:34:01 +01:00
|
|
|
'3.vstring',
|
|
|
|
'3.vstring_with_len',
|
2021-08-13 17:37:34 +02:00
|
|
|
'3.vstring_literal',
|
2021-02-06 08:34:01 +01:00
|
|
|
'4.vstring',
|
|
|
|
'4.vstring_with_len',
|
2021-08-13 17:37:34 +02:00
|
|
|
'4.vstring_literal',
|
2021-02-26 08:01:03 +01:00
|
|
|
// byte. methods
|
2021-09-08 04:53:39 +02:00
|
|
|
'10.str_escaped',
|
2021-02-26 08:01:03 +01:00
|
|
|
// string. methods
|
2021-09-08 04:53:39 +02:00
|
|
|
'20.add',
|
|
|
|
'20.trim_space',
|
|
|
|
'20.repeat',
|
|
|
|
'20.replace',
|
|
|
|
'20.clone',
|
|
|
|
'20.clone_static',
|
|
|
|
'20.trim',
|
|
|
|
'20.substr',
|
|
|
|
'20.at',
|
|
|
|
'20.at_with_check',
|
|
|
|
'20.index_kmp',
|
2021-02-26 08:01:03 +01:00
|
|
|
// string. ==, !=, etc...
|
2021-09-08 04:53:39 +02:00
|
|
|
'20.eq',
|
|
|
|
'20.ne',
|
|
|
|
'20.lt',
|
|
|
|
'20.gt',
|
|
|
|
'20.le',
|
|
|
|
'20.ge',
|
2021-05-02 18:18:11 +02:00
|
|
|
'fast_string_eq',
|
2021-02-26 08:01:03 +01:00
|
|
|
// other array methods
|
2021-09-08 04:53:39 +02:00
|
|
|
'22.get',
|
|
|
|
'22.set',
|
|
|
|
'22.get_unsafe',
|
|
|
|
'22.set_unsafe',
|
|
|
|
'22.get_with_check' /* used for `x := a[i] or {}` */,
|
|
|
|
'22.clone_static_to_depth',
|
|
|
|
'22.clone_to_depth',
|
|
|
|
'22.first',
|
|
|
|
'22.last',
|
|
|
|
'22.pointers' /* TODO: handle generic methods calling array primitives more precisely in pool_test.v */,
|
|
|
|
'22.reverse',
|
|
|
|
'22.repeat_to_depth',
|
|
|
|
'22.slice',
|
|
|
|
'22.slice2',
|
|
|
|
'61.get',
|
|
|
|
'61.set',
|
|
|
|
'65558.last',
|
|
|
|
'65558.pop',
|
|
|
|
'65558.push',
|
|
|
|
'65558.insert_many',
|
|
|
|
'65558.prepend_many',
|
|
|
|
'65558.reverse',
|
|
|
|
'65558.set',
|
|
|
|
'65558.set_unsafe',
|
2021-02-26 08:01:03 +01:00
|
|
|
// TODO: process the _vinit const initializations automatically too
|
2021-07-27 11:36:40 +02:00
|
|
|
'json.decode_string',
|
|
|
|
'json.decode_int',
|
|
|
|
'json.decode_bool',
|
|
|
|
'json.decode_u64',
|
|
|
|
'json.encode_int',
|
|
|
|
'json.encode_string',
|
|
|
|
'json.encode_bool',
|
|
|
|
'json.encode_u64',
|
|
|
|
'json.json_print',
|
|
|
|
'json.json_parse',
|
2021-12-16 14:59:46 +01:00
|
|
|
'main.nasserts',
|
|
|
|
'main.vtest_init',
|
|
|
|
'main.vtest_new_metainfo',
|
|
|
|
'main.vtest_new_filemetainfo',
|
2021-02-06 08:34:01 +01:00
|
|
|
'os.getwd',
|
|
|
|
'os.init_os_args',
|
2021-02-13 15:33:30 +01:00
|
|
|
'os.init_os_args_wide',
|
2021-08-30 16:57:33 +02:00
|
|
|
'v.embed_file.find_index_entry_by_path',
|
2021-02-06 08:34:01 +01:00
|
|
|
]
|
2021-05-23 15:25:34 +02:00
|
|
|
|
|
|
|
if pref.is_bare {
|
|
|
|
all_fn_root_names << [
|
|
|
|
'strlen',
|
|
|
|
'memcmp',
|
|
|
|
'memcpy',
|
|
|
|
'realloc',
|
|
|
|
'vsnprintf',
|
|
|
|
'vsprintf',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-04-14 00:40:26 +02:00
|
|
|
if pref.gc_mode in [.boehm_full_opt, .boehm_incr_opt] {
|
|
|
|
all_fn_root_names << [
|
2021-06-10 20:26:17 +02:00
|
|
|
'memdup_noscan',
|
2021-04-14 00:40:26 +02:00
|
|
|
'__new_array_noscan',
|
|
|
|
'__new_array_with_default_noscan',
|
|
|
|
'__new_array_with_array_default_noscan',
|
|
|
|
'new_array_from_c_array_noscan',
|
2021-09-08 04:53:39 +02:00
|
|
|
'22.clone_static_to_depth_noscan',
|
|
|
|
'22.clone_to_depth_noscan',
|
|
|
|
'22.reverse_noscan',
|
|
|
|
'22.repeat_to_depth_noscan',
|
|
|
|
'65558.pop_noscan',
|
|
|
|
'65558.push_noscan',
|
|
|
|
'65558.push_many_noscan',
|
|
|
|
'65558.insert_noscan',
|
|
|
|
'65558.insert_many_noscan',
|
|
|
|
'65558.prepend_noscan',
|
|
|
|
'65558.prepend_many_noscan',
|
|
|
|
'65558.reverse_noscan',
|
|
|
|
'65558.grow_cap_noscan',
|
|
|
|
'65558.grow_len_noscan',
|
2021-04-14 00:40:26 +02:00
|
|
|
]
|
|
|
|
}
|
2021-02-07 00:01:37 +01:00
|
|
|
|
2021-04-09 19:03:22 +02:00
|
|
|
for k, mut mfn in all_fns {
|
2021-07-05 15:43:58 +02:00
|
|
|
$if trace_skip_unused_all_fns ? {
|
|
|
|
println('k: $k | mfn: $mfn.name')
|
|
|
|
}
|
2021-04-09 19:03:22 +02:00
|
|
|
mut method_receiver_typename := ''
|
|
|
|
if mfn.is_method {
|
|
|
|
method_receiver_typename = table.type_to_str(mfn.receiver.typ)
|
|
|
|
}
|
|
|
|
if method_receiver_typename == '&wyrand.WyRandRNG' {
|
|
|
|
// WyRandRNG is the default rand pseudo random generator
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if method_receiver_typename == '&strings.Builder' {
|
|
|
|
// implicit string builders are generated in auto_eq_methods.v
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
2021-06-01 12:37:37 +02:00
|
|
|
// auto generated string interpolation functions, may
|
|
|
|
// call .str or .auto_str methods for user types:
|
|
|
|
if k.ends_with('.str') || k.ends_with('.auto_str') {
|
2021-02-13 15:08:44 +01:00
|
|
|
all_fn_root_names << k
|
2021-04-09 19:03:22 +02:00
|
|
|
continue
|
2021-02-13 15:08:44 +01:00
|
|
|
}
|
2021-02-07 00:01:37 +01:00
|
|
|
if k.ends_with('.init') {
|
|
|
|
all_fn_root_names << k
|
2021-04-09 19:03:22 +02:00
|
|
|
continue
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
|
|
|
if k.ends_with('.free') {
|
|
|
|
all_fn_root_names << k
|
2021-04-09 19:03:22 +02:00
|
|
|
continue
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
2021-06-05 16:29:23 +02:00
|
|
|
|
2021-06-01 12:37:37 +02:00
|
|
|
// sync:
|
|
|
|
if k == 'sync.new_channel_st' {
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if k == 'sync.channel_select' {
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if method_receiver_typename == '&sync.Channel' {
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
2021-02-13 14:47:09 +01:00
|
|
|
if k.ends_with('.lock') || k.ends_with('.unlock') || k.ends_with('.rlock')
|
|
|
|
|| k.ends_with('.runlock') {
|
2021-02-07 00:01:37 +01:00
|
|
|
all_fn_root_names << k
|
2021-04-09 19:03:22 +02:00
|
|
|
continue
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
2021-10-27 16:07:10 +02:00
|
|
|
if mfn.receiver.typ != ast.void_type && mfn.receiver.typ.has_flag(.generic) {
|
|
|
|
// generic methods may be used in cgen after specialisation :-|
|
|
|
|
// TODO: move generic method specialisation from cgen to before markused
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
2021-06-01 12:37:37 +02:00
|
|
|
// testing framework:
|
2021-02-13 16:36:14 +01:00
|
|
|
if pref.is_test {
|
2021-02-13 14:47:09 +01:00
|
|
|
if k.starts_with('test_') || k.contains('.test_') {
|
|
|
|
all_fn_root_names << k
|
2021-04-09 19:03:22 +02:00
|
|
|
continue
|
2021-02-13 14:47:09 +01:00
|
|
|
}
|
|
|
|
if k.starts_with('testsuite_') || k.contains('.testsuite_') {
|
2021-04-09 19:03:22 +02:00
|
|
|
// eprintln('>>> test suite: $k')
|
2021-02-13 14:47:09 +01:00
|
|
|
all_fn_root_names << k
|
2021-04-09 19:03:22 +02:00
|
|
|
continue
|
2021-02-13 14:47:09 +01:00
|
|
|
}
|
|
|
|
}
|
2021-06-01 12:37:37 +02:00
|
|
|
// public/exported functions can not be skipped,
|
|
|
|
// especially when producing a shared library:
|
2021-04-12 08:24:07 +02:00
|
|
|
if mfn.is_pub && pref.is_shared {
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
2021-05-08 14:12:20 +02:00
|
|
|
if mfn.name in ['+', '-', '*', '%', '/', '<', '=='] {
|
|
|
|
// TODO: mark the used operators in the checker
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
2021-05-19 09:35:56 +02:00
|
|
|
if pref.prealloc && k.starts_with('prealloc_') {
|
|
|
|
all_fn_root_names << k
|
|
|
|
continue
|
|
|
|
}
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
2021-05-03 17:22:10 +02:00
|
|
|
|
|
|
|
// handle assertions and testing framework callbacks:
|
2021-02-13 16:36:14 +01:00
|
|
|
if pref.is_debug {
|
2021-02-07 00:01:37 +01:00
|
|
|
all_fn_root_names << 'panic_debug'
|
|
|
|
}
|
2021-03-24 12:16:36 +01:00
|
|
|
all_fn_root_names << 'panic_optional_not_set'
|
2021-02-13 16:36:14 +01:00
|
|
|
if pref.is_test {
|
2021-02-07 00:01:37 +01:00
|
|
|
all_fn_root_names << 'main.cb_assertion_ok'
|
|
|
|
all_fn_root_names << 'main.cb_assertion_failed'
|
2022-01-02 14:47:58 +01:00
|
|
|
if benched_tests_sym := table.find_sym('main.BenchedTests') {
|
2021-02-07 00:01:37 +01:00
|
|
|
bts_type := benched_tests_sym.methods[0].params[0].typ
|
|
|
|
all_fn_root_names << '${bts_type}.testing_step_start'
|
|
|
|
all_fn_root_names << '${bts_type}.testing_step_end'
|
|
|
|
all_fn_root_names << '${bts_type}.end_testing'
|
|
|
|
all_fn_root_names << 'main.start_testing'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-03 17:22:10 +02:00
|
|
|
// handle interface implementation methods:
|
|
|
|
for isym in table.type_symbols {
|
|
|
|
if isym.kind != .interface_ {
|
|
|
|
continue
|
|
|
|
}
|
2021-12-15 12:30:21 +01:00
|
|
|
if isym.info !is ast.Interface {
|
|
|
|
// Do not remove this check, isym.info could be &IError.
|
|
|
|
continue
|
|
|
|
}
|
2021-05-03 17:22:10 +02:00
|
|
|
interface_info := isym.info as ast.Interface
|
|
|
|
if interface_info.methods.len == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for itype in interface_info.types {
|
2021-10-18 07:43:56 +02:00
|
|
|
ptype := itype.set_nr_muls(1)
|
|
|
|
ntype := itype.set_nr_muls(0)
|
|
|
|
interface_types := [ptype, ntype]
|
2021-05-03 17:22:10 +02:00
|
|
|
for method in interface_info.methods {
|
2021-10-18 07:43:56 +02:00
|
|
|
for typ in interface_types {
|
2021-08-01 14:50:11 +02:00
|
|
|
interface_implementation_method_name := '${int(typ)}.$method.name'
|
|
|
|
$if trace_skip_unused_interface_methods ? {
|
|
|
|
eprintln('>> isym.name: $isym.name | interface_implementation_method_name: $interface_implementation_method_name')
|
|
|
|
}
|
|
|
|
all_fn_root_names << interface_implementation_method_name
|
2021-05-04 18:04:25 +02:00
|
|
|
}
|
2021-05-03 17:22:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle vweb magic router methods:
|
|
|
|
typ_vweb_result := table.find_type_idx('vweb.Result')
|
|
|
|
if typ_vweb_result != 0 {
|
2021-07-27 14:42:25 +02:00
|
|
|
all_fn_root_names << 'vweb.filter'
|
|
|
|
typ_vweb_context := ast.Type(table.find_type_idx('vweb.Context')).set_nr_muls(1)
|
|
|
|
all_fn_root_names << '${int(typ_vweb_context)}.html'
|
2021-05-03 17:22:10 +02:00
|
|
|
for vgt in table.used_vweb_types {
|
2021-12-19 17:25:18 +01:00
|
|
|
sym_app := table.sym(vgt)
|
2021-05-03 17:22:10 +02:00
|
|
|
for m in sym_app.methods {
|
|
|
|
if m.return_type == typ_vweb_result {
|
|
|
|
pvgt := vgt.set_nr_muls(1)
|
2021-05-04 18:04:25 +02:00
|
|
|
// eprintln('vgt: $vgt | pvgt: $pvgt | sym_app.name: $sym_app.name | m.name: $m.name')
|
2021-07-27 14:42:25 +02:00
|
|
|
all_fn_root_names << '${int(pvgt)}.$m.name'
|
2021-05-03 17:22:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:42:25 +02:00
|
|
|
// handle ORM drivers:
|
|
|
|
orm_connection_implementations := table.iface_types['orm.Connection'] or { []ast.Type{} }
|
|
|
|
if orm_connection_implementations.len > 0 {
|
|
|
|
for k, _ in all_fns {
|
|
|
|
if k.starts_with('orm.') {
|
|
|
|
all_fn_root_names << k
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for orm_type in orm_connection_implementations {
|
|
|
|
all_fn_root_names << '${int(orm_type)}.select'
|
|
|
|
all_fn_root_names << '${int(orm_type)}.insert'
|
|
|
|
all_fn_root_names << '${int(orm_type)}.update'
|
|
|
|
all_fn_root_names << '${int(orm_type)}.delete'
|
|
|
|
all_fn_root_names << '${int(orm_type)}.create'
|
|
|
|
all_fn_root_names << '${int(orm_type)}.drop'
|
|
|
|
all_fn_root_names << '${int(orm_type)}.last_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle -live main programs:
|
|
|
|
if pref.is_livemain {
|
|
|
|
all_fn_root_names << 'v.live.executable.start_reloader'
|
|
|
|
all_fn_root_names << 'v.live.executable.new_live_reload_info'
|
|
|
|
}
|
2021-05-03 17:22:10 +02:00
|
|
|
|
2021-02-13 16:36:14 +01:00
|
|
|
mut walker := Walker{
|
2021-04-09 19:03:22 +02:00
|
|
|
table: table
|
2021-02-07 00:01:37 +01:00
|
|
|
files: ast_files
|
|
|
|
all_fns: all_fns
|
|
|
|
all_consts: all_consts
|
2021-07-28 07:11:55 +02:00
|
|
|
all_globals: all_globals
|
2021-07-25 00:13:34 +02:00
|
|
|
pref: pref
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
|
|
|
// println( all_fns.keys() )
|
2021-12-15 13:34:49 +01:00
|
|
|
walker.mark_markused_fns() // tagged with `[markused]`
|
|
|
|
walker.mark_markused_consts() // tagged with `[markused]`
|
|
|
|
walker.mark_markused_globals() // tagged with `[markused]`
|
2021-05-23 15:25:34 +02:00
|
|
|
walker.mark_exported_fns()
|
2021-02-07 00:01:37 +01:00
|
|
|
walker.mark_root_fns(all_fn_root_names)
|
|
|
|
|
|
|
|
if walker.n_asserts > 0 {
|
|
|
|
walker.fn_decl(mut all_fns['__print_assert_failure'])
|
|
|
|
}
|
2021-06-05 16:29:23 +02:00
|
|
|
if table.used_maps > 0 {
|
2021-02-07 00:01:37 +01:00
|
|
|
for k, mut mfn in all_fns {
|
2021-04-09 19:03:22 +02:00
|
|
|
mut method_receiver_typename := ''
|
|
|
|
if mfn.is_method {
|
|
|
|
method_receiver_typename = table.type_to_str(mfn.receiver.typ)
|
|
|
|
}
|
2021-04-10 04:00:29 +02:00
|
|
|
if k in ['new_map', 'new_map_init', 'map_hash_string']
|
2021-04-09 19:03:22 +02:00
|
|
|
|| method_receiver_typename == '&map' || method_receiver_typename == '&DenseArray'
|
|
|
|
|| k.starts_with('map_') {
|
2021-02-07 00:01:37 +01:00
|
|
|
walker.fn_decl(mut mfn)
|
|
|
|
}
|
2021-06-14 17:12:47 +02:00
|
|
|
if pref.gc_mode in [.boehm_full_opt, .boehm_incr_opt] {
|
|
|
|
if k in ['new_map_noscan_key', 'new_map_noscan_value', 'new_map_noscan_key_value',
|
|
|
|
'new_map_init_noscan_key', 'new_map_init_noscan_value',
|
2021-09-21 15:20:09 +02:00
|
|
|
'new_map_init_noscan_key_value'] {
|
2021-06-14 17:12:47 +02:00
|
|
|
walker.fn_decl(mut mfn)
|
|
|
|
}
|
|
|
|
}
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
2021-06-05 16:29:23 +02:00
|
|
|
} else {
|
|
|
|
for map_fn_name in ['new_map', 'new_map_init', 'map_hash_string', 'new_dense_array'] {
|
|
|
|
walker.used_fns.delete(map_fn_name)
|
|
|
|
}
|
|
|
|
for k, mut mfn in all_fns {
|
|
|
|
if !mfn.is_method {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
method_receiver_typename := table.type_to_str(mfn.receiver.typ)
|
|
|
|
if method_receiver_typename in ['&map', '&mapnode', '&SortedMap', '&DenseArray'] {
|
|
|
|
walker.used_fns.delete(k)
|
|
|
|
}
|
|
|
|
}
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$if trace_skip_unused_fn_names ? {
|
2021-02-06 08:34:01 +01:00
|
|
|
for key, _ in walker.used_fns {
|
|
|
|
println('> used fn key: $key')
|
|
|
|
}
|
2021-02-05 09:42:52 +01:00
|
|
|
}
|
|
|
|
|
2021-12-16 14:59:46 +01:00
|
|
|
for kcon, con in all_consts {
|
|
|
|
if pref.is_shared && con.is_pub {
|
|
|
|
walker.mark_const_as_used(kcon)
|
|
|
|
}
|
|
|
|
if !pref.is_shared && con.is_pub && con.name.starts_with('main.') {
|
|
|
|
walker.mark_const_as_used(kcon)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 19:03:22 +02:00
|
|
|
table.used_fns = walker.used_fns.move()
|
|
|
|
table.used_consts = walker.used_consts.move()
|
2021-07-28 07:11:55 +02:00
|
|
|
table.used_globals = walker.used_globals.move()
|
2021-02-05 09:42:52 +01:00
|
|
|
|
2021-02-07 00:01:37 +01:00
|
|
|
$if trace_skip_unused ? {
|
2021-04-09 19:03:22 +02:00
|
|
|
eprintln('>> t.used_fns: $table.used_fns.keys()')
|
|
|
|
eprintln('>> t.used_consts: $table.used_consts.keys()')
|
2021-07-28 07:11:55 +02:00
|
|
|
eprintln('>> t.used_globals: $table.used_globals.keys()')
|
2021-06-05 17:26:56 +02:00
|
|
|
eprintln('>> walker.table.used_maps: $walker.table.used_maps')
|
2021-02-07 00:01:37 +01:00
|
|
|
}
|
2021-02-13 16:36:14 +01:00
|
|
|
}
|
|
|
|
|
2021-07-28 07:11:55 +02:00
|
|
|
fn all_fn_const_and_global(ast_files []&ast.File) (map[string]ast.FnDecl, map[string]ast.ConstField, map[string]ast.GlobalField) {
|
2021-02-13 16:36:14 +01:00
|
|
|
util.timing_start(@METHOD)
|
|
|
|
defer {
|
|
|
|
util.timing_measure(@METHOD)
|
|
|
|
}
|
|
|
|
mut all_fns := map[string]ast.FnDecl{}
|
|
|
|
mut all_consts := map[string]ast.ConstField{}
|
2021-07-28 07:11:55 +02:00
|
|
|
mut all_globals := map[string]ast.GlobalField{}
|
2021-02-13 16:36:14 +01:00
|
|
|
for i in 0 .. ast_files.len {
|
2021-05-22 17:59:17 +02:00
|
|
|
file := ast_files[i]
|
2021-02-13 16:36:14 +01:00
|
|
|
for node in file.stmts {
|
|
|
|
match node {
|
|
|
|
ast.FnDecl {
|
2021-07-24 09:25:16 +02:00
|
|
|
fkey := node.fkey()
|
2021-02-13 16:36:14 +01:00
|
|
|
all_fns[fkey] = node
|
|
|
|
}
|
|
|
|
ast.ConstDecl {
|
|
|
|
for cfield in node.fields {
|
|
|
|
ckey := cfield.name
|
|
|
|
all_consts[ckey] = cfield
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 07:11:55 +02:00
|
|
|
ast.GlobalDecl {
|
|
|
|
for gfield in node.fields {
|
|
|
|
gkey := gfield.name
|
|
|
|
all_globals[gkey] = gfield
|
|
|
|
}
|
|
|
|
}
|
2021-02-13 16:36:14 +01:00
|
|
|
else {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 07:11:55 +02:00
|
|
|
return all_fns, all_consts, all_globals
|
2021-02-05 09:42:52 +01:00
|
|
|
}
|