@@ -80,6 +80,12 @@ pub fn (mut w Walker) mark_global_as_used(ckey string) {
80
80
w.used_globals[ckey] = true
81
81
gfield := w.all_globals[ckey] or { return }
82
82
w.expr (gfield.expr)
83
+ if ! gfield.has_expr && gfield.typ != 0 {
84
+ sym := w.table.sym (gfield.typ)
85
+ if sym.info is ast.Struct {
86
+ w.a_struct_info (sym.name, sym.info)
87
+ }
88
+ }
83
89
}
84
90
85
91
pub fn (mut w Walker) mark_root_fns (all_fn_root_names []string ) {
@@ -434,6 +440,9 @@ fn (mut w Walker) expr(node_ ast.Expr) {
434
440
ast.MapInit {
435
441
w.exprs (node.keys)
436
442
w.exprs (node.vals)
443
+ if node.has_update_expr {
444
+ w.expr (node.update_expr)
445
+ }
437
446
w.features.used_maps++
438
447
}
439
448
ast.MatchExpr {
@@ -489,9 +498,8 @@ fn (mut w Walker) expr(node_ ast.Expr) {
489
498
return
490
499
}
491
500
sym := w.table.sym (node.typ)
492
- if sym.kind == .struct {
493
- info := sym.info as ast.Struct
494
- w.a_struct_info (sym.name, info)
501
+ if sym.info is ast.Struct {
502
+ w.a_struct_info (sym.name, sym.info)
495
503
}
496
504
if node.has_update_expr {
497
505
w.expr (node.update_expr)
@@ -557,15 +565,40 @@ pub fn (mut w Walker) a_struct_info(sname string, info ast.Struct) {
557
565
}
558
566
if ifield.typ != 0 {
559
567
fsym := w.table.sym (ifield.typ)
560
- if fsym.kind == .map {
561
- w.features.used_maps++
562
- } else if fsym.kind == .array {
563
- w.features.used_arrays++
564
- } else if fsym.kind == .struct {
565
- w.a_struct_info (fsym.name, fsym.struct_info ())
568
+ match fsym.info {
569
+ ast.Struct {
570
+ w.a_struct_info (fsym.name, fsym.info)
571
+ }
572
+ ast.Alias {
573
+ value_sym := w.table.final_sym (ifield.typ)
574
+ if value_sym.info is ast.Struct {
575
+ w.a_struct_info (value_sym.name, value_sym.info)
576
+ }
577
+ }
578
+ ast.Array, ast.ArrayFixed {
579
+ w.features.used_arrays++
580
+ value_sym := w.table.final_sym (w.table.value_type (ifield.typ))
581
+ if value_sym.info is ast.Struct {
582
+ w.a_struct_info (value_sym.name, value_sym.info)
583
+ }
584
+ }
585
+ ast.Map {
586
+ w.features.used_maps++
587
+ value_sym := w.table.final_sym (w.table.value_type (ifield.typ))
588
+ if value_sym.info is ast.Struct {
589
+ w.a_struct_info (value_sym.name, value_sym.info)
590
+ }
591
+ }
592
+ else {}
566
593
}
567
594
}
568
595
}
596
+ for embed in info.embeds {
597
+ sym := w.table.final_sym (embed)
598
+ if sym.info is ast.Struct {
599
+ w.a_struct_info (sym.name, sym.info)
600
+ }
601
+ }
569
602
}
570
603
571
604
pub fn (mut w Walker) fn_decl (mut node ast.FnDecl) {
@@ -595,10 +628,13 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
595
628
if node.is_method && node.left_type != 0 {
596
629
left_sym := w.table.sym (node.left_type)
597
630
if left_sym.info is ast.Aggregate {
598
- for types in left_sym.info.types {
599
- fn_name := '${types.idx()} .${node.name} '
600
- if ! w.used_fns[fn_name] {
601
- w.mark_aggregate_call_used (fn_name, types)
631
+ for receiver_type in left_sym.info.types {
632
+ receiver_sym := w.table.sym (receiver_type)
633
+ if m := receiver_sym.find_method (node.name) {
634
+ fn_name := '${int(m.receiver_type)} .${node.name} '
635
+ if ! w.used_fns[fn_name] {
636
+ w.fn_by_name (fn_name)
637
+ }
602
638
}
603
639
}
604
640
} else if left_sym.info is ast.Interface {
@@ -612,6 +648,13 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
612
648
w.fn_by_name (fn_embed)
613
649
}
614
650
}
651
+ } else if node.from_embed_types.len != 0 && ! node.left_type.has_flag (.generic) {
652
+ _ , embed_types := w.table.find_method_from_embeds (w.table.final_sym (node.left_type),
653
+ node.name) or { ast.Fn{}, []ast.Type{} }
654
+ if embed_types.len != 0 {
655
+ fn_embed := '${int(embed_types.last())} .${node.name} '
656
+ w.fn_by_name (fn_embed)
657
+ }
615
658
}
616
659
}
617
660
w.expr (node.left)
@@ -639,6 +682,8 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
639
682
if const_fn_name in w.all_consts {
640
683
w.mark_const_as_used (const_fn_name)
641
684
}
685
+ } else if node.is_fn_var {
686
+ w.mark_global_as_used (node.name)
642
687
}
643
688
w.mark_fn_as_used (fn_name)
644
689
if node.is_method && node.receiver_type.has_flag (.generic) && node.receiver_concrete_type != 0
@@ -656,16 +701,6 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
656
701
}
657
702
}
658
703
659
- // visit aggregate type method declaration
660
- pub fn (mut w Walker) mark_aggregate_call_used (fn_name string , left_type ast.Type) {
661
- if w.used_fns[fn_name] {
662
- return
663
- }
664
- w.mark_fn_as_used (fn_name)
665
- stmt := w.all_fns[fn_name] or { return }
666
- w.stmts (stmt.stmts)
667
- }
668
-
669
704
pub fn (mut w Walker) fn_by_name (fn_name string ) {
670
705
if w.used_fns[fn_name] {
671
706
return
0 commit comments