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 |
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::ArithmeticAssignmentNode, Aseba::FoldedWhileNode, Aseba::WhileNode, Aseba::FoldedIfWhenNode, Aseba::IfWhenNode, and Aseba::AssignmentNode.
Definition at line 185 of file tree-expand.cpp.
virtual void Aseba::Node::emit | ( | PreLinkBytecode & | bytecodes | ) | const [pure virtual] |
Generate bytecode.
Implemented in Aseba::AbstractTreeNode, Aseba::ReturnNode, Aseba::CallNode, Aseba::ArrayReadNode, Aseba::ArrayWriteNode, Aseba::LoadNode, Aseba::StoreNode, Aseba::ImmediateNode, Aseba::UnaryArithmeticNode, Aseba::BinaryArithmeticNode, Aseba::CallSubNode, Aseba::SubDeclNode, Aseba::EmitNode, Aseba::EventDeclNode, Aseba::FoldedWhileNode, Aseba::WhileNode, Aseba::FoldedIfWhenNode, Aseba::IfWhenNode, Aseba::AssignmentNode, Aseba::ProgramNode, and Aseba::BlockNode.
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::UnaryArithmeticAssignmentNode, Aseba::ArithmeticAssignmentNode, Aseba::MemoryVectorNode, Aseba::TupleVectorNode, Aseba::ImmediateNode, Aseba::UnaryArithmeticNode, Aseba::BinaryArithmeticNode, and Aseba::AssignmentNode.
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::MemoryVectorNode, Aseba::ArrayReadNode, Aseba::ArrayWriteNode, Aseba::LoadNode, and Aseba::StoreNode.
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::MemoryVectorNode, Aseba::TupleVectorNode, Aseba::ArrayReadNode, Aseba::ArrayWriteNode, Aseba::LoadNode, Aseba::StoreNode, and Aseba::ImmediateNode.
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::AbstractTreeNode, Aseba::ReturnNode, Aseba::CallNode, Aseba::ArrayReadNode, Aseba::ArrayWriteNode, Aseba::LoadNode, Aseba::StoreNode, Aseba::ImmediateNode, Aseba::UnaryArithmeticNode, Aseba::BinaryArithmeticNode, Aseba::CallSubNode, Aseba::SubDeclNode, Aseba::EmitNode, Aseba::EventDeclNode, Aseba::FoldedWhileNode, Aseba::WhileNode, Aseba::FoldedIfWhenNode, Aseba::IfWhenNode, Aseba::AssignmentNode, and Aseba::BlockNode.
virtual Node* Aseba::Node::shallowCopy | ( | ) | [pure virtual] |
Return a shallow copy of the object (children point to the same objects)
Implemented in Aseba::UnaryArithmeticAssignmentNode, Aseba::ArithmeticAssignmentNode, Aseba::MemoryVectorNode, Aseba::TupleVectorNode, Aseba::ReturnNode, Aseba::CallNode, Aseba::ArrayReadNode, Aseba::ArrayWriteNode, Aseba::LoadNode, Aseba::StoreNode, Aseba::ImmediateNode, Aseba::UnaryArithmeticNode, Aseba::BinaryArithmeticNode, Aseba::CallSubNode, Aseba::SubDeclNode, Aseba::EmitNode, Aseba::EventDeclNode, Aseba::FoldedWhileNode, Aseba::WhileNode, Aseba::FoldedIfWhenNode, Aseba::IfWhenNode, Aseba::AssignmentNode, Aseba::ProgramNode, and Aseba::BlockNode.
virtual std::wstring Aseba::Node::toNodeName | ( | ) | const [pure virtual] |
Return a string representation of the name of this node.
Implemented in Aseba::UnaryArithmeticAssignmentNode, Aseba::ArithmeticAssignmentNode, Aseba::MemoryVectorNode, Aseba::TupleVectorNode, Aseba::ReturnNode, Aseba::CallNode, Aseba::ArrayReadNode, Aseba::ArrayWriteNode, Aseba::LoadNode, Aseba::StoreNode, Aseba::ImmediateNode, Aseba::UnaryArithmeticNode, Aseba::BinaryArithmeticNode, Aseba::CallSubNode, Aseba::SubDeclNode, Aseba::EmitNode, Aseba::EventDeclNode, Aseba::FoldedWhileNode, Aseba::WhileNode, Aseba::FoldedIfWhenNode, Aseba::IfWhenNode, Aseba::AssignmentNode, Aseba::ProgramNode, and Aseba::BlockNode.
virtual std::wstring Aseba::Node::toWString | ( | ) | const [pure virtual] |
Return a string representation of this node.
Implemented in Aseba::UnaryArithmeticAssignmentNode, Aseba::ArithmeticAssignmentNode, Aseba::MemoryVectorNode, Aseba::TupleVectorNode, Aseba::ReturnNode, Aseba::CallNode, Aseba::ArrayReadNode, Aseba::ArrayWriteNode, Aseba::LoadNode, Aseba::StoreNode, Aseba::ImmediateNode, Aseba::UnaryArithmeticNode, Aseba::BinaryArithmeticNode, Aseba::CallSubNode, Aseba::SubDeclNode, Aseba::EmitNode, Aseba::EventDeclNode, Aseba::FoldedWhileNode, Aseba::WhileNode, Aseba::FoldedIfWhenNode, Aseba::IfWhenNode, Aseba::AssignmentNode, Aseba::ProgramNode, and Aseba::BlockNode.