structs

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2019 License: Apache-2.0 Imports: 6 Imported by: 1

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 Field

type Field store.Key

a Field is a store.Key which also contain a pointer to its parent struct.

type SField

type SField struct {
	store.Key
	Struct *Struct
	Index  int
}

SField is a wrapper for struct Field.

func (SField) Name

func (f SField) Name() string

Name returns the Name of the field if defined, otherwise return a synthetic field in the form of "struct_fieldindex"

func (SField) Pos

func (f SField) Pos() token.Pos

func (SField) String

func (f SField) String() string

func (SField) Type

func (f SField) Type() types.Type

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

func FromType(t *types.Struct) *Struct

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 New

func New(scope store.Value, v Typer) *Struct

func (*Struct) Expand

func (s *Struct) Expand() []store.Key

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.

func (*Struct) UniqName

func (s *Struct) UniqName() string

type Typer

type Typer interface {
	Type() types.Type
}

Type is an interface for creating new struct from typable things.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL