meta

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

This section is empty.

Variables

View Source
var (
	UnknownValue = ConstValue{Type: Undefined}
	TrueValue    = ConstValue{Type: Bool, Value: true}
	FalseValue   = ConstValue{Type: Bool, Value: false}
)

Functions

func GetConstValue added in v0.5.0

func GetConstValue(c ConstValue) 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
	ClassShape
	ClassInterface
)

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

	PackageInfo
}

func (*ClassInfo) IsAbstract added in v0.2.0

func (info *ClassInfo) IsAbstract() bool

func (*ClassInfo) IsFinal added in v0.4.0

func (info *ClassInfo) IsFinal() bool

func (*ClassInfo) IsInterface added in v0.4.0

func (info *ClassInfo) IsInterface() bool

func (*ClassInfo) IsShape added in v0.3.0

func (info *ClassInfo) IsShape() bool

type ClassParseState

type ClassParseState struct {
	Info *Info

	IsTrait                 bool
	IsInterface             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
}

TODO: rename it; it's not only class-related.

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

type ConstInfo struct {
	Pos         ElementPosition
	Typ         types.Map
	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 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 ConstantsMap map[string]ConstInfo

type DeprecationInfo added in v0.5.1

type DeprecationInfo struct {
	Deprecated bool
	Removed    bool

	Reason        string
	Replacement   string
	Since         string
	RemovedReason string
}

func (*DeprecationInfo) Append added in v0.5.1

func (i *DeprecationInfo) Append(other DeprecationInfo)

func (DeprecationInfo) String added in v0.5.1

func (i DeprecationInfo) String() (res string)

func (DeprecationInfo) WithDeprecationNote added in v0.5.1

func (i DeprecationInfo) WithDeprecationNote() bool

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
	// FuncFromAnnotation is set if the function is described in the class annotation.
	FuncFromAnnotation
)

type FuncInfo

type FuncInfo struct {
	Pos          ElementPosition
	Name         string
	Params       []FuncParam
	MinParamsCnt int
	Typ          types.Map
	AccessLevel  AccessLevel
	Flags        FuncFlags
	ExitFlags    int // if function has exit/die/throw, then ExitFlags will be <> 0
	Internal     bool

	DeprecationInfo
}

func (*FuncInfo) IsAbstract added in v0.2.0

func (info *FuncInfo) IsAbstract() bool

func (*FuncInfo) IsDeprecated added in v0.5.1

func (info *FuncInfo) IsDeprecated() bool

func (*FuncInfo) IsFinal added in v0.4.0

func (info *FuncInfo) IsFinal() bool

func (*FuncInfo) IsFromAnnotation added in v0.4.0

func (info *FuncInfo) IsFromAnnotation() 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
	Properties   OverrideProperties
	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

type FuncParam

type FuncParam struct {
	IsRef bool
	Name  string
	Typ   types.Map
}

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 Info

type Info struct {
	sync.Mutex
	*Scope
	// contains filtered or unexported fields
}

Info contains meta information for all classes, functions, etc.

func NewInfo added in v0.4.0

func NewInfo() *Info

func (*Info) AddClassesNonLocked added in v0.4.0

func (i *Info) AddClassesNonLocked(filename string, m ClassesMap)

func (*Info) AddConstantsNonLocked added in v0.4.0

func (i *Info) AddConstantsNonLocked(filename string, m ConstantsMap)

func (*Info) AddFilenameNonLocked added in v0.4.0

func (i *Info) AddFilenameNonLocked(filename string)

func (*Info) AddFunctionsNonLocked added in v0.4.0

func (i *Info) AddFunctionsNonLocked(filename string, m FunctionsMap)

func (*Info) AddFunctionsOverridesNonLocked added in v0.4.0

func (i *Info) AddFunctionsOverridesNonLocked(filename string, m FunctionsOverrideMap)

func (*Info) AddToGlobalScopeNonLocked added in v0.4.0

func (i *Info) AddToGlobalScopeNonLocked(filename string, sc *Scope)

