types

package
v0.0.0-...-4cc5765 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Invalid = token.Invalid

	Bool          = token.Bool
	Int           = token.Int
	Int8          = token.Int8
	Int16         = token.Int16
	Int32         = token.Int32
	Int64         = token.Int64
	Uint          = token.Uint
	Uint8         = token.Uint8
	Uint16        = token.Uint16
	Uint32        = token.Uint32
	Uint64        = token.Uint64
	Uintptr       = token.Uintptr
	Float32       = token.Float32
	Float64       = token.Float64
	Complex64     = token.Complex64
	Complex128    = token.Complex128
	ArrayKind     = token.ArrayKind
	ChanKind      = token.ChanKind
	FuncKind      = token.FuncKind
	InterfaceKind = token.InterfaceKind
	MapKind       = token.MapKind
	PtrKind       = token.PtrKind
	SliceKind     = token.SliceKind
	String        = token.String
	StructKind    = token.StructKind
	UnsafePointer = token.UnsafePointer

	// types for untyped values
	UntypedBool    = token.UntypedBool
	UntypedInt     = token.UntypedInt
	UntypedRune    = token.UntypedRune
	UntypedFloat   = token.UntypedFloat
	UntypedComplex = token.UntypedComplex
	UntypedString  = token.UntypedString
	UntypedNil     = token.UntypedNil

	// aliases
	Byte = token.Byte
	Rune = token.Rune
)

Variables

This section is empty.

Functions

func AssignableTo

func AssignableTo(src *Complete, dst *Complete) bool

*

  • return true if values of type 'src' can be assigned to variables of type 'dst' *
  • as per Go specifications https://golang.ir/ref/spec#Assignability
  • a type 'src' is assignable to type 'dst' if at least one of the following applies:
  • - src and dst are identical
  • - src and dst have identical underlying types, and at least one of src, dst is unnamed
  • - dst is an interface type, and src implements it
  • - src is a bidirectional channel value, dst is a channel type, they have identical element types
  • and and at least one of src, dst is unnamed
  • - src is UntypedNil and dst is a channel, function, interface, map, pointer or slice type
  • - src is an untyped and is representable by dst

func ConvertibleTo

func ConvertibleTo(src *Complete, dst *Complete) bool

*

  • return true if values of type 'src' can be converted to type 'dst' *
  • as per Go specifications https://golang.ir/ref/spec#Conversions
  • a type 'src' is convertible to type 'dst' if at least one of the following applies:
  • - src is assignable to dst
  • - ignoring struct tags, src and dst have identical underlying types
  • - ignoring struct tags, src and dst are unnamed pointers,
  • and their element types have identical underlying types
  • - src and dst are both integer or floating point types
  • - src and dst are both complex types
  • - src is an integer (obsolescent) or a slice of byte/rune and dst is a string
  • - src is a string and dst is a slice of byte/rune *
  • notes:
  • - "X is a string" means: "X underlying type is string"
  • - analogously, "X is a complex type" means "X underlying type is complex64 or complex128"
  • - analogously, "X is a floating point" means "X underlying type is float32 or float64"
  • - analogously, "X is an integer" means "X underlying type is one of the basic integer types"
  • - "X is a slice of byte/rune" means: "X underlying type is slice,
  • and the the underlying type of slice element is byte (i.e. uint8) or rune (i.e. int32)"

func IdenticalType

func IdenticalType(c1 *Complete, c2 *Complete, ignoreTags bool) bool

func Implements

func Implements(src *Complete, dst *Complete) bool

return true if values of type 'src' implement interface type 'dst'

func TypeString

func TypeString(t Type, showFullPkgPath bool) string

Types

type Array

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

func NewArray

func NewArray(elem Type, len uint64) *Array

create a new Array type

func (*Array) Elem

func (t *Array) Elem() Type

func (*Array) Len

func (t *Array) Len() uint64

func (*Array) String

func (t *Array) String() string

func (*Array) Underlying

func (t *Array) Underlying() Type

func (*Array) WriteTo

func (t *Array) WriteTo(dst io.StringWriter, flag verbose)

type Basic

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

Basic represents one of Go's predefined basic types

func (*Basic) Complete

func (t *Basic) Complete() *Complete

func (*Basic) Kind

func (t *Basic) Kind() Kind

func (*Basic) Name

func (t *Basic) Name() string

