types

package standard library
go1.17.13 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CMPlt = Cmp(-1)
	CMPeq = Cmp(0)
	CMPgt = Cmp(1)
)
View Source
const (
	IgnoreBlankFields componentsIncludeBlankFields = false
	CountBlankFields  componentsIncludeBlankFields = true
)
View Source
const BADWIDTH = -1000000000
View Source
const BOGUS_FUNARG_OFFSET = -1000000000
View Source
const MaxPkgHeight = 1e9

MaxPkgHeight is a height greater than any likely package height.

Variables

View Source
var (
	SlicePtrOffset int64
	SliceLenOffset int64
	SliceCapOffset int64

	SliceSize  int64
	StringSize int64
)

Slices in the runtime are represented by three components:

type slice struct {
	ptr unsafe.Pointer
	len int
	cap int
}

Strings in the runtime are represented by two components:

type string struct {
	ptr unsafe.Pointer
	len int
}

These variables are the offsets of fields and sizes of these structs.

View Source
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.
	UntypedString = New(TSTRING)
	UntypedBool   = New(TBOOL)

	// Types to represent untyped numeric constants.
	UntypedInt     = New(TIDEAL)
	UntypedRune    = New(TIDEAL)
	UntypedFloat   = New(TIDEAL)
	UntypedComplex = New(TIDEAL)
)
View Source
var (
	// TSSA types. HasPointers assumes these are pointer-free.
	TypeInvalid   = newSSA("invalid")
	TypeMem       = newSSA("mem")
	TypeFlags     = newSSA("flags")
	TypeVoid      = newSSA("void")
	TypeInt128    = newSSA("int128")
	TypeResultMem = newResults([]*Type{TypeMem})
)
View Source
var (
	IsInt     [NTYPE]bool
	IsFloat   [NTYPE]bool
	IsComplex [NTYPE]bool
	IsSimple  [NTYPE]bool
)
View Source
var BasicTypeNames = []string{
	TINT:        "int",
	TUINT:       "uint",
	TINT8:       "int8",
	TUINT8:      "uint8",
	TINT16:      "int16",
	TUINT16:     "uint16",
	TINT32:      "int32",
	TUINT32:     "uint32",
	TINT64:      "int64",
	TUINT64:     "uint64",
	TUINTPTR:    "uintptr",
	TFLOAT32:    "float32",
	TFLOAT64:    "float64",
	TCOMPLEX64:  "complex64",
	TCOMPLEX128: "complex128",
	TBOOL:       "bool",
	TANY:        "any",
	TSTRING:     "string",
	TNIL:        "nil",
	TIDEAL:      "untyped number",
	TBLANK:      "blank",
}
View Source
var Block int32 = 1 // current block number
View Source
var CalcSizeDisabled bool

CalcSizeDisabled indicates whether it is safe to calculate Types' widths and alignments. See CalcSize.

View Source
var IsOrdered [NTYPE]bool
View Source
var MaxWidth int64

MaxWidth is the maximum size of a value on the target architecture.

View Source
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.

View Source
var NumImport = make(map[string]int)

numImport tracks how often a package with a given name is imported. It is used to provide a better error message (by using the package path to disambiguate) if a package that appears multiple times with the same name appears in an error message.

View Source
var ParamsResults = [2]func(*Type) *Type{
	(*Type).Params, (*Type).Results,
}

ParamsResults is like RecvsParamsResults, but omits receiver parameters.

View Source
var PtrSize int
View Source
var RecvsParams = [2]func(*Type) *Type{
	(*Type).Recvs, (*Type).Params,
}

RecvsParams is like RecvsParamsResults, but omits result parameters.

View Source
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.

View Source
var RegSize int
View Source
var SimType [NTYPE]Kind
View Source
var SkipSizeForTracing bool
View Source
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[TNIL] represents the predeclared "nil" value's type.
  • Types[TUNSAFEPTR] is package unsafe's Pointer type.

Functions