func (*Info) AddTraitsNonLocked added in v0.4.0

func (i *Info) AddTraitsNonLocked(filename string, m ClassesMap)

func (*Info) Clone added in v0.4.0

func (i *Info) Clone() *Info

func (*Info) DeleteMetaForFileNonLocked added in v0.4.0

func (i *Info) DeleteMetaForFileNonLocked(filename string)

func (*Info) FileExists added in v0.4.0

func (i *Info) FileExists(filename string) bool

func (*Info) FindConstants added in v0.4.0

func (i *Info) FindConstants(substr string) (res []string)

func (*Info) FindFunctions added in v0.4.0

func (i *Info) FindFunctions(substr string) (res []string)

func (*Info) GetClass added in v0.4.0

func (i *Info) GetClass(nm string) (res ClassInfo, ok bool)

func (*Info) GetClassOrTrait added in v0.4.0

func (i *Info) GetClassOrTrait(nm string) (res ClassInfo, ok bool)

func (*Info) GetConstant added in v0.4.0

func (i *Info) GetConstant(nm string) (res ConstInfo, ok bool)

func (*Info) GetFunction added in v0.4.0

func (i *Info) GetFunction(nm string) (res FuncInfo, ok bool)

func (*Info) GetFunctionOverride added in v0.4.0

func (i *Info) GetFunctionOverride(nm string) (res FuncInfoOverride, ok bool)

func (*Info) GetInternalFunctionInfo added in v0.4.0

func (i *Info) GetInternalFunctionInfo(fn string) (info FuncInfo, ok bool)

func (*Info) GetInternalFunctionOverrideInfo added in v0.4.0

func (i *Info) GetInternalFunctionOverrideInfo(fn string) (info FuncInfoOverride, ok bool)

func (*Info) GetMetaForFile added in v0.4.0

func (i *Info) GetMetaForFile(filename string) (res PerFile)

func (*Info) GetTrait added in v0.4.0

func (i *Info) GetTrait(nm string) (res ClassInfo, ok bool)

func (*Info) InitKphpStubs added in v0.4.0

func (i *Info) InitKphpStubs()

func (*Info) InitStubs added in v0.4.0

func (i *Info) InitStubs()

func (*Info) IsIndexingComplete added in v0.4.0

func (i *Info) IsIndexingComplete() bool

func (*Info) IsInternalClass added in v0.4.0

func (i *Info) IsInternalClass(className string) bool

func (*Info) IsLoadingStubs added in v0.4.0

func (i *Info) IsLoadingStubs() bool

IsLoadingStubs reports whether we're parsing stub files right now.

func (*Info) NumClasses added in v0.4.0

func (i *Info) NumClasses() int

func (*Info) NumConstants added in v0.4.0

func (i *Info) NumConstants() int

func (*Info) NumFilesWithFunctions added in v0.4.0

func (i *Info) NumFilesWithFunctions() int

func (*Info) NumFunctions added in v0.4.0

func (i *Info) NumFunctions() int

func (*Info) OnIndexingComplete added in v0.4.0

func (i *Info) OnIndexingComplete(cb func(*Info))

func (*Info) SetIndexingComplete added in v0.4.0

func (i *Info) SetIndexingComplete(complete bool)

func (*Info) SetLoadingStubs added in v0.4.0

func (i *Info) SetLoadingStubs(isLoading bool)

SetLoadingStubs changes IsLoadingStubs() return value.

Should be only called from linter.InitStubs() function.

type OverrideProperties added in v0.4.0

type OverrideProperties int
const (
	// NotNull means that the null type will be removed from the resulting type.
	NotNull OverrideProperties = 1 << iota
	// NotFalse means that the false type will be removed from the resulting type.
	NotFalse
	// ArrayOf means that the type will be converted to an array of elements of that type.
	ArrayOf
)

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
	// OverrideNullableClassType means that return type of a function is the same as the type represented by the class name, and is also nullable.
	OverrideNullableClassType
)

type PackageInfo added in v0.5.3

type PackageInfo struct {
	Name     string
	Internal bool
}

