types

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// WStaticMethodCall type is "Wrap Static Method Call":
	// E.g. Class::doSomething()
	// Params: [Class name <string>] [Method name <string>]
	WStaticMethodCall byte = iota

	// WInstanceMethodCall is a method call on some expression.
	// You need to specify expression type (might be lazy type, e.g. <WStaticMethodCall, SomeClass, instance> ).
	// E.g. $var->callSomething()
	// Params: [Expression type <string>] [Method <string>]
	WInstanceMethodCall

	// WStaticPropertyFetch is a property fetch for static property :).
	// E.g. Test::$something
	// Params: [Class name <string>] [Property name with $ <string>]
	WStaticPropertyFetch

	// WClassConstFetch is a const fetch from a class.
	// E.g. Test::CONSTANT
	// Params: [Class name <string>] [Constant name <string>]
	WClassConstFetch

	// WInstancePropertyFetch is a property fetch from some instance.
	// You need to provide expression type, see example for WInstanceMethodCall.
	// E.g. $var->something
	// Params: [Expression type <string>] [Property name <string>]
	WInstancePropertyFetch

	// WFunctionCall represents a function call.
	// Function name must contain namespace. It will be first searched in the defined namespace
	// and then it will fall back to root namespace.
	// E.g. callSomething()
	// Params: [Function name with full namespace <string>]
	WFunctionCall

	// WArrayOf means that expression is array of another expression
	// E.g. <WArrayOf, string> would be normally written as "string[]"
	//      <WArrayOf, <WFunctionCall, callSomething>>
	// Params: [Expression type <string>]
	WArrayOf

	// WElemOf is the opposite of WArrayOf: it means the type of an element of the expression
	// E.g. $arr[0] would be "string" if $arr type is "string[]"
	// Params: [Expression type <string>]
	WElemOf

	// WElemOfKey is extended for of WElemOf where we also save the key that
	// was used during the indexing.
	// Params: [Expression type <string>] [Key <string>]
	WElemOfKey

	// WGlobal means global variable.
	// E.g. global $Something;
	// Params: [Global variable name <string>]
	WGlobal

	// WConstant means constant
	// e.g. type of MINUTE constant
	// Params: [Constant name <string>]
	WConstant

	// WBaseMethodParam is a way to inherit base type method type of nth parameter.
	// e.g. type of $x param of foo method from one of the implemented interfaces.
	// Params: [Index <uint8>] [Class name <string>] [Method name <string>]
	WBaseMethodParam

	// WMax must always be last to indicate which byte is the maximum value of a type byte
	WMax
)

Variables

View Source
var (
	MixedType = NewMap("mixed").Immutable()
	VoidType  = NewMap("void").Immutable()
	NullType  = NewMap("null").Immutable()

	PreciseIntType    = NewPreciseMap("int").Immutable()
	PreciseFloatType  = NewPreciseMap("float").Immutable()
	PreciseBoolType   = NewPreciseMap("bool").Immutable()
	PreciseStringType = NewPreciseMap("string").Immutable()
)

Preallocated and shared immutable type maps.

Functions

func Alias

func Alias(s string) (string, bool)

func ArrayType

func ArrayType(typ string) string

func FormatSimpleType

func FormatSimpleType(s string) (res string)

func FormatType

func FormatType(s string) (res string)

func IsAlias

func IsAlias(s string) bool

func IsAnonClass added in v0.5.0

func IsAnonClass(s string) bool

func IsArray

func IsArray(s string) bool

func IsClass

func IsClass(s string) bool

func IsClosure

func IsClosure(s string) bool

func IsClosureFromPHPDoc

func IsClosureFromPHPDoc(s string) bool

func IsShape

func IsShape(s string) bool

func IsTrivial

func IsTrivial(s string) bool

func TypeHintHasMoreAccurateType added in v0.5.0

func TypeHintHasMoreAccurateType(typeHintType, phpDocType Map) bool

func UnwrapArrayOf

func UnwrapArrayOf(s string) (typ string)

func UnwrapBaseMethodParam

func UnwrapBaseMethodParam(s string) (paramIndex uint8, className, methodName string)

func UnwrapClassConstFetch

func UnwrapClassConstFetch(s string) (className, constName string)

func UnwrapConstant

func UnwrapConstant(s string) (constName string)

func UnwrapElemOf

func UnwrapElemOf(s string) (typ string)

func UnwrapElemOfKey

func UnwrapElemOfKey(s string) (typ, key string)

func UnwrapFunctionCall

func UnwrapFunctionCall(s string) (funcName string)

func UnwrapGlobal

func UnwrapGlobal(s string) (varName string)

func UnwrapInstanceMethodCall

func UnwrapInstanceMethodCall(s string) (typ, methodName string)

func UnwrapInstancePropertyFetch

func UnwrapInstancePropertyFetch(s string) (typ, propName string)

func UnwrapStaticMethodCall

func UnwrapStaticMethodCall(s string) (className, methodName string)

func UnwrapStaticPropertyFetch

func UnwrapStaticPropertyFetch(s string) (className, propName string)

func WrapArray2

func WrapArray2(ktyp, vtyp string) string

func WrapArrayOf

func WrapArrayOf(typ string) string

func WrapBaseMethodParam

func WrapBaseMethodParam(paramIndex int, className, methodName string) string

func WrapClassConstFetch

func WrapClassConstFetch(className, constName string) string

func WrapConstant

func WrapConstant(constName string) string

func WrapElemOf

func WrapElemOf(typ string) string

func WrapElemOfKey

func WrapElemOfKey(typ, key string) string

func WrapFunctionCall

func WrapFunctionCall(funcName string) string

func WrapGlobal

