-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastexpressions.h
242 lines (198 loc) · 4.38 KB
/
astexpressions.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
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
#pragma once
#include "asttyping.h"
//////////////// expressions
class expression : public ast
{
public:
type* datatype;
expression(type* dtype)
: datatype(dtype)
{ }
expression()
{ }
virtual void generateStoreCode(registerid reg, operation* &p)
{ printf("cannot store.\n"); exit(1); }
virtual registerid addressOf(operation* &p)
{ printf("cannot get address.\n"); exit(1); }
// note: we would not destroy datatype when destroying this object
};
class ordinal : public expression
{
private:
expression* e;
public:
ordinal(expression* _e)
: e(_e)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
virtual ~ordinal();
};
class theExpr : public expression
{
private:
symbolid sid;
ordinal* ord;
public:
theExpr(symbolid id)
: sid(id)
, ord(0)
{ }
theExpr(ordinal* _ord)
: sid(-1)
, ord(_ord)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
symbolid getSymbolid()
{ return sid; }
};
class literal : public expression
{
private:
datum value;
public:
literal(type* dtype, datum val)
: expression(dtype)
, value(val)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
};
class conditionalExpression : public expression
{
private:
//int opcode;
int ctype;
expression* leftOperand;
expression* rightOperand;
public:
conditionalExpression(int ct, expression * lo, expression *ro)
: ctype(ct)
, leftOperand(lo)
, rightOperand(ro)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
virtual ~conditionalExpression();
};
class binaryExpression : public expression
{
private:
//int opcode;
int optype;
expression* leftOperand;
expression* rightOperand;
public:
binaryExpression(int opt, expression * lo, expression *ro)
: optype(opt)
, leftOperand(lo)
, rightOperand(ro)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
virtual ~binaryExpression();
};
class prepositionval : public ast
{
private:
expression* value;
public:
prepositionval(expression* val)
: value(val)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
virtual ~prepositionval();
};
class prepvallist : public ast
{
private:
astnodelist<prepositionval*> preps;
public:
prepvallist()
{ }
void addPrepositionValue(prepositionval* p)
{ preps.add(p); }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
};
class constructExpression : public expression
{
private:
aExpr* t;
prepvallist* prepvals;
public:
constructExpression(aExpr* tt, prepvallist* pvals)
: t(tt)
, prepvals(pvals)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
virtual ~constructExpression();
};
// could be a getter OR a setter?
class call : public expression
{
private:
theExpr* funcname;
expression* objref; // this expression needs to evaluate to an object reference.
prepvallist* prepval;
public:
call(theExpr* nm)
: funcname(nm)
, objref(0)
, prepval(0)
{ }
call(theExpr* nm, expression* x)
: funcname(nm)
, objref(x)
, prepval(0)
{ }
call(theExpr* nm, expression* x, prepvallist* pval)
: funcname(nm)
, objref(x)
, prepval(pval)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
virtual ~call();
};
class varRef : public expression
{
private:
public:
symbolid varname;
varRef(symbolid vn)
: varname(vn)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
virtual void semanticCheck();
virtual void generateStoreCode(registerid reg, operation* &p);
};
class arrayAccess : public expression
{
private:
ordinal* n;
expression* of;
public:
arrayAccess(ordinal* _n, expression* _of)
: n(_n)
, of(_of)
{ }
virtual void debug(int ind);
virtual registerid generateCode(operation* &p);
// virtual void generateStoreCode(registerid result, operation* &p);
virtual void semanticCheck();
virtual ~arrayAccess();
};