From bc734e7ada413654f1b7d948b2a857260a52dd9c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 1 May 2020 13:05:28 +0200 Subject: prog: rename {PtrType,ArrayType}.Type to Elem Name "Type" is confusing when referring to pointer/array element type. Frequently there are too many Type/typ/typ1/t and typ.Type is not very informative. It _is_ a type, but what's usually more relevant is that it's an _element_ type. Let's leave type checking to compiler and give it a more meaningful name. --- pkg/compiler/gen.go | 16 ++++++++-------- pkg/compiler/types.go | 4 ++-- pkg/host/syscalls_linux.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'pkg') diff --git a/pkg/compiler/gen.go b/pkg/compiler/gen.go index 61dd85eae..07f35d71f 100644 --- a/pkg/compiler/gen.go +++ b/pkg/compiler/gen.go @@ -179,9 +179,9 @@ func (comp *compiler) collectTypes(proxies map[string]*typeProxy, tptr *prog.Typ typ := *tptr switch t := typ.(type) { case *prog.PtrType: - comp.collectTypes(proxies, &t.Type) + comp.collectTypes(proxies, &t.Elem) case *prog.ArrayType: - comp.collectTypes(proxies, &t.Type) + comp.collectTypes(proxies, &t.Elem) case *prog.ResourceType, *prog.BufferType, *prog.VmaType, *prog.LenType, *prog.FlagsType, *prog.ConstType, *prog.IntType, *prog.ProcType, *prog.CsumType, *prog.StructType, *prog.UnionType: @@ -277,7 +277,7 @@ func (ctx *structGen) check(key prog.StructKey, descp **prog.StructDesc) bool { func (ctx *structGen) walk(t0 prog.Type) { switch t := t0.(type) { case *prog.PtrType: - ctx.walk(t.Type) + ctx.walk(t.Elem) case *prog.ArrayType: ctx.walkArray(t) case *prog.StructType: @@ -291,16 +291,16 @@ func (ctx *structGen) walkArray(t *prog.ArrayType) { if ctx.padded[t] { return } - ctx.walk(t.Type) - if !t.Type.Varlen() && t.Type.Size() == sizeUnassigned { + ctx.walk(t.Elem) + if !t.Elem.Varlen() && t.Elem.Size() == sizeUnassigned { // An inner struct is not padded yet. // Leave this array for next iteration. return } ctx.padded[t] = true t.TypeSize = 0 - if t.Kind == prog.ArrayRangeLen && t.RangeBegin == t.RangeEnd && !t.Type.Varlen() { - t.TypeSize = t.RangeBegin * t.Type.Size() + if t.Kind == prog.ArrayRangeLen && t.RangeBegin == t.RangeEnd && !t.Elem.Varlen() { + t.TypeSize = t.RangeBegin * t.Elem.Size() } } @@ -535,7 +535,7 @@ func (comp *compiler) typeAlign(t0 prog.Type) uint64 { case *prog.BufferType: return 1 case *prog.ArrayType: - return comp.typeAlign(t.Type) + return comp.typeAlign(t.Elem) case *prog.StructType: n := comp.structNodes[t.StructDesc] attrs := comp.parseAttrs(structAttrs, n, n.Attrs) diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 6f2c26a6e..bf542c511 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -162,7 +162,7 @@ var typePtr = &typeDesc{ } return &prog.PtrType{ TypeCommon: base.TypeCommon, - Type: comp.genType(args[1], "", 0), + Elem: comp.genType(args[1], "", 0), ElemDir: genDir(args[0]), } }, @@ -240,7 +240,7 @@ var typeArray = &typeDesc{ // TypeSize is assigned later in genStructDescs. return &prog.ArrayType{ TypeCommon: base.TypeCommon, - Type: elemType, + Elem: elemType, Kind: kind, RangeBegin: begin, RangeEnd: end, diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go index dd89733c0..184bf6410 100644 --- a/pkg/host/syscalls_linux.go +++ b/pkg/host/syscalls_linux.go @@ -403,7 +403,7 @@ func extractStringConst(typ prog.Type) (string, bool) { if !ok { panic("first open arg is not a pointer to string const") } - str, ok := ptr.Type.(*prog.BufferType) + str, ok := ptr.Elem.(*prog.BufferType) if !ok || str.Kind != prog.BufferString || len(str.Values) == 0 { return "", false } -- cgit mrf-deployment