Documentation
¶
Index ¶
- Constants
- Variables
- func IsArrayType(s string) bool
- func IsClassType(s string) bool
- func IsIndexingComplete() bool
- func IsInternalClass(className string) bool
- func IsLoadingStubs() bool
- func IsShapeType(s string) bool
- func NameNodeEquals(n ir.Node, s string) bool
- func NameNodeToString(n ir.Node) string
- func OnIndexingComplete(cb func())
- func ResetInfo()
- func SetIndexingComplete(complete bool)
- func SetLoadingStubs(loading 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 AccessLevel
- type ClassFlags
- type ClassInfo
- type ClassParseState
- type ClassesMap
- type ConstInfo
- type ConstValue
- func (c ConstValue) GetBool() bool
- func (c ConstValue) GetFloat() float64
- func (c ConstValue) GetInt() int64
- func (c ConstValue) GetString() string
- func (c *ConstValue) GobDecode(buf []byte) error
- func (c ConstValue) GobEncode() ([]byte, error)
- func (c ConstValue) IsEqual(v ConstValue) bool
- func (c ConstValue) IsValid() bool
- func (c ConstValue) String() string
- func (c ConstValue) ToBool() (value bool, ok bool)
- func (c ConstValue) ToInt() (int64, bool)
- func (c ConstValue) ToString() (string, bool)
- type ConstValueType
- type ConstantsMap
- type ElementPosition
- type FuncFlags
- type FuncInfo
- type FuncInfoOverride
- type FuncParam
- type FunctionsMap
- type FunctionsOverrideMap
- type OverrideType
- type PerFile
- type PhpDocInfo
- type PropertiesMap
- type PropertyInfo
- type Scope
- func (s *Scope) AddVar(v ir.Node, typ TypesMap, reason string, flags VarFlags)
- func (s *Scope) AddVarFromPHPDoc(name string, typ TypesMap, reason string)
- func (s *Scope) AddVarName(name string, typ TypesMap, reason string, flags VarFlags)
- func (s *Scope) Clone() *Scope
- func (s *Scope) DelVar(v ir.Node, reason string)
- func (s *Scope) DelVarName(name, reason string)
- func (s *Scope) GetVarNameType(name string) (m TypesMap, ok bool)
- func (s *Scope) GobDecode(buf []byte) error
- func (s *Scope) GobEncode() ([]byte, error)
- func (s *Scope) HaveVar(v ir.Node) bool
- func (s *Scope) HaveVarName(name string) bool
- func (s *Scope) IsInClosure() bool
- func (s *Scope) IsInInstanceMethod() bool
- func (s *Scope) Iterate(cb func(varName string, typ TypesMap, flags VarFlags))
- func (s *Scope) Len() int
- func (s *Scope) MaybeHaveVar(v ir.Node) bool
- func (s *Scope) MaybeHaveVarName(name string) bool
- func (s *Scope) ReplaceVar(v ir.Node, typ TypesMap, reason string, flags VarFlags)
- func (s *Scope) ReplaceVarName(name string, typ TypesMap, reason string, flags VarFlags)
- func (s *Scope) SetInClosure(v bool)
- func (s *Scope) SetInInstanceMethod(v bool)
- func (s *Scope) String() string
- type Type
- type TypesMap
- func (m TypesMap) Append(n TypesMap) TypesMap
- func (m TypesMap) ArrayElemLazyType() TypesMap
- func (m TypesMap) Clone() TypesMap
- func (m TypesMap) Contains(typ string) bool
- func (m TypesMap) Equals(m2 TypesMap) bool
- func (m TypesMap) Find(pred func(typ string) bool) bool
- func (m *TypesMap) GobDecode(buf []byte) error
- func (m TypesMap) GobEncode() ([]byte, error)
- func (m TypesMap) Immutable() TypesMap
- func (m TypesMap) Is(typ string) bool
- func (m TypesMap) IsArray() bool
- func (m TypesMap) IsArrayOf(typ string) bool
- func (m TypesMap) IsEmpty() bool
- func (m TypesMap) IsPrecise() bool
- func (m TypesMap) IsResolved() bool
- func (m TypesMap) Iterate(cb func(typ string))
- func (m TypesMap) Len() int
- func (m TypesMap) Map(fn func(string) string) TypesMap
- func (m *TypesMap) MarkAsImprecise()
- func (m TypesMap) String() string
- type VarFlags
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 ( UnknownValue = ConstValue{Type: Undefined} TrueValue = ConstValue{Type: Bool, Value: true} FalseValue = ConstValue{Type: Bool, Value: false} )
var ( MixedType = NewTypesMap("mixed").Immutable() VoidType = NewTypesMap("void").Immutable() NullType = NewTypesMap("null").Immutable() PreciseIntType = NewPreciseTypesMap("int").Immutable() PreciseFloatType = NewPreciseTypesMap("float").Immutable() PreciseBoolType = NewPreciseTypesMap("bool").Immutable() PreciseStringType = NewPreciseTypesMap("string").Immutable() )
Preallocated and shared immutable type maps.
var (
// Info contains global meta information for all classes, functions, etc.
Info info
)
Functions ¶
func IsArrayType ¶ added in v0.3.0
func IsClassType ¶ added in v0.3.0
func IsIndexingComplete ¶
func IsIndexingComplete() bool
func IsInternalClass ¶ added in v0.2.0
func IsLoadingStubs ¶ added in v0.3.0
func IsLoadingStubs() bool
IsLoadingStubs reports whether we're parsing stub files right now.
func IsShapeType ¶ added in v0.3.0
func NameNodeEquals ¶
NameNodeEquals checks whether n node name value is identical to s.
func NameNodeToString ¶
NameNodeToString converts nodes of *name.Name, and *node.Identifier to string. This function is a helper function to aid printing function names, not for actual code analysis.
func OnIndexingComplete ¶
func OnIndexingComplete(cb func())
func SetIndexingComplete ¶
func SetIndexingComplete(complete bool)
func SetLoadingStubs ¶ added in v0.3.0
func SetLoadingStubs(loading bool)
SetLoadingStubs changes IsLoadingStubs() return value.
Should be only called from linter.InitStubs() function.
func UnwrapArrayOf ¶
func UnwrapBaseMethodParam ¶
func UnwrapClassConstFetch ¶
func UnwrapConstant ¶
func UnwrapElemOf ¶
func UnwrapElemOfKey ¶ added in v0.3.0
func UnwrapFunctionCall ¶
func UnwrapGlobal ¶
func UnwrapStaticMethodCall ¶
func WrapArray2 ¶ added in v0.2.0
func WrapArrayOf ¶
func WrapBaseMethodParam ¶
func WrapClassConstFetch ¶
func WrapConstant ¶
func WrapElemOf ¶
func WrapElemOfKey ¶ added in v0.3.0
func WrapFunctionCall ¶
func WrapGlobal ¶
func WrapInstanceMethodCall ¶
func WrapStaticMethodCall ¶
func WrapStaticPropertyFetch ¶
Types ¶
type AccessLevel ¶
type AccessLevel int
const ( Public AccessLevel = iota Protected Private )
func (AccessLevel) String ¶
func (l AccessLevel) String() string
type ClassFlags ¶ added in v0.2.0
type ClassFlags uint8
const ( ClassAbstract ClassFlags = 1 << iota ClassFinal ClassShape )
type ClassInfo ¶
type ClassInfo struct {
Pos ElementPosition
Name string
Flags ClassFlags
Parent string
ParentInterfaces []string // interfaces allow multiple inheritance
Traits map[string]struct{}
Interfaces map[string]struct{}
Methods FunctionsMap
Properties PropertiesMap // both instance and static properties are inside. Static properties have "$" prefix
Constants ConstantsMap
Mixins []string
}
func (*ClassInfo) IsAbstract ¶ added in v0.2.0
type ClassParseState ¶
type ClassParseState struct {
IsTrait bool
Namespace string
FunctionUses map[string]string
Uses map[string]string
CurrentFile string
CurrentClass string
CurrentParentClass string
CurrentParentInterfaces []string // interfaces allow for multiple inheritance...
CurrentFunction string // current method or function name
}
type ClassesMap ¶
type ClassesMap struct {
H map[lowercaseString]ClassInfo
}
func NewClassesMap ¶ added in v0.2.0
func NewClassesMap() ClassesMap
func (ClassesMap) Delete ¶ added in v0.2.0
func (m ClassesMap) Delete(name string)
func (ClassesMap) Len ¶ added in v0.2.0
func (m ClassesMap) Len() int
func (ClassesMap) Set ¶ added in v0.2.0
func (m ClassesMap) Set(name string, class ClassInfo)
type ConstInfo ¶ added in v0.3.0
type ConstInfo struct {
Pos ElementPosition
Typ TypesMap
AccessLevel AccessLevel
Value ConstValue
}
type ConstValue ¶ added in v0.3.0
type ConstValue struct {
Type ConstValueType
Value interface{}
}
ConstValue structure is used to store the value and type of a constant.
func NewBoolConst ¶ added in v0.3.0
func NewBoolConst(v bool) ConstValue
NewBoolConst returns a new constant value with the preset bool type and the passed value v.
func NewFloatConst ¶ added in v0.3.0
func NewFloatConst(v float64) ConstValue
NewFloatConst returns a new constant value with the preset float type and the passed value v.
func NewIntConst ¶ added in v0.3.0
func NewIntConst(v int64) ConstValue
NewIntConst returns a new constant value with the preset int type and the passed value v.
func NewStringConst ¶ added in v0.3.0
func NewStringConst(v string) ConstValue
NewStringConst returns a new constant value with the preset string type and the passed value v.
func (ConstValue) GetBool ¶ added in v0.3.0
func (c ConstValue) GetBool() bool
GetBool returns the value stored in c.Value cast to bool type.
Should be used with care, it can panic if the type is not equal to the required one. Usually used in places where the type has already been clearly defined and the probability of panic is 0.
func (ConstValue) GetFloat ¶ added in v0.3.0
func (c ConstValue) GetFloat() float64
GetFloat returns the value stored in c.Value cast to float type.
Should be used with care, it can panic if the type is not equal to the required one. Usually used in places where the type has already been clearly defined and the probability of panic is 0.
func (ConstValue) GetInt ¶ added in v0.3.0
func (c ConstValue) GetInt() int64
GetInt returns the value stored in c.Value cast to int type.
Should be used with care, it can panic if the type is not equal to the required one. Usually used in places where the type has already been clearly defined and the probability of panic is 0.
func (ConstValue) GetString ¶ added in v0.3.0
func (c ConstValue) GetString() string
GetString returns the value stored in c.Value cast to string type.
Should be used with care, it can panic if the type is not equal to the required one. Usually used in places where the type has already been clearly defined and the probability of panic is 0.
func (*ConstValue) GobDecode ¶ added in v0.3.0
func (c *ConstValue) GobDecode(buf []byte) error
func (ConstValue) GobEncode ¶ added in v0.3.0
func (c ConstValue) GobEncode() ([]byte, error)
func (ConstValue) IsEqual ¶ added in v0.3.0
func (c ConstValue) IsEqual(v ConstValue) bool
IsEqual checks for equality with the passed constant value.
If any of the constants are undefined, false is returned.
func (ConstValue) IsValid ¶ added in v0.3.0
func (c ConstValue) IsValid() bool
IsValid checks that the value is valid and its type is not undefined.
func (ConstValue) String ¶ added in v0.3.0
func (c ConstValue) String() string
func (ConstValue) ToBool ¶ added in v0.3.0
func (c ConstValue) ToBool() (value bool, ok bool)
ToBool converts x constant to boolean constants following PHP conversion rules. Second bool result tells whether that conversion was successful.
func (ConstValue) ToInt ¶ added in v0.3.0
func (c ConstValue) ToInt() (int64, bool)
ToInt converts x constant to int constants following PHP conversion rules. Second bool result tells whether that conversion was successful.
func (ConstValue) ToString ¶ added in v0.3.0
func (c ConstValue) ToString() (string, bool)
ToString converts x constant to string constants following PHP conversion rules. Second bool result tells whether that conversion was successful.
type ConstValueType ¶ added in v0.3.0
type ConstValueType uint8
const ( Undefined ConstValueType = iota Integer Float String Bool )
func (ConstValueType) String ¶ added in v0.3.0
func (i ConstValueType) String() string
type ConstantsMap ¶
type ElementPosition ¶
type FuncInfo ¶
type FuncInfo struct {
Pos ElementPosition
Name string
Params []FuncParam
MinParamsCnt int
Typ TypesMap
AccessLevel AccessLevel
Flags FuncFlags
ExitFlags int // if function has exit/die/throw, then ExitFlags will be <> 0
Doc PhpDocInfo
}
func GetInternalFunctionInfo ¶
func (*FuncInfo) IsAbstract ¶ added in v0.2.0
type FuncInfoOverride ¶
type FuncInfoOverride struct {
OverrideType OverrideType
ArgNum int
}
FuncInfoOverride defines return type overrides based on their parameter types. For example, \array_slice($arr) returns type of element (OverrideElementType) of the ArgNum=0
func GetInternalFunctionOverrideInfo ¶
func GetInternalFunctionOverrideInfo(fn string) (info FuncInfoOverride, ok bool)
type FunctionsMap ¶
type FunctionsMap struct {
H map[lowercaseString]FuncInfo
}
func NewFunctionsMap ¶ added in v0.2.0
func NewFunctionsMap() FunctionsMap
func (FunctionsMap) Delete ¶ added in v0.2.0
func (m FunctionsMap) Delete(name string)
func (FunctionsMap) Len ¶ added in v0.2.0
func (m FunctionsMap) Len() int
func (FunctionsMap) Set ¶ added in v0.2.0
func (m FunctionsMap) Set(name string, fn FuncInfo)
type FunctionsOverrideMap ¶
type FunctionsOverrideMap map[string]FuncInfoOverride
type OverrideType ¶
type OverrideType int
const ( // OverrideArgType means that return type of a function is the same as the type of the argument OverrideArgType OverrideType = iota // OverrideElementType means that return type of a function is the same as the type of an element of the argument OverrideElementType // OverrideClassType means that return type of a function is the same as the type represented by the class name. OverrideClassType )
type PerFile ¶
type PerFile struct {
Traits ClassesMap
Classes ClassesMap
Functions FunctionsMap
Constants ConstantsMap
}
PerFile contains all meta information about the specified file
type PhpDocInfo ¶
type PropertiesMap ¶
type PropertiesMap map[string]PropertyInfo
type PropertyInfo ¶
type PropertyInfo struct {
Pos ElementPosition
Typ TypesMap
AccessLevel AccessLevel
}
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope contains variables with their types in the respective scope
func (*Scope) AddVarFromPHPDoc ¶
AddVarFromPHPDoc adds variable with specified types to the scope
func (*Scope) AddVarName ¶
AddVarName adds variable with specified types to the scope
func (*Scope) DelVarName ¶
DelVarName deletes variable from the scope by it's name
func (*Scope) GetVarNameType ¶
GetVarNameType returns type map for variable if it exists
func (*Scope) HaveVar ¶
HaveVar checks whether or not specified variable is present in the scope and that it is always defined
func (*Scope) HaveVarName ¶
HaveVarName checks whether or not specified variable is present in the scope and that it is always defined
func (*Scope) IsInClosure ¶
IsInClosure returns whether or not this scope is inside a closure and thus $this can be late-bound.
func (*Scope) IsInInstanceMethod ¶
IsInInstanceMethod returns whether or not this scope exists in instance method (and thus closures must capture $this)
func (*Scope) MaybeHaveVar ¶
MaybeHaveVar checks that variable is present in the scope (it may be not always defined)
func (*Scope) MaybeHaveVarName ¶
MaybeHaveVarName checks that variable is present in the scope (it may be not always defined)
func (*Scope) ReplaceVar ¶
ReplaceVar replaces variable with specified types to scope
func (*Scope) ReplaceVarName ¶
ReplaceVarName replaces variable with specified types to the scope
func (*Scope) SetInClosure ¶
SetInClosure updates "inClosure" flag that indicates whether or not we are inside a closure and thus late $this binding is possible.
func (*Scope) SetInInstanceMethod ¶
SetInInstanceMethod updates "inInstanceMethod" flag that indicated whether or not scope is located inside instance method and that "$this" needs to be captured
type TypesMap ¶
type TypesMap struct {
// contains filtered or unexported fields
}
TypesMap holds a set of types and can be made immutable to prevent unexpected changes.
func MergeTypeMaps ¶
MergeTypeMaps creates a new types map from union of specified type maps
func NewEmptyTypesMap ¶
NewEmptyTypesMap creates new type map that has no types in it
func NewPreciseTypesMap ¶ added in v0.3.0
func NewTypesMap ¶
NewTypesMap returns new TypesMap that is initialized with the provided types (separated by "|" symbol)
func NewTypesMapFromMap ¶
NewTypesMapFromMap creates TypesMap from provided map[string]struct{}
func NewTypesMapFromTypes ¶ added in v0.3.0
func (TypesMap) Append ¶
Append adds provided types to current map and returns new one (immutable maps are always copied)
func (TypesMap) ArrayElemLazyType ¶ added in v0.3.0
ArrayElemLazyType returns type of array element. T[] -> T, T[][] -> T[]. For *Lazy* type.
func (TypesMap) 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 (TypesMap) Is ¶
Is reports whether m contains exactly one specified type.
Warning: typ must be a proper *lazy* or *solved* type.
func (TypesMap) IsArray ¶ added in v0.2.0
IsArray checks if map contains only array of any type
Warning: use only for *lazy* types!
func (TypesMap) IsArrayOf ¶ added in v0.2.0
IsArrayOf checks if map contains only array of given type
Warning: use only for *lazy* types!
func (TypesMap) IsPrecise ¶ added in v0.3.0
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` is not precise enough.
Adding an imprecise type to a types map makes the entire type map imprecise.
Important invariant: a precise map contains no lazy types.
func (TypesMap) IsResolved ¶ added in v0.3.0
IsResolved reports whether all types inside types map are resolved.
Users should not depend on the "false" result meaning. If "true" is returned, TypesMap is guaranteed to be free of lazy types.
func (TypesMap) Map ¶ added in v0.3.0
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 (*TypesMap) MarkAsImprecise ¶ added in v0.3.0
func (m *TypesMap) MarkAsImprecise()
type VarFlags ¶ added in v0.3.0
type VarFlags uint8
const (
VarAlwaysDefined VarFlags
)