Purple  0.1
Standard Language Specification
Classes | Macros | Typedefs | Functions
symbol_table.h File Reference

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"
Include dependency graph for symbol_table.h:
This graph shows which files directly or indirectly include this file:

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

SymbolTableStacknew_symbol_table_stack (void)
 Create a new Symbol Table Stack. More...
 
SymbolTableStacknew_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...
 
SymbolTablepop_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...
 
SymbolTablepeek_symbol_table (SymbolTableStack *stack)
 Get pointer of the top Symbol Table from Symbol Table Stack. More...
 
SymbolTablenew_symbol_table (void)
 Get pointer to empty Symbol Table with length SYMBOL_TABLE_DEFAULT_LENGTH. More...
 
SymbolTablenew_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...
 
SymbolTableEntryfind_symbol_table_entry (SymbolTable *table, char *symbol_name)
 Find the entry of a symbol in the provided Symbol Table if it exists. More...
 
SymbolTableEntryfind_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...
 
SymbolTableEntrynew_symbol_table_entry (char *symbol_name)
 Get pointer to new Symbol Table Entry. More...
 
SymbolTableEntryadd_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...
 

Detailed Description

Function headers and definitions for the global and local symbol tables.

Author
Charles Averill
Date
16-Sep-2022

Macro Definition Documentation

◆ GST_FIND

#define GST_FIND (   symbol_name)    find_symbol_table_entry(D_GLOBAL_SYMBOL_TABLE, symbol_name)

◆ GST_INSERT

#define GST_INSERT (   symbol_name,
  type 
)     add_symbol_table_entry(D_GLOBAL_SYMBOL_TABLE, symbol_name, type)

◆ STS_FIND

#define STS_FIND (   symbol_name)    find_symbol_table_stack_entry(D_SYMBOL_TABLE_STACK, symbol_name)

◆ STS_INSERT

#define STS_INSERT (   symbol_name,
  type 
)     add_symbol_table_entry(D_SYMBOL_TABLE_STACK->top, symbol_name, type)

◆ SYMBOL_TABLE_DEFAULT_LENGTH

#define SYMBOL_TABLE_DEFAULT_LENGTH   1024

Default length of the symbol table hash table

Typedef Documentation

◆ SymbolTable

typedef struct SymbolTable SymbolTable

Holds data for symbols within a scope.

◆ SymbolTableEntry

Struct holding data about a symbol.

◆ SymbolTableStack

Stack of Symbol Tables used for scoping.

Function Documentation

◆ add_symbol_table_entry()

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.

Parameters
tableTable to put new Symbol Table Entry into
symbol_nameName of symbol to add
typeType of symbol to add
Returns
SymbolTableEntry* Pointer to new Symbol Table Entry

◆ find_symbol_table_entry()

SymbolTableEntry * find_symbol_table_entry ( SymbolTable table,
char *  symbol_name 
)

Find the entry of a symbol in the provided Symbol Table if it exists.

Parameters
tableTable to search in
symbol_nameName of symbol to search for
Returns
SymbolTableEntry* Pointer to entry if it exists, else NULL

◆ find_symbol_table_stack_entry()

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.

Parameters
stackSymbol Table Stack to search
symbol_nameName of symbol to find
Returns
SymbolTableEntry* Pointer to entry if it exists, else NULL

◆ free_symbol_table_stack()

void free_symbol_table_stack ( SymbolTableStack stack)

Free all memory in a Symbol Table Stack.

◆ new_nonempty_symbol_table_stack()

SymbolTableStack * new_nonempty_symbol_table_stack ( void  )

Create a new Symbol Table Stack with one empty Symbol Table at the bottom.

Returns
SymbolTableStack* Pointer to new non-empty Symbol Table Stack

◆ new_symbol_table()

SymbolTable * new_symbol_table ( void  )

Get pointer to empty Symbol Table with length SYMBOL_TABLE_DEFAULT_LENGTH.

Returns
SymbolTable* Pointer to new empty Symbol Table

◆ new_symbol_table_entry()

SymbolTableEntry * new_symbol_table_entry ( char *  symbol_name)

Get pointer to new Symbol Table Entry.

Parameters
symbol_nameName of new symbol
Returns
SymbolTableEntry* Pointer to new Symbol Table Entry

◆ new_symbol_table_stack()

SymbolTableStack * new_symbol_table_stack ( void  )

Create a new Symbol Table Stack.

Returns
SymbolTableStack* Pointer to new empty Symbol Table Stack

◆ new_symbol_table_with_length()

SymbolTable * new_symbol_table_with_length ( int  length)

Get pointer to empty Symbol Table with a custom length.

Returns
SymbolTable* Pointer to new empty Symbol Table

◆ peek_symbol_table()

SymbolTable * peek_symbol_table ( SymbolTableStack stack)

Get pointer of the top Symbol Table from Symbol Table Stack.

Parameters
stackStack to ppek at
Returns
SymbolTable* Pointer to peeked Symbol Table

◆ pop_and_free_symbol_table()

void pop_and_free_symbol_table ( SymbolTableStack stack)

Remove Symbol Table from Symbol Table Stack and free its memory.

Parameters
stackStack to pop from

◆ pop_symbol_table()

SymbolTable * pop_symbol_table ( SymbolTableStack stack)

Remove Symbol Table from Symbol Table Stack and return its pointer.

Parameters
stackStack to pop from
Returns
SymbolTable* Pointer to popped Symbol Table

◆ push_existing_symbol_table()

void push_existing_symbol_table ( SymbolTableStack stack,
SymbolTable new_table 
)

Push existing Symbol Table onto Symbol Table Stack.

Parameters
stackSymbol Table Stack to push existing table onto
new_tableNew table to push onto stack

◆ push_symbol_table()

void push_symbol_table ( SymbolTableStack stack)

Push new empty Symbol Table onto Symbol Table Stack.

Parameters
stackSymbol Table Stack to push new table onto

◆ resize_symbol_table()

void resize_symbol_table ( SymbolTable table)

Double the size of a Symbol Table's buckets array.

Parameters
tableTable to double the size of