-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntaxnodes.h
192 lines (168 loc) · 4.7 KB
/
syntaxnodes.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifndef SYNTAXNODES_H
#define SYNTAXNODES_H
#include "lexer.h"
#include "errors.h"
#include <vector>
#include <set>
#include "utils.h"
#include <string>
#include "asmgenerator.h"
using namespace std;
class Symbol;
class Asm_Code;
enum ArgState { RValue, Var, Const, Out };
#define indent " "
#define print_indent(spaces) for (int i = 0; i < spaces; ++i) cout << indent
enum TypeExpr { BinExp, UnarExp, ConstIntExp, ConstDoubleExp, ConstBoolExp, ConstStringExp, VarExp, ArrayExp, AssignExp, FunctionExp, RecordExp, InitExp,
PointerExp, DereferenceExp };
enum MyTypeID;
class Expr{
public:
TypeExpr TypeExp;
MyTypeID TypeID;
Expr(TypeExpr TypeExp);
virtual void GetIdentStr(ExpArgList* List);
virtual void Print(const int Spaces){};
virtual void Generate(Asm_Code* Code, ArgState State = RValue) {}
virtual string GenerateInitList() { return ""; }
virtual int GetSize() { return 0; };
virtual pair<int, int> GetBound(int depth) { return make_pair(0, 0); };
virtual void ConvertToDouble(Asm_Code* Code, ArgState State = RValue) {};
};
class ExprBinOp : public Expr{
public:
Expr* Left;
Token Op;
Expr* Right;
ExprBinOp(Expr* Left, Token Op, Expr* Right);
void GetIdentStr(ExpArgList* List);
void Print(const int Spaces);
void Generate_Bool_Expr(Asm_Code* Code, ArgState State, AsmOpType Op);
void Generate_Relation_Expr(Asm_Code* Code, ArgState State);
void Generate(Asm_Code* Code, ArgState State = RValue);
void Generate_Double_Expr(Asm_Code* Code, ArgState State);
int GetSize();
};
class ExprUnarOp : public Expr{
public:
Token Op;
Expr* Exp;
ExprUnarOp(Token Op, Expr* Exp);
void GetIdentStr(ExpArgList* List);
void Print(const int Spaces);
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
};
class ExprConst : public Expr{
public:
Token Value;
ExprConst(Token Value, TypeExpr TypeExp);
virtual void GetIdentStr(ExpArgList* List);
virtual void Print(const int Spaces);
virtual string GenerateInitList();
int GetSize();
};
class ExprBoolConst : public ExprConst{
public:
ExprBoolConst(Token Value);
string GenerateInitList();
void Generate(Asm_Code* Code, ArgState State = RValue);
};
class ExprIntConst : public ExprConst{
public:
ExprIntConst(Token Value);
ExprIntConst(string Value);
void Generate(Asm_Code* Code, ArgState State = RValue);
void ConvertToDouble(Asm_Code* Code, ArgState State = RValue);
};
class ExprDoubleConst : public ExprConst{
public:
ExprDoubleConst(Token Value);
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
};
class ExprStringConst : public ExprConst{
public:
ExprStringConst(Token Value);
void Generate(Asm_Code* Code, ArgState State = RValue);
};
class ExprIdent : public Expr{
public:
Position Pos;
Symbol* Sym;
ExprIdent(Symbol* Sym, Position Pos);
void GetIdentStr(ExpArgList* List);
void Print(const int Spaces);
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
pair<int, int> GetBound(int depth);
};
class ExprAssign : public Expr{
public:
Expr* Left;
Expr* Right;
ExprAssign(Expr* Left, Expr* Right);
void GetIdentStr(ExpArgList* List);
void Print(const int Spaces);
void Generate(Asm_Code* Code, ArgState State = RValue);
};
class ExprArrayIndex : public Expr{
public:
Expr* Left;
Expr* Right;
ExprArrayIndex(Expr* Left, Expr* Right);
void GetIdentStr(ExpArgList* List);
void Print(const int Spaces);
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
pair<int, int> GetBound(int depth);
};
class ExprFunction : public Expr{
public:
Expr* Left;
vector<Expr*> Args;
ExprFunction(Expr* Left, vector<Expr*> Args);
void GetIdentStr(ExpArgList* List);
void Print(const int Spaces);
void GenerateWrite(Asm_Code* Code, int argc);
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
pair<int, int> GetBound(int depth);
};
class ExprRecord : public Expr{
public:
Expr* Left;
Symbol* Right;
ExprRecord(Expr* Left, Symbol* Right);
void GetIdentStr(ExpArgList* List);
void Print(const int Spaces);
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
pair<int, int> GetBound(int depth);
};
class ExprInitList : public Expr {
public:
vector<Expr*> List;
ExprInitList(vector<Expr*> List = vector<Expr*>());
void Print(const int Spaces);
string GenerateInitList();
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
};
class ExprPointer : public Expr {
public:
Expr* Exp;
ExprPointer(Expr* Exp);
void Print(const int Spaces);
void Generate(Asm_Code* Code, ArgState State = RValue);
};
class ExprDereference : public Expr {
public:
Expr* Exp;
ExprDereference(Expr* Exp);
void Print(const int Spaces);
void Generate(Asm_Code* Code, ArgState State = RValue);
int GetSize();
pair<int, int> GetBound(int depth);
};
#endif