Documentation ¶
Overview ¶
Package structs implements store.Value for composite struct type.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SField ¶
SField is a wrapper for struct Field.
type Struct ¶
type Struct struct { ssa.Value Fields []Field // Fields references. // contains filtered or unexported fields }
Struct is a wrapper for a type struct SSA value.
Struct keeps track of the fields (and their respective instances). When used as a storage.Key, Struct is the handle to the struct. When used as a storage.Value, Struct is a Field of the holding Struct, but itself is a sub-Struct.
Do not use a Struct across scope. Make a copy so that the fields do not get overwritten.
func FromType ¶
FromType creates a Struct from only the type information, useful for making placeholder structs where the number of fields in the struct is needed.
func (*Struct) Expand ¶
Expand of a Struct traverses (recursively) all its fields and return a slice containing the store.Key to each of their fields.
The input Struct is expected to be filled with field keys in the current scope, any field left empty (nil:store.Key) are treated as undefined (zero value). The exception is when the type of the empty value is also a "go/types".Struct type, in which case empty fields are added as part of the return value. It is designed such that Expand of the same type will result in slices with the same length.
Example:
struct { // t0 = Alloc(...) X int // t1 = Field(t0, 1) Y struct { // t2 = Field(t0, 2) Z byte // ; unused A string // t3 = Field(t2, 2) } }
if x is ssa.Value t0, Struct(t0).Expand() would become
[]store.Key{t0, t1 /*t0_0*/, t2 /*t0_1*/, SField(nil) /*t2_0*/, t3 /*t2_2*/}
Fields are always wrapped with SField.