diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-04-25 07:40:50 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-04-25 07:40:50 +0200 |
| commit | a113ba3838a191c8d2aeb531731af5cb31aa6e26 (patch) | |
| tree | d350cdedc14e5f06e2a810ba581cc5938b96167d | |
| parent | 3e9855a1768604bcb70da0d76a57b16a54848855 (diff) | |
prog: dedup code in ForeachType
| -rw-r--r-- | prog/types.go | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/prog/types.go b/prog/types.go index f07de2b16..4fd602c87 100644 --- a/prog/types.go +++ b/prog/types.go @@ -634,8 +634,17 @@ type ConstValue struct { } func ForeachType(meta *Syscall, f func(Type)) { - seen := make(map[*StructDesc]bool) var rec func(t Type) + seen := make(map[*StructDesc]bool) + recStruct := func(desc *StructDesc) { + if seen[desc] { + return // prune recursion via pointers to structs/unions + } + seen[desc] = true + for _, f := range desc.Fields { + rec(f) + } + } rec = func(t Type) { f(t) switch a := t.(type) { @@ -644,21 +653,9 @@ func ForeachType(meta *Syscall, f func(Type)) { case *ArrayType: rec(a.Type) case *StructType: - if seen[a.StructDesc] { - return // prune recursion via pointers to structs/unions - } - seen[a.StructDesc] = true - for _, f := range a.Fields { - rec(f) - } + recStruct(a.StructDesc) case *UnionType: - if seen[a.StructDesc] { - return // prune recursion via pointers to structs/unions - } - seen[a.StructDesc] = true - for _, opt := range a.Fields { - rec(opt) - } + recStruct(a.StructDesc) case *ResourceType, *BufferType, *VmaType, *LenType, *FlagsType, *ConstType, *IntType, *ProcType, *CsumType: default: |