type PerFile

type PerFile struct {
	Traits    ClassesMap
	Classes   ClassesMap
	Functions FunctionsMap
	Constants ConstantsMap
}

PerFile contains all meta information about the specified file

type PropertiesMap

type PropertiesMap map[string]PropertyInfo

type PropertyFlags added in v0.4.0

type PropertyFlags uint8
const (
	// PropFromAnnotation is set if the property is described in the class annotation.
	PropFromAnnotation PropertyFlags = 1 << iota
)

type PropertyInfo

type PropertyInfo struct {
	Pos         ElementPosition
	Typ         types.Map
	AccessLevel AccessLevel
	Flags       PropertyFlags
}

func (*PropertyInfo) IsFromAnnotation added in v0.4.0

func (info *PropertyInfo) IsFromAnnotation() bool

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) AddImplicitVar added in v0.4.0

func (s *Scope) AddImplicitVar(varNode ir.Node, typ types.Map, reason string, flags VarFlags)

AddImplicitVar adds implicit variable with specified types to scope

func (*Scope) AddVar

func (s *Scope) AddVar(v ir.Node, typ types.Map, reason string, flags VarFlags)

AddVar adds variable with specified types to scope

func (*Scope) AddVarFromPHPDoc

func (s *Scope) AddVarFromPHPDoc(name string, typ types.Map, reason string)

AddVarFromPHPDoc adds variable with specified types to the scope

func (*Scope) AddVarName

func (s *Scope) AddVarName(name string, typ types.Map, reason string, flags VarFlags)

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 ir.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) GetVar added in v0.4.0

func (s *Scope) GetVar(v ir.Node) (m *ScopeVar, ok bool)

GetVar returns variable if it exists

func (*Scope) GetVarName added in v0.5.0

func (s *Scope) GetVarName(name string) (m *ScopeVar, ok bool)

GetVarName returns variable if it exists

func (*Scope) GetVarNameType

func (s *Scope) GetVarNameType(name string) (m types.Map, ok bool)

GetVarNameType returns type map for variable if it exists

func (*Scope) GetVarType added in v0.4.0

func (s *Scope) GetVarType(v ir.Node) (m types.Map, ok bool)

GetVarType 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) GobWrite added in v0.4.0

func (s *Scope) GobWrite(w io.Writer) error

func (*Scope) HaveImplicitVar added in v0.5.0

func (s *Scope) HaveImplicitVar(v ir.Node) bool

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

func (*Scope) HaveImplicitVarName added in v0.5.0

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

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

func (*Scope) HaveVar

func (s *Scope) HaveVar(v ir.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 types.Map, flags VarFlags))

func (*Scope) Len

func (s *Scope) Len() int

func (*Scope) MaybeHaveVar

func (s *Scope) MaybeHaveVar(v ir.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 ir.Node, typ types.Map, reason string, flags VarFlags)

ReplaceVar replaces variable with specified types to scope

func (*Scope) ReplaceVarName

func (s *Scope) ReplaceVarName(name string, typ types.Map, reason string, flags VarFlags)

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

type ScopeVar struct {
	Type  types.Map
	Flags VarFlags
}

func (*ScopeVar) GobDecode added in v0.4.0

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

GobDecode is custom gob unmarshaller

func (*ScopeVar) GobEncode added in v0.4.0

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

GobEncode is a custom gob marshaller

type VarFlags added in v0.3.0

type VarFlags uint8
const (
	VarAlwaysDefined VarFlags
	VarImplicit
)

func (VarFlags) IsAlwaysDefined added in v0.3.0

func (flags VarFlags) IsAlwaysDefined() bool

func (VarFlags) IsImplicit added in v0.4.0

func (flags VarFlags) IsImplicit() bool

func (VarFlags) IsNoReplace added in v0.3.0

func (flags VarFlags) IsNoReplace() bool

func (*VarFlags) SetAlwaysDefined added in v0.3.0

func (flags *VarFlags) SetAlwaysDefined(v bool)

Jump to

Keyboard shortcuts

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