Documentation ¶
Index ¶
- Constants
- Variables
- func CleanroomDo(f func())
- func Haspointers(t *Type) bool
- func Haspointers1(t *Type, ignoreNotInHeap bool) bool
- func InternString(b []byte) string
- func IsDclstackValid() bool
- func Markdcl()
- func Popdcl()
- func Pushdcl(s *Sym)
- type Array
- type Chan
- type ChanArgs
- type ChanDir
- type Cmp
- type DDDField
- type EType
- type Field
- type Fields
- type Forward
- type Funarg
- type Func
- type FuncArgs
- type Interface
- type Map
- type Node
- type Pkg
- type Ptr
- type Slice
- type Struct
- type Sym
- func (sym *Sym) AlgGen() bool
- func (sym *Sym) Asm() bool
- func (sym *Sym) Export() bool
- func (sym *Sym) Exported() bool
- func (sym *Sym) Format(s fmt.State, verb rune)
- func (sym *Sym) IsBlank() bool
- func (sym *Sym) Linksym() *obj.LSym
- func (sym *Sym) LinksymName() string
- func (sym *Sym) Package() bool
- func (sym *Sym) SetAlgGen(b bool)
- func (sym *Sym) SetAsm(b bool)
- func (sym *Sym) SetExport(b bool)
- func (sym *Sym) SetExported(b bool)
- func (sym *Sym) SetPackage(b bool)
- 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
- type Type
- func FakeRecvType() *Type
- func New(et EType) *Type
- func NewArray(elem *Type, bound int64) *Type
- func NewChan(elem *Type, dir ChanDir) *Type
- func NewChanArgs(c *Type) *Type
- func NewDDDArray(elem *Type) *Type
- func NewDDDField(s *Type) *Type
- func NewFuncArgs(f *Type) *Type
- func NewMap(k, v *Type) *Type
- func NewPtr(elem *Type) *Type
- func NewSlice(elem *Type) *Type
- func NewTuple(t1, t2 *Type) *Type
- func SubstAny(t *Type, types *[]*Type) *Type
- func (t *Type) Alignment() int64
- func (t *Type) AllMethods() *Fields
- func (t *Type) ArgWidth() int64
- func (t *Type) Broke() bool
- func (t *Type) ChanArgs() *Type
- func (t *Type) ChanDir() ChanDir
- func (t *Type) ChanType() *Chan
- func (t *Type) Compare(x *Type) Cmp
- func (t *Type) DDDField() *Type
- func (t *Type) Deferwidth() bool
- func (t *Type) Elem() *Type
- func (t *Type) ElemType() *Type
- func (t *Type) Field(i int) *Field
- func (t *Type) FieldName(i int) string
- func (t *Type) FieldOff(i int) int64
- func (t *Type) FieldSlice() []*Field
- 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
- func (t *Type) FuncArgs() *Type
- func (t *Type) FuncType() *Func
- func (t *Type) HasHeapPointer() bool
- 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
- func (t *Type) IsFlags() bool
- func (t *Type) IsFloat() bool
- func (t *Type) IsFuncArgStruct() bool
- func (t *Type) IsInteger() bool
- func (t *Type) IsInterface() bool
- func (t *Type) IsKind(et EType) bool
- func (t *Type) IsMap() bool
- func (t *Type) IsMemory() bool
- func (t *Type) IsPtr() bool
- func (t *Type) IsPtrShaped() bool
- 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
- func (t *Type) IsUntyped() bool
- func (t *Type) IsVoid() bool
- func (t *Type) Key() *Type
- func (t *Type) LongString() string
- func (t *Type) MapType() *Map
- func (t *Type) Methods() *Fields
- func (t *Type) Nname() *Node
- func (t *Type) Noalg() bool
- func (t *Type) NotInHeap() bool
- func (t *Type) NumComponents() int64
- 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) PtrTo() *Type
- func (t *Type) Recur() bool
- func (t *Type) Recv() *Field
- 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)
- func (t *Type) SetInterface(methods []*Field)
- func (t *Type) SetNname(n *Node)
- func (t *Type) SetNoalg(b bool)
- func (t *Type) SetNotInHeap(b bool)
- func (t *Type) SetNumElem(n int64)
- func (t *Type) SetRecur(b bool)
- func (t *Type) ShortString() string
- func (t *Type) SimpleString() string
- func (t *Type) Size() int64
- func (t *Type) String() string
- func (t *Type) StructType() *Struct
- func (t *Type) Symbol() *obj.LSym
- func (t *Type) Tie() byte
- func (t *Type) ToUnsigned() *Type
- func (t *Type) Val() *Type
- func (t *Type) WidthCalculated() bool
Constants ¶
const ( CMPlt = Cmp(-1) CMPeq = Cmp(0) CMPgt = Cmp(1) )
const BADWIDTH = -1000000000
Variables ¶
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 ( 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
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 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.
Functions ¶
func CleanroomDo ¶
func CleanroomDo(f func())
CleanroomDo invokes f in an environment with with no preexisting packages. For testing of import/export only.
func Haspointers ¶
func Haspointers1 ¶ added in go1.10
func InternString ¶
func IsDclstackValid ¶
func IsDclstackValid() bool
Types ¶
type Array ¶
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 ChanArgs ¶
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 Cmp ¶
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 ¶
type DDDField struct {
T *Type // reference to a slice type for ... args
}
DDDField contains Type fields specific to TDDDFIELD types.
type EType ¶
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 TPTR32 TPTR64 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 )
var Tptr EType // either TPTR32 or TPTR64
Initialized by frontend. Exists only here.
type Field ¶
type Field struct { Embedded uint8 // embedded field Funarg Funarg Sym *Sym Nname *Node Type *Type // field type // Offset in bytes of this field or method within its enclosing struct // or interface Type. Offset int64 Note string // literal string annotation // 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 (*Field) Nointerface ¶
func (*Field) SetNointerface ¶
type Fields ¶
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 (*Fields) Index ¶
Index returns the i'th element of Fields. It panics if f does not have at least i+1 elements.
type Forward ¶
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 Func ¶
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 }
Func contains Type fields specific to func types.
type FuncArgs ¶
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 ¶
type Interface struct {
Fields Fields
}
Interface contains Type fields specific to interface types.
type Map ¶
type Map struct { Key *Type // Key type Val *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 ¶
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 ¶
type Pkg struct { Path string // string literal used in import statement, e.g. "runtime/internal/sys" Name string // package name, e.g. "sys" Pathsym *obj.LSym Prefix string // escaped path for use in symbol table Imported bool // export data of this package was parsed Direct bool // imported directly Syms map[string]*Sym }
func ImportedPkgList ¶
func ImportedPkgList() []*Pkg
ImportedPkgList returns the list of directly imported packages. The list is sorted by package path.
func NewPkg ¶
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) LookupBytes ¶
type Ptr ¶
type Ptr struct {
Elem *Type // element type
}
Ptr contains Type fields specific to pointer types.
type Slice ¶
type Slice struct {
Elem *Type // element type
}
Slice contains Type fields specific to slice types.
type Struct ¶
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 ¶
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. 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.
func (*Sym) LinksymName ¶
func (*Sym) SetExported ¶
func (*Sym) SetPackage ¶
type Type ¶
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: *Inter // TDDDFIELD: DDDField // TFUNCARGS: FuncArgs // TCHANARGS: ChanArgs // TCHAN: *Chan // TPTR32, TPTR64: Ptr // TARRAY: *Array // TSLICE: Slice Extra interface{} // Width is the width of this Type in bytes. Width int64 Nod *Node // canonical OTYPE node Orig *Type // original type (type literal or predefined type) SliceOf *Type PtrBase *Type 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 // contains filtered or unexported fields }
A Type represents a Go type.
func FakeRecvType ¶
func FakeRecvType() *Type
FakeRecvType returns the singleton type used for interface method receivers.
func NewChanArgs ¶
NewChanArgs returns a new TCHANARGS type for channel type c.
func NewDDDField ¶
NewDDDField returns a new TDDDFIELD type for slice type s.
func NewFuncArgs ¶
NewFuncArgs returns a new TFUNCARGS type for func type f.
func SubstAny ¶
SubstAny walks t, replacing instances of "any" with successive elements removed from types. It returns the substituted type.
func (*Type) AllMethods ¶
func (*Type) ArgWidth ¶
ArgWidth returns the total aligned argument size for a function. It includes the receiver, parameters, and results.
func (*Type) ChanDir ¶
ChanDir returns the direction of a channel type t. The direction will be one of Crecv, Csend, or Cboth.
func (*Type) Compare ¶
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 (*Type) Deferwidth ¶
func (*Type) Elem ¶
Elem returns the type of elements of t. Usable with pointers, channels, arrays, and slices.
func (*Type) FieldSlice ¶
FieldSlice returns a slice of containing all fields/methods of struct/interface type t.
func (*Type) ForwardType ¶
ForwardType returns t's extra forward-type-specific fields.
func (*Type) HasHeapPointer ¶ added in go1.10
HasHeapPointer returns whether t contains a heap pointer. This is used for write barrier insertion, so it ignores pointers to go:notinheap types.
func (*Type) IsDDDArray ¶
func (*Type) IsEmptyInterface ¶
IsEmptyInterface reports whether t is an empty interface type.
func (*Type) IsFuncArgStruct ¶
IsFuncArgStruct reports whether t is a struct representing function parameters.
func (*Type) IsInterface ¶
func (*Type) IsPtr ¶
IsPtr reports whether t is a regular Go pointer type. This does not include unsafe.Pointer.
func (*Type) IsPtrShaped ¶
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 (*Type) IsUnsafePtr ¶
IsUnsafePtr reports whether t is an unsafe pointer.
func (*Type) LongString ¶
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 (*Type) NumComponents ¶ added in go1.10
func (*Type) NumResults ¶ added in go1.10
func (*Type) SetDeferwidth ¶
func (*Type) SetInterface ¶
func (*Type) SetNotInHeap ¶
func (*Type) SetNumElem ¶
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 (*Type) ShortString ¶
ShortString generates a short description of t. It is used in autogenerated method names, reflection, and itab names.
func (*Type) SimpleString ¶
func (*Type) StructType ¶
StructType returns t's extra struct-specific fields.
func (*Type) Tie ¶
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 (*Type) ToUnsigned ¶
ToUnsigned returns the unsigned equivalent of integer type t.