Documentation
¶
Index ¶
- Constants
- func GensymEmbedded(name string) string
- func GensymPrivate(name string) string
- func IsGoUntypedKind(gkind types.BasicKind) bool
- func SameType(t, u Type) bool
- func ToBasicKind(kind reflect.Kind, untyped bool) types.BasicKind
- func ToReflectKind(gkind types.BasicKind) reflect.Kind
- func Zero(t Type) reflect.Value
- type Error
- type Importer
- type InterfaceHeader
- type Method
- type Package
- type QName
- type QNameI
- type QNameI_github_com_cosmos72_gomacro_xreflect
- type StructField
- type Type
- func ArrayOf(count int, elem Type) Type
- func ChanOf(dir reflect.ChanDir, elem Type) Type
- func FuncOf(in []Type, out []Type, variadic bool) Type
- func InterfaceOf(methodnames []string, methods []Type, embeddeds []Type) Type
- func MapOf(key, elem Type) Type
- func MethodOf(recv Type, in []Type, out []Type, variadic bool) Type
- func PtrTo(elem Type) Type
- func SliceOf(elem Type) Type
- func StructOf(fields []StructField) Type
- func (t Type) AddMethod(name string, signature Type) int
- func (t Type) Align() int
- func (t Type) AssignableTo(u Type) bool
- func (t Type) Bits() int
- func (t Type) ChanDir() reflect.ChanDir
- func (t Type) Comparable() bool
- func (t Type) Complete() Type
- func (t Type) ConvertibleTo(u Type) bool
- func (t Type) Elem() Type
- func (t Type) Field(i int) StructField
- func (t Type) FieldAlign() int
- func (t Type) FieldByName(name, pkgpath string) (field StructField, count int)
- func (t Type) GetMethods() *[]reflect.Value
- func (t Type) GoType() types.Type
- func (t Type) Implements(u Type) bool
- func (t Type) In(i int) Type
- func (t Type) IsMethod() bool
- func (t Type) IsVariadic() bool
- func (t Type) Key() Type
- func (t Type) Kind() reflect.Kind
- func (t Type) Len() int
- func (t Type) Method(i int) Method
- func (t Type) MethodByName(name, pkgpath string) (method Method, count int)
- func (t Type) Name() string
- func (t Type) Named() bool
- func (t Type) NumField() int
- func (t Type) NumIn() int
- func (t Type) NumMethod() int
- func (t Type) NumOut() int
- func (t Type) Out(i int) Type
- func (t Type) Pkg() *Package
- func (t Type) PkgName() string
- func (t Type) PkgPath() string
- func (t Type) ReflectType() reflect.Type
- func (t Type) RemoveMethods(names []string, pkgpath string)
- func (t Type) SetUnderlying(underlying Type)
- func (t Type) Size() uintptr
- func (t Type) String() string
- func (t Type) Universe() *Universe
- func (t Type) UnsafeForceReflectType(rtype reflect.Type)
- type Types
- type Universe
- func (v *Universe) ArrayOf(count int, elem Type) Type
- func (v *Universe) CachePackage(pkg *types.Package)
- func (v *Universe) ChanOf(dir reflect.ChanDir, elem Type) Type
- func (v *Universe) FromReflectType(rtype reflect.Type) Type
- func (v *Universe) FuncOf(in []Type, out []Type, variadic bool) Type
- func (v *Universe) Init() *Universe
- func (v *Universe) InterfaceOf(methodnames []string, methods []Type, embeddeds []Type) Type
- func (v *Universe) InvalidateCache()
- func (v *Universe) InvalidateMethodCache()
- func (v *Universe) LoadPackage(path string) *Package
- func (v *Universe) MakeType(gtype types.Type, rtype reflect.Type) Type
- func (v *Universe) MapOf(key, elem Type) Type
- func (v *Universe) MethodOf(recv Type, in []Type, out []Type, variadic bool) Type
- func (v *Universe) NamedOf(name, pkgpath string) Type
- func (v *Universe) PtrTo(elem Type) Type
- func (v *Universe) SliceOf(elem Type) Type
- func (v *Universe) StructOf(fields []StructField) Type
- func (v *Universe) TypeOf(rvalue interface{}) Type
- type Value
Constants ¶
const ( StrGensymInterface = "\U0001202A" // name of extra struct field needed by the interpreter when creating interpreted interfaces StrGensymPrivate = "\U00012038" // prefix to generate names for unexported struct fields. StrGensymEmbedded = "\U00012039" // prefix to generate names for embedded struct fields. )
the following constants must match with github.com/cosmos72/gomacro/base/constants.go
const MaxDepth = int(^uint(0) >> 1)
Variables ¶
This section is empty.
Functions ¶
func GensymEmbedded ¶
func GensymPrivate ¶
func IsGoUntypedKind ¶
Types ¶
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
func DefaultImporter ¶
func DefaultImporter() *Importer
func (*Importer) ImportFrom ¶
type InterfaceHeader ¶
type InterfaceHeader struct {
// contains filtered or unexported fields
}
InterfaceHeader is the internal header of interpreted interfaces
func MakeInterfaceHeader ¶
func MakeInterfaceHeader(val reflect.Value, typ Type) InterfaceHeader
func (InterfaceHeader) Type ¶
func (h InterfaceHeader) Type() Type
func (InterfaceHeader) Value ¶
func (h InterfaceHeader) Value() reflect.Value
type Method ¶
type Method struct {
Name string
Pkg *Package
Type Type // method type
Funs *[]reflect.Value // (*Funs)[Index] is the method, with receiver as first argument
Index int // index for Type.Method
FieldIndex []int // embedded fields index sequence for reflect.Type.FieldByIndex or reflect.Value.FieldByIndex
GoFun *types.Func // for completeness
}
type QName ¶
type QName struct {
// contains filtered or unexported fields
}
QName is a replacement for go/types.Id and implements accurate comparison of type names, field names and method names. It recognizes unexported names, and names declared in different packages.
To compare two names, build two QNames with the functions QName* then compare the two QName structs with ==
type QNameI_github_com_cosmos72_gomacro_xreflect ¶
type QNameI_github_com_cosmos72_gomacro_xreflect struct {
Object interface{}
Name_ func() string
PkgPath_ func() string
}
--------------- proxy for github.com/cosmos72/gomacro/xreflect.QNameI ---------------
func (*QNameI_github_com_cosmos72_gomacro_xreflect) Name ¶
func (Proxy *QNameI_github_com_cosmos72_gomacro_xreflect) Name() string
func (*QNameI_github_com_cosmos72_gomacro_xreflect) PkgPath ¶
func (Proxy *QNameI_github_com_cosmos72_gomacro_xreflect) PkgPath() string
type StructField ¶
type StructField struct {
// Name is the field name.
Name string
// Pkg is the package that qualifies a lower case (unexported)
// field name. It may be nil for upper case (exported) field names.
// See https://golang.org/ref/spec#Uniqueness_of_identifiers
Pkg *Package
Type Type // field type
Tag reflect.StructTag // field tag string
Offset uintptr // offset within struct, in bytes
Index []int // index sequence for reflect.Type.FieldByIndex or reflect.Value.FieldByIndex
Anonymous bool // is an embedded field. Note: embedded field's name should be set to the type's name
}
type Type ¶
type Type []xtype
func InterfaceOf ¶
InterfaceOf returns a new interface for the given methods and embedded types. After the methods and embeddeds are fully defined, call Complete() to mark the interface as complete and compute wrapper methods for embedded fields.
WARNING: the Type returned by InterfaceOf is not complete, i.e. its method set is not computed yet. Once you know that methods and embedded interfaces are complete, call Complete() to compute the method set and mark this Type as complete.
func StructOf ¶
func StructOf(fields []StructField) Type
func (Type) AddMethod ¶
AddMethod adds method with given name and signature to type, unless it is already in the method list. It panics if the type is unnamed, or if the signature is not a function-with-receiver type. Returns the method index, or < 0 in case of errors
func (Type) Align ¶
Align returns the alignment in bytes of a value of this type when allocated in memory.
func (Type) AssignableTo ¶
AssignableTo reports whether a value of the type is assignable to type u.
func (Type) Bits ¶
Bits returns the size of the type in bits. It panics if the type's Kind is not one of the sized or unsized Int, Uint, Float, or Complex kinds.
func (Type) ChanDir ¶
ChanDir returns a channel type's direction. It panics if the type's Kind is not Chan.
func (Type) Comparable ¶
Comparable reports whether values of this type are comparable.
func (Type) Complete ¶
Complete marks an interface type as complete and computes wrapper methods for embedded fields. It must be called by users of InterfaceOf after the interface's embedded types are fully defined and before using the interface type in any way other than to form other types. Complete returns the receiver.
func (Type) ConvertibleTo ¶
ConvertibleTo reports whether a value of the type is convertible to type u.
func (Type) Elem ¶
Elem returns a type's element type. It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
func (Type) Field ¶
func (t Type) Field(i int) StructField
Field returns a struct type's i-th field. It panics if the type's Kind is not Struct. It panics if i is not in the range [0, NumField()).
func (Type) FieldAlign ¶
FieldAlign returns the alignment in bytes of a value of this type when used as a field in a struct.
func (Type) FieldByName ¶
func (t Type) FieldByName(name, pkgpath string) (field StructField, count int)
FieldByName returns the (possibly embedded) struct field with the given name and the number of fields found at the same (shallowest) depth: 0 if not found. Private fields are returned only if they were declared in pkgpath.
func (Type) GetMethods ¶
GetMethods returns the pointer to the method values. It panics if the type is unnamed
func (Type) Implements ¶
Implements reports whether the type implements the interface type u. It panics if u's Kind is not Interface
func (Type) In ¶
In returns the type of a function type's i'th input parameter. It panics if the type's Kind is not Func. It panics if i is not in the range [0, NumIn()).
func (Type) IsMethod ¶
IsMethod reports whether a function type's contains a receiver, i.e. is a method. If IsMethod returns true, the actual receiver type is available as the first parameter, i.e. Type.In(0) It panics if the type's Kind is not Func.
func (Type) IsVariadic ¶
IsVariadic reports whether a function type's final input parameter is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's implicit actual type []T. IsVariadic panics if the type's Kind is not Func.
func (Type) Method ¶
Method return the i-th explicitly declared method of named type or interface t. Wrapper methods for embedded fields or embedded interfaces are not returned. It panics if the type is unnamed, or if the type's Kind is not Interface
func (Type) MethodByName ¶
MethodByName returns the method with given name (including wrapper methods for embedded fields) and the number of methods found at the same (shallowest) depth: 0 if not found. Private methods are returned only if they were declared in pkgpath.
func (Type) Name ¶
Name returns the type's name within its package. It returns an empty string for unnamed types.
func (Type) NumField ¶
NumField returns a struct type's field count. It panics if the type's Kind is not Struct.
func (Type) NumIn ¶
NumIn returns a function type's input parameter count. It panics if the type's Kind is not Func.
func (Type) NumMethod ¶
NumMethod returns the number of explicitly declared methods of named type or interface t. Wrapper methods for embedded fields or embedded interfaces are not counted.
func (Type) NumOut ¶
NumOut returns a function type's output parameter count. It panics if the type's Kind is not Func.
func (Type) Out ¶
Out returns the type of a function type's i'th output parameter. It panics if the type's Kind is not Func. It panics if i is not in the range [0, NumOut()).
func (Type) Pkg ¶
Pkg returns a named type's package, that is, the package where it was defined. If the type was predeclared (string, error) or unnamed (*T, struct{}, []int), Pkg will return nil.
func (Type) PkgName ¶
PkgName returns a named type's package name, that is, the default name that the package provides when imported. If the type was predeclared (string, error) or unnamed (*T, struct{}, []int), the package name will be the empty string.
func (Type) PkgPath ¶
PkgPath returns a named type's package path, that is, the import path that uniquely identifies the package, such as "encoding/base64". If the type was predeclared (string, error) or unnamed (*T, struct{}, []int), the package path will be the empty string.
func (Type) ReflectType ¶
ReflectType returns a best-effort reflect.Type that approximates the type. It may be inexact for the following reasons:
- missing reflect.NamedOf(): no way to programmatically create named types, or to access the underlying type of a named type
- missing reflect.InterfaceOf(): interface types created at runtime will be approximated by structs
- missing reflect.MethodOf(): method types created at runtime will be approximated by functions whose first parameter is the receiver
- reflect.StructOf() does not support embedded or unexported fields
- go/reflect lacks the ability to create self-referencing types: references to the type itself will be replaced by interface{}.
Examples:
after invoking at runtime type2.NewStruct() and type2.NewNamed()
to create the following type:
type List struct { Elem int; Rest *List }
ReflectType will return a reflect.Type equivalent to:
struct { Elem int; Rest interface{} }
i.e. the type name will be missing due to limitation 1 above,
and the field 'Rest' will have type interface{} instead of *List due to limitation 5.
func (Type) RemoveMethods ¶
RemoveMethods removes given methods from type. It panics if the type is unnamed.
func (Type) SetUnderlying ¶
SetUnderlying sets the underlying type of a named type and marks it as complete. It panics if the type is unnamed, or if the underlying type is named, or if SetUnderlying() was already invoked on the named type.
func (Type) Size ¶
Size returns the number of bytes needed to store a value of the given type; it is analogous to unsafe.Sizeof.
func (Type) UnsafeForceReflectType ¶
type Universe ¶
type Universe struct {
Types
ReflectTypes map[reflect.Type]Type
BasicTypes []Type
TypeOfInterface Type
TypeOfError Type
TryResolve func(name, pkgpath string) Type
Packages map[string]*Package
Importer types.ImporterFrom
RebuildDepth int
ThreadSafe bool
// contains filtered or unexported fields
}
func DefaultUniverse ¶
func DefaultUniverse() *Universe
func NewUniverse ¶
func NewUniverse() *Universe
func (*Universe) CachePackage ¶
CachePackage unconditionally adds pkg to Universe.Packages, then also adds its imports if not cached already
func (*Universe) InterfaceOf ¶
func (*Universe) InvalidateCache ¶
func (v *Universe) InvalidateCache()
clears all xtype.fieldcache and xtype.methodcache. invoked by NamedOf() when a type is redefined.
func (*Universe) InvalidateMethodCache ¶
func (v *Universe) InvalidateMethodCache()
clears all xtype.methodcache. invoked by AddMethod() when a method is redefined.
func (*Universe) LoadPackage ¶
func (*Universe) StructOf ¶
func (v *Universe) StructOf(fields []StructField) Type