-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol_table.h
49 lines (32 loc) · 944 Bytes
/
symbol_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
#ifndef PROJECT_SYMBOL_TABLE_H
#define PROJECT_SYMBOL_TABLE_H
#include "decls.h"
#include <unordered_map> // hash table
struct symbol_info {
type_t type;
size_t addr;
symbol_info(type_t type, size_t addr);
};
typedef unordered_map<std::string, symbol_info> symbol_table_t;
struct Scope {
vector<Scope *> child;
std::string name;
Scope *parent;
symbol_table_t symbol_table;
size_t level;
Scope();
explicit Scope(Scope *parent_);
Scope(Scope *parent_, const std::string &name_);
~Scope();
};
extern Scope *GLOBAL;
extern Scope *current_scope;
void enter_scope();
void exit_scope();
void enter_scope(const std::string &scope_name);
int insert_symbol(const std::string &name, symbol_info type);
/* Lookups Return NONE if there is no such symbol. */
symbol_info local_lookup(const std::string &name);
symbol_info lookup(const std::string &name);
void print_symbol_table(char *file_name);
#endif //PROJECT_SYMBOL_TABLE_H