From 959ec07095ff4ec4423a1365e0f0f94844a77507 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 19 Oct 2016 16:20:37 +0200 Subject: sys: always use pointers to types Currently we store most types by value in sys.Type. This is somewhat counter-intuitive for C++ programmers, because one can't easily update the type object. Store pointers to type objects for all types. It also makes it easier to update types, e.g. adding paddings. --- sys/align.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sys/align.go') diff --git a/sys/align.go b/sys/align.go index 055a433f8..1b1ea66ac 100644 --- a/sys/align.go +++ b/sys/align.go @@ -7,9 +7,9 @@ func initAlign() { var rec func(t Type) rec = func(t Type) { switch t1 := t.(type) { - case PtrType: + case *PtrType: rec(t1.Type) - case ArrayType: + case *ArrayType: rec(t1.Type) case *StructType: if !t1.padded { @@ -49,10 +49,10 @@ func addAlignment(t *StructType) { fields = append(fields, makePad(pad)) } fields = append(fields, f) - if at, ok := f.(ArrayType); ok && (at.Kind == ArrayRandLen || (at.Kind == ArrayRangeLen && at.RangeBegin != at.RangeEnd)) { + if at, ok := f.(*ArrayType); ok && (at.Kind == ArrayRandLen || (at.Kind == ArrayRangeLen && at.RangeBegin != at.RangeEnd)) { varLen = true } - if at, ok := f.(BufferType); ok && (at.Kind == BufferBlobRand || (at.Kind == BufferBlobRange && at.RangeBegin != at.RangeEnd)) { + if at, ok := f.(*BufferType); ok && (at.Kind == BufferBlobRand || (at.Kind == BufferBlobRange && at.RangeBegin != at.RangeEnd)) { varLen = true } if varLen && i != len(t.Fields)-1 { @@ -71,7 +71,7 @@ func addAlignment(t *StructType) { } func makePad(sz uintptr) Type { - return ConstType{ + return &ConstType{ TypeCommon: TypeCommon{TypeName: "pad", IsOptional: false}, TypeSize: sz, Val: 0, -- cgit mrf-deployment