-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol.h
155 lines (136 loc) · 3.12 KB
/
symbol.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef SYMBOL_H
#define SYMBOL_H
#include "syntaxnodes.h"
#include "checktype.h"
class Statement;
class SymTable;
enum DeclSection { DeclNull, DeclConst, DeclVar, DeclLabel, DeclType, DeclFunction, DeclProcedure, DeclRecord };
using namespace std;
class Symbol{
public:
string Name;
DeclSection Section;
virtual bool Compare(Symbol* Sym);
Symbol(DeclSection Section = DeclNull, string Name = "");
Symbol(Symbol* Sym);
bool isSame(string Value);
virtual void Print(int Spaces){};
virtual int GetSize() { return 0; }
virtual void Generate(Asm_Code* Code) {}
virtual string GenerateName() { return ""; };
virtual Symbol* GetType() { return nullptr; }
};
class SymLabel : public Symbol{
public:
SymLabel(string Name);
void Print(int Spaces);
};
class SymType : public Symbol{
public:
Symbol* Type;
MyTypeID TypeID;
SymType(string Name, Symbol* Type);
SymType(string Name, MyTypeID TypeID);
void Print(int Spaces);
string GenerateName();
int GetSize();
Symbol* GetType();
};
class SymPointer : public Symbol {
public:
Symbol* Type;
SymPointer(string Name, Symbol* Type);
void Print(int Spaces);
string GenerateName();
int GetSize();
Symbol* GetType();
};
class SymIdent : public Symbol {
protected:
SymIdent(DeclSection Section, string Name, Expr* InitExp, Symbol* Type, ArgState State);
public:
Symbol* Type;
Expr* InitExp;
ArgState State;
bool isLocal;
int offset;
string GenerateName();
string GetInitList();
void Generate(Asm_Code* Code);
int GetSize();
int depth;
Symbol* GetType();
};
class SymVar : public SymIdent {
public:
SymVar(string Name, Expr* InitExp, Symbol* Type, ArgState State);
void Print(int Spaces);
};
class SymConst : public SymIdent {
public:
SymConst(string Name, Expr* InitExp, Symbol* Type, ArgState State);
void Print(int Spaces);
};
class SymDynArray : public Symbol{
public:
Symbol* Type;
MyTypeID TypeID;
SymDynArray(Symbol* Type);
void Print(int Spaces);
virtual int GetLow();
virtual int GetHigh();
int GetSize();
Symbol* GetType();
};
class SymArray : public SymDynArray{
public:
int Left;
int Right;
SymArray(Symbol* Type, int Left, int Right);
void Print(int Spaces);
string GenerateName();
int GetLow();
int GetHigh();
int GetSize();
};
class SymStringType : public Symbol{
public:
int Length;
MyTypeID TypeID;
SymStringType(int Length);
void Print(int Spaces);
int GetSize();
};
class SymCall : public Symbol {
protected:
SymCall(DeclSection Section, string Name, SymTable* Table, Statement* Stmt, int argc);
public:
SymTable* Table;
Statement* Stmt;
int argc;
string GenerateName();
void Generate(Asm_Code* Code);
};
class SymFunction : public SymCall {
public:
SymFunction(string Name, SymTable* Table, Statement* Stmt, int argc, Symbol* Type);
void Print(int Spaces);
Symbol* Type;
int GetSize();
Symbol* GetType();
};
class SymProcedure : public SymCall {
public:
SymProcedure(string Name, SymTable* Table, Statement* Stmt, int argc);
void Print(int Spaces);
};
class SymRecord : public Symbol {
public:
SymTable* Table;
int argc;
SymRecord(SymTable* Table, string Name, int argc);
void Print(int Spaces);
int GetSize();
string GenerateName();
};
#endif