compiler/typesutil
import "github.com/gopherjs/gopherjs/compiler/typesutil"
Functions
func IsJsObject(t types.Type) bool
func IsJsPackage(pkg *types.Package) bool
func IsMethod(o types.Object) bool
Source: compiler/typesutil/typesutil.go:112
IsMethod returns true if the passed object is a method.
func NewSelection(kind types.SelectionKind, recv types.Type, index []int, obj types.Object, typ types.Type) Selection
Source: compiler/typesutil/typesutil.go:60
NewSelection creates a new selection.
func OffsetOf(sizes types.Sizes, sel Selection) int64
Source: compiler/typesutil/typesutil.go:96
OffsetOf returns byte offset of a struct field specified by the provided selection.
Adapted from go/types.Config.offsetof().
func RecvAsFirstArg(sig *types.Signature) *types.Signature
Source: compiler/typesutil/typesutil.go:40
RecvAsFirstArg takes a method signature and returns a function signature with receiver as the first parameter.
func RecvType(sig *types.Signature) *types.Named
Source: compiler/typesutil/typesutil.go:24
RecvType returns a named type of a method receiver, or nil if it's not a method.
For methods on a pointer receiver, the underlying named type is returned.
Types
type Map
Source: compiler/typesutil/map.go:10
Map is a type-safe wrapper around golang.org/x/tools/go/types/typeutil.Map.
type Map[Val any] struct {
// contains filtered or unexported fields
}func At(key types.Type) Val
func Delete(key types.Type) bool
func Len() int
func Set(key types.Type, value Val) (prev Val)
func String() string
type Selection
Source: compiler/typesutil/typesutil.go:51
Selection is a common interface for go/types.Selection and our custom-constructed method and field selections.
type Selection interface {
Kind() types.SelectionKind
Recv() types.Type
Index() []int
Obj() types.Object
Type() types.Type
}Methods
Kind func() types.SelectionKindRecv func() types.TypeIndex func() []intObj func() types.ObjectType func() types.Type
type Signature
Source: compiler/typesutil/signature.go:10
Signature is a helper that provides convenient access to function signature type information.
type Signature struct {
Sig *types.Signature
}Fields
Sig *types.Signature
func HasNamedResults() bool
Source: compiler/typesutil/signature.go:65
HasNamedResults returns true if the function signature returns something and
returned results are names (e.g. func () (val int, err error)).
func HasResults() bool
Source: compiler/typesutil/signature.go:59
HasResults returns true if the function signature returns something.
func Param(i int, ellipsis bool) types.Type
Source: compiler/typesutil/signature.go:44
Param returns the expected argument type for the i'th argument position.
This function is able to return correct expected types for variadic calls both when ellipsis syntax (e.g. myFunc(requiredArg, optionalArgSlice...)) is used and when optional args are passed individually.
The returned types may differ from the actual argument expression types if there is an implicit type conversion involved (e.g. passing a struct into a function that expects an interface).
func RequiredParams() int
Source: compiler/typesutil/signature.go:15
RequiredParams returns the number of required parameters in the function signature.
func VariadicType() types.Type
Source: compiler/typesutil/signature.go:28
VariadicType returns the slice-type corresponding to the signature's variadic
parameter, or nil of the signature is not variadic. With the exception of
the special-case append([]byte{}, "string"...), the returned type is
*types.Slice and .Elem() method can be used to get the type of individual
arguments.
type TypeList
Source: compiler/typesutil/typelist.go:9
TypeList an ordered list of types.
type TypeList []types.Typefunc Equal(other TypeList) bool
Source: compiler/typesutil/typelist.go:23
Equal returns true if both lists of type arguments are identical.
func String() string
type TypeNames
Source: compiler/typesutil/typenames.go:8
TypeNames implements an ordered set of *types.TypeName pointers.
The set is ordered to ensure deterministic behavior across compiler runs.
type TypeNames struct {
// contains filtered or unexported fields
}func Add(name *types.TypeName)
Source: compiler/typesutil/typenames.go:16
Add a type name to the set. If the type name has been previously added, this operation is a no-op. Two type names are considered equal iff they have the same memory address.
func Slice() []*types.TypeName
Source: compiler/typesutil/typenames.go:28
Slice returns set elements in the order they were first added to the set.
