}
t.Width = -2
- t.Align = 0
+ t.Align = 0 // 0 means use t.Width, below
et := t.Etype
switch et {
}
}
- w := int64(0)
+ var w int64
switch et {
default:
Fatalf("dowidth: unknown type: %v", t)
t.Width = w
if t.Align == 0 {
- if w > 8 || w&(w-1) != 0 || w == 0 {
+ if w == 0 || w > 8 || w&(w-1) != 0 {
Fatalf("invalid alignment for %v", t)
}
t.Align = uint8(w)
return
}
- if t.Deferwidth() {
- return
+ // if type has not yet been pushed on deferredTypeStack yet, do it now
+ if !t.Deferwidth() {
+ t.SetDeferwidth(true)
+ deferredTypeStack = append(deferredTypeStack, t)
}
- t.SetDeferwidth(true)
-
- deferredTypeStack = append(deferredTypeStack, t)
}
func defercheckwidth() {
if defercalc == 0 {
Fatalf("resumecheckwidth")
}
+
for len(deferredTypeStack) > 0 {
t := deferredTypeStack[len(deferredTypeStack)-1]
deferredTypeStack = deferredTypeStack[:len(deferredTypeStack)-1]
Extra interface{}
// Width is the width of this Type in bytes.
- Width int64
+ Width int64 // valid if Align > 0
methods Fields
allMethods Fields
Vargen int32 // unique name for OTYPE/ONAME
Etype EType // kind of type
- Align uint8 // the required alignment of this type, in bytes
+ Align uint8 // the required alignment of this type, in bytes (0 means Width and Align have not yet been computed)
flags bitset8
}
const (
- typeNotInHeap = 1 << iota // type cannot be heap allocated
- typeBroke // broken type definition
- typeNoalg // suppress hash and eq algorithm generation
- typeDeferwidth
+ typeNotInHeap = 1 << iota // type cannot be heap allocated
+ typeBroke // broken type definition
+ typeNoalg // suppress hash and eq algorithm generation
+ typeDeferwidth // width computation has been deferred and type is on deferredTypeStack
typeRecur
)