const ( CMPlt = Cmp(-1) CMPeq = Cmp(0) CMPgt = Cmp(1) )
const ( IgnoreBlankFields componentsIncludeBlankFields = false CountBlankFields componentsIncludeBlankFields = true )
const BADWIDTH = -1000000000
const MaxPkgHeight = 1e9
MaxPkgHeight is a height greater than any likely package height.
var ( // Predeclared alias types. Kept separate for better error messages. Bytetype *Type Runetype *Type // Predeclared error interface type. Errortype *Type // Types to represent untyped string and boolean constants. Idealstring *Type Idealbool *Type // Types to represent untyped numeric constants. // Note: Currently these are only used within the binary export // data format. The rest of the compiler only uses Types[TIDEAL]. Idealint = New(TIDEAL) Idealrune = New(TIDEAL) Idealfloat = New(TIDEAL) Idealcomplex = New(TIDEAL) )
var ( // TSSA types. Haspointers assumes these are pointer-free. TypeInvalid = newSSA("invalid") TypeMem = newSSA("mem") TypeFlags = newSSA("flags") TypeVoid = newSSA("void") TypeInt128 = newSSA("int128") )
var ( Widthptr int Dowidth func(*Type) Fatalf func(string, ...interface{}) Sconv func(*Sym, int, int) string // orig: func sconv(s *Sym, flag FmtFlag, mode fmtMode) string Tconv func(*Type, int, int, int) string // orig: func tconv(t *Type, flag FmtFlag, mode fmtMode, depth int) string FormatSym func(*Sym, fmt.State, rune, int) // orig: func symFormat(sym *Sym, s fmt.State, verb rune, mode fmtMode) FormatType func(*Type, fmt.State, rune, int) // orig: func typeFormat(t *Type, s fmt.State, verb rune, mode fmtMode) TypeLinkSym func(*Type) *obj.LSym Ctxt *obj.Link FmtLeft int FmtUnsigned int FErr int )
The following variables must be initialized early by the frontend. They are here to break import cycles. TODO(gri) eliminate these dependencies.
var Block int32 // current block number
var InitSyms []*Sym
List of .inittask entries in imported packages, in source code order.
var NewPtrCacheEnabled = true
NewPtrCacheEnabled controls whether *T Types are cached in T. Caching is disabled just before starting the backend. This allows the backend to run concurrently.
var ParamsResults = [2]func(*Type) *Type{ (*Type).Params, (*Type).Results, }
ParamsResults is like RecvsParamsResults, but omits receiver parameters.
var RecvsParams = [2]func(*Type) *Type{ (*Type).Recvs, (*Type).Params, }
RecvsParams is like RecvsParamsResults, but omits result parameters.
var RecvsParamsResults = [3]func(*Type) *Type{ (*Type).Recvs, (*Type).Params, (*Type).Results, }
RecvsParamsResults stores the accessor functions for a function Type's receiver, parameters, and result parameters, in that order. It can be used to iterate over all of a function's parameter lists.
var Types [NTYPE]*Type
Types stores pointers to predeclared named types.
It also stores pointers to several special types:
- Types[TANY] is the placeholder "any" type recognized by substArgTypes. - Types[TBLANK] represents the blank variable's type. - Types[TIDEAL] represents untyped numeric constants. - Types[TNIL] represents the predeclared "nil" value's type. - Types[TUNSAFEPTR] is package unsafe's Pointer type.
func CleanroomDo(f func())
CleanroomDo invokes f in an environment with no preexisting packages. For testing of import/export only.
func Haspointers(t *Type) bool
func Haspointers1(t *Type, ignoreNotInHeap bool) bool
func Identical(t1, t2 *Type) bool
Identical reports whether t1 and t2 are identical types, following the spec rules. Receiver parameter types are ignored.
func IdenticalIgnoreTags(t1, t2 *Type) bool
IdenticalIgnoreTags is like Identical, but it ignores struct tags for struct identity.
func ImportedPkgList() []*Pkg
ImportedPkgList returns the list of directly imported packages. The list is sorted by package path.
func InternString(b []byte) string
func IsDclstackValid() bool
func IsExported(name string) bool
IsExported reports whether name is an exported Go symbol (that is, whether it begins with an upper-case letter).
func Markdcl()
Markdcl records the start of a new block scope for declarations.
func Popdcl()
Popdcl pops the innermost block scope and restores all symbol declarations to their previous state.
func Pushdcl(s *Sym)
Pushdcl pushes the current declaration for symbol s (if any) so that it can be shadowed by a new declaration within a nested block scope.
type Array struct { Elem *Type // element type Bound int64 // number of elements; <0 if unknown yet }
Array contains Type fields specific to array types.
type Chan struct { Elem *Type // element type Dir ChanDir // channel direction }
Chan contains Type fields specific to channel types.
type ChanArgs struct { T *Type // reference to a chan type whose elements need a width check }
ChanArgs contains Type fields specific to TCHANARGS types.
type ChanDir uint8
ChanDir is whether a channel can send, receive, or both.
const ( // types of channel // must match ../../../../reflect/type.go:/ChanDir Crecv ChanDir = 1 << 0 Csend ChanDir = 1 << 1 Cboth ChanDir = Crecv | Csend )
func (c ChanDir) CanRecv() bool
func (c ChanDir) CanSend() bool
type Cmp int8
Cmp is a comparison between values a and b. -1 if a < b
0 if a == b 1 if a > b
type DDDField struct { T *Type // reference to a slice type for ... args }
DDDField contains Type fields specific to TDDDFIELD types.
type EType uint8
EType describes a kind of type.
const ( Txxx EType = iota TINT8 TUINT8 TINT16 TUINT16 TINT32 TUINT32 TINT64 TUINT64 TINT TUINT TUINTPTR TCOMPLEX64 TCOMPLEX128 TFLOAT32 TFLOAT64 TBOOL TPTR TFUNC TSLICE TARRAY TSTRUCT TCHAN TMAP TINTER TFORW TANY TSTRING TUNSAFEPTR // pseudo-types for literals TIDEAL TNIL TBLANK // pseudo-types for frame layout TFUNCARGS TCHANARGS // pseudo-types for import/export TDDDFIELD // wrapper: contained type is a ... field // SSA backend types TSSA // internal types used by SSA backend (flags, memory, etc.) TTUPLE // a pair of types, used by SSA backend NTYPE )
func (i EType) String() string
type Field struct { Embedded uint8 // embedded field Pos src.XPos Sym *Sym Type *Type // field type Note string // literal string annotation // For fields that represent function parameters, Nname points // to the associated ONAME Node. Nname *Node // Offset in bytes of this field or method within its enclosing struct // or interface Type. Offset int64 // contains filtered or unexported fields }
A Field represents a field in a struct or a method in an interface or associated with a named type.
func NewField() *Field
func (f *Field) Broke() bool
func (f *Field) Copy() *Field
func (f *Field) End() int64
End returns the offset of the first byte immediately after this field.
func (f *Field) IsDDD() bool
func (f *Field) IsMethod() bool
IsMethod reports whether f represents a method rather than a struct field.
func (f *Field) Nointerface() bool
func (f *Field) SetBroke(b bool)
func (f *Field) SetIsDDD(b bool)
func (f *Field) SetNointerface(b bool)
type Fields struct {
// contains filtered or unexported fields
}
Fields is a pointer to a slice of *Field. This saves space in Types that do not have fields or methods compared to a simple slice of *Field.
func (f *Fields) Append(s ...*Field)
Append appends entries to f.
func (f *Fields) Index(i int) *Field
Index returns the i'th element of Fields. It panics if f does not have at least i+1 elements.
func (f *Fields) Len() int
Len returns the number of entries in f.
func (f *Fields) Set(s []*Field)
Set sets f to a slice. This takes ownership of the slice.
func (f *Fields) Slice() []*Field
Slice returns the entries in f as a slice. Changes to the slice entries will be reflected in f.
type Forward struct { Copyto []*Node // where to copy the eventual value to Embedlineno src.XPos // first use of this type as an embedded type }
Forward contains Type fields specific to forward types.
type Funarg uint8
Fnstruct records the kind of function argument
const ( FunargNone Funarg = iota FunargRcvr // receiver FunargParams // input parameters FunargResults // output results )
type Func struct { Receiver *Type // function receiver Results *Type // function results Params *Type // function params Nname *Node // Argwid is the total width of the function receiver, params, and results. // It gets calculated via a temporary TFUNCARGS type. // Note that TFUNC's Width is Widthptr. Argwid int64 Outnamed bool // contains filtered or unexported fields }
Func contains Type fields specific to func types.
type FuncArgs struct { T *Type // reference to a func type whose elements need a width check }
// FuncArgs contains Type fields specific to TFUNCARGS types.
type Interface struct { Fields Fields // contains filtered or unexported fields }
Interface contains Type fields specific to interface types.
type Map struct { Key *Type // Key type Elem *Type // Val (elem) type Bucket *Type // internal struct type representing a hash bucket Hmap *Type // internal struct type representing the Hmap (map header object) Hiter *Type // internal struct type representing hash iterator state }
Map contains Type fields specific to maps.
type Node struct {
// contains filtered or unexported fields
}
Dummy Node so we can refer to *Node without actually having a gc.Node. Necessary to break import cycles. TODO(gri) try to eliminate soon
type Pkg struct { Path string // string literal used in import statement, e.g. "runtime/internal/sys" Name string // package name, e.g. "sys" Prefix string // escaped path for use in symbol table Syms map[string]*Sym Pathsym *obj.LSym // Height is the package's height in the import graph. Leaf // packages (i.e., packages with no imports) have height 0, // and all other packages have height 1 plus the maximum // height of their imported packages. Height int Imported bool // export data of this package was parsed Direct bool // imported directly }
func NewPkg(path, name string) *Pkg
NewPkg returns a new Pkg for the given package path and name. Unless name is the empty string, if the package exists already, the existing package name and the provided name must match.
func (pkg *Pkg) Lookup(name string) *Sym
func (pkg *Pkg) LookupBytes(name []byte) *Sym
func (pkg *Pkg) LookupOK(name string) (s *Sym, existed bool)
LookupOK looks up name in pkg and reports whether it previously existed.
type Ptr struct { Elem *Type // element type }
Ptr contains Type fields specific to pointer types.
type Slice struct { Elem *Type // element type }
Slice contains Type fields specific to slice types.
type Struct struct { // Maps have three associated internal structs (see struct MapType). // Map links such structs back to their map type. Map *Type Funarg Funarg // type of function arguments for arg struct // contains filtered or unexported fields }
StructType contains Type fields specific to struct types.
type Sym struct { Importdef *Pkg // where imported definition was found Linkname string // link name Pkg *Pkg Name string // object name // saved and restored by dcopy Def *Node // definition: ONAME OTYPE OPACK or OLITERAL Block int32 // blocknumber to catch redeclaration Lastlineno src.XPos // last declaration for diagnostic Label *Node // corresponding label (ephemeral) Origpkg *Pkg // original package for . import // contains filtered or unexported fields }
Sym represents an object name in a segmented (pkg, name) namespace. Most commonly, this is a Go identifier naming an object declared within a package, but Syms are also used to name internal synthesized objects.
As an exception, field and method names that are exported use the Sym associated with localpkg instead of the package that declared them. This allows using Sym pointer equality to test for Go identifier uniqueness when handling selector expressions.
Ideally, Sym should be used for representing Go language constructs, while cmd/internal/obj.LSym is used for representing emitted artifacts.
NOTE: In practice, things can be messier than the description above for various reasons (historical, convenience).
func (sym *Sym) AlgGen() bool
func (sym *Sym) Asm() bool
func (sym *Sym) Format(s fmt.State, verb rune)
func (sym *Sym) Func() bool
func (sym *Sym) IsBlank() bool
func (a *Sym) Less(b *Sym) bool
Less reports whether symbol a is ordered before symbol b.
Symbols are ordered exported before non-exported, then by name, and finally (for non-exported symbols) by package height and path.
Ordering by package height is necessary to establish a consistent ordering for non-exported names with the same spelling but from different packages. We don't necessarily know the path for the package being compiled, but by definition it will have a height greater than any other packages seen within the compilation unit. For more background, see issue #24693.
func (sym *Sym) Linksym() *obj.LSym
func (sym *Sym) LinksymName() string
func (sym *Sym) OnExportList() bool
func (s *Sym) PkgDef() *Node
PkgDef returns the definition associated with s at package scope.
func (sym *Sym) SetAlgGen(b bool)
func (sym *Sym) SetAsm(b bool)
func (sym *Sym) SetFunc(b bool)
func (sym *Sym) SetOnExportList(b bool)
func (s *Sym) SetPkgDef(n *Node)
SetPkgDef sets the definition associated with s at package scope.
func (sym *Sym) SetSiggen(b bool)
func (sym *Sym) SetUniq(b bool)
func (sym *Sym) Siggen() bool
func (s *Sym) String() string
func (sym *Sym) Uniq() bool
type Tuple struct {
// contains filtered or unexported fields
}
type Type struct { // Extra contains extra etype-specific fields. // As an optimization, those etype-specific structs which contain exactly // one pointer-shaped field are stored as values rather than pointers when possible. // // TMAP: *Map // TFORW: *Forward // TFUNC: *Func // TSTRUCT: *Struct // TINTER: *Interface // TDDDFIELD: DDDField // TFUNCARGS: FuncArgs // TCHANARGS: ChanArgs // TCHAN: *Chan // TPTR: Ptr // TARRAY: *Array // TSLICE: Slice Extra interface{} // Width is the width of this Type in bytes. Width int64 // valid if Align > 0 Nod *Node // canonical OTYPE node Orig *Type // original type (type literal or predefined type) // Cache of composite types, with this type being the element type. Cache struct { // contains filtered or unexported fields } Sym *Sym // symbol containing name, for named types Vargen int32 // unique name for OTYPE/ONAME Etype EType // kind of type Align uint8 // the required alignment of this type, in bytes (0 means Width and Align have not yet been computed) // contains filtered or unexported fields }
A Type represents a Go type.
func FakeRecvType() *Type
FakeRecvType returns the singleton type used for interface method receivers.
func New(et EType) *Type
New returns a new Type of the specified kind.
func NewArray(elem *Type, bound int64) *Type
NewArray returns a new fixed-length array Type.
func NewChan(elem *Type, dir ChanDir) *Type
NewChan returns a new chan Type with direction dir.
func NewChanArgs(c *Type) *Type
NewChanArgs returns a new TCHANARGS type for channel type c.
func NewDDDArray(elem *Type) *Type
NewDDDArray returns a new [...]T array Type.
func NewDDDField(s *Type) *Type
NewDDDField returns a new TDDDFIELD type for slice type s.
func NewFuncArgs(f *Type) *Type
NewFuncArgs returns a new TFUNCARGS type for func type f.
func NewMap(k, v *Type) *Type
NewMap returns a new map Type with key type k and element (aka value) type v.
func NewPtr(elem *Type) *Type
NewPtr returns the pointer type pointing to t.
func NewSlice(elem *Type) *Type
NewSlice returns the slice Type with element type elem.
func NewTuple(t1, t2 *Type) *Type
func SubstAny(t *Type, types *[]*Type) *Type
SubstAny walks t, replacing instances of "any" with successive elements removed from types. It returns the substituted type.
func (t *Type) Alignment() int64
func (t *Type) AllMethods() *Fields
func (t *Type) ArgWidth() int64
ArgWidth returns the total aligned argument size for a function. It includes the receiver, parameters, and results.
func (t *Type) Broke() bool
func (t *Type) ChanArgs() *Type
ChanArgs returns the channel type for TCHANARGS type t.
func (t *Type) ChanDir() ChanDir
ChanDir returns the direction of a channel type t. The direction will be one of Crecv, Csend, or Cboth.
func (t *Type) ChanType() *Chan
ChanType returns t's extra channel-specific fields.
func (t *Type) Compare(x *Type) Cmp
Compare compares types for purposes of the SSA back end, returning a Cmp (one of CMPlt, CMPeq, CMPgt). The answers are correct for an optimizer or code generator, but not necessarily typechecking. The order chosen is arbitrary, only consistency and division into equivalence classes (Types that compare CMPeq) matters.
func (t *Type) DDDField() *Type
DDDField returns the slice ... type for TDDDFIELD type t.
func (t *Type) Deferwidth() bool
func (t *Type) Elem() *Type
Elem returns the type of elements of t. Usable with pointers, channels, arrays, slices, and maps.
func (t *Type) Field(i int) *Field
Field returns the i'th field/method of struct/interface type t.
func (t *Type) FieldName(i int) string
func (t *Type) FieldOff(i int) int64
func (t *Type) FieldSlice() []*Field
FieldSlice returns a slice of containing all fields/methods of struct/interface type t.
func (t *Type) FieldType(i int) *Type
func (t *Type) Fields() *Fields
func (t *Type) Format(s fmt.State, verb rune)
func (t *Type) ForwardType() *Forward
ForwardType returns t's extra forward-type-specific fields.
func (t *Type) FuncArgs() *Type
FuncArgs returns the func type for TFUNCARGS type t.
func (t *Type) FuncType() *Func
FuncType returns t's extra func-specific fields.
func (t *Type) HasHeapPointer() bool
HasHeapPointer reports whether t contains a heap pointer. This is used for write barrier insertion, so it ignores pointers to go:notinheap types.
func (t *Type) IsArray() bool
func (t *Type) IsBoolean() bool
func (t *Type) IsChan() bool
func (t *Type) IsComplex() bool
func (t *Type) IsDDDArray() bool
func (t *Type) IsEmptyInterface() bool
IsEmptyInterface reports whether t is an empty interface type.
func (t *Type) IsFlags() bool
func (t *Type) IsFloat() bool
func (t *Type) IsFuncArgStruct() bool
IsFuncArgStruct reports whether t is a struct representing function parameters.
func (t *Type) IsInteger() bool
func (t *Type) IsInterface() bool
func (t *Type) IsKind(et EType) bool
IsKind reports whether t is a Type of the specified kind.
func (t *Type) IsMap() bool
func (t *Type) IsMemory() bool
func (t *Type) IsPtr() bool
IsPtr reports whether t is a regular Go pointer type. This does not include unsafe.Pointer.
func (t *Type) IsPtrElem() bool
IsPtrElem reports whether t is the element of a pointer (to t).
func (t *Type) IsPtrShaped() bool
IsPtrShaped reports whether t is represented by a single machine pointer. In addition to regular Go pointer types, this includes map, channel, and function types and unsafe.Pointer. It does not include array or struct types that consist of a single pointer shaped type. TODO(mdempsky): Should it? See golang.org/issue/15028.
func (t *Type) IsSigned() bool
func (t *Type) IsSlice() bool
func (t *Type) IsString() bool
func (t *Type) IsStruct() bool
func (t *Type) IsTuple() bool
func (t *Type) IsUnsafePtr() bool
IsUnsafePtr reports whether t is an unsafe pointer.
func (t *Type) IsUntyped() bool
IsUntyped reports whether t is an untyped type.
func (t *Type) IsVariadic() bool
IsVariadic reports whether function type t is variadic.
func (t *Type) IsVoid() bool
func (t *Type) Key() *Type
Key returns the key type of map type t.
func (t *Type) LongString() string
LongString generates a complete description of t. It is useful for reflection, or when a unique fingerprint or hash of a type is required.
func (t *Type) MapType() *Map
MapType returns t's extra map-specific fields.
func (t *Type) Methods() *Fields
func (t *Type) Nname() *Node
Nname returns the associated function's nname.
func (t *Type) Noalg() bool
func (t *Type) NotInHeap() bool
func (t *Type) NumComponents(countBlank componentsIncludeBlankFields) int64
NumComponents returns the number of primitive elements that compose t. Struct and array types are flattened for the purpose of counting. All other types (including string, slice, and interface types) count as one element. If countBlank is IgnoreBlankFields, then blank struct fields (and their comprised elements) are excluded from the count. struct { x, y [3]int } has six components; [10]struct{ x, y string } has twenty.
func (t *Type) NumElem() int64
func (t *Type) NumFields() int
func (t *Type) NumParams() int
func (t *Type) NumRecvs() int
func (t *Type) NumResults() int
func (t *Type) Params() *Type
func (t *Type) Pkg() *Pkg
Pkg returns the package that t appeared in.
Pkg is only defined for function, struct, and interface types (i.e., types with named elements). This information isn't used by cmd/compile itself, but we need to track it because it's exposed by the go/types API.
func (t *Type) PtrTo() *Type
func (t *Type) Recur() bool
func (t *Type) Recv() *Field
Recv returns the receiver of function type t, if any.
func (t *Type) Recvs() *Type
func (t *Type) Results() *Type
func (t *Type) SetBroke(b bool)
func (t *Type) SetDeferwidth(b bool)
func (t *Type) SetFields(fields []*Field)
SetFields sets struct/interface type t's fields/methods to fields.
func (t *Type) SetInterface(methods []*Field)
func (t *Type) SetNname(n *Node)
Nname sets the associated function's nname.
func (t *Type) SetNoalg(b bool)
func (t *Type) SetNotInHeap(b bool)
func (t *Type) SetNumElem(n int64)
SetNumElem sets the number of elements in an array type. The only allowed use is on array types created with NewDDDArray. For other uses, create a new array with NewArray instead.
func (t *Type) SetPkg(pkg *Pkg)
SetPkg sets the package that t appeared in.
func (t *Type) SetRecur(b bool)
func (t *Type) ShortString() string
ShortString generates a short description of t. It is used in autogenerated method names, reflection, and itab names.
func (t *Type) SimpleString() string
func (t *Type) Size() int64
func (t *Type) SoleComponent() *Type
SoleComponent returns the only primitive component in t, if there is exactly one. Otherwise, it returns nil. Components are counted as in NumComponents, including blank fields.
func (t *Type) String() string
func (t *Type) StructType() *Struct
StructType returns t's extra struct-specific fields.
func (t *Type) Symbol() *obj.LSym
func (t *Type) Tie() byte
Tie returns 'T' if t is a concrete type, 'I' if t is an interface type, and 'E' if t is an empty interface type. It is used to build calls to the conv* and assert* runtime routines.
func (t *Type) ToUnsigned() *Type
ToUnsigned returns the unsigned equivalent of integer type t.
func (t *Type) WidthCalculated() bool