func (*Basic) Size

func (t *Basic) Size() uint64

func (*Basic) String

func (t *Basic) String() string

func (*Basic) Underlying

func (t *Basic) Underlying() Type

func (*Basic) WriteTo

func (t *Basic) WriteTo(dst io.StringWriter, flag verbose)

type Chan

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

func NewChan

func NewChan(dir ChanDir, elem Type) *Chan

create a new Chan type

func (*Chan) Dir

func (t *Chan) Dir() ChanDir

func (*Chan) Elem

func (t *Chan) Elem() Type

func (*Chan) String

func (t *Chan) String() string

func (*Chan) Underlying

func (t *Chan) Underlying() Type

func (*Chan) WriteTo

func (t *Chan) WriteTo(dst io.StringWriter, flag verbose)

type ChanDir

type ChanDir flags
const (
	RecvDir ChanDir = 1
	SendDir ChanDir = 2
	BothDir         = RecvDir | SendDir
)

type Class

type Class uint8
const (
	InvalidObj Class = iota
	BuiltinObj
	ConstObj
	FuncObj
	ImportObj
	TypeObj
	VarObj
	GenericFuncObj
	GenericTypeObj
)

func (Class) String

func (cl Class) String() string

type Complete

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

Complete represent a Go type. It is similar in spirit to reflect.Type

func BasicType

func BasicType(kind Kind) *Complete

return *Complete basic type for specified Kind and current GetArchSizeBits() and GetTargetOs()

func BasicTypes

func BasicTypes() []*Complete

create and return a slice containing *Complete basic types for current GetArchSizeBits() and GetTargetOs() use Kind as index in returned slice.

func BinaryOp

func BinaryOp(t1 *Complete, op token.Token, t2 *Complete) (t *Complete)

return the type of 'e1 op e2' where e1's type = t1 and e2's type = t2 return nil if t1 and t2 are not compatible with op.

func CompleteTypes

func CompleteTypes(ts ...Type) []*Complete

resolve circular dependencies and incomplete Types, and return equivalent *Complete objects

func NewBuiltin

func NewBuiltin(name string, nin uint32, nout uint32, variadic bool) *Complete

create a new type representing a builtin function. the returned *Complete has .Kind() = Invalid and .Type() = nil, as it cannot be used as component in new types.

func (*Complete) Align

func (t *Complete) Align() uint64

func (*Complete) ChanDir

func (t *Complete) ChanDir() ChanDir

func (*Complete) Comparable

func (t *Complete) Comparable() bool

func (*Complete) Elem

func (t *Complete) Elem() *Complete

func (*Complete) Field

func (t *Complete) Field(i int) CompleteField

func (*Complete) In

func (t *Complete) In(i int) *Complete

func (*Complete) IsVariadic

func (t *Complete) IsVariadic() bool

func (*Complete) Key

func (t *Complete) Key() *Complete

func (*Complete) Kind

func (t *Complete) Kind() Kind

func (*Complete) Len

func (t *Complete) Len() uint64

func (*Complete) Method

func (t *Complete) Method(i int) CompleteMethod

func (*Complete) Name

func (t *Complete) Name() string

func (*Complete) NumField

func (t *Complete) NumField() int

func (*Complete) NumIn

func (t *Complete) NumIn() int

func (*Complete) NumMethod

func (t *Complete) NumMethod() int

func (*Complete) NumOut

func (t *Complete) NumOut() int

func (*Complete) Out

func (t *Complete) Out(i int) *Complete

func (*Complete) PkgPath

func (t *Complete) PkgPath() string

func (*Complete) Size

func (t *Complete) Size() uint64

func (*Complete) String

func (t *Complete) String() string

func (*Complete) Type

func (t *Complete) Type() Type

convert *Complete to Type

func (*Complete) Underlying

func (t *Complete) Underlying() *Complete

type CompleteField

type CompleteField struct {
	Type     *Complete
	Name     string
	PkgPath  string
	Tag      string
	Offset   uint64
	Index    int
	Embedded bool
}

type CompleteMethod

type CompleteMethod struct {
	Type    *Complete
	Name    string
	PkgPath string
	Index   int
}

returned by Complete.Method(int)

type Constraint

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

Constraint represents a constraint on a generic type. it is either a named or unnamed interface type (i.e. .Kind() = InterfaceKind) or a generic type that, when instantiated, declares a named or unnamed interface type

