table: .is_used => .usages (a counter, instead of a boolean flag)

pull/8575/head
Delyan Angelov 2021-02-05 10:03:17 +02:00
parent 231182c3ff
commit 80697ec7f3
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 12 additions and 9 deletions

View File

@ -1799,7 +1799,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
call_expr.name = name_prefixed call_expr.name = name_prefixed
found = true found = true
f = f1 f = f1
c.table.fns[name_prefixed].is_used = true c.table.fns[name_prefixed].usages++
} }
} }
if !found && call_expr.left is ast.IndexExpr { if !found && call_expr.left is ast.IndexExpr {
@ -1833,7 +1833,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
if f1 := c.table.find_fn(fn_name) { if f1 := c.table.find_fn(fn_name) {
found = true found = true
f = f1 f = f1
c.table.fns[fn_name].is_used = true c.table.fns[fn_name].usages++
} }
} }
if c.pref.is_script && !found { if c.pref.is_script && !found {
@ -1845,7 +1845,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
call_expr.name = os_name call_expr.name = os_name
found = true found = true
f = f1 f = f1
c.table.fns[os_name].is_used = true c.table.fns[os_name].usages++
} }
} }
// check for arg (var) of fn type // check for arg (var) of fn type

View File

@ -26,13 +26,16 @@ fn (mut g Gen) gen_fn_decl(node ast.FnDecl, skip bool) {
return return
} }
} }
if f := g.table.find_fn(node.name) { */
if !f.is_used { if g.pref.experimental {
g.writeln('// fn $node.name UNUSED') if f := g.table.find_fn(node.name) {
// return println('> usages: ${f.usages:-10} | node.name: $node.name')
if f.usages == 0 {
g.writeln('// fn $node.name UNUSED')
return
}
} }
} }
*/
g.returned_var_name = '' g.returned_var_name = ''
// //

View File

@ -39,7 +39,7 @@ pub:
pub mut: pub mut:
name string name string
source_fn voidptr // set in the checker, while processing fn declarations source_fn voidptr // set in the checker, while processing fn declarations
is_used bool usages int
} }
fn (f &Fn) method_equals(o &Fn) bool { fn (f &Fn) method_equals(o &Fn) bool {