Documentation ¶
Index ¶
- Constants
- Variables
- func FullyQualifiedToString(n *name.FullyQualified) string
- func IsIndexingComplete() bool
- func IsInternalClass(className string) bool
- func NameEquals(n *name.Name, s string) bool
- func NameNodeEquals(n node.Node, s string) bool
- func NameNodeToString(n node.Node) string
- func NamePartsToString(parts []node.Node) string
- func NameToString(n *name.Name) string
- func OnIndexingComplete(cb func())
- func ResetInfo()
- func SetIndexingComplete(complete bool)
- func StringToName(nm string) *name.Name
- 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 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 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 ConstantInfo
- 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 node.Node, typ TypesMap, reason string, alwaysDefined bool)
- func (s *Scope) AddVarFromPHPDoc(name string, typ TypesMap, reason string)
- func (s *Scope) AddVarName(name string, typ TypesMap, reason string, alwaysDefined bool)
- func (s *Scope) Clone() *Scope
- func (s *Scope) DelVar(v node.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 node.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, alwaysDefined bool))
- func (s *Scope) Len() int
- func (s *Scope) MaybeHaveVar(v node.Node) bool
- func (s *Scope) MaybeHaveVarName(name string) bool
- func (s *Scope) ReplaceVar(v node.Node, typ TypesMap, reason string, alwaysDefined bool)
- func (s *Scope) ReplaceVarName(name string, typ TypesMap, reason string, alwaysDefined bool)
- func (s *Scope) SetInClosure(v bool)
- func (s *Scope) SetInInstanceMethod(v bool)
- func (s *Scope) String() string
- type TypesMap
- func (m TypesMap) Append(n TypesMap) TypesMap
- func (m TypesMap) AppendString(str string) TypesMap
- 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) IsInt() bool
- func (m TypesMap) IsString() bool
- func (m TypesMap) Iterate(cb func(typ string))
- func (m TypesMap) Len() int
- func (m TypesMap) String() string
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 // 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<0-N> 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 = NewTypesMap("mixed").Immutable() VoidType = NewTypesMap("void").Immutable() )
Preallocated and shared immutable type maps.
var (
// Info contains global meta information for all classes, functions, etc.
Info info
)
Functions ¶
func FullyQualifiedToString ¶
func FullyQualifiedToString(n *name.FullyQualified) string
func IsIndexingComplete ¶
func IsIndexingComplete() bool
func IsInternalClass ¶ added in v0.2.0
func NameNodeEquals ¶
NameNodeEquals checks whether n node name value is identical to s.
func NameNodeToString ¶
NameNodeToString converts nodes of *name.Name, *name.FullyQualified and *node.Identifier to string. This function is a helper function to aid printing function names, not for actual code analysis.
func NamePartsToString ¶
NamePartsToString converts slice of *name.NamePart to string
func NameToString ¶
NameToString returns string like 'NS\SomeClass' for given name node
func OnIndexingComplete ¶
func OnIndexingComplete(cb func())
func SetIndexingComplete ¶
func SetIndexingComplete(complete bool)
func StringToName ¶
StringToName creates name node that can be analyzed using solver
func UnwrapArrayOf ¶
func UnwrapBaseMethodParam ¶
func UnwrapClassConstFetch ¶
func UnwrapConstant ¶
func UnwrapElemOf ¶
func UnwrapFunctionCall ¶
func UnwrapGlobal ¶
func UnwrapStaticMethodCall ¶
func WrapArray2 ¶ added in v0.2.0
func WrapArrayOf ¶
func WrapBaseMethodParam ¶
func WrapClassConstFetch ¶
func WrapConstant ¶
func WrapElemOf ¶
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 )
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 }
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 ConstantInfo ¶
type ConstantInfo struct { Pos ElementPosition Typ TypesMap AccessLevel AccessLevel }
type ConstantsMap ¶
type ConstantsMap map[string]ConstantInfo
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 )
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 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 (TypesMap) Append ¶
Append adds provided types to current map and returns new one (immutable maps are always copied)
func (TypesMap) AppendString ¶
AppendString adds provided types to current map and returns new one (immutable maps are always copied)
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) IsArrayOf ¶ added in v0.2.0
IsArrayOf checks if map contains only array of given type