meta

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 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

	// 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

View Source
var (
	MixedType = NewTypesMap("mixed").Immutable()
	VoidType  = NewTypesMap("void").Immutable()
)

Preallocated and shared immutable type maps.

View Source
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 IsInternalClass(className string) bool

func NameEquals

func NameEquals(n *name.Name, s string) bool

func NameNodeEquals

func NameNodeEquals(n node.Node, s string) bool

NameNodeEquals checks whether n node name value is identical to s.

func NameNodeToString

func NameNodeToString(n node.Node) string

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

func NamePartsToString(parts []node.Node) string

NamePartsToString converts slice of *name.NamePart to string

func NameToString

func NameToString(n *name.Name) string

NameToString returns string like 'NS\SomeClass' for given name node

func OnIndexingComplete

func OnIndexingComplete(cb func())

func ResetInfo

func ResetInfo()

ResetInfo creates empty meta info

func SetIndexingComplete

func SetIndexingComplete(complete bool)

func StringToName

func StringToName(nm string) *name.Name

StringToName creates name node that can be analyzed using solver

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 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 added in v0.2.0

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 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 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

func (info *ClassInfo) IsAbstract() bool

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) Get added in v0.2.0

func (m ClassesMap) Get(name string) (ClassInfo, bool)

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 ElementPosition struct {
	Filename  string
	Line      int32
	EndLine   int32
	Character int32
	Length    int32 // body length
}

type FuncFlags added in v0.2.0

type FuncFlags uint8
const (
	FuncStatic FuncFlags = 1 << iota
	FuncPure
	FuncAbstract
	FuncFinal
)

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 GetInternalFunctionInfo(fn string) (info FuncInfo, ok bool)

func (*FuncInfo) IsAbstract added in v0.2.0

func (info *FuncInfo) IsAbstract() bool

func (*FuncInfo) IsPure added in v0.2.0

func (info *FuncInfo) IsPure() bool

func (*FuncInfo) IsStatic added in v0.2.0

func (info *FuncInfo) IsStatic() bool

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 FuncParam

type FuncParam struct {
	IsRef bool
	Name  string
	Typ   TypesMap
}

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) Get added in v0.2.0

func (m FunctionsMap) Get(name string) (FuncInfo, bool)

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 PhpDocInfo struct {
	Deprecated      bool
	DeprecationNote string
}

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 NewScope

func NewScope() *Scope

NewScope creates new empty scope

func (*Scope) AddVar

func (s *Scope) AddVar(v node.Node, typ TypesMap, reason string, alwaysDefined bool)

AddVar adds variable with specified types to scope

func (*Scope) AddVarFromPHPDoc

func (s *Scope) AddVarFromPHPDoc(name string, typ TypesMap, reason string)

AddVarFromPHPDoc adds variable with specified types to the scope

func (*Scope) AddVarName

func (s *Scope) AddVarName(name string, typ TypesMap, reason string, alwaysDefined bool)

AddVarName adds variable with specified types to the scope

func (*Scope) Clone

func (s *Scope) Clone() *Scope

Clone creates a full scope copy (used in branches)

func (*Scope) DelVar

func (s *Scope) DelVar(v node.Node, reason string)

DelVar deletes specified variable from scope

func (*Scope) DelVarName

func (s *Scope) DelVarName(name, reason string)

DelVarName deletes variable from the scope by it's name

func (*Scope) GetVarNameType

func (s *Scope) GetVarNameType(name string) (m TypesMap, ok bool)

GetVarNameType returns type map for variable if it exists

func (*Scope) GobDecode

func (s *Scope) GobDecode(buf []byte) error

GobDecode is custom gob unmarshaller

func (*Scope) GobEncode

func (s *Scope) GobEncode() ([]byte, error)

GobEncode is a custom gob marshaller

func (*Scope) HaveVar

func (s *Scope) HaveVar(v node.Node) bool

HaveVar checks whether or not specified variable is present in the scope and that it is always defined

func (*Scope) HaveVarName

func (s *Scope) HaveVarName(name string) bool

HaveVarName checks whether or not specified variable is present in the scope and that it is always defined

