forked from sahilpparmar/emmCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymTabEntry.h
113 lines (90 loc) · 3.57 KB
/
SymTabEntry.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef STE_H
#define STE_H
#include "SymTab.h"
#include "Value.h"
#include "ProgramElem.h"
class SymTabEntry;
class ExprNode;
class InterCodesClass;
class SymTabEntry: public ProgramElem {
public:
enum class Kind {
// If this enum is changed, kindTag() needs to be updated correspondingly
UNKNOWN_KIND,
GLOBAL_KIND,
CLASS_KIND,
FUNCTION_KIND,
VARIABLE_KIND,
EVENT_KIND,
RULE_KIND,
BLOCK_KIND,
RULE_BLOCK_KIND,
EVENT_BLOCK_KIND,
ERROR_KIND
};
static string kindTag(Kind k);
public:
/*****************************************************************
The implementation of this class, as well its descendents.
makes definite assumtions about the use of kind, name, prev, next
and the symbol table fields. As such, methods operating on these
fields are non-virtual. (Overriding them in subclasses is strongly
discouraged.) All other operations are virtual, whether or not
we can see any potential use of overriding them.
****************************************************************/
SymTabEntry(string name, Kind kind, int line, int column, string file,
Type* t=nullptr);
virtual ~SymTabEntry() {};
string name() const { return name_; }
void name(string str) { name_=str; };
Kind kind() const { return kind_; }
void kind(Kind kind) { kind_ = kind; };
const SymTab* symTab() const { return st_; };
const SymTabEntry* prev() const { return prev_ ;};
const SymTabEntry* next() const { return next_ ;};
void prev(SymTabEntry *se) { prev_ = se; }
void next(SymTabEntry *se) { next_ = se; }
SymTab* symTab() { return st_; };
SymTabEntry* prev() { return prev_ ;};
SymTabEntry* next() { return next_ ;};
ErrorST insert(SymTabEntry* ste) {
if (st_ == nullptr) st_ = new SymTab();
return st_->insert(ste);
}
virtual bool operator==(const SymTabEntry&) const;
virtual bool operator!=(const SymTabEntry& ste) const
{ return !operator==(ste); };
virtual void print(ostream& os, int indent=0) const {}
virtual void printST(ostream& os,int ind=0,char ldelim='{',char rdelim='}',
bool linebreaks=true, int first=0, int last=0) const {
if (symTab() != nullptr)
symTab()->printST(os, ind, ldelim, rdelim, linebreaks, first, last);
}
virtual const Type* typeCheck() {return NULL;};
virtual void typeCheckST(int first = 0, int last = 0) const {
if (symTab() != nullptr)
symTab()->typeCheckST(first, last);
}
virtual void memAlloc() {}
virtual void memAllocST(int first = 0, int last = 0) {
if (symTab() != nullptr)
symTab()->memAllocST(first, last);
}
private:
string name_;
Kind kind_;
SymTab* st_;
private:
// These two fields are used to link the STEs so that their order
// of declaration can be maintained.
SymTabEntry* next_;
SymTabEntry* prev_;
private:
const SymTabEntry& operator=(const SymTabEntry&); // Disable assignment
SymTabEntry(const SymTabEntry&); // and copy constructor
};
inline ostream& operator<<(ostream& out, const SymTabEntry* ste){
ste->print(out, 0);
return out;
}
#endif