Abstract base class for all AST nodes.
ASTNodes define the elements of the program in a tree structured form. A key concept to undestand is that of "ownership". Every node in the tree is "owned" by its parent. The parent maintains a "shared pointer" to each of its children. This greatly simplifies memory management as the tree can be reclaimed once its root is no longer needed. It is important to understand that the "shared pointer" is only used to manage the lifetime of the child nodes. The values of those pointers can be passed around freely to other parts of the compiler that want to view the ASTNodes.
Each node has information about the line and column in the source program on which the element begins. Subtypes define "<<" operator that print a custom representation of the ASTNode, by overriding the print method.
There are two virtual methods that are used in a generic visitor and for code generation pass.
Visit the children of this node and apply the visitor.
This virtual function is overridden by each ASTNode subtype in order to visit each of its child nodes, by calling their accept methods. The visitor parameter defines the operations that are applied to each node that is visited; a subtype of ASTVisitor defines those operations.
- Parameters
-
visitor | The subtype of ASTVisitor that carries out per-ASTNode work. |
Implemented in ASTWhileStmt, ASTVariableExpr, ASTReturnStmt, ASTRefExpr, ASTRecordExpr, ASTProgram, ASTOutputStmt, ASTNumberExpr, ASTNullExpr, ASTInputExpr, ASTIfStmt, ASTFunction, ASTFunAppExpr, ASTFieldExpr, ASTErrorStmt, ASTDeRefExpr, ASTDeclStmt, ASTDeclNode, ASTBlockStmt, ASTBinaryExpr, ASTAssignStmt, ASTAllocExpr, and ASTAccessExpr.
Perform code generation and return an LLVM value the code.
This virtual function is overridden by each ASTNode subtype in order to generate the executable code. This function does not use the visitor due to the fact that a high-degree of control on the ordering of the nodes is required.
- Returns
- LLVM value holding an representation of the generated code.
Implemented in ASTWhileStmt, ASTVariableExpr, ASTReturnStmt, ASTRefExpr, ASTRecordExpr, ASTOutputStmt, ASTNumberExpr, ASTNullExpr, ASTInputExpr, ASTIfStmt, ASTFunction, ASTFunAppExpr, ASTFieldExpr, ASTErrorStmt, ASTDeRefExpr, ASTDeclStmt, ASTDeclNode, ASTBlockStmt, ASTBinaryExpr, ASTAssignStmt, ASTAllocExpr, and ASTAccessExpr.
Return all of the children for the node.
This is not a pure virtual function so subclasses can selectively override it.
- Returns
- a collection of the nodes children.
Reimplemented in ASTWhileStmt, ASTReturnStmt, ASTRefExpr, ASTRecordExpr, ASTProgram, ASTOutputStmt, ASTIfStmt, ASTFunction, ASTFunAppExpr, ASTFieldExpr, ASTErrorStmt, ASTDeRefExpr, ASTDeclStmt, ASTBlockStmt, ASTBinaryExpr, ASTAssignStmt, ASTAllocExpr, and ASTAccessExpr.