Base class for nodes of abstract syntax trees of module ALib Expressions . Note that AST objects (and their data) are allocated in a MonoAllocator and hence have empty destructors.
#include <ast.hpp>
Public Type Index: | |
enum class | Types { Literal , Identifier , Function , UnaryOp , BinaryOp , TernaryOp } |
Public Field Index: | |
Types | NodeType |
integer | Position |
Public Method Index: | |
AST ()=delete | |
AST (Types type, integer position) | |
virtual | ~AST () |
virtual void | Assemble (Program &program, MonoAllocator &allocator, AString &normalized)=0 |
virtual AST * | Optimize (Normalization normalization)=0 |
|
delete |
Deleted default constructor.
|
pure virtual |
Recursively compiles nested nodes and invokes one of the add-methods of program for itself.
program | The program to be compiled. | |
allocator | An allocator usable for temporary objects. Its memory is invalid after the compilation process. | |
[out] | normalized | The normalized string, built during recursive compilation of the AST. |
Implemented in ASTLiteral, ASTIdentifier, ASTFunction, ASTUnaryOp, ASTBinaryOp, and ASTConditional.
|
pure virtual |
Recursively walks through the tree and performs optimizations, dependent on given flags.
As of today, the only optimization performed in this AST itself is to combine nested unary '+' and '-' operators on literals.
normalization | The compiler flags denoting the normalization settings. |
Implemented in ASTLiteral, ASTIdentifier, ASTFunction, ASTUnaryOp, ASTBinaryOp, and ASTConditional.