func AlgType added in go1.17

func AlgType(t *Type) (AlgKind, *Type)

AlgType returns the AlgKind used for comparing and hashing Type t. If it returns ANOEQ, it also returns the component type of t that makes it incomparable.

func AllowsGoVersion added in go1.17

func AllowsGoVersion(pkg *Pkg, major, minor int) bool

AllowsGoVersion reports whether a particular package is allowed to use Go version major.minor. We assume the imported packages have all been checked, so we only have to check the local package against the -lang flag.

func CalcSize added in go1.17

func CalcSize(t *Type)

CalcSize calculates and stores the size and alignment for t. If CalcSizeDisabled is set, and the size/alignment have not already been calculated, it calls Fatal. This is used to prevent data races in the back end.

func CalcStructSize added in go1.17

func CalcStructSize(s *Type)

CalcStructSize calculates the size of s, filling in s.Width and s.Align, even if size calculation is otherwise disabled.

func CheckDclstack added in go1.17

func CheckDclstack()

func CheckSize added in go1.17

func CheckSize(t *Type)

func CleanroomDo

func CleanroomDo(f func())

CleanroomDo invokes f in an environment with no preexisting packages. For testing of import/export only.

func DeferCheckSize added in go1.17

func DeferCheckSize()

func FmtConst added in go1.17

func FmtConst(v constant.Value, sharp bool) string

func Identical added in go1.12

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 added in go1.12

func IdenticalIgnoreTags(t1, t2 *Type) bool

IdenticalIgnoreTags is like Identical, but it ignores struct tags for struct identity.

func InternString

func InternString(b []byte) string

func IsComparable added in go1.17

func IsComparable(t *Type) bool

IsComparable reports whether t is a comparable type.

func IsDirectIface added in go1.17

func IsDirectIface(t *Type) bool

Can this type be stored directly in an interface word? Yes, if the representation is a single pointer.

func IsDotAlias added in go1.17

func IsDotAlias(sym *Sym) bool

func IsExported added in go1.11

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 IsInterfaceMethod added in go1.17

func IsInterfaceMethod(f *Type) bool

IsInterfaceMethod reports whether (field) m is an interface method. Such methods have the special receiver type types.FakeRecvType().

func IsMethodApplicable added in go1.17

func IsMethodApplicable(t *Type, m *Field) bool

IsMethodApplicable reports whether method m can be called on a value of type t. This is necessary because we compute a single method set for both T and *T, but some *T methods are not applicable to T receivers.

func IsPaddedField added in go1.17

func IsPaddedField(t *Type, i int) bool

IsPaddedField reports whether the i'th field of struct type t is followed by padding.

func IsReflectPkg added in go1.17

func IsReflectPkg(p *Pkg) bool

IsReflectPkg reports whether p is package reflect.

func IsReflexive added in go1.17

func IsReflexive(t *Type) bool

IsReflexive reports whether t has a reflexive equality operator. That is, if x==x for all x of type t.

func IsRuntimePkg added in go1.17

func IsRuntimePkg(p *Pkg) bool

IsRuntimePkg reports whether p is package runtime.

func Markdcl

func Markdcl()

Markdcl records the start of a new block scope for declarations.

func ParseLangFlag added in go1.17

func ParseLangFlag()

ParseLangFlag verifies that the -lang flag holds a valid value, and exits if not. It initializes data used by langSupported.

func Popdcl

func Popdcl()

Popdcl pops the innermost block scope and restores all symbol declarations to their previous state.

func PtrDataSize added in go1.17

func PtrDataSize(t *Type) int64

PtrDataSize returns the length in bytes of the prefix of t containing pointer data. Anything after this offset is scalar data.

func Pushdcl

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.

func ResumeCheckSize added in go1.17

func ResumeCheckSize()

func Rnd added in go1.17

func Rnd(o int64, r int64) int64

func TypeHasNoAlg added in go1.17

func TypeHasNoAlg(t *Type) bool

