aboutsummaryrefslogtreecommitdiffstats
path: root/prog/size.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-05-14 15:45:36 +0200
committerDmitry Vyukov <dvyukov@google.com>2019-05-14 19:28:01 +0200
commit9a4969814ea6a65b306ca7d3192c23381c778ad4 (patch)
treefde0c7de13aee6c47838a6b7a55e8145b3e068b6 /prog/size.go
parent30e50d7959d0256b284225900da6a0e132412f7d (diff)
pkg/compiler: refactor len target checking
Create named const for "parent" and move some code into a helper function.
Diffstat (limited to 'prog/size.go')
-rw-r--r--prog/size.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/prog/size.go b/prog/size.go
index 46afbd426..ab8e69292 100644
--- a/prog/size.go
+++ b/prog/size.go
@@ -8,6 +8,11 @@ import (
"strings"
)
+const (
+ // Special reference to the outer struct used in len targets.
+ ParentRef = "parent"
+)
+
func (target *Target) assignSizes(args []Arg, parentsMap map[Arg]Arg, autos map[Arg]bool) {
for _, arg := range args {
if arg = InnerArg(arg); arg == nil {
@@ -43,12 +48,12 @@ func (target *Target) assignSize(dst *ConstArg, pos Arg, path []string, args []A
}
return
}
- if elem == "parent" {
+ if elem == ParentRef {
buf := parentsMap[pos]
if len(path) == 0 {
dst.Val = target.computeSize(buf, dst.Type().(*LenType))
} else {
- if path[0] == "parent" {
+ if path[0] == ParentRef {
buf = parentsMap[buf]
}
target.assignSize(dst, buf, path, buf.(*GroupArg).Inner, parentsMap)