-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.h
More file actions
314 lines (274 loc) · 5.66 KB
/
Copy pathast.h
File metadata and controls
314 lines (274 loc) · 5.66 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include "symtable.h"
using namespace std;
enum OPBinaryNames{
OR=1,
AND=2,
EQ_OP=3,
NE_OP=4,
LT=5,
LT_FLOAT=6,
LT_INT=7,
LE_OP=8,
LE_OP_FLOAT=9,
LE_OP_INT=10,
GT=11,
GT_FLOAT=12,
GT_INT=13,
GE_OP=14,
GE_OP_FLOAT=15,
GE_OP_INT=16,
PLUS=17,
PLUS_FLOAT=18,
PLUS_INT=19,
MINUS=20,
MINUS_FLOAT=21,
MINUS_INT=22,
MULT=23,
MULT_FLOAT=24,
MULT_INT=25,
DIV=26,
DIV_FLOAT=27,
DIV_INT=28,
};
enum OPUnaryNames{
UMINUS=30,
NOT=31,
PP=32,
ADDRESS=33,
STAR =34,
};
class abstract_astnode
{
public:
Type* type;
bool l_value;
abstract_astnode();
Record_global* function_record;
virtual void print () = 0;
virtual void generate_code(SymTable_local*, int=0) = 0;
Type* getType();
void setType(Type* type);
protected:
};
class StmtAst: public abstract_astnode{
public:
string nextlabel;
virtual void print () = 0;
virtual void generate_code(SymTable_local*, int=0) = 0;
};
class ExpAst: public StmtAst{ //pain aayega to baad me change karenge --charmi
public:
bool left;
ExpAst();
virtual void print () = 0;
virtual void generate_code(SymTable_local*, int=0) = 0;
};
class Empty: public StmtAst{
public:
Empty();
void print();
void generate_code(SymTable_local*, int=0);
};
class Seq: public StmtAst{
public:
vector<StmtAst*> stmt_list;
Seq();
void addNode(StmtAst*);
Seq(vector<StmtAst *> stmt_list);
void print();
void generate_code(SymTable_local*, int=0);
};
class Ass : public StmtAst{
ExpAst* expAst1;
ExpAst* expAst2;
public:
Ass();
Ass(ExpAst* expAst1, ExpAst* expAst2);
void print();
void generate_code(SymTable_local*, int=0);
};
class Return: public StmtAst{
ExpAst* expAst;
public:
Return();
Return(ExpAst* expAst);
void print();
void generate_code(SymTable_local*, int=0);
};
class If: public StmtAst{
ExpAst * expAst;
StmtAst* stmtAst1;
StmtAst* stmtAst2;
public:
If();
void print();
If(ExpAst* expAst, StmtAst* stmtAst1, StmtAst* stmtAst2);
void generate_code(SymTable_local*, int=0);
};
class While: public StmtAst{
ExpAst* expAst;
StmtAst* stmtAst;
public:
While();
While(ExpAst* expAst, StmtAst* stmtAst);
void print();
void generate_code(SymTable_local*, int=0);
};
class For: public StmtAst{
ExpAst *expAst1, *expAst2, *expAst3;
StmtAst* stmtAst;
public:
For();
For(ExpAst* expAst1,ExpAst* expAst2,ExpAst* expAst3,StmtAst* stmtAst);
void print();
void generate_code(SymTable_local*, int=0);
};
class Op_binary: public ExpAst{
OPBinaryNames op_name;
ExpAst * expAst1, *expAst2;
public:
Op_binary();
Op_binary(OPBinaryNames);/*needed? later*/
Op_binary(OPBinaryNames op_name, ExpAst* expAst1, ExpAst* expAst2);
void SetChildren(ExpAst *expAst1, ExpAst* expAst2);/**/
void print();
void generate_code(SymTable_local*, int=0);
};
class Op_unary: public ExpAst{
OPUnaryNames op_name;
ExpAst* expAst;
public:
Op_unary();
// Op_unary(OPUnaryNames op_name);
void SetChild(ExpAst * expAst);
Op_unary(OPUnaryNames op_name, ExpAst* expAst);
void print();
void generate_code(SymTable_local*, int=0);
};
class StringConst: public ExpAst{
string stringValue;
public:
StringConst();
StringConst(string stringValue);
void print();
void generate_code(SymTable_local*, int=0);
};
class Identifier: public ExpAst{
public:
string identifier;
Identifier();
Identifier(string identifier);
void print();
void generate_code(SymTable_local*, int=0);
};
class Assign: public ExpAst{
ExpAst* expAst1;
ExpAst* expAst2;
public:
Assign();
Assign(ExpAst* expAst1, ExpAst* expAst2);
void print();
void generate_code(SymTable_local*, int=0);
};
class Funcall: public ExpAst{
public:
Identifier* identifier;
std::vector<ExpAst*>* exp_list;
Funcall();
Funcall(Identifier * identifier);
Funcall(Identifier* identifier, std::vector<ExpAst* >* exp_list);
void print();
void generate_code(SymTable_local*, int=0);
};
class ToFloat: public ExpAst{
public:
ExpAst *expAst;
ToFloat();
ToFloat(ExpAst *expAst);
void print();
void generate_code(SymTable_local*, int=0);
};
class ToInt: public ExpAst{
public:
ExpAst *expAst;
ToInt();
ToInt(ExpAst *expAst);
void print();
void generate_code(SymTable_local*, int=0);
};
class FloatConst: public ExpAst{
float floatValue;
public:
FloatConst();
FloatConst(std::string floatValue);
void print();
void generate_code(SymTable_local*, int=0);
};
class IntConst: public ExpAst{
int intValue;
public:
IntConst();
IntConst(std::string intValue);
void print();
void generate_code(SymTable_local*, int=0);
};
class Pointer: public ExpAst{
ExpAst* expAst;
public:
Pointer();
Pointer(ExpAst*);
void print();
void generate_code(SymTable_local*, int=0);
};
class ArrayRef: public ExpAst{
ExpAst* expAst1;
ExpAst* expAst2;
public:
ArrayRef();
ArrayRef(ExpAst*, ExpAst*);
void print();
void generate_code(SymTable_local*, int=0);
};
class Deref: public ExpAst{
ExpAst* expAst;
public:
Deref();
Deref(ExpAst* expAst);
void print();
void generate_code(SymTable_local*, int=0);
};
class Member: public ExpAst{
ExpAst* expAst;
Identifier* identifier;
public:
Member();
Member(ExpAst* , Identifier*);
void print();
void generate_code(SymTable_local*, int=0);
};
class Arrow: public ExpAst{
ExpAst* expAst;
Identifier* identifier;
public:
Arrow();
Arrow(ExpAst* , Identifier*);
void print();
void generate_code(SymTable_local*, int=0);
};
void load_offset(int );
void stack_pop();
void stack_pop2();
void stack_push();
void float_push();
void float_pop();
void printf_float();
void printf_int();
void printf_string();
void printf_space();
void printf_endline();
string newlabel();
extern Seq printSequence;