TypeHasNoAlg reports whether t does not have any associated hash/eq algorithms because t, or some component of t, is marked Noalg.

func TypeHash added in go1.17

func TypeHash(t *Type) uint32

TypeHash computes a hash value for type t to use in type switch statements.

func TypeSymName added in go1.17

func TypeSymName(t *Type) string

Types

type AlgKind added in go1.17

type AlgKind int

AlgKind describes the kind of algorithms used for comparing and hashing a Type.

const (
	// These values are known by runtime.
	ANOEQ AlgKind = iota
	AMEM0
	AMEM8
	AMEM16
	AMEM32
	AMEM64
	AMEM128
	ASTRING
	AINTER
	ANILINTER
	AFLOAT32
	AFLOAT64
	ACPLX64
	ACPLX128

	// Type can be compared/hashed as regular memory.
	AMEM AlgKind = 100

	// Type needs special comparison/hashing functions.
	ASPECIAL AlgKind = -1
)

func (AlgKind) String added in go1.17

func (i AlgKind) String() string

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 Chan

type Chan struct {
	Elem *Type   // element type
	Dir  ChanDir // channel direction
}

Chan contains Type fields specific to channel 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 ChanDir

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 (ChanDir) CanRecv

func (c ChanDir) CanRecv() bool

func (ChanDir) CanSend

func (c ChanDir) CanSend() bool

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 Field

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 Object

	// Offset in bytes of this field or method within its enclosing struct
	// or interface Type.  Exception: if field is function receiver, arg or
	// result, then this is BOGUS_FUNARG_OFFSET; types does not know the Abi.
	Offset int64
	// contains filtered or unexported fields
}

A Field is a (Sym, Type) pairing along with some other information, and, depending on the context, is used to represent:

  • a field in a struct
  • a method in an interface or associated with a named type
  • a function parameter

func IncomparableField added in go1.17

func IncomparableField(t *Type) *Field

IncomparableField returns an incomparable Field of struct Type t, if any.

func NewField

func NewField(pos src.XPos, sym *Sym, typ *Type) *Field

func (*Field) Broke

func (f *Field) Broke() bool

func (*Field) Copy

func (f *Field) Copy() *Field

func (*Field) End

func (f *Field) End() int64

End returns the offset of the first byte immediately after this field.

func (*Field) IsDDD added in go1.12

func (f *Field) IsDDD() bool

func (*Field) IsMethod added in go1.13

func (f *Field) IsMethod() bool

IsMethod reports whether f represents a method rather than a struct field.

func (*Field) Nointerface

func (f *Field) Nointerface() bool

func (*Field) SetBroke

func (f *Field) SetBroke(b bool)

func (*Field) SetIsDDD added in go1.12

func (f *Field) SetIsDDD(b bool)

func (*Field) SetNointerface

func (f *Field) SetNointerface(b bool)

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) Append

func (f *Fields) Append(s ...*Field)

Append appends entries to f.

func (*Fields) Index

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 (*Fields) Len

func (f *Fields) Len() int

Len returns the number of entries in f.

func (*Fields) Set

func (f *Fields) Set(s []*Field)

Set sets f to a slice. This takes ownership of the slice.

func (*Fields) 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

