ast

package
v0.0.0-...-84a1f60 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SimpleType = iota
	SliceType
	MapType
	ChanType
	FuncType
)

Variables

View Source
var BreakPlaceHolder = func(m *common.Memory, stk *common.Stack) {}
View Source
var ContinuePlaceHolder = func(m *common.Memory, stk *common.Stack) {}

Functions

This section is empty.

Types

type ASTNode

type ASTNode interface {
	Compile(c *CompileContext)
	SetLhs()
	SetRequiredType(dt *common.DataType)

	GetDataType() *common.DataType
	SetDataType(*common.DataType)

	IsVariadic() bool

	GetInstructions() []common.Instruction

	AppendInstruction(instruction ...common.Instruction)

	GetConstantValue() interface{}

	CheckIsConstant()
	PostProcess()

	SetSource(ctx antlr.ParserRuleContext)
	GetText() string
	ErrorWithSource(string) string

	SetStackPtr()
	IsStackPtr() bool
	GetStackIncrement() int
}

type AssertNode

type AssertNode struct {
	Node
	Type  ASTNode
	Value ASTNode
}

func (*AssertNode) CheckIsConstant

func (a *AssertNode) CheckIsConstant()

func (*AssertNode) Compile

func (a *AssertNode) Compile(c *CompileContext)

type AssignNode

type AssignNode struct {
	Node
	Lhs ASTNode
	Rhs ASTNode
	Op  string
}

func (*AssignNode) Compile

func (n *AssignNode) Compile(c *CompileContext)

type BinaryNode

type BinaryNode struct {
	Node
	Lhs ASTNode
	Rhs ASTNode
	Op  string
}

func (*BinaryNode) CheckIsConstant

func (n *BinaryNode) CheckIsConstant()

func (*BinaryNode) Compile

func (n *BinaryNode) Compile(c *CompileContext)

type BlockNode

type BlockNode struct {
	Node
	Executions []ASTNode
}

func (*BlockNode) Compile

func (b *BlockNode) Compile(c *CompileContext)

type BreakNode

type BreakNode struct {
	Node
}

func (*BreakNode) Compile

func (b *BreakNode) Compile(_ *CompileContext)

type BuiltinFunctionNode

type BuiltinFunctionNode struct {
	Node
	Params      []ASTNode
	BuiltinName string
	Aux         interface{}
}

func (*BuiltinFunctionNode) Compile

func (b *BuiltinFunctionNode) Compile(c *CompileContext)

type ChanRecv

type ChanRecv struct {
	Node
	Chan     ASTNode
	NonBlock bool
}

func (*ChanRecv) Compile

func (v *ChanRecv) Compile(c *CompileContext)

type ChanSend

type ChanSend struct {
	Node
	ToSend   ASTNode
	Chan     ASTNode
	NonBlock bool
}

func (*ChanSend) Compile

func (v *ChanSend) Compile(c *CompileContext)

type CompileContext

type CompileContext struct {
	TypeRegistry *common.TypeRegistry
	Scope        *common.Scope
	FunctionInfo []*common.FunctionMeta
}

func (*CompileContext) AddBuiltType

func (c *CompileContext) AddBuiltType(dtb *common.DataTypeBuilder)

func (*CompileContext) AddEnum

func (c *CompileContext) AddEnum(name string, e map[string]int32)

func (*CompileContext) AddType

func (c *CompileContext) AddType(name string, dType *common.DataType)

func (*CompileContext) CurrentFunctionMeta

func (c *CompileContext) CurrentFunctionMeta() *common.FunctionMeta

func (*CompileContext) FindFuncType

func (c *CompileContext) FindFuncType(meta *common.FunctionMeta) *common.DataType

func (*CompileContext) FindMapType

func (c *CompileContext) FindMapType(key, value string) *common.DataType

func (*CompileContext) FindSliceType

func (c *CompileContext) FindSliceType(name string) *common.DataType

func (*CompileContext) FindType

func (c *CompileContext) FindType(name string) *common.DataType

