public abstract class ASTNode extends Object
ASTNode.DataType
definitions
and attribute management. AST nodes are designed to be semi-mutable by means
of the attributes
map that is stored in every
node. Several of the more important attributes (e.g., parent links and tree
depth) are widely used and thus have special handlers implemented in this
class. However, this class is not intended to be instantiated directly,
and thus is declared abstract
.
List of potential attributes (not exhaustive):
Key | Description |
---|---|
parent | Uptree parent ASTNode reference |
depth | Tree depth (int ) |
source | SourceInfo reference |
symbolTable | SymbolTable reference (only in ASTProgram , ASTFunction , and ASTBlock ) |
type | ASTNode.DataType of node (only in ASTExpression subclasses) |
staticSize | Size (in bytes) of global variables (only in ASTProgram ) |
localSize | Size (in bytes) of local variables (only in ASTFunction ) |
Modifier and Type | Class and Description |
---|---|
static class |
ASTNode.DataType
List of Decaf AST data types.
|
Modifier and Type | Field and Description |
---|---|
Map<String,Object> |
attributes
Generic key/value store.
|
Constructor and Description |
---|
ASTNode()
Generic constructor.
|
Modifier and Type | Method and Description |
---|---|
String |
getASTTypeStr()
Returns a string with the AST class type (mainly used for debugging)
|
int |
getDepth()
Retrieve the tree depth marker
|
ASTNode |
getParent()
Retrieve the uptree parent pointer
|
SourceInfo |
getSourceInfo()
Retrieve the source code information
|
ASTNode.DataType |
getType()
Retrieve the type
|
void |
setDepth(int depth)
Initialize the tree depth marker
|
void |
setParent(ASTNode parent)
Initialize the uptree parent pointer
|
void |
setSourceInfo(SourceInfo source)
Initialize source code information
|
void |
setType(ASTNode.DataType type)
Initialize type
|
void |
traverse(ASTVisitor visitor)
Generic traversal method for the visitor pattern.
|
static String |
typeToString(ASTNode.DataType t)
Returns a human-readable version of Decaf data types.
|
public static String typeToString(ASTNode.DataType t)
t
- Data typepublic String getASTTypeStr()
public void setParent(ASTNode parent)
parent
- Parent AST objectpublic ASTNode getParent()
ASTNode
reference or null
if the
corresponding attribute is not presentpublic void setDepth(int depth)
depth
- Node depthpublic int getDepth()
public void setSourceInfo(SourceInfo source)
source
- Source infopublic SourceInfo getSourceInfo()
SourceInfo
reference or SourceInfo.INVALID
if
the corresponding attribute is not present.public void setType(ASTNode.DataType type)
type
- Node typepublic ASTNode.DataType getType()
public void traverse(ASTVisitor visitor)
visitor
- Visitor objectCopyright © 2019. All rights reserved.