-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbols.h
70 lines (56 loc) · 1.45 KB
/
symbols.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
65
66
67
68
69
70
#ifndef SYMBOLS_H
#define SYMBOLS_H
#include "interpreter.h"
#include <unordered_map>
#include <memory>
#include <string>
#include "gc/include/gc_cpp.h"
using namespace std;
using namespace Interpreter;
namespace Symbols
{
class SymbolTable;
enum Type {SymbolInt,SymbolString,SymbolProcedure};
class Object : public gc
{
private:
Type kind;
string sVal;
int iVal;
public:
SymbolTable* closure; // TODO: Make private
ProcedureDeclaration* const fVal;
Object(string s);
Object(int i);
Object(ProcedureDeclaration* p, SymbolTable* closure);
Type GetKind();
string GetString();
int GetInt();
void SetInt(int val);
ProcedureDeclaration* GetProcedure();
};
class SymbolTable : public gc
{
private:
unordered_map<string, Object*> symbols; // TODO: Change to const char*?
static int last_sequence;
public:
const int sequence;
SymbolTable();
SymbolTable(const SymbolTable& cloneFrom);
Object* Get(string name);
bool Contains(const char* name);
void Set(string name, Object* symbol);
};
class SymbolTableStateGuard
{
private:
SymbolTable* prev_symbol_table;
public:
SymbolTableStateGuard();
~SymbolTableStateGuard();
};
extern SymbolTable* global_symbol_table;
extern SymbolTable* current_symbol_table;
}
#endif