func (*CompileContext) GetEnums

func (c *CompileContext) GetEnums(name string) interface{}

func (*CompileContext) GetREnums

func (c *CompileContext) GetREnums(name string) map[int32]string

func (*CompileContext) Include

func (c *CompileContext) Include(libName string)

func (*CompileContext) MakeChildScope

func (c *CompileContext) MakeChildScope()

func (*CompileContext) MakeFunctionScope

func (c *CompileContext) MakeFunctionScope()

func (*CompileContext) PopFunctionMeta

func (c *CompileContext) PopFunctionMeta()

func (*CompileContext) PushFunctionMeta

func (c *CompileContext) PushFunctionMeta(meta *common.FunctionMeta)

func (*CompileContext) ReturnParentScope

func (c *CompileContext) ReturnParentScope()

type ConstructorNode

type ConstructorNode struct {
	Node
	Params []ASTNode
	Type   ASTNode
}

func (*ConstructorNode) Compile

func (n *ConstructorNode) Compile(c *CompileContext)

type ContinueNode

type ContinueNode struct {
	Node
}

func (*ContinueNode) Compile

func (c *ContinueNode) Compile(_ *CompileContext)

type ConvertNode

type ConvertNode struct {
	Node
	Type  ASTNode
	Value ASTNode
}

func (*ConvertNode) CheckIsConstant

func (b *ConvertNode) CheckIsConstant()

func (*ConvertNode) Compile

func (b *ConvertNode) Compile(c *CompileContext)

type EnumNode

type EnumNode struct {
	Node
	Name string
	Enum map[string]int32
}

func (*EnumNode) Compile

func (e *EnumNode) Compile(c *CompileContext)

type FetchSymbolNode

type FetchSymbolNode struct {
	Node
	SymbolName string
	Symbol     *common.Symbol
}

func (*FetchSymbolNode) CheckIsConstant

func (v *FetchSymbolNode) CheckIsConstant()

func (*FetchSymbolNode) Compile

func (v *FetchSymbolNode) Compile(c *CompileContext)

type ForMapNode

type ForMapNode struct {
	Node
	KeyName string
	ValName string
	Map     ASTNode
	Serial  ASTNode
}

func (*ForMapNode) Compile

func (f *ForMapNode) Compile(c *CompileContext)

type ForNode

type ForNode struct {
	Node
	Init      ASTNode
	Condition ASTNode
	Step      ASTNode
	Block     ASTNode
}

func (*ForNode) Compile

func (f *ForNode) Compile(c *CompileContext)

type ForSliceNode

type ForSliceNode struct {
	Node
	ItemName string
	Slice    ASTNode
	Serial   ASTNode
}

func (*ForSliceNode) Compile

func (f *ForSliceNode) Compile(c *CompileContext)

type FunctionAssignNode

type FunctionAssignNode struct {
	Node
	Lhs      []ASTNode
	Function ASTNode
}

func (*FunctionAssignNode) Compile

func (f *FunctionAssignNode) Compile(c *CompileContext)

type FunctionCallNode

type FunctionCallNode struct {
	Node
	Function ASTNode
	Params   []ASTNode
	Meta     *common.FunctionMeta
}

func (*FunctionCallNode) Compile

func (f *FunctionCallNode) Compile(c *CompileContext)

type FunctionDefNode

type FunctionDefNode struct {
	Node
	FuncName  string
	Block     ASTNode
	InParam   []ASTNode
	OutParam  []ASTNode
	TailArray bool

	Function *common.Instruction
}

func (*FunctionDefNode) Compile

func (f *FunctionDefNode) Compile(c *CompileContext)

type IfNode

type IfNode struct {
	Node
	Condition ASTNode
	Block     ASTNode
	ElseBlock ASTNode
}

func (*IfNode) Compile

func (n *IfNode) Compile(c *CompileContext)

type IndexNode

type IndexNode struct {
	Node
	ToIndex ASTNode
	Index   ASTNode
}