func (*Scope) IsInClosure

func (s *Scope) IsInClosure() bool

IsInClosure returns whether or not this scope is inside a closure and thus $this can be late-bound.

func (*Scope) IsInInstanceMethod

func (s *Scope) IsInInstanceMethod() bool

IsInInstanceMethod returns whether or not this scope exists in instance method (and thus closures must capture $this)

func (*Scope) Iterate

func (s *Scope) Iterate(cb func(varName string, typ TypesMap, alwaysDefined bool))

func (*Scope) Len

func (s *Scope) Len() int

func (*Scope) MaybeHaveVar

func (s *Scope) MaybeHaveVar(v node.Node) bool

MaybeHaveVar checks that variable is present in the scope (it may be not always defined)

func (*Scope) MaybeHaveVarName

func (s *Scope) MaybeHaveVarName(name string) bool

MaybeHaveVarName checks that variable is present in the scope (it may be not always defined)

func (*Scope) ReplaceVar

func (s *Scope) ReplaceVar(v node.Node, typ TypesMap, reason string, alwaysDefined bool)

ReplaceVar replaces variable with specified types to scope

func (*Scope) ReplaceVarName

func (s *Scope) ReplaceVarName(name string, typ TypesMap, reason string, alwaysDefined bool)

ReplaceVarName replaces variable with specified types to the scope

func (*Scope) SetInClosure

func (s *Scope) SetInClosure(v bool)

SetInClosure updates "inClosure" flag that indicates whether or not we are inside a closure and thus late $this binding is possible.

func (*Scope) SetInInstanceMethod

func (s *Scope) SetInInstanceMethod(v bool)

SetInInstanceMethod updates "inInstanceMethod" flag that indicated whether or not scope is located inside instance method and that "$this" needs to be captured

func (*Scope) String

func (s *Scope) String() string

String returns vars contents (for debug purposes)

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

func MergeTypeMaps(maps ...TypesMap) TypesMap

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

func NewEmptyTypesMap

func NewEmptyTypesMap(cap int) TypesMap

NewEmptyTypesMap creates new type map that has no types in it

func NewTypesMap

func NewTypesMap(str string) TypesMap

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

func NewTypesMapFromMap

func NewTypesMapFromMap(m map[string]struct{}) TypesMap

NewTypesMapFromMap creates TypesMap from provided map[string]struct{}

func (TypesMap) Append

func (m TypesMap) Append(n TypesMap) TypesMap

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

func (TypesMap) AppendString

func (m TypesMap) AppendString(str string) TypesMap

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

func (TypesMap) Equals added in v0.2.0

func (m TypesMap) Equals(m2 TypesMap) bool

Equals check if two typesmaps are the same

func (TypesMap) Find

func (m TypesMap) 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 (*TypesMap) GobDecode

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

GobDecode is custom gob unmarshaller

func (TypesMap) GobEncode

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

GobEncode is a custom gob marshaller

func (TypesMap) Immutable

func (m TypesMap) Immutable() TypesMap

Immutable returns immutable copy of TypesMap

func (TypesMap) Is

func (m TypesMap) Is(typ string) bool

Is reports whether m contains exactly one specified type.

func (TypesMap) IsArray added in v0.2.0

func (m TypesMap) IsArray() bool

IsArray checks if map contains only array of any type

func (TypesMap) IsArrayOf added in v0.2.0

func (m TypesMap) IsArrayOf(typ string) bool

IsArrayOf checks if map contains only array of given type

func (TypesMap) IsEmpty

func (m TypesMap) IsEmpty() bool

IsEmpty checks if map has no types at all

func (TypesMap) IsInt added in v0.2.0

func (m TypesMap) IsInt() bool

IsInt checks if map contains only int type

func (TypesMap) IsString added in v0.2.0

func (m TypesMap) IsString() bool

IsString checks if map contains only string type

func (TypesMap) Iterate

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

Iterate applies cb to all contained types

func (TypesMap) Len

func (m TypesMap) Len() int

Len returns number of different types in map

func (TypesMap) String

func (m TypesMap) String() string

String returns string representation of a map

Jump to

Keyboard shortcuts

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