type Forward struct {
	Copyto      []*Type  // 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

type Funarg uint8

Fnstruct records the kind of function argument

const (
	FunargNone    Funarg = iota
	FunargRcvr           // receiver
	FunargParams         // input parameters
	FunargResults        // output results
	FunargTparams        // type params
)

type Func

type Func struct {
	Receiver *Type // function receiver
	Results  *Type // function results
	Params   *Type // function params
	TParams  *Type // type params of receiver (if method) or function

	// 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
	// contains filtered or unexported fields
}

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 {
	// contains filtered or unexported fields
}

Interface contains Type fields specific to interface types.

type Kind added in go1.17

type Kind uint8

Kind describes a kind of type.

const (
	Txxx Kind = 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
	TTYPEPARAM

	// pseudo-types for literals
	TIDEAL // untyped numeric constants
	TNIL
	TBLANK

	// pseudo-types for frame layout
	TFUNCARGS
	TCHANARGS

	// SSA backend types
	TSSA     // internal types used by SSA backend (flags, memory, etc.)
	TTUPLE   // a pair of types, used by SSA backend
	TRESULTS // multiple types; the result of calling a function or method, with a memory at the end.

	NTYPE
)

func (Kind) String added in go1.17

func (i Kind) String() string

type Map

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 MethodsByName added in go1.17

type MethodsByName []*Field

MethodsByName sorts methods by symbol.

func (MethodsByName) Len added in go1.17

func (x MethodsByName) Len() int

func (MethodsByName) Less added in go1.17

func (x MethodsByName) Less(i, j int) bool

func (MethodsByName) Swap added in go1.17

func (x MethodsByName) Swap(i, j int)

type Object added in go1.17

type Object interface {
	Pos() src.XPos
	Sym() *Sym
	Type() *Type
}

Object represents an ir.Node, but without needing to import cmd/compile/internal/ir, which would cause an import cycle. The uses in other packages must type assert values of type Object to ir.Node or a more specific type.

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"
	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

	Direct bool // imported directly
}
var BuiltinPkg *Pkg

BuiltinPkg is a fake package that declares the universe block.

var LocalPkg *Pkg

LocalPkg is the package being compiled.

var NoPkg *Pkg = nil

NoPkg is a nil *Pkg value for clarity. It's intended for use when constructing types that aren't exported and thus don't need to be associated with any package.

func ImportedPkgList

func ImportedPkgList() []*Pkg

ImportedPkgList returns the list of directly imported packages. The list is sorted by package path.

func NewPkg

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) Lookup

func (pkg *Pkg) Lookup(name string) *Sym

func (*Pkg) LookupBytes

func (pkg *Pkg) LookupBytes(name []byte) *Sym

func (*Pkg) LookupOK

func (pkg *Pkg) LookupOK(name string) (s *Sym, existed bool)

LookupOK looks up name in pkg and reports whether it previously existed.

type Ptr

type Ptr struct {
	Elem *Type // element type
}

Ptr contains Type fields specific to pointer types.

type Results added in go1.16

type Results struct {
	Types []*Type // Last element is memory output from call.
}

Results are the output from calls that will be late-expanded.

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 {
	Linkname string // link name

	Pkg  *Pkg
	Name string // object name

	// The unique ONAME, OTYPE, OPACK, or OLITERAL node that this symbol is
	// bound to within the current scope. (Most parts of the compiler should
	// prefer passing the Node directly, rather than relying on this field.)
	Def        Object
	Block      int32    // blocknumber to catch redeclaration
	Lastlineno src.XPos // last declaration for diagnostic
	// 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).

var BlankSym *Sym

BlankSym is the blank (_) symbol.

func OrigSym added in go1.17

func OrigSym(s *Sym) *Sym

OrigSym returns the original symbol written by the user.

func TypeSym added in go1.17

func TypeSym(t *Type) *Sym

func TypeSymLookup added in go1.17

func TypeSymLookup(name string) *Sym

func (*Sym) Asm

func (sym *Sym) Asm() bool

func (*Sym) Format

func (s *Sym) Format(f fmt.State, verb rune)

Format implements formatting for a Sym. The valid formats are:

%v	Go syntax: Name for symbols in the local package, PkgName.Name for imported symbols.
%+v	Debug syntax: always include PkgName. prefix even for local names.
%S	Short syntax: Name only, no matter what.

func (*Sym) Func added in go1.12

func (sym *Sym) Func() bool

func (*Sym) IsBlank

func (sym *Sym) IsBlank() bool

func (*Sym) Less added in go1.11

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) Linksym deprecated

func (sym *Sym) Linksym() *obj.LSym

