typeparams

package
Version: v0.1.8-0...-affba50 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package typeparams provides functions to work indirectly with type parameter data stored in go/ast and go/types objects, while these API are guarded by a build constraint.

This package exists to make it easier for tools to work with generic code, while also compiling against older Go versions.

Index

Constants

View Source
const Enabled = false

Enabled reports whether type parameters are enabled in the current build environment.

Variables

This section is empty.

Functions

func ForFuncType added in v0.1.7

func ForFuncType(*ast.FuncType) *ast.FieldList

ForFuncType returns an empty field list, as type parameters are not supported at this Go version.

func ForTypeSpec added in v0.1.7

func ForTypeSpec(*ast.TypeSpec) *ast.FieldList

ForTypeSpec returns an empty field list, as type parameters on not supported at this Go version.

func GetInstances

func GetInstances(info *types.Info) map[*ast.Ident]Instance

GetInstances returns a nil map, as type parameters are not supported at this Go version.

func InitInstanceInfo added in v0.1.7

func InitInstanceInfo(*types.Info)

InitInstanceInfo is a noop at this Go version.

func Instantiate added in v0.1.6

func Instantiate(ctxt *Context, typ types.Type, targs []types.Type, validate bool) (types.Type, error)

Instantiate is unsupported on this Go version, and panics.

func IsComparable

func IsComparable(*types.Interface) bool

IsComparable returns false, as no interfaces are type-restricted at this Go version.

func IsImplicit

func IsImplicit(*types.Interface) bool

IsImplicit returns false, as no interfaces are implicit at this Go version.

func IsMethodSet

func IsMethodSet(*types.Interface) bool

IsMethodSet returns true, as no interfaces are type-restricted at this Go version.

func NamedTypeOrigin added in v0.1.7

func NamedTypeOrigin(named *types.Named) types.Type

NamedTypeOrigin is the identity method at this Go version.

func NewSignatureType

func NewSignatureType(recv *types.Var, recvTypeParams, typeParams []*TypeParam, params, results *types.Tuple, variadic bool) *types.Signature

NewSignatureType calls types.NewSignature, panicking if recvTypeParams or typeParams is non-empty.

func NormalizeInterface

func NormalizeInterface(iface *types.Interface) (*types.Interface, error)

NormalizeInterface returns the normal form of the interface iface, or nil if iface has an empty type set (i.e. there are no types that satisfy iface). If the resulting interface is non-nil, it will be identical to iface.

An error is returned if the interface type is invalid, or too complicated to reasonably normalize (for example, contains unions with more than a hundred terms).

An interface is in normal form if and only if:

- it has 0 or 1 embedded types.
- its embedded type is either a types.Union or has a concrete
  (non-interface) underlying type
- if the embedded type is a union, each term of the union has a concrete
  underlying type, and no terms may be removed without changing the type set
  of the interface

func PackIndexExpr

func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack token.Pos) ast.Expr

PackIndexExpr returns an *ast.IndexExpr with the given index. Calling PackIndexExpr with len(indices) != 1 will panic.

func SetForNamed added in v0.1.6

func SetForNamed(_ *types.Named, tparams []*TypeParam)

SetForNamed panics if tparams is non-empty.

func SetTypeParamConstraint added in v0.1.6

func SetTypeParamConstraint(tparam *TypeParam, constraint types.Type)

SetTypeParamConstraint is unsupported at this Go version, and panics.

Types

type Context

type Context struct{}

Context is a placeholder type, as type parameters are not supported at this Go version.

type IndexExprData added in v0.1.6

type IndexExprData struct {
	X       ast.Expr   // expression
	Lbrack  token.Pos  // position of "["
	Indices []ast.Expr // index expressions
	Rbrack  token.Pos  // position of "]"
}

A IndexExprData holds data from both ast.IndexExpr and the new ast.MultiIndexExpr, which was introduced in Go 1.18.

func GetIndexExprData added in v0.1.6

func GetIndexExprData(n ast.Node) *IndexExprData

GetIndexExprData extracts data from *ast.IndexExpr nodes. For other nodes, GetIndexExprData returns nil.

type IndexListExpr

type IndexListExpr struct {
	ast.Expr
	X       ast.Expr   // expression
	Lbrack  token.Pos  // position of "["
	Indices []ast.Expr // index expressions
	Rbrack  token.Pos  // position of "]"
}

IndexListExpr is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.

type Instance

type Instance struct {
	TypeArgs *TypeList
	Type     types.Type
}

Instance is a placeholder type, as type parameters are not supported at this Go version.

type Term added in v0.1.6

type Term struct{}

Term is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.

func NewTerm added in v0.1.6

func NewTerm(tilde bool, typ types.Type) *Term

NewTerm is unsupported at this Go version, and panics.

func (*Term) String added in v0.1.7

func (*Term) String() string

func (*Term) Tilde added in v0.1.7

func (*Term) Tilde() bool

func (*Term) Type added in v0.1.7

func (*Term) Type() types.Type

func (*Term) Underlying added in v0.1.7

func (*Term) Underlying() types.Type

type TypeList added in v0.1.6

type TypeList struct{}

TypeList is a placeholder for an empty type list.

func NamedTypeArgs added in v0.1.6

func NamedTypeArgs(*types.Named) *TypeList

NamedTypeArgs returns nil.

func (*TypeList) At added in v0.1.6

func (*TypeList) At(int) types.Type

func (*TypeList) Len added in v0.1.6

func (*TypeList) Len() int

type TypeParam added in v0.1.6

type TypeParam struct{ types.Type }

TypeParam is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.

func NewTypeParam added in v0.1.6

func NewTypeParam(name *types.TypeName, constraint types.Type) *TypeParam

NewTypeParam is unsupported at this Go version, and panics.

func (*TypeParam) Constraint added in v0.1.7

func (*TypeParam) Constraint() types.Type

func (*TypeParam) Obj added in v0.1.7

func (*TypeParam) Obj() *types.TypeName

type TypeParamList added in v0.1.6

type TypeParamList struct{}

TypeParamList is a placeholder for an empty type parameter list.

func ForNamed

func ForNamed(*types.Named) *TypeParamList

ForNamed returns an empty type parameter list, as type parameters are not supported at this Go version.

func ForSignature

func ForSignature(*types.Signature) *TypeParamList

ForSignature returns an empty slice.

func RecvTypeParams added in v0.1.6

func RecvTypeParams(sig *types.Signature) *TypeParamList

RecvTypeParams returns a nil slice.

func (*TypeParamList) At added in v0.1.6

func (*TypeParamList) At(int) *TypeParam

func (*TypeParamList) Len added in v0.1.6

func (*TypeParamList) Len() int

type Union added in v0.1.6

type Union struct{ types.Type }

Union is a placeholder type, as type parameters are not supported at this Go version. Its methods panic on use.

func NewUnion added in v0.1.6

func NewUnion(terms []*Term) *Union

NewUnion is unsupported at this Go version, and panics.

func (*Union) Len added in v0.1.7

func (*Union) Len() int

func (*Union) Term added in v0.1.7

func (*Union) Term(i int) *Term

Jump to

Keyboard shortcuts

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