Documentation ¶
Index ¶
- Constants
- Variables
- func Alias(s string) (string, bool)
- func ArrayType(typ string) string
- func FormatSimpleType(s string) (res string)
- func FormatType(s string) (res string)
- func IsAlias(s string) bool
- func IsAnonClass(s string) bool
- func IsArray(s string) bool
- func IsClass(s string) bool
- func IsClosure(s string) bool
- func IsClosureFromPHPDoc(s string) bool
- func IsShape(s string) bool
- func IsTrivial(s string) bool
- func TypeHintHasMoreAccurateType(typeHintType, phpDocType Map) bool
- func UnwrapArrayOf(s string) (typ string)
- func UnwrapBaseMethodParam(s string) (paramIndex uint8, className, methodName string)
- func UnwrapClassConstFetch(s string) (className, constName string)
- func UnwrapConstant(s string) (constName string)
- func UnwrapElemOf(s string) (typ string)
- func UnwrapElemOfKey(s string) (typ, key string)
- func UnwrapFunctionCall(s string) (funcName string)
- func UnwrapGlobal(s string) (varName string)
- func UnwrapInstanceMethodCall(s string) (typ, methodName string)
- func UnwrapInstancePropertyFetch(s string) (typ, propName string)
- func UnwrapStaticMethodCall(s string) (className, methodName string)
- func UnwrapStaticPropertyFetch(s string) (className, propName string)
- func WrapArray2(ktyp, vtyp string) string
- func WrapArrayOf(typ string) string
- func WrapBaseMethodParam(paramIndex int, className, methodName string) string
- func WrapClassConstFetch(className, constName string) string
- func WrapConstant(constName string) string
- func WrapElemOf(typ string) string
- func WrapElemOfKey(typ, key string) string
- func WrapFunctionCall(funcName string) string
- func WrapGlobal(varName string) string
- func WrapInstanceMethodCall(typ, methodName string) string
- func WrapInstancePropertyFetch(typ, propName string) string
- func WrapStaticMethodCall(className, methodName string) string
- func WrapStaticPropertyFetch(className, propName string) string
- type ClosureInfo
- type ClosureMap
- type Map
- func MergeMaps(maps ...Map) Map
- func NewEmptyMap(cap int) Map
- func NewMap(str string) Map
- func NewMapFromMap(m map[string]struct{}) Map
- func NewMapFromTypes(types []Type) Map
- func NewMapWithNormalization(norm Normalizer, types []Type) Map
- func NewPreciseMap(str string) Map
- func NormalizedTypeHintTypes(normalizer Normalizer, typeNode ir.Node) Map
- func (m Map) Append(n Map) Map
- func (m Map) Clone() Map
- func (m Map) Contains(typ string) bool
- func (m Map) Empty() bool
- func (m Map) Equals(m2 Map) bool
- func (m Map) Erase(typ string) Map
- func (m Map) Filter(fn func(string) bool) Map
- func (m Map) Find(pred func(typ string) bool) bool
- func (m *Map) GobDecode(buf []byte) error
- func (m Map) GobEncode() ([]byte, error)
- func (m Map) Immutable() Map
- func (m Map) Is(typ string) bool
- func (m Map) IsArray() bool
- func (m Map) IsLazyArray() bool
- func (m Map) IsLazyArrayOf(typ string) bool
- func (m Map) IsPrecise() bool
- func (m Map) IsResolved() bool
- func (m Map) Iterate(cb func(typ string))
- func (m Map) LazyArrayElemType() Map
- func (m Map) Len() int
- func (m Map) Map(fn func(string) string) Map
- func (m *Map) MarkAsImprecise()
- func (m Map) String() string
- type Normalizer
- type ShapeInfo
- type ShapeProp
- type ShapesMap
- type Type
Constants ¶
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 ¶
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 FormatSimpleType ¶
func FormatType ¶
func IsAnonClass ¶ added in v0.5.0
func IsClosureFromPHPDoc ¶
func TypeHintHasMoreAccurateType ¶ added in v0.5.0
func UnwrapArrayOf ¶
func UnwrapBaseMethodParam ¶
func UnwrapClassConstFetch ¶
func UnwrapConstant ¶
func UnwrapElemOf ¶
func UnwrapElemOfKey ¶
func UnwrapFunctionCall ¶
func UnwrapGlobal ¶
func UnwrapStaticMethodCall ¶
func WrapArray2 ¶
func WrapArrayOf ¶
func WrapBaseMethodParam ¶
func WrapClassConstFetch ¶
func WrapConstant ¶
func WrapElemOf ¶
func WrapElemOfKey ¶
func WrapFunctionCall ¶
func WrapGlobal ¶
func WrapInstanceMethodCall ¶
func WrapStaticMethodCall ¶
func WrapStaticPropertyFetch ¶
Types ¶
type ClosureInfo ¶
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 NewEmptyMap ¶
NewEmptyMap creates new type map that has no types in it
func NewMap ¶
NewMap returns new Map that is initialized with the provided types (separated by "|" symbol)
func NewMapFromMap ¶
NewMapFromMap creates Map from provided map[string]struct{}
func NewMapFromTypes ¶
func NewMapWithNormalization ¶
func NewMapWithNormalization(norm Normalizer, types []Type) Map
func NewPreciseMap ¶
func NormalizedTypeHintTypes ¶
func NormalizedTypeHintTypes(normalizer Normalizer, typeNode ir.Node) Map
func (Map) Append ¶
Append adds provided types to current map and returns new one (immutable maps are always copied)
func (Map) Filter ¶
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 ¶
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) Is ¶
Is reports whether m contains exactly one specified type.
Warning: typ must be a proper *lazy* or *solved* type.
func (Map) IsLazyArray ¶
IsLazyArray checks if map contains only array of any type
func (Map) IsLazyArrayOf ¶
IsLazyArrayOf checks if map contains only array of given type
func (Map) IsPrecise ¶
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 ¶
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) LazyArrayElemType ¶
LazyArrayElemType returns type of array element. T[] -> T, T[][] -> T[]. For *Lazy* type.
func (Map) 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()
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)