Deprecated: This method should not be used directly. Instead, use a higher-level abstraction that directly returns the linker symbol for a named object. For example, reflectdata.TypeLinksym(t) instead of reflectdata.TypeSym(t).Linksym().

func (*Sym) LinksymABI deprecated added in go1.17

func (sym *Sym) LinksymABI(abi obj.ABI) *obj.LSym

Deprecated: This method should not be used directly. Instead, use a higher-level abstraction that directly returns the linker symbol for a named object. For example, (*ir.Name).LinksymABI(abi) instead of (*ir.Name).Sym().LinksymABI(abi).

func (*Sym) OnExportList added in go1.11

func (sym *Sym) OnExportList() bool

func (*Sym) PkgDef added in go1.11

func (s *Sym) PkgDef() Object

PkgDef returns the definition associated with s at package scope.

func (*Sym) SetAsm

func (sym *Sym) SetAsm(b bool)

func (*Sym) SetFunc added in go1.12

func (sym *Sym) SetFunc(b bool)

func (*Sym) SetOnExportList added in go1.11

func (sym *Sym) SetOnExportList(b bool)

func (*Sym) SetPkgDef added in go1.11

func (s *Sym) SetPkgDef(n Object)

SetPkgDef sets the definition associated with s at package scope.

func (*Sym) SetSiggen

func (sym *Sym) SetSiggen(b bool)

func (*Sym) SetUniq

func (sym *Sym) SetUniq(b bool)

func (*Sym) Siggen

func (sym *Sym) Siggen() bool

func (*Sym) String

func (s *Sym) String() string

func (*Sym) Uniq

func (sym *Sym) Uniq() bool

type Tuple

type Tuple struct {
	// contains filtered or unexported fields
}

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: *Interface
	// TFUNCARGS: FuncArgs
	// TCHANARGS: ChanArgs
	// TCHAN: *Chan
	// TPTR: Ptr
	// TARRAY: *Array
	// TSLICE: Slice
	// TSSA: string
	// TTYPEPARAM:  *Interface (though we may not need to store/use the Interface info)
	Extra interface{}

	// Width is the width of this Type in bytes.
	Width int64 // valid if Align > 0

	Vargen int32 // unique name for OTYPE/ONAME

	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 ComplexForFloat added in go1.17

func ComplexForFloat(t *Type) *Type

func FakeRecvType

func FakeRecvType() *Type

FakeRecvType returns the singleton type used for interface method receivers.

func FloatForComplex added in go1.17

func FloatForComplex(t *Type) *Type

func New

func New(et Kind) *Type

New returns a new Type of the specified kind.

func NewArray

func NewArray(elem *Type, bound int64) *Type

NewArray returns a new fixed-length array Type.

func NewBasic added in go1.17

func NewBasic(kind Kind, obj Object) *Type

NewBasic returns a new basic type of the given kind.

func NewChan

func NewChan(elem *Type, dir ChanDir) *Type

NewChan returns a new chan Type with direction dir.

func NewChanArgs

func NewChanArgs(c *Type) *Type

NewChanArgs returns a new TCHANARGS type for channel type c.

func NewFuncArgs

func NewFuncArgs(f *Type) *Type

NewFuncArgs returns a new TFUNCARGS type for func type f.

func NewInterface added in go1.17

func NewInterface(pkg *Pkg, methods []*Field) *Type

NewInterface returns a new interface for the given methods and embedded types. Embedded types are specified as fields with no Sym.

func NewMap

func NewMap(k, v *Type) *Type

NewMap returns a new map Type with key type k and element (aka value) type v.

func NewNamed added in go1.17

func NewNamed(obj Object) *Type

NewNamed returns a new named type for the given type name. obj should be an ir.Name. The new type is incomplete (marked as TFORW kind), and the underlying type should be set later via SetUnderlying(). References to the type are maintained until the type is filled in, so those references can be updated when the type is complete.

func NewPtr

func NewPtr(elem *Type) *Type

NewPtr returns the pointer type pointing to t.