func (*IndexNode) CheckIsConstant

func (i *IndexNode) CheckIsConstant()

func (*IndexNode) Compile

func (i *IndexNode) Compile(c *CompileContext)

type IndicesNode

type IndicesNode struct {
	Node
	From ASTNode
	To   ASTNode
	Step ASTNode
}

func (*IndicesNode) CheckIsConstant

func (i *IndicesNode) CheckIsConstant()

func (*IndicesNode) Compile

func (i *IndicesNode) Compile(c *CompileContext)

type InitializationKVNode

type InitializationKVNode struct {
	Node
	Keys   []ASTNode
	Values []ASTNode
	Type   ASTNode
}

func (*InitializationKVNode) Compile

func (i *InitializationKVNode) Compile(c *CompileContext)

type InitializationSliceNode

type InitializationSliceNode struct {
	Node
	Items []ASTNode
	Type  ASTNode
}

func (*InitializationSliceNode) Compile

func (i *InitializationSliceNode) Compile(c *CompileContext)

type LeftUnaryNode

type LeftUnaryNode struct {
	Node
	Operand ASTNode
	Op      string
}

func (*LeftUnaryNode) CheckIsConstant

func (u *LeftUnaryNode) CheckIsConstant()

func (*LeftUnaryNode) Compile

func (u *LeftUnaryNode) Compile(c *CompileContext)

type MapMultiIndexNode

type MapMultiIndexNode struct {
	Node
	Map    ASTNode
	Fields []ASTNode
}

func (*MapMultiIndexNode) CheckIsConstant

func (m *MapMultiIndexNode) CheckIsConstant()

func (*MapMultiIndexNode) Compile

func (m *MapMultiIndexNode) Compile(c *CompileContext)

type MessageFieldDef

type MessageFieldDef struct {
	Node
	Name string
	Type ASTNode
}

type MessageTypeDef

type MessageTypeDef struct {
	Node
	Name       string
	Field      map[string]ASTNode
	OneOfGroup map[string][]string
}

func (*MessageTypeDef) Compile

func (t *MessageTypeDef) Compile(c *CompileContext)

type Node

type Node struct {
	LineNumber     int
	Text           string
	Instructions   []common.Instruction
	DataType       *common.DataType
	RequiredType   *common.DataType
	StackPtr       bool
	LhsFlag        bool
	Variadic       bool
	StackIncrement int
	ConstantValue  interface{}
}

func (*Node) AppendInstruction

func (n *Node) AppendInstruction(instruction ...common.Instruction)

func (*Node) CheckIsConstant

func (n *Node) CheckIsConstant()

func (*Node) Compile

func (n *Node) Compile(_ *CompileContext)

func (*Node) ErrorWithSource

func (n *Node) ErrorWithSource(message string) string

func (*Node) GetConstantValue

func (n *Node) GetConstantValue() interface{}

func (*Node) GetDataType

func (n *Node) GetDataType() *common.DataType

func (*Node) GetInstructions

func (n *Node) GetInstructions() []common.Instruction

func (*Node) GetStackIncrement

func (n *Node) GetStackIncrement() int

func (*Node) GetText

func (n *Node) GetText() string

func (*Node) IsStackPtr

func (n *Node) IsStackPtr() bool

func (*Node) IsVariadic

func (n *Node) IsVariadic() bool

func (*Node) PostProcess

func (n *Node) PostProcess()

func (*Node) SetDataType

func (n *Node) SetDataType(dt *common.DataType)

func (*Node) SetLhs

func (n *Node) SetLhs()

func (*Node) SetRequiredType

func (n *Node) SetRequiredType(dt *common.DataType)

func (*Node) SetSource

func (n *Node) SetSource(ctx antlr.ParserRuleContext)

func (*Node) SetStackPtr

func (n *Node) SetStackPtr()

type OneofFieldDef

type OneofFieldDef struct {
	Node
	Name    string
	Choices []*MessageFieldDef
}

type ParamNode