func MakeConstraintGeneric

func MakeConstraintGeneric(generic *Generic) Constraint

func MakeConstraintType

func MakeConstraintType(typ Type) Constraint

func (Constraint) Generic

func (c Constraint) Generic() *Generic

func (Constraint) Type

func (c Constraint) Type() Type

type Field

type Field struct {
	Type     Type
	Name     string
	PkgPath  string
	Tag      string
	Offset   uint64
	Index    int
	Embedded bool
}

func (*Field) WriteTo

func (f *Field) WriteTo(dst io.StringWriter, flag verbose)

type Func

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

Func represents the type of a function

func NewFunc

func NewFunc(in []Type, out []Type, variadic bool) *Func

create a new Func type

func (*Func) In

func (t *Func) In(i int) Type

func (*Func) IsVariadic

func (t *Func) IsVariadic() bool

func (*Func) NumIn

func (t *Func) NumIn() int

func (*Func) NumOut

func (t *Func) NumOut() int

func (*Func) Out

func (t *Func) Out(i int) Type

func (*Func) String

func (t *Func) String() string

func (*Func) Underlying

func (t *Func) Underlying() Type

func (*Func) WriteTo

func (t *Func) WriteTo(dst io.StringWriter, flag verbose)

type Generic

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

Generic represents a generic type or generic function

func NewGeneric

func NewGeneric(
	name string, pkgPath string, paramNames []string, constraints []Constraint, instantiate Instantiate,
) *Generic

Declare a new Generic type. A generic type *cannot* be an alias

func (*Generic) Instantiate

func (g *Generic) Instantiate(concreteTypes []Type) Type

func (*Generic) Name

func (g *Generic) Name() string

func (*Generic) NumTypes

func (g *Generic) NumTypes() int

func (*Generic) PkgPath

func (g *Generic) PkgPath() string

func (*Generic) String

func (g *Generic) String() string

func (*Generic) TypeConstraint

func (g *Generic) TypeConstraint(i int) Constraint

func (*Generic) TypeParam

func (g *Generic) TypeParam(i int) string

func (*Generic) WriteTo

func (g *Generic) WriteTo(dst io.StringWriter, flag verbose)

type Instantiate

type Instantiate = func(g *Generic, concreteTypes []Type) Type

user-provided function to instantiate a generic type or generic function

type Interface

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

func NewInterface

func NewInterface(embedded []Type, method ...Method) *Interface

create a new Interface type

func (*Interface) Embedded

func (t *Interface) Embedded(i int) Type

return i-th embedded interface.

func (*Interface) Method

func (t *Interface) Method(i int) Method

return i-th method, including methods from embedded interfaces

func (*Interface) NumEmbedded

func (t *Interface) NumEmbedded() int

return number of embedded interfaces.

func (*Interface) NumMethod

func (t *Interface) NumMethod() int

return number of method, including methods from embedded interfaces

func (*Interface) String

func (t *Interface) String() string

func (*Interface) Underlying

func (t *Interface) Underlying() Type

func (*Interface) WriteTo

func (t *Interface) WriteTo(dst io.StringWriter, flag verbose)

type Kind

type Kind = token.Kind

type Map

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

func NewMap

func NewMap(key Type, elem Type) *Map

create a new Map type

func (*Map) Elem

func (t *Map) Elem() Type

func (*Map) Key

func (t *Map) Key() Type

func (*Map) String

func (t *Map) String() string

func (*Map) Underlying

func (t *Map) Underlying() Type

func (*Map) WriteTo

func (t *Map) WriteTo(dst io.StringWriter, flag verbose)

type Method

type Method struct {
	Type    Type
	Name    string
	PkgPath string
	Index   int
}

returned by Named.Method(int)

func (*Method) String

func (m *Method) String() string

func (*Method) WriteTo

func (m *Method) WriteTo(dst io.StringWriter, flag verbose)

type Named

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

represents a named type

func NewNamed

func NewNamed(name string, pkgPath string) *Named

create a new Named type

func (*Named) AddMethod

func (t *Named) AddMethod(mtd *Method)

add a method. always appends to the list of methods, even if another method with the same name already exists.

func (*Named) Method

func (t *Named) Method(i int) Method

return i-th declared method. Ignores methods from embedded fields

func (*Named) Name

func (t *Named) Name() string

