diff options
Diffstat (limited to 'src/symbol-table.h')
-rw-r--r-- | src/symbol-table.h | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/src/symbol-table.h b/src/symbol-table.h index 2afd1b0..1d71e09 100644 --- a/src/symbol-table.h +++ b/src/symbol-table.h @@ -1,18 +1,70 @@ #ifndef CCMMC_HEADER_SYMBOL_TABLE_H #define CCMMC_HEADER_SYMBOL_TABLE_H +#include "ast.h" + +#include <stdbool.h> +#include <stdint.h> + +#define CCMMC_SYMBOL_SCOPE_HASH_TABLE_SIZE 256 + +typedef enum CcmmcSymbolKind_enum { + CCMMC_SYMBOL_KIND_VARIABLE, + CCMMC_SYMBOL_KIND_TYPE, + CCMMC_SYMBOL_KIND_FUNCTION +} CcmmcSymbolKind; + +typedef struct CcmmcSymbolType_struct CcmmcSymbolType; +typedef struct CcmmcSymbolType_struct { + CcmmcAstValueType type_base; + size_t array_dimension; + size_t *array_size; + size_t param_count; + CcmmcSymbolType *param_list; +} CcmmcSymbolType; + +typedef struct CcmmcSymbolAttr_struct { + uint64_t addr; +} CcmmcSymbolAttr; + +typedef struct CcmmcSymbol_struct CcmmcSymbol; typedef struct CcmmcSymbol_struct { - char lexeme[256]; - struct CcmmcSymbol_struct *front; - struct CcmmcSymbol_struct *back; - int line; - int counter; + CcmmcSymbolKind kind; + CcmmcSymbolType type; + CcmmcSymbolAttr attr; + const char *name; + CcmmcSymbol *next; } CcmmcSymbol; -CcmmcSymbol *ccmmc_symbol_table_lookup (char *name); -void ccmmc_symbol_table_insert_id (char *name, - int line_number); -void ccmmc_symbol_table_print (void); +typedef struct CcmmcSymbolScope_struct CcmmcSymbolScope; +typedef struct CcmmcSymbolScope_struct { + CcmmcSymbol *hash_table[CCMMC_SYMBOL_SCOPE_HASH_TABLE_SIZE]; + CcmmcSymbolScope *all_next; + CcmmcSymbolScope *current_next; +} CcmmcSymbolScope; + +typedef struct CcmmcSymbolTable_struct { + CcmmcSymbolScope *all; + CcmmcSymbolScope *all_last; + CcmmcSymbolScope *current; +} CcmmcSymbolTable; + +static inline bool ccmmc_symbol_is_scalar(CcmmcSymbol *symbol) { + return symbol->type.array_dimension == 0; +} +static inline bool ccmmc_symbol_is_array(CcmmcSymbol *symbol) { + return symbol->type.array_dimension != 0; +} + +void ccmmc_symbol_table_open_scope (CcmmcSymbolTable *table); +void ccmmc_symbol_table_close_scope (CcmmcSymbolTable *table); +void ccmmc_symbol_table_init (CcmmcSymbolTable *table); +void ccmmc_symbol_table_insert (CcmmcSymbolTable *table, + const char *name, + CcmmcSymbolKind kind, + CcmmcSymbolType type); +CcmmcSymbol *ccmmc_symbol_table_retrive (CcmmcSymbolTable *table, + const char *name); #endif // vim: set sw=4 ts=4 sts=4 et: |