type ParamNode struct {
	Node
	Symbol   string
	TypeNode ASTNode
}

func (*ParamNode) Compile

func (p *ParamNode) Compile(c *CompileContext)

type ProgramRoot

type ProgramRoot struct {
	Node
	TypeDefNode   []ASTNode
	StatementNode []ASTNode
}

func (*ProgramRoot) Compile

func (p *ProgramRoot) Compile(c *CompileContext)

type RestoreStackNode

type RestoreStackNode struct {
	Node
	Line ASTNode
}

func (*RestoreStackNode) Compile

func (b *RestoreStackNode) Compile(c *CompileContext)

type ReturnNode

type ReturnNode struct {
	Node
	Expr []ASTNode
}

func (*ReturnNode) Compile

func (r *ReturnNode) Compile(c *CompileContext)

type RightUnaryNode

type RightUnaryNode struct {
	Node
	Operand ASTNode
	Op      string
}

func (*RightUnaryNode) Compile

func (u *RightUnaryNode) Compile(c *CompileContext)

type SelectorNode

type SelectorNode struct {
	Node
	Data      ASTNode // selector or var
	FieldName string
}

func (*SelectorNode) CheckIsConstant

func (s *SelectorNode) CheckIsConstant()

func (*SelectorNode) Compile

func (s *SelectorNode) Compile(c *CompileContext)

type SliceFilterNode

type SliceFilterNode struct {
	Node
	Slice ASTNode
	Expr  ASTNode
}

func (*SliceFilterNode) CheckIsConstant

func (s *SliceFilterNode) CheckIsConstant()

func (*SliceFilterNode) Compile

func (s *SliceFilterNode) Compile(c *CompileContext)

type SliceIterator

type SliceIterator struct {
	// contains filtered or unexported fields
}

func InitSliceIterator

func InitSliceIterator(s []interface{}) *SliceIterator

func (*SliceIterator) Item

func (i *SliceIterator) Item() interface{}

func (*SliceIterator) Next

func (i *SliceIterator) Next() bool

type SliceMultiIndexNode

type SliceMultiIndexNode struct {
	Node
	Slice   ASTNode
	Indices []ASTNode
}

func (*SliceMultiIndexNode) CheckIsConstant

func (s *SliceMultiIndexNode) CheckIsConstant()

func (*SliceMultiIndexNode) Compile

func (s *SliceMultiIndexNode) Compile(c *CompileContext)

type SwitchNode

type SwitchNode struct {
	Node
	Expr       ASTNode
	Conditions []interface{}
	Blocks     []ASTNode
}

func (*SwitchNode) Compile

func (s *SwitchNode) Compile(c *CompileContext)

type SymbolNode

type SymbolNode struct {
	Node
	SymbolName    string
	SymbolType    common.SymbolType
	DataTypeNode  ASTNode
	ValueToAssign ASTNode
}

func (*SymbolNode) Compile

func (t *SymbolNode) Compile(c *CompileContext)

type TypeDefNode

type TypeDefNode struct {
	Node
	SimpleTypeName string
	TypeNodeType   TypeNodeType
	Key            *common.DataType // map
	Value          ASTNode          // map slice chan
	InParam        []ASTNode        // func
	OutParam       []ASTNode        // func
	TailArray      bool
}

func (*TypeDefNode) Compile

func (t *TypeDefNode) Compile(c *CompileContext)

type TypeNode

type TypeNode struct {
	Node
	SimpleTypeName string
	TypeNodeType   TypeNodeType
	Key            *common.DataType // map
	Value          ASTNode          // map slice chan
	InParam        []ASTNode        // func
	OutParam       []ASTNode        // func
	TailArray      bool
}

func (*TypeNode) Compile

func (t *TypeNode) Compile(c *CompileContext)

type TypeNodeType

type TypeNodeType int

type ValueNode

type ValueNode struct {
	Node
}

func (*ValueNode) Compile

func (v *ValueNode) Compile(_ *CompileContext)

Jump to

Keyboard shortcuts

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