types

package
v0.0.0-...-8baa2bd Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Txxx = 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
)
View Source
const (
	CMPlt = Cmp(-1)
	CMPeq = Cmp(0)
	CMPgt = Cmp(1)
)
View Source
const BADWIDTH = -1000000000

Variables

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

View Source
var Block int32 // current block number
View Source
var InitSyms []*Sym
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 ParamsResults = [2]func(*Type) *Type{
	(*Type).Params, (*Type).Results,
}

ParamsResults is like RecvsParamsResults, but omits receiver 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 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 Haspointers(t *Type) bool

func InternString

func InternString(b []byte) string

func IsDclstackValid

func IsDclstackValid() bool

func Markdcl

func Markdcl()

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

func Popdcl

func Popdcl()

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

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.

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

var Tptr EType // either TPTR32 or TPTR64

Initialized by frontend. Exists only here.

func (EType) String

func (et EType) String() string

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 NewField

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

func (f *Field) Isddd() bool

func (*Field) Nointerface

func (f *Field) Nointerface() bool

func (*Field) SetBroke

func (f *Field) SetBroke(b bool)

func (*Field) SetIsddd

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      []*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

type Funarg uint8

Fnstruct records the kind of function argument

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

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

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

	// saved and restored by dcopy
	Pkg        *Pkg
	Name       string   // object name
	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) AlgGen

func (sym *Sym) AlgGen() bool

func (*Sym) Asm

func (sym *Sym) Asm() bool

func (*Sym) Export

func (sym *Sym) Export() bool

func (*Sym) Exported

func (sym *Sym) Exported() bool

func (*Sym) Format

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

func (*Sym) IsBlank

func (sym *Sym) IsBlank() bool

func (*Sym) Linksym

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

func (*Sym) LinksymName

func (sym *Sym) LinksymName() string

func (*Sym) Package

func (sym *Sym) Package() bool

func (*Sym) SetAlgGen

func (sym *Sym) SetAlgGen(b bool)

func (*Sym) SetAsm

func (sym *Sym) SetAsm(b bool)

func (*Sym) SetExport

func (sym *Sym) SetExport(b bool)

func (*Sym) SetExported

func (sym *Sym) SetExported(b bool)

func (*Sym) SetPackage

func (sym *Sym) SetPackage(b bool)

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: *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.

var (
	TypeInvalid *Type = newSSA("invalid")
	TypeMem     *Type = newSSA("mem")
	TypeFlags   *Type = newSSA("flags")
	TypeVoid    *Type = newSSA("void")
	TypeInt128  *Type = newSSA("int128")
)

func FakeRecvType

func FakeRecvType() *Type

FakeRecvType returns the singleton type used for interface method receivers.

func New

func New(et EType) *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 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 NewDDDArray

func NewDDDArray(elem *Type) *Type

NewDDDArray returns a new [...]T array Type.

func NewDDDField

func NewDDDField(s *Type) *Type

NewDDDField returns a new TDDDFIELD type for slice type s.

func NewFuncArgs

func NewFuncArgs(f *Type) *Type

NewFuncArgs returns a new TFUNCARGS type for func type f.

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 NewPtr

func NewPtr(elem *Type) *Type

NewPtr returns the pointer type pointing to t.

func NewSlice

func NewSlice(elem *Type) *Type

NewSlice returns the slice Type with element type elem.

func NewTuple

func NewTuple(t1, t2 *Type) *Type

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

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

func (t *Type) Copy() *Type

Copy returns a shallow copy of the Type.

func (*Type) DDDField

func (t *Type) DDDField() *Type

DDDField returns the slice ... type for TDDDFIELD type t.

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, and slices.

func (*Type) ElemType

func (t *Type) ElemType() *Type

func (*Type) Field

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

Field returns the i'th field/method of struct/interface 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/methods of struct/interface type t.

func (*Type) FieldType

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

func (*Type) Fields

func (t *Type) Fields() *Fields

func (*Type) Format

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

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 channel type for TFUNCARGS type t.

func (*Type) FuncType

func (t *Type) FuncType() *Func

FuncType returns t's extra func-specific fields.

func (*Type) HasPointer

func (t *Type) HasPointer() bool

HasPointer returns whether t contains heap pointer. This is used for write barrier insertion, so we ignore pointers to go:notinheap types.

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

func (t *Type) IsDDDArray() 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 EType) 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) 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) 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) IsUnsafePtr

func (t *Type) IsUnsafePtr() bool

IsUnsafePtr reports whether t is an unsafe pointer.

func (*Type) IsUntyped

func (t *Type) IsUntyped() bool

IsUntyped reports whether t is an untyped type.

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

func (t *Type) Local() bool

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

func (*Type) Nname

func (t *Type) Nname() *Node

Nname returns the associated function's nname.

func (*Type) Noalg

func (t *Type) Noalg() bool

func (*Type) NotInHeap

func (t *Type) NotInHeap() bool

func (*Type) NumElem

func (t *Type) NumElem() int64

func (*Type) NumFields

func (t *Type) NumFields() int

func (*Type) Params

func (t *Type) Params() *Type

func (*Type) PtrTo

func (t *Type) PtrTo() *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) 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/interface type t's fields/methods to fields.

func (*Type) SetInterface

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

func (*Type) SetLocal

func (t *Type) SetLocal(b bool)

func (*Type) SetNname

func (t *Type) SetNname(n *Node)

Nname sets the associated function's nname.

func (*Type) SetNoalg

func (t *Type) SetNoalg(b bool)

func (*Type) SetNotInHeap

func (t *Type) SetNotInHeap(b bool)

func (*Type) SetNumElem

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

func (t *Type) SetRecur(b bool)

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

func (t *Type) String() string

func (*Type) StructType

func (t *Type) StructType() *Struct

StructType returns t's extra struct-specific fields.

func (*Type) Symbol

func (t *Type) Symbol() *obj.LSym

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

func (t *Type) Val() *Type

Val returns the value type of map type t.

func (*Type) WidthCalculated

func (t *Type) WidthCalculated() bool

Jump to

Keyboard shortcuts

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