func WrapGlobal(varName string) string

func WrapInstanceMethodCall

func WrapInstanceMethodCall(typ, methodName string) string

func WrapInstancePropertyFetch

func WrapInstancePropertyFetch(typ, propName string) string

func WrapStaticMethodCall

func WrapStaticMethodCall(className, methodName string) string

func WrapStaticPropertyFetch

func WrapStaticPropertyFetch(className, propName string) string

Types

type ClosureInfo

type ClosureInfo struct {
	Name       string
	ReturnType []Type
	ParamTypes [][]Type
}

type ClosureMap

type ClosureMap map[string]ClosureInfo

type Map

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

Map holds a set of types and can be made immutable to prevent unexpected changes.

func MergeMaps

func MergeMaps(maps ...Map) Map

MergeMaps creates a new types map from union of specified type maps

func NewEmptyMap

func NewEmptyMap(cap int) Map

NewEmptyMap creates new type map that has no types in it

func NewMap

func NewMap(str string) Map

NewMap returns new Map that is initialized with the provided types (separated by "|" symbol)

func NewMapFromMap

func NewMapFromMap(m map[string]struct{}) Map

NewMapFromMap creates Map from provided map[string]struct{}

func NewMapFromTypes

func NewMapFromTypes(types []Type) Map

func NewMapWithNormalization

func NewMapWithNormalization(norm Normalizer, types []Type) Map

func NewPreciseMap

func NewPreciseMap(str string) Map

func NormalizedTypeHintTypes

func NormalizedTypeHintTypes(normalizer Normalizer, typeNode ir.Node) Map

func (Map) Append

func (m Map) Append(n Map) Map

Append adds provided types to current map and returns new one (immutable maps are always copied)

func (Map) Clone

func (m Map) Clone() Map

func (Map) Contains

func (m Map) Contains(typ string) bool

func (Map) Empty

func (m Map) Empty() bool

Empty checks if map has no types at all

func (Map) Equals

func (m Map) Equals(m2 Map) bool

Equals check if two typesmaps are the same

func (Map) Erase

func (m Map) Erase(typ string) Map

func (Map) Filter

func (m Map) Filter(fn func(string) bool) Map

Filter returns a new types map with the types of m for which fn returns true. The result type map is never marked as precise.

func (Map) Find

func (m Map) Find(pred func(typ string) bool) bool

Find applies a predicate function to every contained type. If callback returns true for any of them, this is a result of Find call. False is returned if none of the contained types made pred function return true.

func (*Map) GobDecode

func (m *Map) GobDecode(buf []byte) error

GobDecode is custom gob unmarshaller

func (Map) GobEncode

func (m Map) GobEncode() ([]byte, error)

GobEncode is a custom gob marshaller

func (Map) Immutable

func (m Map) Immutable() Map

Immutable returns immutable view of Map

func (Map) Is

func (m Map) Is(typ string) bool

Is reports whether m contains exactly one specified type.

Warning: typ must be a proper *lazy* or *solved* type.

func (Map) IsArray

func (m Map) IsArray() bool

IsArray checks if map contains only array of any type

func (Map) IsLazyArray

func (m Map) IsLazyArray() bool

IsLazyArray checks if map contains only array of any type

func (Map) IsLazyArrayOf

func (m Map) IsLazyArrayOf(typ string) bool

IsLazyArrayOf checks if map contains only array of given type

func (Map) IsPrecise

func (m Map) IsPrecise() bool

IsPrecise reports whether the type set represented by the map is precise enough to perform typecheck-like analysis.

Type precision determined by a type information source. For example, Int literal has a precise type of `int`, while having a phpdoc that promises some variable to have type `T` too generic.

Adding an imprecise type to a types map makes the entire type map imprecise.

Important invariant: a precise map contains no lazy types.

func (Map) IsResolved

func (m Map) IsResolved() bool

IsResolved reports whether all types inside types map are resolved.

Users should not depend on the "false" result meaning. If "true" is returned, Map is guaranteed to be free of lazy types.

func (Map) Iterate

func (m Map) Iterate(cb func(typ string))

Iterate applies cb to all contained types

func (Map) LazyArrayElemType

func (m Map) LazyArrayElemType() Map

LazyArrayElemType returns type of array element. T[] -> T, T[][] -> T[]. For *Lazy* type.

func (Map) Len

func (m Map) Len() int

Len returns number of different types in map

func (Map) Map

func (m Map) Map(fn func(string) string) Map

Map returns a new types map with the results of calling fn for every type contained inside m. The result type map is never marked as precise.

func (*Map) MarkAsImprecise

func (m *Map) MarkAsImprecise()

func (Map) String

func (m Map) String() string

String returns string representation of a map

type Normalizer

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

func NewNormalizer

func NewNormalizer(classFQNProvider func(string) (string, bool), kphp bool) Normalizer

func (Normalizer) ClassFQNProvider

func (n Normalizer) ClassFQNProvider() func(string) (string, bool)

func (Normalizer) KPHP added in v0.5.2

func (n Normalizer) KPHP() bool

func (Normalizer) NormalizeTypes

func (n Normalizer) NormalizeTypes(typeList []Type)

type ShapeInfo

type ShapeInfo struct {
	Name  string
	Props []ShapeProp
}

type ShapeProp

type ShapeProp struct {
	Key   string
	Types []Type
}

type ShapesMap

type ShapesMap map[string]ShapeInfo

type Type

type Type struct {
	Elem string
	Dims int
}

func TypeHintTypes

func TypeHintTypes(typeNode ir.Node) []Type

TypeHintTypes converts type hint node to meta types.

No normalization is performed.

Jump to

Keyboard shortcuts

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