func NewResults added in go1.16

func NewResults(types []*Type) *Type

func NewSignature added in go1.17

func NewSignature(pkg *Pkg, recv *Field, tparams, params, results []*Field) *Type

NewSignature returns a new function type for the given receiver, parameters, results, and type parameters, any of which may be nil.

func NewSlice

func NewSlice(elem *Type) *Type

NewSlice returns the slice Type with element type elem.

func NewStruct added in go1.17

func NewStruct(pkg *Pkg, fields []*Field) *Type

NewStruct returns a new struct with the given fields.

func NewTuple

func NewTuple(t1, t2 *Type) *Type

func NewTypeParam added in go1.17

func NewTypeParam(pkg *Pkg) *Type

NewTypeParam returns a new type param.

func ReceiverBaseType added in go1.17

func ReceiverBaseType(t *Type) *Type

ReceiverBaseType returns the underlying type, if any, that owns methods with receiver parameter t. The result is either a named type or an anonymous struct.

func SubstAny

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 (*Type) Alignment

func (t *Type) Alignment() int64

func (*Type) AllMethods

func (t *Type) AllMethods() *Fields

AllMethods returns a pointer to all the methods (including embedding) for type t. For an interface type, this is the set of methods that are typically iterated over.

func (*Type) ArgWidth

func (t *Type) ArgWidth() int64

ArgWidth returns the total aligned argument size for a function. It includes the receiver, parameters, and results.

func (*Type) Broke

func (t *Type) Broke() bool

func (*Type) CanBeAnSSAAux added in go1.17

func (*Type) CanBeAnSSAAux()

func (*Type) ChanArgs

func (t *Type) ChanArgs() *Type

ChanArgs returns the channel type for TCHANARGS type t.

func (*Type) ChanDir

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 (*Type) ChanType

func (t *Type) ChanType() *Chan

ChanType returns t's extra channel-specific fields.

func (*Type) Compare

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 (*Type) Deferwidth

func (t *Type) Deferwidth() bool

func (*Type) Elem

func (t *Type) Elem() *Type

Elem returns the type of elements of t. Usable with pointers, channels, arrays, slices, and maps.

func (*Type) Field

func (t *Type) Field(i int) *Field

Field returns the i'th field of struct type t.

func (*Type) FieldName

func (t *Type) FieldName(i int) string

func (*Type) FieldOff

func (t *Type) FieldOff(i int) int64

func (*Type) FieldSlice

func (t *Type) FieldSlice() []*Field

FieldSlice returns a slice of containing all fields of a struct type t.

func (*Type) FieldType

func (t *Type) FieldType(i int) *Type

func (*Type) Fields

func (t *Type) Fields() *Fields

Fields returns the fields of struct type t.

func (*Type) Format

func (t *Type) Format(s fmt.State, verb rune)

Format implements formatting for a Type. The valid formats are:

%v	Go syntax
%+v	Debug syntax: Go syntax with a KIND- prefix for all but builtins.
%L	Go syntax for underlying type if t is named
%S	short Go syntax: drop leading "func" in function type
%-S	special case for method receiver symbol

func (*Type) ForwardType

func (t *Type) ForwardType() *Forward

ForwardType returns t's extra forward-type-specific fields.

func (*Type) FuncArgs

func (t *Type) FuncArgs() *Type

FuncArgs returns the func type for TFUNCARGS type t.

func (*Type) FuncType

func (t *Type) FuncType() *Func

FuncType returns t's extra func-specific fields.

func (*Type) HasNil added in go1.14

func (t *Type) HasNil() bool

HasNil reports whether the set of values determined by t includes nil.

func (*Type) HasPointers added in go1.15.3

func (t *Type) HasPointers() bool

HasPointers reports whether t contains a heap pointer. Note that this function ignores pointers to go:notinheap types.

func (*Type) HasTParam added in go1.17

func (t *Type) HasTParam() bool

func (*Type) IsArray

func (t *Type) IsArray() bool

