-
Notifications
You must be signed in to change notification settings - Fork 0
/
sym_table.h
64 lines (52 loc) · 1.71 KB
/
sym_table.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef __SYMTABLE_H__
#define __SYMTABLE_H__
#include <string>
#include <vector>
#include <bitset>
#include <unordered_map>
#include "auxlib.h"
#include "astree.h"
using namespace std;
struct symbol;
using symbol_table = unordered_map<string*,symbol*>;
using symbol_entry = symbol_table::value_type;
// Symbol table node (3.0)
struct symbol {
attr_bitset attributes;
size_t sequence;
symbol_table* fields;
location lloc;
size_t block_nr;
vector<symbol*>* parameters;
attr type;
};
const string to_string (attr attribute);
attr to_attr (const string* string);
// Traverse Functions
void traverse(FILE* outfile, astree* tree, int depth = 0);
void traverse_struct(astree* root, symbol* sym);
void traverse_function(astree* root, symbol* sym);
void traverse_block(astree* root, int cur_block);
void process_id(astree* root);
// Function helper functions
void fn_read_param(astree* root, symbol* func_sym, size_t block_nr);
void fn_read_vardecl(astree* root, size_t block_nr, int seq_num,
symbol_table* id_table_local);
// Typecheck Functions
bool typecheck(astree* root);
bool tc_bin_op(astree* root);
bool tc_bool_op(astree* root);
attr get_type(const string* key);
attr find_type(astree* root);
location get_lloc(const string* key);
// Print Functions
void print_local_ident(symbol* sym, astree* type, astree* name);
void print_func(symbol* sym, astree* type, astree* name);
void print_struct(symbol* sym, astree* name);
void print_field(symbol* sym, astree* type, astree* name);
void print_globalid(symbol* sym, astree* type, astree* name);
// Other
void set_attr(symbol* sym, attr a1);
void insert_table_node(astree* name, symbol* sym, symbol_table* st);
void dump_tables();
#endif