Decaf Compiler
|
Symbols, symbol tables, and static analysis errors. More...
Go to the source code of this file.
Classes | |
struct | Symbol |
Single Decaf symbol. More... | |
struct | SymbolList |
Linked list of struct Symbol* elements. More... | |
struct | SymbolTable |
Stores symbol info for a single lexical scope. More... | |
struct | AnalysisError |
Static analysis error structure. More... | |
struct | ErrorList |
Linked list of AnalysisError* elements. More... | |
Typedefs | |
typedef struct Symbol | Symbol |
Single Decaf symbol. More... | |
typedef struct SymbolList | SymbolList |
Linked list of struct Symbol* elements. | |
typedef struct SymbolTable | SymbolTable |
Stores symbol info for a single lexical scope. More... | |
typedef struct AnalysisError | AnalysisError |
Static analysis error structure. | |
typedef struct ErrorList | ErrorList |
Linked list of AnalysisError* elements. | |
Functions | |
void | type_attr_print (void *value, FILE *output) |
Simple "print" function that prints an attribute value as a Decaf type. | |
void | symtable_attr_print (void *value, FILE *output) |
Function that prints a symbol table attribute using DOT formatting. | |
Symbol * | Symbol_new (const char *name, DecafType type) |
Create a new scalar symbol. More... | |
Symbol * | Symbol_new_array (const char *name, DecafType type, int length) |
Create a new array symbol. More... | |
Symbol * | Symbol_new_function (const char *name, DecafType return_type, ParameterList *parameters) |
Create a new function symbol. More... | |
void | Symbol_print (Symbol *symbol, FILE *output) |
Print simplified string representation. | |
void | Symbol_free (Symbol *symbol) |
Deallocate a symbol. | |
SymbolList * | SymbolList_new () |
Allocate and initialize a new, empty list. | |
void | SymbolList_add (SymbolList *list, struct Symbol *item) |
Add an item to the end of a list. | |
int | SymbolList_size (SymbolList *list) |
Look up the size of a list. | |
bool | SymbolList_is_empty (SymbolList *list) |
Test a list to see if it is empty. | |
void | SymbolList_free (SymbolList *list) |
Deallocate a list and any contained items. | |
SymbolTable * | SymbolTable_new () |
Create a new symbol table with no parent link. | |
SymbolTable * | SymbolTable_new_child (SymbolTable *parent) |
Create a new symbol table with a parent link. More... | |
void | SymbolTable_insert (SymbolTable *table, Symbol *symbol) |
Add a symbol to a table. More... | |
Symbol * | SymbolTable_lookup (SymbolTable *table, const char *name) |
Retrieve a symbol from a table. More... | |
void | SymbolTable_free (SymbolTable *table) |
Deallocate a symbol table. | |
Symbol * | lookup_symbol (ASTNode *node, const char *name) |
Look up a symbol in an AST. More... | |
NodeVisitor * | BuildSymbolTablesVisitor_new () |
Create a new visitor that builds symbol tables. More... | |
NodeVisitor * | PrintSymbolsVisitor_new (FILE *output) |
Create a new visitor that prints symbol tables. More... | |
ErrorList * | ErrorList_new () |
Allocate and initialize a new, empty list. | |
void | ErrorList_add (ErrorList *list, AnalysisError *item) |
Add an item to the end of a list. | |
int | ErrorList_size (ErrorList *list) |
Look up the size of a list. | |
bool | ErrorList_is_empty (ErrorList *list) |
Test a list to see if it is empty. | |
void | ErrorList_free (ErrorList *list) |
Deallocate a list and any contained items. | |
void | ErrorList_printf (ErrorList *list, const char *format,...) |
Add an error message to a list of errors using printf syntax. | |
Symbols, symbol tables, and static analysis errors.
This module provides declarations for the symbol table and static analysis framework. The declarations in this file will be will be critical for Project 3 (static analysis) and 4 (code generation).
Single Decaf symbol.
Might represent a scalar variable, an array, or a formal function parameter.
typedef struct SymbolTable SymbolTable |
Stores symbol info for a single lexical scope.
Symbol tables are generated using a simple AST traversal algorithm, and are used during code generation to look up type and location information for individual symbols.
NodeVisitor* BuildSymbolTablesVisitor_new | ( | ) |
Create a new visitor that builds symbol tables.
Look up a symbol in an AST.
The search has two phases: 1) searching AST nodes for a symbol table as a "symbolTable" attribute and following "parent" attributes as necessary (requires the links as set up by a SetParentVisitor), and 2) searching symbol tables for the given symbol name and following parent pointers as necessary.
node | AST node to begin the search at |
name | Name of symbol to find |
NULL
NodeVisitor* PrintSymbolsVisitor_new | ( | FILE * | output | ) |
Create a new visitor that prints symbol tables.
output | File stream for the print output |
Create a new scalar symbol.
name | Name in source code |
type | Data type |
Create a new array symbol.
name | Name in source code |
type | Data type |
length | Array length |
Symbol* Symbol_new_function | ( | const char * | name, |
DecafType | return_type, | ||
ParameterList * | parameters | ||
) |
Create a new function symbol.
name | Name in source code |
return_type | Function return type |
parameters | List of formal parameter names and data types |
void SymbolTable_insert | ( | SymbolTable * | table, |
Symbol * | symbol | ||
) |
Symbol* SymbolTable_lookup | ( | SymbolTable * | table, |
const char * | name | ||
) |
SymbolTable* SymbolTable_new_child | ( | SymbolTable * | parent | ) |
Create a new symbol table with a parent link.
parent | Pointer to parent table |