Purple
0.1
Standard Language Specification
|
Function headers and definitions for the global and local symbol tables. More...
#include <stdbool.h>
#include "translate/llvm.h"
#include "types/identifier.h"
#include "types/type.h"
#include "data.h"
Go to the source code of this file.
Classes | |
struct | SymbolTableEntry |
Struct holding data about a symbol. More... | |
struct | SymbolTable |
Holds data for symbols within a scope. More... | |
struct | SymbolTableStack |
Stack of Symbol Tables used for scoping. More... | |
Macros | |
#define | SYMBOL_TABLE_DEFAULT_LENGTH 1024 |
#define | GST_FIND(symbol_name) find_symbol_table_entry(D_GLOBAL_SYMBOL_TABLE, symbol_name) |
#define | STS_FIND(symbol_name) find_symbol_table_stack_entry(D_SYMBOL_TABLE_STACK, symbol_name) |
#define | STS_INSERT(symbol_name, type) add_symbol_table_entry(D_SYMBOL_TABLE_STACK->top, symbol_name, type) |
#define | GST_INSERT(symbol_name, type) add_symbol_table_entry(D_GLOBAL_SYMBOL_TABLE, symbol_name, type) |
Typedefs | |
typedef struct SymbolTableEntry | SymbolTableEntry |
Struct holding data about a symbol. More... | |
typedef struct SymbolTable | SymbolTable |
Holds data for symbols within a scope. More... | |
typedef struct SymbolTableStack | SymbolTableStack |
Stack of Symbol Tables used for scoping. More... | |
Functions | |
SymbolTableStack * | new_symbol_table_stack (void) |
Create a new Symbol Table Stack. More... | |
SymbolTableStack * | new_nonempty_symbol_table_stack (void) |
Create a new Symbol Table Stack with one empty Symbol Table at the bottom. More... | |
void | free_symbol_table_stack (SymbolTableStack *stack) |
Free all memory in a Symbol Table Stack. More... | |
void | push_symbol_table (SymbolTableStack *stack) |
Push new empty Symbol Table onto Symbol Table Stack. More... | |
void | push_existing_symbol_table (SymbolTableStack *stack, SymbolTable *new_table) |
Push existing Symbol Table onto Symbol Table Stack. More... | |
SymbolTable * | pop_symbol_table (SymbolTableStack *stack) |
Remove Symbol Table from Symbol Table Stack and return its pointer. More... | |
void | pop_and_free_symbol_table (SymbolTableStack *stack) |
Remove Symbol Table from Symbol Table Stack and free its memory. More... | |
SymbolTable * | peek_symbol_table (SymbolTableStack *stack) |
Get pointer of the top Symbol Table from Symbol Table Stack. More... | |
SymbolTable * | new_symbol_table (void) |
Get pointer to empty Symbol Table with length SYMBOL_TABLE_DEFAULT_LENGTH. More... | |
SymbolTable * | new_symbol_table_with_length (int length) |
Get pointer to empty Symbol Table with a custom length. More... | |
void | resize_symbol_table (SymbolTable *table) |
Double the size of a Symbol Table's buckets array. More... | |
SymbolTableEntry * | find_symbol_table_entry (SymbolTable *table, char *symbol_name) |
Find the entry of a symbol in the provided Symbol Table if it exists. More... | |
SymbolTableEntry * | find_symbol_table_stack_entry (SymbolTableStack *table, char *symbol_name) |
Find the entry of a symbol in the provided Symbol Table Stack if it exists, working from the top of the stack to the bottom. More... | |
SymbolTableEntry * | new_symbol_table_entry (char *symbol_name) |
Get pointer to new Symbol Table Entry. More... | |
SymbolTableEntry * | add_symbol_table_entry (SymbolTable *table, char *symbol_name, Type type) |
Hash symbol_name with hash function FNV-1 and put it into the chained Symbol Table. More... | |
Function headers and definitions for the global and local symbol tables.
#define GST_FIND | ( | symbol_name | ) | find_symbol_table_entry(D_GLOBAL_SYMBOL_TABLE, symbol_name) |
#define GST_INSERT | ( | symbol_name, | |
type | |||
) | add_symbol_table_entry(D_GLOBAL_SYMBOL_TABLE, symbol_name, type) |
#define STS_FIND | ( | symbol_name | ) | find_symbol_table_stack_entry(D_SYMBOL_TABLE_STACK, symbol_name) |
#define STS_INSERT | ( | symbol_name, | |
type | |||
) | add_symbol_table_entry(D_SYMBOL_TABLE_STACK->top, symbol_name, type) |
#define SYMBOL_TABLE_DEFAULT_LENGTH 1024 |
Default length of the symbol table hash table
typedef struct SymbolTable SymbolTable |
Holds data for symbols within a scope.
typedef struct SymbolTableEntry SymbolTableEntry |
Struct holding data about a symbol.
typedef struct SymbolTableStack SymbolTableStack |
Stack of Symbol Tables used for scoping.
SymbolTableEntry * add_symbol_table_entry | ( | SymbolTable * | table, |
char * | symbol_name, | ||
Type | type | ||
) |
Hash symbol_name with hash function FNV-1 and put it into the chained Symbol Table.
table | Table to put new Symbol Table Entry into |
symbol_name | Name of symbol to add |
type | Type of symbol to add |
SymbolTableEntry * find_symbol_table_entry | ( | SymbolTable * | table, |
char * | symbol_name | ||
) |
Find the entry of a symbol in the provided Symbol Table if it exists.
table | Table to search in |
symbol_name | Name of symbol to search for |
SymbolTableEntry * find_symbol_table_stack_entry | ( | SymbolTableStack * | stack, |
char * | symbol_name | ||
) |
Find the entry of a symbol in the provided Symbol Table Stack if it exists, working from the top of the stack to the bottom.
stack | Symbol Table Stack to search |
symbol_name | Name of symbol to find |
void free_symbol_table_stack | ( | SymbolTableStack * | stack | ) |
Free all memory in a Symbol Table Stack.
SymbolTableStack * new_nonempty_symbol_table_stack | ( | void | ) |
Create a new Symbol Table Stack with one empty Symbol Table at the bottom.
SymbolTable * new_symbol_table | ( | void | ) |
Get pointer to empty Symbol Table with length SYMBOL_TABLE_DEFAULT_LENGTH.
SymbolTableEntry * new_symbol_table_entry | ( | char * | symbol_name | ) |
Get pointer to new Symbol Table Entry.
symbol_name | Name of new symbol |
SymbolTableStack * new_symbol_table_stack | ( | void | ) |
Create a new Symbol Table Stack.
SymbolTable * new_symbol_table_with_length | ( | int | length | ) |
Get pointer to empty Symbol Table with a custom length.
SymbolTable * peek_symbol_table | ( | SymbolTableStack * | stack | ) |
Get pointer of the top Symbol Table from Symbol Table Stack.
stack | Stack to ppek at |
void pop_and_free_symbol_table | ( | SymbolTableStack * | stack | ) |
Remove Symbol Table from Symbol Table Stack and free its memory.
stack | Stack to pop from |
SymbolTable * pop_symbol_table | ( | SymbolTableStack * | stack | ) |
Remove Symbol Table from Symbol Table Stack and return its pointer.
stack | Stack to pop from |
void push_existing_symbol_table | ( | SymbolTableStack * | stack, |
SymbolTable * | new_table | ||
) |
Push existing Symbol Table onto Symbol Table Stack.
stack | Symbol Table Stack to push existing table onto |
new_table | New table to push onto stack |
void push_symbol_table | ( | SymbolTableStack * | stack | ) |
Push new empty Symbol Table onto Symbol Table Stack.
stack | Symbol Table Stack to push new table onto |
void resize_symbol_table | ( | SymbolTable * | table | ) |
Double the size of a Symbol Table's buckets array.
table | Table to double the size of |