$search
An abstract node of syntax tree. More...
#include <tree.h>
Public Types | |
enum | MemoryErrorCode { E_NOVAL = UINT_MAX } |
typedef std::vector< Node * > | NodesVector |
Vector for children of a node. | |
enum | ReturnType { TYPE_UNIT = 0, TYPE_BOOL, TYPE_INT } |
A type a node can return. More... | |
Public Member Functions | |
virtual void | checkVectorSize () const |
Check the consistency in vectors' size. | |
virtual Node * | deepCopy () |
Return a deep copy of the object (children are also copied). | |
virtual void | dump (std::wostream &dest, unsigned &indent) const |
Dump this node and the rest of the tree. | |
virtual void | emit (PreLinkBytecode &bytecodes) const =0 |
Generate bytecode. | |
virtual Node * | expandToAsebaTree (std::wostream *dump, unsigned int index=0) |
Second pass to expand "abstract" nodes into more concrete ones. | |
void | expectType (const Node::ReturnType &expected, const Node::ReturnType &type) const |
Check for a specific type, throw an exception otherwise. | |
virtual unsigned | getStackDepth () const |
Return the stack depth requirement for this node and its children. | |
virtual unsigned | getVectorAddr () const |
return the address of the left-most operand, or E_NOVAL if none | |
virtual unsigned | getVectorSize () const |
return the children's size, check for equal size, or E_NOVAL if no child | |
Node (const SourcePos &sourcePos) | |
Constructor. | |
virtual Node * | optimize (std::wostream *dump)=0 |
Optimize this node, return the optimized node. | |
virtual Node * | shallowCopy ()=0 |
Return a shallow copy of the object (children point to the same objects). | |
virtual std::wstring | toNodeName () const =0 |
Return a string representation of the name of this node. | |
virtual std::wstring | toWString () const =0 |
Return a string representation of this node. | |
virtual ReturnType | typeCheck () const |
Typecheck this node, throw an exception if there is any type violation. | |
std::wstring | typeName (const Node::ReturnType &type) const |
Return the name of a type. | |
virtual | ~Node () |
Destructor, delete all children. | |
Public Attributes | |
NodesVector | children |
children of this node | |
SourcePos | sourcePos |
position is source |
An abstract node of syntax tree.
Definition at line 46 of file tree.h.
typedef std::vector<Node *> Aseba::Node::NodesVector |
Aseba::Node::Node | ( | const SourcePos & | sourcePos | ) | [inline] |
void Aseba::Node::checkVectorSize | ( | ) | const [virtual] |
Check the consistency in vectors' size.
Reimplemented in Aseba::AssignmentNode, Aseba::IfWhenNode, Aseba::FoldedIfWhenNode, Aseba::WhileNode, Aseba::FoldedWhileNode, and Aseba::ArithmeticAssignmentNode.
Definition at line 185 of file tree-expand.cpp.
virtual void Aseba::Node::emit | ( | PreLinkBytecode & | bytecodes | ) | const [pure virtual] |
Generate bytecode.
Implemented in Aseba::BlockNode, Aseba::ProgramNode, Aseba::AssignmentNode, Aseba::IfWhenNode, Aseba::FoldedIfWhenNode, Aseba::WhileNode, Aseba::FoldedWhileNode, Aseba::EventDeclNode, Aseba::EmitNode, Aseba::SubDeclNode, Aseba::CallSubNode, Aseba::BinaryArithmeticNode, Aseba::UnaryArithmeticNode, Aseba::ImmediateNode, Aseba::StoreNode, Aseba::LoadNode, Aseba::ArrayWriteNode, Aseba::ArrayReadNode, Aseba::CallNode, Aseba::ReturnNode, and Aseba::AbstractTreeNode.
Node * Aseba::Node::expandToAsebaTree | ( | std::wostream * | dump, | |
unsigned int | index = 0 | |||
) | [virtual] |
Second pass to expand "abstract" nodes into more concrete ones.
Reimplemented in Aseba::AssignmentNode, Aseba::BinaryArithmeticNode, Aseba::UnaryArithmeticNode, Aseba::ImmediateNode, Aseba::TupleVectorNode, Aseba::MemoryVectorNode, Aseba::ArithmeticAssignmentNode, and Aseba::UnaryArithmeticAssignmentNode.
Definition at line 31 of file tree-expand.cpp.
unsigned Aseba::Node::getVectorAddr | ( | ) | const [virtual] |
return the address of the left-most operand, or E_NOVAL if none
Reimplemented in Aseba::StoreNode, Aseba::LoadNode, Aseba::ArrayWriteNode, Aseba::ArrayReadNode, and Aseba::MemoryVectorNode.
Definition at line 281 of file tree-expand.cpp.
unsigned Aseba::Node::getVectorSize | ( | ) | const [virtual] |
return the children's size, check for equal size, or E_NOVAL if no child
Reimplemented in Aseba::ImmediateNode, Aseba::StoreNode, Aseba::LoadNode, Aseba::ArrayWriteNode, Aseba::ArrayReadNode, Aseba::TupleVectorNode, and Aseba::MemoryVectorNode.
Definition at line 291 of file tree-expand.cpp.
virtual Node* Aseba::Node::optimize | ( | std::wostream * | dump | ) | [pure virtual] |
Optimize this node, return the optimized node.
Implemented in Aseba::BlockNode, Aseba::AssignmentNode, Aseba::IfWhenNode, Aseba::FoldedIfWhenNode, Aseba::WhileNode, Aseba::FoldedWhileNode, Aseba::EventDeclNode, Aseba::EmitNode, Aseba::SubDeclNode, Aseba::CallSubNode, Aseba::BinaryArithmeticNode, Aseba::UnaryArithmeticNode, Aseba::ImmediateNode, Aseba::StoreNode, Aseba::LoadNode, Aseba::ArrayWriteNode, Aseba::ArrayReadNode, Aseba::CallNode, Aseba::ReturnNode, and Aseba::AbstractTreeNode.
virtual Node* Aseba::Node::shallowCopy | ( | ) | [pure virtual] |
Return a shallow copy of the object (children point to the same objects).
Implemented in Aseba::BlockNode, Aseba::ProgramNode, Aseba::AssignmentNode, Aseba::IfWhenNode, Aseba::FoldedIfWhenNode, Aseba::WhileNode, Aseba::FoldedWhileNode, Aseba::EventDeclNode, Aseba::EmitNode, Aseba::SubDeclNode, Aseba::CallSubNode, Aseba::BinaryArithmeticNode, Aseba::UnaryArithmeticNode, Aseba::ImmediateNode, Aseba::StoreNode, Aseba::LoadNode, Aseba::ArrayWriteNode, Aseba::ArrayReadNode, Aseba::CallNode, Aseba::ReturnNode, Aseba::TupleVectorNode, Aseba::MemoryVectorNode, Aseba::ArithmeticAssignmentNode, and Aseba::UnaryArithmeticAssignmentNode.
virtual std::wstring Aseba::Node::toNodeName | ( | ) | const [pure virtual] |
Return a string representation of the name of this node.
Implemented in Aseba::BlockNode, Aseba::ProgramNode, Aseba::AssignmentNode, Aseba::IfWhenNode, Aseba::FoldedIfWhenNode, Aseba::WhileNode, Aseba::FoldedWhileNode, Aseba::EventDeclNode, Aseba::EmitNode, Aseba::SubDeclNode, Aseba::CallSubNode, Aseba::BinaryArithmeticNode, Aseba::UnaryArithmeticNode, Aseba::ImmediateNode, Aseba::StoreNode, Aseba::LoadNode, Aseba::ArrayWriteNode, Aseba::ArrayReadNode, Aseba::CallNode, Aseba::ReturnNode, Aseba::TupleVectorNode, Aseba::MemoryVectorNode, Aseba::ArithmeticAssignmentNode, and Aseba::UnaryArithmeticAssignmentNode.
virtual std::wstring Aseba::Node::toWString | ( | ) | const [pure virtual] |
Return a string representation of this node.
Implemented in Aseba::BlockNode, Aseba::ProgramNode, Aseba::AssignmentNode, Aseba::IfWhenNode, Aseba::FoldedIfWhenNode, Aseba::WhileNode, Aseba::FoldedWhileNode, Aseba::EventDeclNode, Aseba::EmitNode, Aseba::SubDeclNode, Aseba::CallSubNode, Aseba::BinaryArithmeticNode, Aseba::UnaryArithmeticNode, Aseba::ImmediateNode, Aseba::StoreNode, Aseba::LoadNode, Aseba::ArrayWriteNode, Aseba::ArrayReadNode, Aseba::CallNode, Aseba::ReturnNode, Aseba::TupleVectorNode, Aseba::MemoryVectorNode, Aseba::ArithmeticAssignmentNode, and Aseba::UnaryArithmeticAssignmentNode.