Decaf Compiler
Loading...
Searching...
No Matches
symbol.h
Go to the documentation of this file.
1
9#ifndef __ANALYSIS_H
10#define __ANALYSIS_H
11
12#include "ast.h"
13#include "visitor.h"
14
18void type_attr_print(void* value, FILE* output);
19
23void symtable_attr_print(void* value, FILE* output);
24
30typedef struct Symbol
31{
35 enum {
36 SCALAR_SYMBOL,
37 ARRAY_SYMBOL,
38 FUNCTION_SYMBOL
40
45
50
54 int length;
55
60
64 enum {
65 UNKNOWN_LOC,
66 STATIC_VAR,
67 STACK_PARAM,
68 STACK_LOCAL
70
74 int offset;
75
79 struct Symbol* next;
80
82
89Symbol* Symbol_new (const char* name, DecafType type);
90
98Symbol* Symbol_new_array (const char* name, DecafType type, int length);
99
108
112void Symbol_print (Symbol* symbol, FILE* output);
113
117void Symbol_free (Symbol* symbol);
118
120
121
141
146
153
160void SymbolTable_insert (SymbolTable* table, Symbol* symbol);
161
171Symbol* SymbolTable_lookup (SymbolTable* table, const char* name);
172
176void SymbolTable_free (SymbolTable* table);
177
191Symbol* lookup_symbol(ASTNode* node, const char* name);
192
199
207
216
218
219
222void ErrorList_printf (ErrorList* list, const char* format, ...);
223
224#endif
AST nodes and attributes.
#define MAX_ERROR_LEN
Maximum length (in characters) of any error message.
Definition common.h:52
#define DECL_LIST_TYPE(NAME, ELEMTYPE)
Declare a singly-linked list structure of the given type.
Definition common.h:132
#define MAX_ID_LEN
Maximum length (in characters) of any identifier.
Definition common.h:57
DecafType
Valid Decaf types.
Definition common.h:66
Main AST node structure.
Definition ast.h:471
Static analysis error structure.
Definition symbol.h:212
char message[256]
Error message.
Definition symbol.h:213
struct AnalysisError * next
Next message (if stored in a list)
Definition symbol.h:214
Linked list of AnalysisError* elements.
Definition symbol.h:217
Node visitor structure.
Definition visitor.h:28
Linked list of struct Parameter* elements.
Definition ast.h:123
Single Decaf symbol.
Definition symbol.h:31
int length
Length (for array symbols only)
Definition symbol.h:54
ParameterList * parameters
List of parameters (for function symbols only)
Definition symbol.h:59
char name[256]
Name of symbol in code.
Definition symbol.h:44
DecafType type
Variable or function return type.
Definition symbol.h:49
enum Symbol::@7 location
Memory access location (initialized during code generation)
enum Symbol::@6 symbol_type
Kind of symbol (scalar, array, or function)
struct Symbol * next
Next symbol (if stored in a list)
Definition symbol.h:79
int offset
Memory offset (initialized during code generation)
Definition symbol.h:74
Linked list of struct Symbol* elements.
Definition symbol.h:119
Stores symbol info for a single lexical scope.
Definition symbol.h:129
SymbolList * local_symbols
List of symbols defined in the scope associated with this table.
Definition symbol.h:133
struct SymbolTable * parent
Link to parent table.
Definition symbol.h:138
Symbol * SymbolTable_lookup(SymbolTable *table, const char *name)
Retrieve a symbol from a table.
Definition symbol.c:136
Symbol * lookup_symbol(ASTNode *node, const char *name)
Look up a symbol in an AST.
Definition symbol.c:155
void symtable_attr_print(void *value, FILE *output)
Function that prints a symbol table attribute using DOT formatting.
Definition symbol.c:9
NodeVisitor * BuildSymbolTablesVisitor_new(void)
Create a new visitor that builds symbol tables.
Definition symbol.c:251
void type_attr_print(void *value, FILE *output)
Simple "print" function that prints an attribute value as a Decaf type.
Definition symbol.c:4
SymbolTable * SymbolTable_new_child(SymbolTable *parent)
Create a new symbol table with a parent link.
Definition symbol.c:124
Symbol * Symbol_new(const char *name, DecafType type)
Create a new scalar symbol.
Definition symbol.c:26
SymbolTable * SymbolTable_new(void)
Create a new symbol table with no parent link.
Definition symbol.c:115
void SymbolTable_insert(SymbolTable *table, Symbol *symbol)
Add a symbol to a table.
Definition symbol.c:131
void Symbol_print(Symbol *symbol, FILE *output)
Print simplified string representation.
Definition symbol.c:74
NodeVisitor * PrintSymbolsVisitor_new(FILE *output)
Create a new visitor that prints symbol tables.
Definition symbol.c:324
Symbol * Symbol_new_function(const char *name, DecafType return_type, ParameterList *parameters)
Create a new function symbol.
Definition symbol.c:56
void SymbolTable_free(SymbolTable *table)
Deallocate a symbol table.
Definition symbol.c:149
void Symbol_free(Symbol *symbol)
Deallocate a symbol.
Definition symbol.c:107
Symbol * Symbol_new_array(const char *name, DecafType type, int length)
Create a new array symbol.
Definition symbol.c:41
void ErrorList_printf(ErrorList *list, const char *format,...)
Add an error message to a list of errors using printf syntax.
Definition symbol.c:341
AST visitors.