checker: fix -skip-unused with struct inits with default expressions
parent
eb7009b60a
commit
4646c414d8
|
@ -131,6 +131,7 @@ fn (mut c Checker) mark_used(ast_files []ast.File) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mut walker := mark_used_walker.Walker{
|
mut walker := mark_used_walker.Walker{
|
||||||
|
table: c.table
|
||||||
files: ast_files
|
files: ast_files
|
||||||
all_fns: all_fns
|
all_fns: all_fns
|
||||||
all_consts: all_consts
|
all_consts: all_consts
|
||||||
|
|
|
@ -5,9 +5,11 @@ module mark_used_walker
|
||||||
// This module walks the entire program starting at fn main and marks used (called) functions.
|
// This module walks the entire program starting at fn main and marks used (called) functions.
|
||||||
// Unused functions can be safely skipped by the backends to save CPU time and space.
|
// Unused functions can be safely skipped by the backends to save CPU time and space.
|
||||||
import v.ast
|
import v.ast
|
||||||
|
import v.table
|
||||||
|
|
||||||
pub struct Walker {
|
pub struct Walker {
|
||||||
pub mut:
|
pub mut:
|
||||||
|
table &table.Table
|
||||||
used_fns map[string]bool // used_fns['println'] == true
|
used_fns map[string]bool // used_fns['println'] == true
|
||||||
used_consts map[string]bool // used_consts['os.args'] == true
|
used_consts map[string]bool // used_consts['os.args'] == true
|
||||||
n_maps int
|
n_maps int
|
||||||
|
@ -258,8 +260,19 @@ fn (mut w Walker) expr(node ast.Expr) {
|
||||||
w.expr(node.where_expr)
|
w.expr(node.where_expr)
|
||||||
}
|
}
|
||||||
ast.StructInit {
|
ast.StructInit {
|
||||||
// eprintln('>>>> ast.StructInit: $node')
|
sym := w.table.get_type_symbol(node.typ)
|
||||||
w.expr(node.update_expr)
|
if sym.kind == .struct_ {
|
||||||
|
info := sym.info as table.Struct
|
||||||
|
for ifield in info.fields {
|
||||||
|
if ifield.has_default_expr {
|
||||||
|
defex := ast.fe2ex(ifield.default_expr)
|
||||||
|
w.expr(defex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.has_update_expr {
|
||||||
|
w.expr(node.update_expr)
|
||||||
|
}
|
||||||
for sif in node.fields {
|
for sif in node.fields {
|
||||||
w.expr(sif.expr)
|
w.expr(sif.expr)
|
||||||
}
|
}
|
||||||
|
@ -321,13 +334,13 @@ pub fn (mut w Walker) fn_decl(mut node ast.FnDecl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
|
pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
|
||||||
|
for arg in node.args {
|
||||||
|
w.expr(arg.expr)
|
||||||
|
}
|
||||||
if node.language == .c {
|
if node.language == .c {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.expr(node.left)
|
w.expr(node.left)
|
||||||
for arg in node.args {
|
|
||||||
w.expr(arg.expr)
|
|
||||||
}
|
|
||||||
w.or_block(node.or_block)
|
w.or_block(node.or_block)
|
||||||
//
|
//
|
||||||
fn_name := if node.is_method { node.receiver_type.str() + '.' + node.name } else { node.name }
|
fn_name := if node.is_method { node.receiver_type.str() + '.' + node.name } else { node.name }
|
||||||
|
|
Loading…
Reference in New Issue