func (*Type) IsBoolean

func (t *Type) IsBoolean() bool

func (*Type) IsChan

func (t *Type) IsChan() bool

func (*Type) IsComplex

func (t *Type) IsComplex() bool

func (*Type) IsEmptyInterface

func (t *Type) IsEmptyInterface() bool

IsEmptyInterface reports whether t is an empty interface type.

func (*Type) IsFlags

func (t *Type) IsFlags() bool

func (*Type) IsFloat

func (t *Type) IsFloat() bool

func (*Type) IsFuncArgStruct

func (t *Type) IsFuncArgStruct() bool

IsFuncArgStruct reports whether t is a struct representing function parameters.

func (*Type) IsInteger

func (t *Type) IsInteger() bool

func (*Type) IsInterface

func (t *Type) IsInterface() bool

func (*Type) IsKind

func (t *Type) IsKind(et Kind) bool

IsKind reports whether t is a Type of the specified kind.

func (*Type) IsMap

func (t *Type) IsMap() bool

func (*Type) IsMemory

func (t *Type) IsMemory() bool

func (*Type) IsPtr

func (t *Type) IsPtr() bool

IsPtr reports whether t is a regular Go pointer type. This does not include unsafe.Pointer.

func (*Type) IsPtrElem added in go1.12

func (t *Type) IsPtrElem() bool

IsPtrElem reports whether t is the element of a pointer (to t).

func (*Type) IsPtrShaped

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 (*Type) IsResults added in go1.16

func (t *Type) IsResults() bool

func (*Type) IsScalar added in go1.17

func (t *Type) IsScalar() bool

IsScalar reports whether 't' is a scalar Go type, e.g. bool/int/float/complex. Note that struct and array types consisting of a single scalar element are not considered scalar, likewise pointer types are also not considered scalar.

func (*Type) IsSigned

func (t *Type) IsSigned() bool

func (*Type) IsSlice

func (t *Type) IsSlice() bool

func (*Type) IsString

func (t *Type) IsString() bool

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) IsTuple

func (t *Type) IsTuple() bool

func (*Type) IsUintptr added in go1.16

func (t *Type) IsUintptr() bool

IsUintptr reports whether t is an uintptr.

func (*Type) IsUnsafePtr

func (t *Type) IsUnsafePtr() bool

IsUnsafePtr reports whether t is an unsafe pointer.

func (*Type) IsUnsigned added in go1.17

func (t *Type) IsUnsigned() bool

func (*Type) IsUntyped

func (t *Type) IsUntyped() bool

IsUntyped reports whether t is an untyped type.

func (*Type) IsVariadic added in go1.11

func (t *Type) IsVariadic() bool

IsVariadic reports whether function type t is variadic.

func (*Type) IsVoid

func (t *Type) IsVoid() bool

func (*Type) Key

func (t *Type) Key() *Type

Key returns the key type of map type t.

func (*Type) Kind added in go1.17

func (t *Type) Kind() Kind

Kind returns the kind of type t.

func (*Type) LongString

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 (*Type) MapType

func (t *Type) MapType() *Map

MapType returns t's extra map-specific fields.

func (*Type) Methods

func (t *Type) Methods() *Fields

Methods returns a pointer to the base methods (excluding embedding) for type t. These can either be concrete methods (for non-interface types) or interface methods (for interface types).

func (*Type) Noalg

func (t *Type) Noalg() bool

func (*Type) NotInHeap

func (t *Type) NotInHeap() bool

func (*Type) NumComponents added in go1.10

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 (*Type) NumElem

func (t *Type) NumElem() int64

func (*Type) NumFields

func (t *Type) NumFields() int

func (*Type) NumParams added in go1.10

func (t *Type) NumParams() int

func (*Type) NumRecvs added in go1.10

func (t *Type) NumRecvs() int

func (*Type) NumResults added in go1.10

func (t *Type) NumResults() int

func (*Type) NumTParams added in go1.17

