ast

package
v0.0.0-...-37d2667 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2014 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const AnyType = String | Integer | Float | Boolean | Null | Resource | Array | Object

AnyType is a bitmask of all the valid types.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnonymousFunction

type AnonymousFunction struct {
	ClosureVariables []*FunctionArgument
	Arguments        []*FunctionArgument
	Body             *Block
}

func (AnonymousFunction) Children

func (a AnonymousFunction) Children() []Node

func (AnonymousFunction) EvaluatesTo

func (a AnonymousFunction) EvaluatesTo() Type

func (AnonymousFunction) String

func (a AnonymousFunction) String() string

type ArrayAppendExpression

type ArrayAppendExpression struct {
	Array Expression
}

func (ArrayAppendExpression) AssignableType

func (a ArrayAppendExpression) AssignableType() Type

func (ArrayAppendExpression) Children

func (a ArrayAppendExpression) Children() []Node

func (ArrayAppendExpression) EvaluatesTo

func (a ArrayAppendExpression) EvaluatesTo() Type

func (ArrayAppendExpression) String

func (a ArrayAppendExpression) String() string

type ArrayExpression

type ArrayExpression struct {
	ArrayType
	Pairs []ArrayPair
}

func (ArrayExpression) AssignableType

func (a ArrayExpression) AssignableType() Type

func (ArrayExpression) Children

func (a ArrayExpression) Children() []Node

func (ArrayExpression) EvaluatesTo

func (a ArrayExpression) EvaluatesTo() Type

func (ArrayExpression) String

func (a ArrayExpression) String() string

type ArrayLookupExpression

type ArrayLookupExpression struct {
	Array Expression
	Index Expression
}

func (ArrayLookupExpression) AssignableType

func (a ArrayLookupExpression) AssignableType() Type

func (ArrayLookupExpression) Children

func (a ArrayLookupExpression) Children() []Node

func (ArrayLookupExpression) EvaluatesTo

func (a ArrayLookupExpression) EvaluatesTo() Type

func (ArrayLookupExpression) String

func (a ArrayLookupExpression) String() string

type ArrayPair

type ArrayPair struct {
	Key   Expression
	Value Expression
}

func (ArrayPair) Children

func (p ArrayPair) Children() []Node

func (ArrayPair) String

func (p ArrayPair) String() string

type ArrayType

type ArrayType struct {
	KeyType   KeyType
	ValueType Type
}

type Assignable

type Assignable interface {
	Node
	AssignableType() Type
}

type AssignmentExpression

type AssignmentExpression struct {
	Assignee Assignable
	Value    Expression
	Operator string
}

func (AssignmentExpression) Children

func (a AssignmentExpression) Children() []Node

func (AssignmentExpression) EvaluatesTo

func (a AssignmentExpression) EvaluatesTo() Type

func (AssignmentExpression) String

func (a AssignmentExpression) String() string

type BinaryExpression

type BinaryExpression struct {
	Antecedent Expression
	Subsequent Expression
	Type       Type
	Operator   string
}

OperatorExpression is an expression that applies an operator to one, two, or three operands. The operator determines how many operands it should contain.

func (BinaryExpression) Children

func (b BinaryExpression) Children() []Node

func (BinaryExpression) EvaluatesTo

func (b BinaryExpression) EvaluatesTo() Type

func (BinaryExpression) String

func (b BinaryExpression) String() string

type Block

type Block struct {
	Statements []Statement
	Scope      Scope
}

func (Block) Children

func (b Block) Children() []Node

func (Block) String

func (b Block) String() string

type BreakStmt

type BreakStmt struct {
	Expression
}

func (BreakStmt) Children

func (b BreakStmt) Children() []Node

func (BreakStmt) String

func (b BreakStmt) String() string

type CatchStmt

type CatchStmt struct {
	CatchBlock *Block
	CatchType  string
	CatchVar   *Variable
}

func (CatchStmt) Children

func (c CatchStmt) Children() []Node

func (CatchStmt) String

func (c CatchStmt) String() string

type Class

type Class struct {
	Name       string
	Extends    string
	Implements []string
	Methods    []*Method
	Properties []*Property
	Constants  []*Constant
}

func (Class) Children

func (c Class) Children() []Node

func (Class) String

func (c Class) String() string

type ClassExpression

type ClassExpression struct {
	Receiver   Expression
	Expression Expression
	Type       Type
}

func NewClassExpression

func NewClassExpression(r string, e Expression) *ClassExpression

func (ClassExpression) AssignableType

