-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllast.cpp
198 lines (149 loc) · 5.42 KB
/
llast.cpp
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
#include "llast.hpp"
#include <iostream>
void DJProgram::print() {
std::cout << 0 << ":"
<< "DJ PROGRAM\n";
for (auto e : mainExprs) {
e->print(1);
}
}
void DJNat::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ NAT("
<< value << ")\n";
}
void DJFalse::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ FALSE\n";
}
void DJTrue::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ TRUE\n";
}
void DJPlus::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ PLUS\n";
lhs->print(offset + 1);
rhs->print(offset + 1);
}
void DJMinus::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ MINUS\n";
lhs->print(offset + 1);
rhs->print(offset + 1);
}
void DJTimes::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ TIMES\n";
lhs->print(offset + 1);
rhs->print(offset + 1);
}
void DJEqual::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ EQUAL\n";
lhs->print(offset + 1);
rhs->print(offset + 1);
}
void DJGreater::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ GREATER\n";
lhs->print(offset + 1);
rhs->print(offset + 1);
}
void DJAnd::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ AND\n";
lhs->print(offset + 1);
rhs->print(offset + 1);
}
void DJPrint::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ PRINT\n";
printee->print(offset + 1);
}
void DJRead::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ READ\n";
}
void DJNot::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ NOT\n";
}
void DJIf::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ IF\n";
cond->print(offset + 1);
for (auto &e : thenBlock) {
e->print(offset + 1);
}
for (auto &e : elseBlock) {
e->print(offset + 1);
}
}
void DJFor::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ FOR\n";
init->print(offset + 1);
test->print(offset + 1);
update->print(offset + 1);
for (auto &e : body) {
e->print(offset + 1);
}
}
void DJId::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ ID(" << ID
<< ")\n";
}
void DJAssign::print(int offset) {
// FIXME: look at printing behavior for a = new A()
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ ASSIGN\n";
std::cout << std::string(4 * (offset + 1), ' ') << LHS << "\n";
RHS->print(offset + 1);
}
void DJNull::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ NULL\n";
}
void DJNew::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ NEW("
<< assignee << ")\n";
}
void DJDotId::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ DOT ID ("
<< typeString(staticClassNum) << ", " << ID << "):\n";
objectLike->print(offset + 1);
}
void DJDotAssign::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ')
<< "DJ DOT ASSIGN (" << typeString(staticClassNum) << ", " << ID
<< "):\n";
objectLike->print(offset + 1);
assignVal->print(offset + 1);
}
void DJInstanceOf::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJ INSTANCEOF"
<< typeString(classID) << ":\n";
objectLike->print(offset + 1);
}
void DJDotMethodCall::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ')
<< "DJ DOT METHOD CALL\n";
// TODO: do
}
void DJThis::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ') << "DJThis\n";
}
void DJUndotMethodCall::print(int offset) {
std::cout << offset << ":" << std::string(4 * offset, ' ')
<< "DJ UNDOT METHOD CALL\n";
// TODO: do
}
std::string DJNat::className() { return "DJNat"; }
std::string DJFalse::className() { return "DJFalse"; }
std::string DJTrue::className() { return "DJTrue"; }
std::string DJPlus::className() { return "DJPlus"; }
std::string DJMinus::className() { return "DJMinus"; }
std::string DJTimes::className() { return "DJTimes"; }
std::string DJEqual::className() { return "DJEqual"; }
std::string DJGreater::className() { return "DJGreater"; }
std::string DJAnd::className() { return "DJAnd"; }
std::string DJPrint::className() { return "DJPrint"; }
std::string DJRead::className() { return "DJRead"; }
std::string DJNot::className() { return "DJNot"; }
std::string DJIf::className() { return "DJIf"; }
std::string DJFor::className() { return "DJFor"; }
std::string DJId::className() { return "DJId"; }
std::string DJAssign::className() { return "DJAssign"; }
std::string DJNull::className() { return "DJNull"; }
std::string DJNew::className() { return "DJNew"; }
std::string DJDotId::className() { return "DJDotId"; }
std::string DJDotAssign::className() { return "DJDotAssign"; }
std::string DJInstanceOf::className() { return "DJInstanceOf"; }
std::string DJDotMethodCall::className() { return "DJDotMethodCall"; }
std::string DJThis::className() { return "DJThis"; }
std::string DJUndotMethodCall::className() { return "DJUndotMethodCall"; }