nature

package
v1.17.7 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 5 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StructFields

func StructFields(c *Cache, t reflect.Type) map[string]Nature

Types

type Cache added in v1.17.7

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

Cache is a shared cache of type information. It is only used in the stages where type information becomes relevant, so packages like ast, parser, types, and lexer do not need to use the cache because they don't need any service from the Nature type, they only describe. However, when receiving a Nature from one of those packages, the cache must be set immediately.

func (*Cache) FromType added in v1.17.7

func (c *Cache) FromType(t reflect.Type) Nature

FromType returns a Nature describing a value of type "t". If "t" is nil then it returns a Nature describing an unknown value.

func (*Cache) NatureOf added in v1.17.7

func (c *Cache) NatureOf(i any) Nature

NatureOf returns a Nature describing "i". If "i" is nil then it returns a Nature describing the value "nil".

type Nature

type Nature struct {
	Type reflect.Type // Type of the value. If nil, then value is unknown.
	Kind reflect.Kind // Kind of the value.

	*TypeData

	// Ref is a reference used for multiple, disjoint purposes. When the Nature
	// is for a:
	//	- Predicate: then Ref is the nature of the Out of the predicate.
	//	- Array-like types: then Ref is the Elem nature of array type (usually Type is []any, but ArrayOf can be any nature).
	Ref *Nature

	Nil       bool // If value is nil.
	Strict    bool // If map is types.StrictMap.
	Method    bool // If value retrieved from method. Usually used to determine amount of in arguments.
	IsInteger bool // If it's a builtin integer or unsigned integer type.
	IsFloat   bool // If it's a builtin float type.
}

func ArrayFromType added in v1.17.7

func ArrayFromType(c *Cache, t reflect.Type) Nature

func FromType added in v1.17.7

func FromType(t reflect.Type) Nature

FromType calls FromType on a nil *Cache. See the comment on Cache.

func NatureOf added in v1.17.7

func NatureOf(i any) Nature

NatureOf calls NatureOf on a nil *Cache. See the comment on Cache.

func (*Nature) All

func (n *Nature) All(c *Cache) map[string]Nature

func (*Nature) AssignableTo

func (n *Nature) AssignableTo(nt Nature) bool

func (*Nature) ComparableTo added in v1.17.7

func (n *Nature) ComparableTo(c *Cache, rhs Nature) bool

func (*Nature) Deref

func (n *Nature) Deref(c *Cache) Nature

func (*Nature) Elem

func (n *Nature) Elem(c *Cache) Nature

func (*Nature) FieldByName

func (n *Nature) FieldByName(c *Cache, name string) (Nature, bool)

func (*Nature) FieldIndex

func (n *Nature) FieldIndex(c *Cache, name string) ([]int, bool)

func (*Nature) Get

func (n *Nature) Get(c *Cache, name string) (Nature, bool)

func (*Nature) In

func (n *Nature) In(c *Cache, i int) Nature

func (*Nature) InElem added in v1.17.7

func (n *Nature) InElem(c *Cache, i int) Nature

func (*Nature) IsAny

func (n *Nature) IsAny(c *Cache) bool

func (*Nature) IsAnyOf added in v1.17.7

func (n *Nature) IsAnyOf(cs ...NatureCheck) bool

func (*Nature) IsArray added in v1.17.7

func (n *Nature) IsArray() bool

func (*Nature) IsBool added in v1.17.7

func (n *Nature) IsBool() bool

func (*Nature) IsByteSlice added in v1.17.7

func (n *Nature) IsByteSlice() bool

func (*Nature) IsDuration added in v1.17.7

func (n *Nature) IsDuration() bool

func (*Nature) IsFastMap

func (n *Nature) IsFastMap() bool

func (*Nature) IsFirstArgUnknown added in v1.17.7

func (n *Nature) IsFirstArgUnknown(c *Cache) bool

func (*Nature) IsFunc added in v1.17.7

func (n *Nature) IsFunc() bool

func (*Nature) IsMap added in v1.17.7

func (n *Nature) IsMap() bool

func (*Nature) IsNumber added in v1.17.7

func (n *Nature) IsNumber() bool

func (*Nature) IsPointer added in v1.17.7

func (n *Nature) IsPointer() bool

func (*Nature) IsString added in v1.17.7

func (n *Nature) IsString() bool

func (*Nature) IsStruct added in v1.17.7

func (n *Nature) IsStruct() bool

func (*Nature) IsTime added in v1.17.7

func (n *Nature) IsTime() bool

func (*Nature) IsUnknown

func (n *Nature) IsUnknown(c *Cache) bool

func (*Nature) IsVariadic

func (n *Nature) IsVariadic() bool

func (*Nature) Key

func (n *Nature) Key(c *Cache) Nature

func (*Nature) MakeArrayOf added in v1.17.7

func (n *Nature) MakeArrayOf(c *Cache) Nature

func (*Nature) MaybeCompatible added in v1.17.7

func (n *Nature) MaybeCompatible(c *Cache, rhs Nature, cs ...NatureCheck) bool

func (*Nature) MethodByName

func (n *Nature) MethodByName(c *Cache, name string) (Nature, bool)

func (*Nature) NumIn

func (n *Nature) NumIn() int

func (*Nature) NumMethods

func (n *Nature) NumMethods(c *Cache) int

func (*Nature) NumOut

func (n *Nature) NumOut() int

func (*Nature) Out

func (n *Nature) Out(c *Cache, i int) Nature

func (*Nature) PromoteNumericNature added in v1.17.7

func (n *Nature) PromoteNumericNature(c *Cache, rhs Nature) Nature

func (*Nature) String

func (n *Nature) String() string

type NatureCheck added in v1.17.7

type NatureCheck int
const (
	BoolCheck NatureCheck
	StringCheck
	IntegerCheck
	NumberCheck
	MapCheck
	ArrayCheck
	TimeCheck
	DurationCheck
)

type TypeData added in v1.17.7

type TypeData struct {

	// map-only data
	Fields          map[string]Nature // Fields of map type.
	DefaultMapValue *Nature           // Default value of map type.

	// callable-only data
	Func        *builtin.Function // Used to pass function type from callee to CallNode.
	MethodIndex int               // Index of method in type.
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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