func (c ClassExpression) AssignableType() Type

func (ClassExpression) Children

func (c ClassExpression) Children() []Node

func (ClassExpression) EvaluatesTo

func (c ClassExpression) EvaluatesTo() Type

func (ClassExpression) String

func (c ClassExpression) String() string

type Constant

type Constant struct {
	*Variable
	Value interface{}
}

type ConstantExpression

type ConstantExpression struct {
	*Variable
}

type ContinueStmt

type ContinueStmt struct {
	Expression
}

func (ContinueStmt) Children

func (c ContinueStmt) Children() []Node

func (ContinueStmt) String

func (c ContinueStmt) String() string

type DeclareBlock

type DeclareBlock struct {
	Statements   *Block
	Declarations []string
}

func (DeclareBlock) Children

func (d DeclareBlock) Children() []Node

func (DeclareBlock) String

func (d DeclareBlock) String() string

type DefaultWalker

type DefaultWalker struct {
	Nodes  []Node
	Errors []error
}

func (*DefaultWalker) Errorf

func (d *DefaultWalker) Errorf(format string, params ...interface{})

type DoWhileStmt

type DoWhileStmt struct {
	Termination Expression
	LoopBlock   Statement
}

func (DoWhileStmt) Children

func (d DoWhileStmt) Children() []Node

func (DoWhileStmt) String

func (d DoWhileStmt) String() string

type EchoStmt

type EchoStmt struct {
	Expressions []Expression
}

Echo represents an echo statement. It may be either a literal statement or it may be from data outside PHP-mode, such as "here" in: <? not here ?> here <? not here ?>

func Echo

func Echo(exprs ...Expression) EchoStmt

Echo returns a new echo statement.

func (EchoStmt) Children

func (e EchoStmt) Children() []Node

func (EchoStmt) String

func (e EchoStmt) String() string

type EmptyStatement

type EmptyStatement struct {
}

EmptyStatement represents a statement that does nothing.

func (EmptyStatement) Children

func (e EmptyStatement) Children() []Node

func (EmptyStatement) Print

func (e EmptyStatement) Print(f Format) string

func (EmptyStatement) String

func (e EmptyStatement) String() string

type ExitStmt

type ExitStmt struct {
	Expression Expression
}

func (ExitStmt) Children

func (e ExitStmt) Children() []Node

func (ExitStmt) String

func (e ExitStmt) String() string

type Expression

type Expression interface {
	Node
	EvaluatesTo() Type
}

An Expression is a snippet of code that evaluates to a single value when run and does not represent a program instruction.

type ExpressionStmt

type ExpressionStmt struct {
	Expression
}

func (ExpressionStmt) Children

func (e ExpressionStmt) Children() []Node

func (ExpressionStmt) String

func (e ExpressionStmt) String() string

type ForStmt

type ForStmt struct {
	Initialization []Expression
	Termination    []Expression
	Iteration      []Expression
	LoopBlock      Statement
}

func (ForStmt) Children

func (f ForStmt) Children() []Node

func (ForStmt) String

func (f ForStmt) String() string

type ForeachStmt

type ForeachStmt struct {
	Source    Expression
	Key       *Variable
	Value     *Variable
	LoopBlock Statement
}

func (ForeachStmt) Children

func (f ForeachStmt) Children() []Node

func (ForeachStmt) String

func (f ForeachStmt) String() string

type Format

type Format struct{}

type FunctionArgument

type FunctionArgument struct {
	TypeHint string
	Default  Expression
	Variable *Variable
}

func (FunctionArgument) Children

func (fa FunctionArgument) Children() []Node

func (FunctionArgument) String

func (fa FunctionArgument) String() string

type FunctionCallExpression

type FunctionCallExpression struct {
	FunctionName Expression
	Arguments    []Expression
}

func (FunctionCallExpression) Children

func (f FunctionCallExpression) Children() []Node

func (FunctionCallExpression) EvaluatesTo

func (f FunctionCallExpression) EvaluatesTo() Type

func (FunctionCallExpression) String

func (f FunctionCallExpression) String() string

type FunctionCallStmt

type FunctionCallStmt struct {
	FunctionCallExpression
}

type FunctionDefinition

type FunctionDefinition struct {
	Name      string
	Arguments []*FunctionArgument
}

func (FunctionDefinition) Children

func (fd FunctionDefinition) Children() []Node

func (FunctionDefinition) String

func (fd FunctionDefinition) String() string

type FunctionStmt

type FunctionStmt struct {
	*FunctionDefinition
	Body *Block
}