func (*Named) NumMethod

func (t *Named) NumMethod() int

return number of declared methods. Ignores methods from embedded fields

func (*Named) PkgPath

func (t *Named) PkgPath() string

func (*Named) SetUnderlying

func (t *Named) SetUnderlying(u Type)

Set underlying type of t to be the same as underlying type of u. u can also be a *Named (and possibly incomplete) type: its underlying type will be retrieved by CompleteTypes(t)

func (*Named) String

func (t *Named) String() string

func (*Named) Underlying

func (t *Named) Underlying() Type

returns nil if SetUnderlying() was not invoked yet

func (*Named) WriteTo

func (t *Named) WriteTo(dst io.StringWriter, flag verbose)

type Object

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

func NewBuiltinObj

func NewBuiltinObj(name string, nin uint32, nout uint32, variadic bool) Object

create a new Object representing a builtin function.

func NewObject

func NewObject(cls Class, name string, typ *Complete) *Object

func (*Object) Class

func (obj *Object) Class() Class

func (*Object) Decl

func (obj *Object) Decl() interface{}

func (*Object) Name

func (obj *Object) Name() string

func (*Object) SetDecl

func (obj *Object) SetDecl(decl interface{}) *Object

func (*Object) SetType

func (obj *Object) SetType(t *Complete)

func (*Object) SetValue

func (obj *Object) SetValue(value interface{}) *Object

func (*Object) String

func (obj *Object) String() string

func (*Object) Type

func (obj *Object) Type() *Complete

func (*Object) Value

func (obj *Object) Value() interface{}

*

  • Value returns the value associated to given *Object, or nil if no value was set.
  • If non nil, it is expected to be:
  • constant.Value for constants
  • *Package for imports,
  • Label for global variables and functions/methods
  • Generic for generic types and generic functions/methods

type Package

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

func NewPackage

func NewPackage(name string, pkgPath string) *Package

func (*Package) Name

func (pkg *Package) Name() string

func (*Package) PkgPath

func (pkg *Package) PkgPath() string

func (*Package) Scope

func (pkg *Package) Scope() *Scope

type Packages

type Packages map[string]*Package

map path -> *Package of all known packages

type Pointer

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

func NewPointer

func NewPointer(elem Type) *Pointer

create a new Pointer type

func (*Pointer) Elem

func (t *Pointer) Elem() Type

func (*Pointer) String

func (t *Pointer) String() string

func (*Pointer) Underlying

func (t *Pointer) Underlying() Type

func (*Pointer) WriteTo

func (t *Pointer) WriteTo(dst io.StringWriter, flag verbose)

type Scope

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

func NewScope

func NewScope(parent *Scope) *Scope

func Universe

func Universe() *Scope

return the top-level scope, containing all predeclared objects of Go. result depends on config.Target()

func (*Scope) Insert

func (s *Scope) Insert(obj *Object)

insert obj into Scope s. overwrites any existing object with the same name

func (*Scope) Len

func (s *Scope) Len() int

func (*Scope) Lookup

func (s *Scope) Lookup(name string) *Object

search object by name in specified Scope.

func (*Scope) LookupParent

func (s *Scope) LookupParent(name string) (*Scope, *Object)

search object by name in specified Scope and all its parent scopes.

func (*Scope) Names

func (s *Scope) Names() []string

return the sorted names of all objects in Scope

func (*Scope) Parent

func (s *Scope) Parent() *Scope

type Slice

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

func NewSlice

func NewSlice(elem Type) *Slice

create a new Slice type

func (*Slice) Elem

func (t *Slice) Elem() Type

func (*Slice) String

func (t *Slice) String() string

func (*Slice) Underlying

func (t *Slice) Underlying() Type

func (*Slice) WriteTo

func (t *Slice) WriteTo(dst io.StringWriter, flag verbose)

type Struct

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

func NewStruct

func NewStruct(fields ...Field) *Struct

create a new Struct type

func (*Struct) Field

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

func (*Struct) NumField

func (t *Struct) NumField() int

func (*Struct) String

func (t *Struct) String() string

func (*Struct) Underlying

func (t *Struct) Underlying() Type

func (*Struct) WriteTo

func (t *Struct) WriteTo(dst io.StringWriter, flag verbose)

type Type

type Type interface {
	String() string
	Underlying() Type

	WriteTo(io.StringWriter, verbose)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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