func (t *Type) NumTParams() int

func (*Type) Obj added in go1.17

func (t *Type) Obj() Object

Obj returns the canonical type name node for a named type t, nil for an unnamed type.

func (*Type) Params

func (t *Type) Params() *Type

func (*Type) Pkg added in go1.11

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 (*Type) Pos added in go1.17

func (t *Type) Pos() src.XPos

Pos returns a position associated with t, if any. This should only be used for diagnostics.

func (*Type) PtrTo

func (t *Type) PtrTo() *Type

func (*Type) RParams added in go1.17

func (t *Type) RParams() []*Type

func (*Type) Recur

func (t *Type) Recur() bool

func (*Type) Recv

func (t *Type) Recv() *Field

Recv returns the receiver of function type t, if any.

func (*Type) Recvs

func (t *Type) Recvs() *Type

func (*Type) Results

func (t *Type) Results() *Type

func (*Type) SetAllMethods added in go1.17

func (t *Type) SetAllMethods(fs []*Field)

SetAllMethods sets the set of all methods (including embedding) for type t. Use this method instead of t.AllMethods().Set(), which might call CalcSize() on an uninitialized interface type.

func (*Type) SetBroke

func (t *Type) SetBroke(b bool)

func (*Type) SetDeferwidth

func (t *Type) SetDeferwidth(b bool)

func (*Type) SetFields

func (t *Type) SetFields(fields []*Field)

SetFields sets struct type t's fields to fields.

func (*Type) SetHasTParam added in go1.17

func (t *Type) SetHasTParam(b bool)

func (*Type) SetInterface

func (t *Type) SetInterface(methods []*Field)

SetInterface sets the base methods of an interface type t.

func (*Type) SetNoalg

func (t *Type) SetNoalg(b bool)

func (*Type) SetNod added in go1.17

func (t *Type) SetNod(n Object)

SetNod associates t with syntax node n.

func (*Type) SetNotInHeap

func (t *Type) SetNotInHeap(b bool)

func (*Type) SetRParams added in go1.17

func (t *Type) SetRParams(rparams []*Type)

func (*Type) SetRecur

func (t *Type) SetRecur(b bool)

func (*Type) SetSym added in go1.17

func (t *Type) SetSym(sym *Sym)

func (*Type) SetUnderlying added in go1.17

func (t *Type) SetUnderlying(underlying *Type)

SetUnderlying sets the underlying type. SetUnderlying automatically updates any types that were waiting for this type to be completed.

func (*Type) ShortString

func (t *Type) ShortString() string

ShortString generates a short description of t. It is used in autogenerated method names, reflection, and itab names.

func (*Type) SimpleString

func (t *Type) SimpleString() string

func (*Type) Size

func (t *Type) Size() int64

func (*Type) SoleComponent added in go1.13

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 (*Type) String

func (t *Type) String() string

String returns the Go syntax for the type t.

func (*Type) StructType

func (t *Type) StructType() *Struct

StructType returns t's extra struct-specific fields.

func (*Type) Sym

func (t *Type) Sym() *Sym

Sym returns the name of type t.

func (*Type) TParams added in go1.17

func (t *Type) TParams() *Type

func (*Type) Tie

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 (*Type) ToUnsigned

func (t *Type) ToUnsigned() *Type

ToUnsigned returns the unsigned equivalent of integer type t.

func (*Type) Underlying added in go1.17

func (t *Type) Underlying() *Type

Underlying returns the underlying type of type t.

func (*Type) WidthCalculated

func (t *Type) WidthCalculated() bool

type TypeObject added in go1.17

type TypeObject interface {
	Object
	TypeDefn() *Type // for "type T Defn", returns Defn
}

A TypeObject is an Object representing a named type.

type VarObject added in go1.17

type VarObject interface {
	Object
	RecordFrameOffset(int64) // save frame offset
}

A VarObject is an Object representing a function argument, variable, or struct field.

Jump to

Keyboard shortcuts

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