func (FunctionStmt) Children

func (f FunctionStmt) Children() []Node

func (FunctionStmt) String

func (f FunctionStmt) String() string

type GlobalDeclaration

type GlobalDeclaration struct {
	Identifiers []*Variable
}

func (GlobalDeclaration) Children

func (g GlobalDeclaration) Children() []Node

func (GlobalDeclaration) String

func (g GlobalDeclaration) String() string

type GlobalScope

type GlobalScope struct {
	Functions  []FunctionStmt
	Classes    []Class
	Interfaces []Interface
	Cconstants []Constant
	Namespace  string
	*Scope
}

globalScope represents the global scope on which functions and classes are defined. This is always within a namespace, but in many cases that may just be the default global namespace ("\")

type Identifier

type Identifier struct {
	Parent Node
	Value  string
}

An Identifier is a raw string that can be used to identify a variable, function, class, constant, property, etc.

func (Identifier) Children

func (i Identifier) Children() []Node

func (Identifier) EvaluatesTo

func (i Identifier) EvaluatesTo() Type

func (Identifier) String

func (i Identifier) String() string

type IfStmt

type IfStmt struct {
	Condition   Expression
	TrueBranch  Statement
	FalseBranch Statement
}

func (IfStmt) Children

func (i IfStmt) Children() []Node

func (IfStmt) String

func (i IfStmt) String() string

type Include

type Include struct {
	Expressions []Expression
}

func (Include) Children

func (i Include) Children() []Node

func (Include) EvaluatesTo

func (i Include) EvaluatesTo() Type

func (Include) String

func (i Include) String() string

type IncludeStmt

type IncludeStmt struct {
	Include
}

type Interface

type Interface struct {
	Name      string
	Inherits  []string
	Methods   []Method
	Constants []Constant
}

func (Interface) Children

func (i Interface) Children() []Node

func (Interface) String

func (i Interface) String() string

type KeyType

type KeyType Type
const (
	StringKey  KeyType = KeyType(String)
	IntegerKey KeyType = KeyType(Integer)
)

type ListStatement

type ListStatement struct {
	Assignees []Assignable
	Value     Expression
	Operator  string
}

func (ListStatement) Children

func (l ListStatement) Children() []Node

func (ListStatement) EvaluatesTo

func (l ListStatement) EvaluatesTo() Type

func (ListStatement) String

func (l ListStatement) String() string

type Literal

type Literal struct {
	Type  Type
	Value string
}

func (Literal) Children

func (l Literal) Children() []Node

func (Literal) EvaluatesTo

func (l Literal) EvaluatesTo() Type

func (Literal) String

func (l Literal) String() string

type Method

type Method struct {
	*FunctionStmt
	Visibility Visibility
}

func (Method) Children

func (m Method) Children() []Node

func (Method) String

func (m Method) String() string

type MethodCallExpression

type MethodCallExpression struct {
	Receiver Expression
	*FunctionCallExpression
}

func (MethodCallExpression) Children

func (m MethodCallExpression) Children() []Node

func (MethodCallExpression) String

func (m MethodCallExpression) String() string

type NewExpression

type NewExpression struct {
	Class     Expression
	Arguments []Expression
}

func (NewExpression) Children

func (c NewExpression) Children() []Node

func (NewExpression) EvaluatesTo

func (n NewExpression) EvaluatesTo() Type

func (NewExpression) String

func (n NewExpression) String() string

type Node

type Node interface {
	String() string
	Children() []Node
}

Node encapsulates every AST node.

type ObjectType

type ObjectType struct {
	Class             *Class
	DynamicProperties []Variable
}

type Property

type Property struct {
	Name           string
	Visibility     Visibility
	Type           Type
	Initialization Expression
}

func (Property) AssignableType

func (p Property) AssignableType() Type

func (Property) Children

func (p Property) Children() []Node

func (Property) String

func (p Property) String() string

type PropertyExpression

type PropertyExpression struct {
	Receiver Expression
	Name     Expression
	Type     Type
}

func (PropertyExpression) AssignableType

func (p PropertyExpression) AssignableType() Type

func (PropertyExpression) Children

func (p PropertyExpression) Children() []Node

func (PropertyExpression) EvaluatesTo

func (p PropertyExpression) EvaluatesTo() Type

func (PropertyExpression) String

func (p PropertyExpression) String() string

type ReturnStmt

type ReturnStmt struct {
	Expression
}

ReturnStmt represents a function return.

func (ReturnStmt) Children

func (r ReturnStmt) Children() []Node

func (ReturnStmt) String

func (r ReturnStmt) String() string

type Scope

type Scope struct {
	Identifiers      []Variable
	EnclosingScope   *Scope
	GlobalScope      *GlobalScope
	SuperGlobalScope *SuperGlobalScope
}

scope represents a particular local scope (such as within a function).

type ShellCommand

type ShellCommand struct {
	Command string
}

func (ShellCommand) Children

func (s ShellCommand) Children() []Node

func (ShellCommand) EvaluatesTo

func (s ShellCommand) EvaluatesTo() Type

func (ShellCommand) String

func (s ShellCommand) String() string

type Statement

type Statement interface {
	Node
}

A statement is an executable piece of code. It may be as simple as a function call or a variable assignment. It also includes things like "if".

type StaticVariableDeclaration

type StaticVariableDeclaration struct {
	Declarations []Expression
}

func (StaticVariableDeclaration) Children

func (s StaticVariableDeclaration) Children() []Node

func (StaticVariableDeclaration) String

func (s StaticVariableDeclaration) String() string

type SuperGlobalScope

type SuperGlobalScope struct {
	Identifiers []Variable
}

superGlobalScope represents the scope containing superglobals such as $_GET

type SwitchCase

type SwitchCase struct {
	Expression Expression
	Block      Block
}

func (SwitchCase) Children

func (s SwitchCase) Children() []Node

func (SwitchCase) String

func (s SwitchCase) String() string

type SwitchStmt

type SwitchStmt struct {
	Expression  Expression
	Cases       []*SwitchCase
	DefaultCase *Block
}

func (SwitchStmt) Children

func (s SwitchStmt) Children() []Node

func (SwitchStmt) String

func (s SwitchStmt) String() string

type TernaryExpression

type TernaryExpression struct {
	Condition, True, False Expression
	Type                   Type
}

func (TernaryExpression) Children

func (t TernaryExpression) Children() []Node

func (TernaryExpression) EvaluatesTo

func (t TernaryExpression) EvaluatesTo() Type

func (TernaryExpression) String

func (t TernaryExpression) String() string

type ThrowStmt

type ThrowStmt struct {
	Expression
}

type TryStmt

type TryStmt struct {
	TryBlock     *Block
	FinallyBlock *Block
	CatchStmts   []*CatchStmt
}

func (TryStmt) Children

func (t TryStmt) Children() []Node

func (TryStmt) String

func (t TryStmt) String() string

type Type

type Type int
const (
	String Type = 1 << iota
	Integer
	Float
	Boolean
	Null
	Resource
	Array
	Object
	Function

	Numeric = Float | Integer
	Unknown = String | Integer | Float | Boolean | Null | Resource | Array | Object | Function
)

func (Type) Contains

func (t Type) Contains(typ Type) bool

func (Type) List

func (t Type) List() []Type

func (Type) String

func (t Type) String() string

type UnaryExpression

type UnaryExpression struct {
	Operand   Expression
	Operator  string
	Preceding bool
}

UnaryExpression is an expression that applies an operator to only one operand. The operator may precede or follow the operand.

func (UnaryExpression) Children

func (u UnaryExpression) Children() []Node

func (UnaryExpression) EvaluatesTo

func (u UnaryExpression) EvaluatesTo() Type

func (UnaryExpression) String

func (u UnaryExpression) String() string

type Variable

type Variable struct {

	// Name is the identifier for the variable, which may be
	// a dynamic expression.
	Name Expression
	Type Type
}

func NewVariable

func NewVariable(name string) *Variable

NewVariable intializes a variable node with its name being a simple identifier and its type set to AnyType. The name argument should not include the $ operator.

func (Variable) AssignableType

func (i Variable) AssignableType() Type

func (Variable) Children

func (v Variable) Children() []Node

func (Variable) EvaluatesTo

func (i Variable) EvaluatesTo() Type

EvaluatesTo returns the known type of the variable.

func (Variable) String

func (v Variable) String() string

type Visibility

type Visibility int
const (
	Private Visibility = iota
	Protected
	Public
)

func (Visibility) Token

func (v Visibility) Token() token.Token

type Walker

type Walker interface {
	Walk(n Node)
	Errorf(fmt string, params ...interface{})
}

type WhileStmt

type WhileStmt struct {
	Termination Expression
	LoopBlock   Statement
}

func (WhileStmt) Children

func (w WhileStmt) Children() []Node

func (WhileStmt) String

func (w WhileStmt) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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