Decaf Compiler
Public Attributes | List of all members
ASTNode Struct Reference

Main AST node structure. More...

#include <ast.h>

Public Attributes

NodeType type
 Node type (discriminator/tag for the anonymous union)
 
int source_line
 Source code line number.
 
Attributeattributes
 Attribute list (not a formal list because of the provided accessor methods)
 
struct ASTNodenext
 Next node (if stored in a list)
 
union {
   struct ProgramNode   program
 
   struct VarDeclNode   vardecl
 
   struct FuncDeclNode   funcdecl
 
   struct BlockNode   block
 
   struct AssignmentNode   assignment
 
   struct ConditionalNode   conditional
 
   struct WhileLoopNode   whileloop
 
   struct ReturnNode   funcreturn
 
   struct BinaryOpNode   binaryop
 
   struct UnaryOpNode   unaryop
 
   struct LocationNode   location
 
   struct FuncCallNode   funccall
 
   struct LiteralNode   literal
 
}; 
 

Detailed Description

Main AST node structure.

Provides some basic definitions used across many nodes, such as source code info and attribute management. Storage of type-specific node data is managed using a tagged union of the other *Node structures declared earlier in this file.

AST nodes are designed to be semi-mutable even after parsing by means of the attributes key-value mapping that is stored in every node. List of potential attributes (not exhaustive, and most are irrelevant to Project 2):

KeyDescription
parent Uptree parent ASTNode reference
depth Tree depth (int)
symbolTable Symbol table reference (only in program, function, and block nodes)
type DecafType of node (only in expression nodes)
staticSize Size (in bytes as int) of global variables (only in program node)
localSize Size (in bytes as int) of local variables (only in function nodes)
code ILOC instructions generated from the subtree rooted at this node
reg Register storing the result of the expression rooted at this node (only in expression nodes)

Generally, the node-type-specific allocators (e.g., ProgramNode_new) should be used to ensure that all of the node-specific data members are initialized correctly. Node structures must be explicitly freed using ASTNode_free.

Methods:


The documentation for this struct was generated from the following file: