summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/astclone/cloner.cc
blob: 8e26fa7e962973612556c3fb337dc1c9f024bc4b (plain)
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
/**
 ** \file astclone/cloner.cc
 ** \brief Implementation of astclone::Cloner.
 */

#include <ast/all.hh>
#include <astclone/cloner.hh>
#include <misc/symbol.hh>

namespace astclone
{
  using namespace ast;

  Cloner::Cloner()
    : result_(nullptr)
  {}

  Ast* Cloner::result_get() { return result_; }

  void Cloner::operator()(const ast::ArrayExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& loc = e.location_get();
    NameTy* type_name = recurse(e.type_name_get());
    Exp* size = recurse(e.size_get());
    Exp* init = recurse(e.init_get());
    result_ = new ArrayExp(loc, type_name, size, init);
  }

  void Cloner::operator()(const ast::ArrayTy& e)
  {
    const Location& location = e.location_get();
    NameTy* base_type = recurse(e.base_type_get());
    result_ = new ArrayTy(location, base_type);
  }

  void Cloner::operator()(const ast::AssertExp& e)
  {
    const Location& location = e.location_get();
    Exp* cond = recurse(e.cond_get());
    result_ = new AssertExp(location, cond);
  }

  void Cloner::operator()(const ast::AssignExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    Var* variable = recurse(e.var_get());
    Exp* value = recurse(e.exp_get());
    result_ = new AssignExp(location, variable, value);
  }

  void Cloner::operator()(const ast::BreakExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    result_ = new BreakExp(location);
  }

  void Cloner::operator()(const ast::CallExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    // Apparently, we DO have a default copy constructor for symbols...
    misc::symbol id = e.name_get();
    exps_type* args = recurse_collection(e.args_get());
    result_ = new CallExp(location, id, args);
  }

  void Cloner::operator()(const ast::CastExp& e)
  {
    const Location& location = e.location_get();
    Exp* exp = recurse(e.exp_get());
    Ty* ty = recurse(e.ty_get());
    result_ = new CastExp(location, exp, ty);
  }

  void Cloner::operator()(const ast::ChunkList& e)
  {
    const Location& location = e.location_get();
    ChunkList::list_type chunks = *recurse_collection(e.chunks_get());
    result_ = new ChunkList(location, chunks);
  }

  void Cloner::operator()(const ast::ClassTy& e)
  {
    const Location& location = e.location_get();
    NameTy* super = recurse(e.super_get());
    ChunkList* chunks = recurse(e.chunks_get());
    result_ = new ClassTy(location, super, chunks);
  }

  void Cloner::operator()(const ast::Field& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    NameTy* type_name = recurse(e.type_name_get());
    result_ = new Field(location, name, type_name);
  }

  void Cloner::operator()(const ast::FieldInit& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    Exp* init = recurse(e.init_get());
    result_ = new FieldInit(location, name, init);
  }

  void Cloner::operator()(const ast::FieldVar& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    Var* variable = recurse(e.var_get());
    misc::symbol id = e.name_get();
    result_ = new FieldVar(location, variable, id);
  }

  void Cloner::operator()(const ast::ForExp& e)
  {
    const Location& location = e.location_get();
    VarDec* vardec = recurse(e.vardec_get());
    Exp* hi = recurse(e.hi_get());
    Exp* body = recurse(e.body_get());
    result_ = new ForExp(location, vardec, hi, body);
  }

  void Cloner::operator()(const ast::FunctionDec& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    VarChunk* formals = recurse(e.formals_get());
    NameTy* result = recurse(e.result_get());
    Exp* body = recurse(e.body_get());
    auto fundec = new FunctionDec(location, name, formals, result, body);
    result_ = fundec;
  }

  void Cloner::operator()(const ast::IfExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    Exp* cond = recurse(e.test_get());
    Exp* thenclause = recurse(e.thenclause_get());
    Exp* elseclause = recurse(e.elseclause_get());
    result_ = new IfExp(location, cond, thenclause, elseclause);
  }

  void Cloner::operator()(const ast::IntExp& e)
  {
    const Location& location = e.location_get();
    int value = e.value_get();
    result_ = new IntExp(location, value);
  }

  void Cloner::operator()(const ast::LetExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    Exp* body = recurse(e.body_get());
    ChunkList* chunky = recurse(e.chunks_get());
    result_ = new LetExp(location, chunky, body);
  }

  void Cloner::operator()(const ast::MethodCallExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    misc::symbol id = e.name_get();
    exps_type* args = recurse_collection(e.args_get());
    Var* variable = recurse(e.object_get());
    result_ = new MethodCallExp(location, id, args, variable);
  }

  void Cloner::operator()(const ast::MethodDec& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    VarChunk* formals = recurse(e.formals_get());
    NameTy* result = recurse(e.result_get());
    Exp* body = recurse(e.body_get());
    result_ = new MethodDec(location, name, formals, result, body);
  }

  void Cloner::operator()(const ast::NameTy& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    result_ = new NameTy(location, name);
  }

  void Cloner::operator()(const ast::NilExp& e)
  {
    const Location& location = e.location_get();
    result_ = new NilExp(location);
  }

  void Cloner::operator()(const ast::ObjectExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    NameTy* name = recurse(e.type_name_get());
    result_ = new ObjectExp(location, name);
  }

  void Cloner::operator()(const ast::OpExp& e)
  {
    const Location& location = e.location_get();
    Exp* left = recurse(e.left_get());
    OpExp::Oper oper = e.oper_get();
    Exp* right = recurse(e.right_get());
    result_ = new OpExp(location, left, oper, right);
  }

  void Cloner::operator()(const ast::RecordExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    NameTy* name = recurse(e.type_name_get());
    fieldinits_type* fields = recurse_collection(e.fields_get());
    result_ = new RecordExp(location, name, fields);
  }

  void Cloner::operator()(const ast::RecordTy& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    fields_type* fields = recurse_collection(e.fields_get());
    result_ = new RecordTy(location, fields);
  }

  void Cloner::operator()(const ast::SeqExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    exps_type* types = recurse_collection(e.exps_get());
    result_ = new SeqExp(location, types);
  }

  void Cloner::operator()(const ast::SimpleVar& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    result_ = new SimpleVar(location, name);
  }

  void Cloner::operator()(const ast::StringExp& e)
  {
    // FIXME DONE: Some code was deleted here.
    const Location& location = e.location_get();
    const std::string& txt = e.value_get();
    result_ = new StringExp(location, txt);
  }

  void Cloner::operator()(const ast::SubscriptVar& e)
  {
    const Location& location = e.location_get();
    Var* var = recurse(e.var_get());
    Exp* index = recurse(e.index_get());
    result_ = new SubscriptVar(location, var, index);
  }

  void Cloner::operator()(const ast::TypeDec& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    Ty* ty = recurse(e.ty_get());
    result_ = new TypeDec(location, name, ty);
  }

  void Cloner::operator()(const ast::VarDec& e)
  {
    const Location& location = e.location_get();
    misc::symbol name = e.name_get();
    NameTy* type_name = recurse(e.type_name_get());
    Exp* init = recurse(e.init_get());
    // FIXME DONE: Some code was deleted here (Cloned node instantiation).
    result_ = new VarDec(location, name, type_name, init);
  }

  void Cloner::operator()(const ast::WhileExp& e)
  {
    const Location& location = e.location_get();
    Exp* test = recurse(e.test_get());
    Exp* body = recurse(e.body_get());
    result_ = new WhileExp(location, test, body);
  }

  void Cloner::operator()(const ast::FunctionChunk& e)
  {
    chunk_visit<ast::FunctionChunk>(e);
  }

  void Cloner::operator()(const ast::MethodChunk& e)
  {
    // FIXME DONE: Some code was deleted here.
    chunk_visit<ast::MethodChunk>(e);
  }

  void Cloner::operator()(const ast::TypeChunk& e)
  {
    // FIXME DONE: Some code was deleted here.
    chunk_visit<ast::TypeChunk>(e);
  }

  void Cloner::operator()(const ast::VarChunk& e)
  {
    // FIXME DONE: Some code was deleted here.
    chunk_visit<ast::VarChunk>(e);
  }

} // namespace astclone