1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // Convert.cpp -- Convert between the new and old syntax trees. |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Thu May 09 15::37::05 2019 |
---|
11 | // Last Modified By : Andrew Beach |
---|
12 | // Last Modified On : Fri May 17 16:01:00 2019 |
---|
13 | // Update Count : 4 |
---|
14 | // |
---|
15 | |
---|
16 | #include "Convert.hpp" |
---|
17 | |
---|
18 | #include "AST/Pass.hpp" |
---|
19 | |
---|
20 | #include "AST/Attribute.hpp" |
---|
21 | #include "AST/Decl.hpp" |
---|
22 | #include "AST/Expr.hpp" |
---|
23 | #include "AST/Init.hpp" |
---|
24 | #include "AST/Stmt.hpp" |
---|
25 | |
---|
26 | |
---|
27 | #include "SynTree/Attribute.h" |
---|
28 | #include "SynTree/Declaration.h" |
---|
29 | |
---|
30 | //================================================================================================ |
---|
31 | // Utilities |
---|
32 | template<template <class...> class C> |
---|
33 | struct to { |
---|
34 | template<typename T> |
---|
35 | static auto from( T && v ) -> C< typename T::value_type > { |
---|
36 | C< typename T::value_type > l; |
---|
37 | std::move(std::begin(v), std::end(v), std::back_inserter(l)); |
---|
38 | return l; |
---|
39 | } |
---|
40 | }; |
---|
41 | |
---|
42 | //================================================================================================ |
---|
43 | class ConverterNewToOld : public ast::Visitor { |
---|
44 | BaseSyntaxNode * node = nullptr; |
---|
45 | |
---|
46 | template<typename T> |
---|
47 | struct Getter { |
---|
48 | ConverterNewToOld & visitor; |
---|
49 | |
---|
50 | template<typename U> |
---|
51 | T * accept1( const ast::ptr<U> & ptr ) { |
---|
52 | ptr->accept( visitor ); |
---|
53 | T * ret = strict_dynamic_cast< T * >( visitor.node ); |
---|
54 | visitor.node = nullptr; |
---|
55 | return ret; |
---|
56 | } |
---|
57 | |
---|
58 | template<typename U> |
---|
59 | std::list< T * > acceptL( const U & container ) { |
---|
60 | std::list< T * > ret; |
---|
61 | for (auto ptr : container ) { |
---|
62 | ret.emplace_back( accept1( ptr ) ); |
---|
63 | } |
---|
64 | return ret; |
---|
65 | } |
---|
66 | }; |
---|
67 | |
---|
68 | template<typename T> |
---|
69 | Getter<T> get() { |
---|
70 | return Getter<T>{ *this }; |
---|
71 | } |
---|
72 | |
---|
73 | Label makeLabel(Statement * labelled, const ast::Label& label) { |
---|
74 | return Label( |
---|
75 | label.name, |
---|
76 | labelled, |
---|
77 | get<Attribute>().acceptL(label.attributes) |
---|
78 | ); |
---|
79 | } |
---|
80 | |
---|
81 | template<template <class...> class C> |
---|
82 | std::list<Label> makeLabelL(Statement * labelled, const C<ast::Label>& labels) { |
---|
83 | std::list<Label> ret; |
---|
84 | for (auto label : labels) { |
---|
85 | ret.push_back( makeLabel(labelled, label) ); |
---|
86 | } |
---|
87 | return ret; |
---|
88 | } |
---|
89 | |
---|
90 | public: |
---|
91 | Declaration * decl( const ast::Decl * declNode ) { |
---|
92 | return get<Declaration>().accept1( ast::ptr<ast::Decl>( declNode ) ); |
---|
93 | } |
---|
94 | |
---|
95 | private: |
---|
96 | const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { |
---|
97 | (void)node; |
---|
98 | return nullptr; |
---|
99 | } |
---|
100 | |
---|
101 | const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { |
---|
102 | (void)node; |
---|
103 | return nullptr; |
---|
104 | } |
---|
105 | |
---|
106 | const ast::Decl * visit( const ast::StructDecl * node ) override final { |
---|
107 | (void)node; |
---|
108 | return nullptr; |
---|
109 | } |
---|
110 | |
---|
111 | const ast::Decl * visit( const ast::UnionDecl * node ) override final { |
---|
112 | (void)node; |
---|
113 | return nullptr; |
---|
114 | } |
---|
115 | |
---|
116 | const ast::Decl * visit( const ast::EnumDecl * node ) override final { |
---|
117 | (void)node; |
---|
118 | return nullptr; |
---|
119 | } |
---|
120 | |
---|
121 | const ast::Decl * visit( const ast::TraitDecl * node ) override final { |
---|
122 | (void)node; |
---|
123 | return nullptr; |
---|
124 | } |
---|
125 | |
---|
126 | const ast::Decl * visit( const ast::TypeDecl * node ) override final { |
---|
127 | (void)node; |
---|
128 | return nullptr; |
---|
129 | } |
---|
130 | |
---|
131 | const ast::Decl * visit( const ast::TypedefDecl * node ) override final { |
---|
132 | (void)node; |
---|
133 | return nullptr; |
---|
134 | } |
---|
135 | |
---|
136 | const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { |
---|
137 | (void)node; |
---|
138 | return nullptr; |
---|
139 | } |
---|
140 | |
---|
141 | const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { |
---|
142 | (void)node; |
---|
143 | return nullptr; |
---|
144 | } |
---|
145 | |
---|
146 | const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { |
---|
147 | auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); |
---|
148 | stmt->location = node->location; |
---|
149 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
150 | this->node = stmt; |
---|
151 | return nullptr; |
---|
152 | } |
---|
153 | |
---|
154 | const ast::Stmt * visit( const ast::ExprStmt * node ) override final { |
---|
155 | auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); |
---|
156 | stmt->location = node->location; |
---|
157 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
158 | this->node = stmt; |
---|
159 | return nullptr; |
---|
160 | } |
---|
161 | |
---|
162 | const ast::Stmt * visit( const ast::AsmStmt * node ) override final { |
---|
163 | auto stmt = new AsmStmt( |
---|
164 | node->isVolatile, |
---|
165 | get<Expression>().accept1( node->instruction ), |
---|
166 | get<Expression>().acceptL( node->output ), |
---|
167 | get<Expression>().acceptL( node->input ), |
---|
168 | get<ConstantExpr>().acceptL( node->clobber ), |
---|
169 | makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? |
---|
170 | ); |
---|
171 | stmt->location = node->location; |
---|
172 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
173 | this->node = stmt; |
---|
174 | return nullptr; |
---|
175 | } |
---|
176 | |
---|
177 | const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { |
---|
178 | auto stmt = new DirectiveStmt( node->directive ); |
---|
179 | stmt->location = node->location; |
---|
180 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
181 | this->node = stmt; |
---|
182 | return nullptr; |
---|
183 | } |
---|
184 | |
---|
185 | const ast::Stmt * visit( const ast::IfStmt * node ) override final { |
---|
186 | auto stmt = new IfStmt( |
---|
187 | get<Expression>().accept1( node->cond ), |
---|
188 | get<Statement>().accept1( node->thenPart ), |
---|
189 | get<Statement>().accept1( node->elsePart ), |
---|
190 | get<Statement>().acceptL( node->inits ) |
---|
191 | ); |
---|
192 | stmt->location = node->location; |
---|
193 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
194 | this->node = stmt; |
---|
195 | return nullptr; |
---|
196 | } |
---|
197 | |
---|
198 | const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { |
---|
199 | auto stmt = new SwitchStmt( |
---|
200 | get<Expression>().accept1( node->cond ), |
---|
201 | get<Statement>().acceptL( node->stmts ) |
---|
202 | ); |
---|
203 | stmt->location = node->location; |
---|
204 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
205 | this->node = stmt; |
---|
206 | return nullptr; |
---|
207 | } |
---|
208 | |
---|
209 | const ast::Stmt * visit( const ast::CaseStmt * node ) override final { |
---|
210 | auto stmt = new CaseStmt( |
---|
211 | get<Expression>().accept1( node->cond ), |
---|
212 | get<Statement>().acceptL( node->stmts ), |
---|
213 | node->isDefault() |
---|
214 | ); |
---|
215 | stmt->location = node->location; |
---|
216 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
217 | this->node = stmt; |
---|
218 | return nullptr; |
---|
219 | } |
---|
220 | |
---|
221 | const ast::Stmt * visit( const ast::WhileStmt * node ) override final { |
---|
222 | auto inits = get<Statement>().acceptL( node->inits ); |
---|
223 | auto stmt = new WhileStmt( |
---|
224 | get<Expression>().accept1( node->cond ), |
---|
225 | get<Statement>().accept1( node->body ), |
---|
226 | inits, |
---|
227 | node->isDoWhile |
---|
228 | ); |
---|
229 | stmt->location = node->location; |
---|
230 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
231 | this->node = stmt; |
---|
232 | return nullptr; |
---|
233 | } |
---|
234 | |
---|
235 | const ast::Stmt * visit( const ast::ForStmt * node ) override final { |
---|
236 | auto stmt = new ForStmt( |
---|
237 | get<Statement>().acceptL( node->inits ), |
---|
238 | get<Expression>().accept1( node->cond ), |
---|
239 | get<Expression>().accept1( node->inc ), |
---|
240 | get<Statement>().accept1( node->body ) |
---|
241 | ); |
---|
242 | stmt->location = node->location; |
---|
243 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
244 | this->node = stmt; |
---|
245 | return nullptr; |
---|
246 | } |
---|
247 | |
---|
248 | const ast::Stmt * visit( const ast::BranchStmt * node ) override final { |
---|
249 | BranchStmt * stmt; |
---|
250 | if (node->computedTarget) { |
---|
251 | stmt = new BranchStmt( get<Expression>().accept1( node->computedTarget ), |
---|
252 | BranchStmt::Goto ); |
---|
253 | } else { |
---|
254 | BranchStmt::Type type; |
---|
255 | switch (node->kind) { |
---|
256 | #define CASE(n) \ |
---|
257 | case ast::BranchStmt::n: \ |
---|
258 | type = BranchStmt::n; \ |
---|
259 | break |
---|
260 | CASE(Goto); |
---|
261 | CASE(Break); |
---|
262 | CASE(Continue); |
---|
263 | CASE(FallThrough); |
---|
264 | CASE(FallThroughDefault); |
---|
265 | #undef CASE |
---|
266 | default: |
---|
267 | assertf(false, "Invalid ast::BranchStmt::Kind: %d\n", node->kind); |
---|
268 | } |
---|
269 | |
---|
270 | // The labels here are also weird. |
---|
271 | stmt = new BranchStmt( makeLabel( nullptr, node->originalTarget ), type ); |
---|
272 | stmt->target = makeLabel( stmt, node->target ); |
---|
273 | } |
---|
274 | stmt->location = node->location; |
---|
275 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
276 | this->node = stmt; |
---|
277 | return nullptr; |
---|
278 | } |
---|
279 | |
---|
280 | const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { |
---|
281 | auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); |
---|
282 | stmt->location = node->location; |
---|
283 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
284 | this->node = stmt; |
---|
285 | return nullptr; |
---|
286 | } |
---|
287 | |
---|
288 | const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { |
---|
289 | ThrowStmt::Kind kind; |
---|
290 | switch (node->kind) { |
---|
291 | case ast::ThrowStmt::Terminate: |
---|
292 | kind = ThrowStmt::Terminate; |
---|
293 | break; |
---|
294 | case ast::ThrowStmt::Resume: |
---|
295 | kind = ThrowStmt::Resume; |
---|
296 | break; |
---|
297 | default: |
---|
298 | assertf(false, "Invalid ast::ThrowStmt::Kind: %d\n", node->kind); |
---|
299 | } |
---|
300 | auto stmt = new ThrowStmt( |
---|
301 | kind, |
---|
302 | get<Expression>().accept1( node->expr ), |
---|
303 | get<Expression>().accept1( node->target ) |
---|
304 | ); |
---|
305 | stmt->location = node->location; |
---|
306 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
307 | this->node = stmt; |
---|
308 | return nullptr; |
---|
309 | } |
---|
310 | |
---|
311 | const ast::Stmt * visit( const ast::TryStmt * node ) override final { |
---|
312 | auto handlers = get<CatchStmt>().acceptL( node->handlers ); |
---|
313 | auto stmt = new TryStmt( |
---|
314 | get<CompoundStmt>().accept1( node->body ), |
---|
315 | handlers, |
---|
316 | get<FinallyStmt>().accept1( node->finally ) |
---|
317 | ); |
---|
318 | stmt->location = node->location; |
---|
319 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
320 | this->node = stmt; |
---|
321 | return nullptr; |
---|
322 | } |
---|
323 | |
---|
324 | const ast::Stmt * visit( const ast::CatchStmt * node ) override final { |
---|
325 | CatchStmt::Kind kind; |
---|
326 | switch (node->kind) { |
---|
327 | case ast::CatchStmt::Terminate: |
---|
328 | kind = CatchStmt::Terminate; |
---|
329 | break; |
---|
330 | case ast::CatchStmt::Resume: |
---|
331 | kind = CatchStmt::Resume; |
---|
332 | break; |
---|
333 | default: |
---|
334 | assertf(false, "Invalid ast::CatchStmt::Kind: %d\n", node->kind); |
---|
335 | } |
---|
336 | auto stmt = new CatchStmt( |
---|
337 | kind, |
---|
338 | get<Declaration>().accept1( node->decl ), |
---|
339 | get<Expression>().accept1( node->cond ), |
---|
340 | get<Statement>().accept1( node->body ) |
---|
341 | ); |
---|
342 | stmt->location = node->location; |
---|
343 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
344 | this->node = stmt; |
---|
345 | return nullptr; |
---|
346 | } |
---|
347 | |
---|
348 | const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { |
---|
349 | auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); |
---|
350 | stmt->location = node->location; |
---|
351 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
352 | this->node = stmt; |
---|
353 | return nullptr; |
---|
354 | } |
---|
355 | |
---|
356 | const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { |
---|
357 | auto stmt = new WaitForStmt; |
---|
358 | stmt->clauses.reserve( node->clauses.size() ); |
---|
359 | for ( auto clause : node->clauses ) { |
---|
360 | stmt->clauses.push_back({{ |
---|
361 | get<Expression>().accept1( clause.target.function ), |
---|
362 | get<Expression>().acceptL( clause.target.arguments ), |
---|
363 | }, |
---|
364 | get<Statement>().accept1( clause.stmt ), |
---|
365 | get<Expression>().accept1( clause.cond ), |
---|
366 | }); |
---|
367 | } |
---|
368 | stmt->timeout = { |
---|
369 | get<Expression>().accept1( node->timeout.time ), |
---|
370 | get<Statement>().accept1( node->timeout.stmt ), |
---|
371 | get<Expression>().accept1( node->timeout.cond ), |
---|
372 | }; |
---|
373 | stmt->orelse = { |
---|
374 | get<Statement>().accept1( node->orElse.stmt ), |
---|
375 | get<Expression>().accept1( node->orElse.cond ), |
---|
376 | }; |
---|
377 | stmt->location = node->location; |
---|
378 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
379 | this->node = stmt; |
---|
380 | return nullptr; |
---|
381 | } |
---|
382 | |
---|
383 | const ast::Stmt * visit( const ast::WithStmt * node ) override final { |
---|
384 | auto stmt = new WithStmt( |
---|
385 | get<Expression>().acceptL( node->exprs ), |
---|
386 | get<Statement>().accept1( node->stmt ) |
---|
387 | ); |
---|
388 | stmt->location = node->location; |
---|
389 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
390 | this->node = stmt; |
---|
391 | return nullptr; |
---|
392 | } |
---|
393 | |
---|
394 | const ast::NullStmt * visit( const ast::NullStmt * node ) override final { |
---|
395 | auto stmt = new NullStmt(); |
---|
396 | stmt->location = node->location; |
---|
397 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
398 | this->node = stmt; |
---|
399 | return nullptr; |
---|
400 | } |
---|
401 | |
---|
402 | const ast::Stmt * visit( const ast::DeclStmt * node ) override final { |
---|
403 | auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); |
---|
404 | stmt->location = node->location; |
---|
405 | stmt->labels = makeLabelL( stmt, node->labels ); |
---|
406 | this->node = stmt; |
---|
407 | return nullptr; |
---|
408 | } |
---|
409 | |
---|
410 | const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { |
---|
411 | (void)node; |
---|
412 | return nullptr; |
---|
413 | } |
---|
414 | |
---|
415 | const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { |
---|
416 | (void)node; |
---|
417 | return nullptr; |
---|
418 | } |
---|
419 | |
---|
420 | const ast::Expr * visit( const ast::UntypedExpr * node ) override final { |
---|
421 | (void)node; |
---|
422 | return nullptr; |
---|
423 | } |
---|
424 | |
---|
425 | const ast::Expr * visit( const ast::NameExpr * node ) override final { |
---|
426 | (void)node; |
---|
427 | return nullptr; |
---|
428 | } |
---|
429 | |
---|
430 | const ast::Expr * visit( const ast::AddressExpr * node ) override final { |
---|
431 | (void)node; |
---|
432 | return nullptr; |
---|
433 | } |
---|
434 | |
---|
435 | const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { |
---|
436 | (void)node; |
---|
437 | return nullptr; |
---|
438 | } |
---|
439 | |
---|
440 | const ast::Expr * visit( const ast::CastExpr * node ) override final { |
---|
441 | (void)node; |
---|
442 | return nullptr; |
---|
443 | } |
---|
444 | |
---|
445 | const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { |
---|
446 | (void)node; |
---|
447 | return nullptr; |
---|
448 | } |
---|
449 | |
---|
450 | const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { |
---|
451 | (void)node; |
---|
452 | return nullptr; |
---|
453 | } |
---|
454 | |
---|
455 | const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { |
---|
456 | (void)node; |
---|
457 | return nullptr; |
---|
458 | } |
---|
459 | |
---|
460 | const ast::Expr * visit( const ast::MemberExpr * node ) override final { |
---|
461 | (void)node; |
---|
462 | return nullptr; |
---|
463 | } |
---|
464 | |
---|
465 | const ast::Expr * visit( const ast::VariableExpr * node ) override final { |
---|
466 | (void)node; |
---|
467 | return nullptr; |
---|
468 | } |
---|
469 | |
---|
470 | const ast::Expr * visit( const ast::ConstantExpr * node ) override final { |
---|
471 | (void)node; |
---|
472 | return nullptr; |
---|
473 | } |
---|
474 | |
---|
475 | const ast::Expr * visit( const ast::SizeofExpr * node ) override final { |
---|
476 | (void)node; |
---|
477 | return nullptr; |
---|
478 | } |
---|
479 | |
---|
480 | const ast::Expr * visit( const ast::AlignofExpr * node ) override final { |
---|
481 | (void)node; |
---|
482 | return nullptr; |
---|
483 | } |
---|
484 | |
---|
485 | const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { |
---|
486 | (void)node; |
---|
487 | return nullptr; |
---|
488 | } |
---|
489 | |
---|
490 | const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { |
---|
491 | (void)node; |
---|
492 | return nullptr; |
---|
493 | } |
---|
494 | |
---|
495 | const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { |
---|
496 | (void)node; |
---|
497 | return nullptr; |
---|
498 | } |
---|
499 | |
---|
500 | const ast::Expr * visit( const ast::LogicalExpr * node ) override final { |
---|
501 | (void)node; |
---|
502 | return nullptr; |
---|
503 | } |
---|
504 | |
---|
505 | const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { |
---|
506 | (void)node; |
---|
507 | return nullptr; |
---|
508 | } |
---|
509 | |
---|
510 | const ast::Expr * visit( const ast::CommaExpr * node ) override final { |
---|
511 | (void)node; |
---|
512 | return nullptr; |
---|
513 | } |
---|
514 | |
---|
515 | const ast::Expr * visit( const ast::TypeExpr * node ) override final { |
---|
516 | (void)node; |
---|
517 | return nullptr; |
---|
518 | } |
---|
519 | |
---|
520 | const ast::Expr * visit( const ast::AsmExpr * node ) override final { |
---|
521 | (void)node; |
---|
522 | return nullptr; |
---|
523 | } |
---|
524 | |
---|
525 | const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { |
---|
526 | (void)node; |
---|
527 | return nullptr; |
---|
528 | } |
---|
529 | |
---|
530 | const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { |
---|
531 | (void)node; |
---|
532 | return nullptr; |
---|
533 | } |
---|
534 | |
---|
535 | const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { |
---|
536 | (void)node; |
---|
537 | return nullptr; |
---|
538 | } |
---|
539 | |
---|
540 | const ast::Expr * visit( const ast::RangeExpr * node ) override final { |
---|
541 | (void)node; |
---|
542 | return nullptr; |
---|
543 | } |
---|
544 | |
---|
545 | const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { |
---|
546 | (void)node; |
---|
547 | return nullptr; |
---|
548 | } |
---|
549 | |
---|
550 | const ast::Expr * visit( const ast::TupleExpr * node ) override final { |
---|
551 | (void)node; |
---|
552 | return nullptr; |
---|
553 | } |
---|
554 | |
---|
555 | const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { |
---|
556 | (void)node; |
---|
557 | return nullptr; |
---|
558 | } |
---|
559 | |
---|
560 | const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { |
---|
561 | (void)node; |
---|
562 | return nullptr; |
---|
563 | } |
---|
564 | |
---|
565 | const ast::Expr * visit( const ast::StmtExpr * node ) override final { |
---|
566 | (void)node; |
---|
567 | return nullptr; |
---|
568 | } |
---|
569 | |
---|
570 | const ast::Expr * visit( const ast::UniqueExpr * node ) override final { |
---|
571 | (void)node; |
---|
572 | return nullptr; |
---|
573 | } |
---|
574 | |
---|
575 | const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { |
---|
576 | (void)node; |
---|
577 | return nullptr; |
---|
578 | } |
---|
579 | |
---|
580 | const ast::Expr * visit( const ast::InitExpr * node ) override final { |
---|
581 | (void)node; |
---|
582 | return nullptr; |
---|
583 | } |
---|
584 | |
---|
585 | const ast::Expr * visit( const ast::DeletedExpr * node ) override final { |
---|
586 | (void)node; |
---|
587 | return nullptr; |
---|
588 | } |
---|
589 | |
---|
590 | const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { |
---|
591 | (void)node; |
---|
592 | return nullptr; |
---|
593 | } |
---|
594 | |
---|
595 | const ast::Expr * visit( const ast::GenericExpr * node ) override final { |
---|
596 | (void)node; |
---|
597 | return nullptr; |
---|
598 | } |
---|
599 | |
---|
600 | const ast::Type * visit( const ast::VoidType * node ) override final { |
---|
601 | (void)node; |
---|
602 | return nullptr; |
---|
603 | } |
---|
604 | |
---|
605 | const ast::Type * visit( const ast::BasicType * node ) override final { |
---|
606 | (void)node; |
---|
607 | return nullptr; |
---|
608 | } |
---|
609 | |
---|
610 | const ast::Type * visit( const ast::PointerType * node ) override final { |
---|
611 | (void)node; |
---|
612 | return nullptr; |
---|
613 | } |
---|
614 | |
---|
615 | const ast::Type * visit( const ast::ArrayType * node ) override final { |
---|
616 | (void)node; |
---|
617 | return nullptr; |
---|
618 | } |
---|
619 | |
---|
620 | const ast::Type * visit( const ast::ReferenceType * node ) override final { |
---|
621 | (void)node; |
---|
622 | return nullptr; |
---|
623 | } |
---|
624 | |
---|
625 | const ast::Type * visit( const ast::QualifiedType * node ) override final { |
---|
626 | (void)node; |
---|
627 | return nullptr; |
---|
628 | } |
---|
629 | |
---|
630 | const ast::Type * visit( const ast::FunctionType * node ) override final { |
---|
631 | (void)node; |
---|
632 | return nullptr; |
---|
633 | } |
---|
634 | |
---|
635 | const ast::Type * visit( const ast::StructInstType * node ) override final { |
---|
636 | (void)node; |
---|
637 | return nullptr; |
---|
638 | } |
---|
639 | |
---|
640 | const ast::Type * visit( const ast::UnionInstType * node ) override final { |
---|
641 | (void)node; |
---|
642 | return nullptr; |
---|
643 | } |
---|
644 | |
---|
645 | const ast::Type * visit( const ast::EnumInstType * node ) override final { |
---|
646 | (void)node; |
---|
647 | return nullptr; |
---|
648 | } |
---|
649 | |
---|
650 | const ast::Type * visit( const ast::TraitInstType * node ) override final { |
---|
651 | (void)node; |
---|
652 | return nullptr; |
---|
653 | } |
---|
654 | |
---|
655 | const ast::Type * visit( const ast::TypeInstType * node ) override final { |
---|
656 | (void)node; |
---|
657 | return nullptr; |
---|
658 | } |
---|
659 | |
---|
660 | const ast::Type * visit( const ast::TupleType * node ) override final { |
---|
661 | (void)node; |
---|
662 | return nullptr; |
---|
663 | } |
---|
664 | |
---|
665 | const ast::Type * visit( const ast::TypeofType * node ) override final { |
---|
666 | (void)node; |
---|
667 | return nullptr; |
---|
668 | } |
---|
669 | |
---|
670 | const ast::Type * visit( const ast::VarArgsType * node ) override final { |
---|
671 | (void)node; |
---|
672 | return nullptr; |
---|
673 | } |
---|
674 | |
---|
675 | const ast::Type * visit( const ast::ZeroType * node ) override final { |
---|
676 | (void)node; |
---|
677 | return nullptr; |
---|
678 | } |
---|
679 | |
---|
680 | const ast::Type * visit( const ast::OneType * node ) override final { |
---|
681 | (void)node; |
---|
682 | return nullptr; |
---|
683 | } |
---|
684 | |
---|
685 | const ast::Type * visit( const ast::GlobalScopeType * node ) override final { |
---|
686 | (void)node; |
---|
687 | return nullptr; |
---|
688 | } |
---|
689 | |
---|
690 | const ast::Designation * visit( const ast::Designation * node ) override final { |
---|
691 | (void)node; |
---|
692 | return nullptr; |
---|
693 | } |
---|
694 | |
---|
695 | const ast::Init * visit( const ast::SingleInit * node ) override final { |
---|
696 | (void)node; |
---|
697 | return nullptr; |
---|
698 | } |
---|
699 | |
---|
700 | const ast::Init * visit( const ast::ListInit * node ) override final { |
---|
701 | (void)node; |
---|
702 | return nullptr; |
---|
703 | } |
---|
704 | |
---|
705 | const ast::Init * visit( const ast::ConstructorInit * node ) override final { |
---|
706 | (void)node; |
---|
707 | return nullptr; |
---|
708 | } |
---|
709 | |
---|
710 | const ast::Attribute * visit( const ast::Attribute * node ) override final { |
---|
711 | (void)node; |
---|
712 | return nullptr; |
---|
713 | } |
---|
714 | |
---|
715 | const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { |
---|
716 | (void)node; |
---|
717 | return nullptr; |
---|
718 | } |
---|
719 | }; |
---|
720 | |
---|
721 | std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > && translationUnit ) { |
---|
722 | ConverterNewToOld c; |
---|
723 | std::list< Declaration * > decls; |
---|
724 | for(auto d : translationUnit) { |
---|
725 | decls.emplace_back( c.decl( d ) ); |
---|
726 | delete d; |
---|
727 | } |
---|
728 | return decls; |
---|
729 | } |
---|
730 | |
---|
731 | //================================================================================================ |
---|
732 | |
---|
733 | class ConverterOldToNew : public Visitor { |
---|
734 | public: |
---|
735 | ast::Decl * decl() { |
---|
736 | return strict_dynamic_cast< ast::Decl * >( node ); |
---|
737 | } |
---|
738 | private: |
---|
739 | ast::Node * node; |
---|
740 | |
---|
741 | // Local Utilities: |
---|
742 | |
---|
743 | template<typename NewT, typename OldT> |
---|
744 | NewT * getAccept1( OldT old ) { |
---|
745 | old->accept(*this); |
---|
746 | return strict_dynamic_cast< NewT * >( node ); |
---|
747 | } |
---|
748 | |
---|
749 | # define GET_ACCEPT_1(child, type) \ |
---|
750 | getAccept1< ast::type, decltype( old->child ) >( old->child ) |
---|
751 | |
---|
752 | template<typename NewT, typename OldC> |
---|
753 | std::vector< ast::ptr<NewT> > getAcceptV( OldC& old ) { |
---|
754 | std::vector< ast::ptr<NewT> > ret; |
---|
755 | ret.reserve( old.size() ); |
---|
756 | for ( auto a : old ) { |
---|
757 | a->accept( *this ); |
---|
758 | ret.emplace_back( strict_dynamic_cast< NewT * >(node) ); |
---|
759 | } |
---|
760 | return ret; |
---|
761 | } |
---|
762 | |
---|
763 | # define GET_ACCEPT_V(child, type) \ |
---|
764 | getAcceptV< ast::type, decltype( old->child ) >( old->child ) |
---|
765 | |
---|
766 | ast::Label make_label(Label* old) { |
---|
767 | return ast::Label( |
---|
768 | old->labelled->location, |
---|
769 | old->name, |
---|
770 | GET_ACCEPT_V(attributes, Attribute) |
---|
771 | ); |
---|
772 | } |
---|
773 | |
---|
774 | template<template <class...> class C> |
---|
775 | C<ast::Label> make_labels(C<Label> olds) { |
---|
776 | C<ast::Label> ret; |
---|
777 | for (auto oldn : olds) { |
---|
778 | ret.push_back( make_label( &oldn ) ); |
---|
779 | } |
---|
780 | return ret; |
---|
781 | } |
---|
782 | |
---|
783 | # define GET_LABELS_V(labels) \ |
---|
784 | to<std::vector>::from( make_labels( std::move( labels ) ) ) |
---|
785 | |
---|
786 | // Now all the visit functions: |
---|
787 | |
---|
788 | virtual void visit( ObjectDecl * old ) override final { |
---|
789 | auto decl = new ast::ObjectDecl( |
---|
790 | old->location, |
---|
791 | old->name, |
---|
792 | GET_ACCEPT_1(type, Type), |
---|
793 | GET_ACCEPT_1(init, Init), |
---|
794 | { old->get_storageClasses().val }, |
---|
795 | { old->linkage.val }, |
---|
796 | GET_ACCEPT_1(bitfieldWidth, Expr), |
---|
797 | GET_ACCEPT_V(attributes, Attribute), |
---|
798 | { old->get_funcSpec().val } |
---|
799 | ); |
---|
800 | decl->scopeLevel = old->scopeLevel; |
---|
801 | decl->mangleName = old->mangleName; |
---|
802 | decl->isDeleted = old->isDeleted; |
---|
803 | decl->uniqueId = old->uniqueId; |
---|
804 | decl->extension = old->extension; |
---|
805 | |
---|
806 | this->node = decl; |
---|
807 | } |
---|
808 | |
---|
809 | virtual void visit( FunctionDecl * ) override final { |
---|
810 | |
---|
811 | } |
---|
812 | |
---|
813 | virtual void visit( StructDecl * old ) override final { |
---|
814 | auto decl = new ast::StructDecl( |
---|
815 | old->location, |
---|
816 | old->name, |
---|
817 | old->kind, |
---|
818 | GET_ACCEPT_V(attributes, Attribute), |
---|
819 | { old->linkage.val } |
---|
820 | ); |
---|
821 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
822 | decl->body = old->body; |
---|
823 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
824 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
825 | decl->extension = old->extension; |
---|
826 | decl->uniqueId = old->uniqueId; |
---|
827 | decl->storage = { old->storageClasses.val }; |
---|
828 | |
---|
829 | this->node = decl; |
---|
830 | } |
---|
831 | |
---|
832 | virtual void visit( UnionDecl * old ) override final { |
---|
833 | auto decl = new ast::UnionDecl( |
---|
834 | old->location, |
---|
835 | old->name, |
---|
836 | GET_ACCEPT_V(attributes, Attribute), |
---|
837 | { old->linkage.val } |
---|
838 | ); |
---|
839 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
840 | decl->body = old->body; |
---|
841 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
842 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
843 | decl->extension = old->extension; |
---|
844 | decl->uniqueId = old->uniqueId; |
---|
845 | decl->storage = { old->storageClasses.val }; |
---|
846 | |
---|
847 | this->node = decl; |
---|
848 | } |
---|
849 | |
---|
850 | virtual void visit( EnumDecl * old ) override final { |
---|
851 | auto decl = new ast::UnionDecl( |
---|
852 | old->location, |
---|
853 | old->name, |
---|
854 | GET_ACCEPT_V(attributes, Attribute), |
---|
855 | { old->linkage.val } |
---|
856 | ); |
---|
857 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
858 | decl->body = old->body; |
---|
859 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
860 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
861 | decl->extension = old->extension; |
---|
862 | decl->uniqueId = old->uniqueId; |
---|
863 | decl->storage = { old->storageClasses.val }; |
---|
864 | |
---|
865 | this->node = decl; |
---|
866 | } |
---|
867 | |
---|
868 | virtual void visit( TraitDecl * old ) override final { |
---|
869 | auto decl = new ast::UnionDecl( |
---|
870 | old->location, |
---|
871 | old->name, |
---|
872 | GET_ACCEPT_V(attributes, Attribute), |
---|
873 | { old->linkage.val } |
---|
874 | ); |
---|
875 | decl->parent = GET_ACCEPT_1(parent, AggregateDecl); |
---|
876 | decl->body = old->body; |
---|
877 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
878 | decl->members = GET_ACCEPT_V(members, Decl); |
---|
879 | decl->extension = old->extension; |
---|
880 | decl->uniqueId = old->uniqueId; |
---|
881 | decl->storage = { old->storageClasses.val }; |
---|
882 | |
---|
883 | this->node = decl; |
---|
884 | } |
---|
885 | |
---|
886 | virtual void visit( TypeDecl * ) override final { |
---|
887 | |
---|
888 | } |
---|
889 | |
---|
890 | virtual void visit( TypedefDecl * old ) override final { |
---|
891 | auto decl = new ast::TypedefDecl( |
---|
892 | old->location, |
---|
893 | old->name, |
---|
894 | { old->storageClasses.val }, |
---|
895 | GET_ACCEPT_1(base, Type), |
---|
896 | { old->linkage.val } |
---|
897 | ); |
---|
898 | decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); |
---|
899 | decl->params = GET_ACCEPT_V(parameters, TypeDecl); |
---|
900 | decl->extension = old->extension; |
---|
901 | decl->uniqueId = old->uniqueId; |
---|
902 | decl->storage = { old->storageClasses.val }; |
---|
903 | |
---|
904 | this->node = decl; |
---|
905 | } |
---|
906 | |
---|
907 | virtual void visit( AsmDecl * ) override final { |
---|
908 | |
---|
909 | } |
---|
910 | |
---|
911 | virtual void visit( StaticAssertDecl * ) override final { |
---|
912 | |
---|
913 | } |
---|
914 | |
---|
915 | virtual void visit( CompoundStmt * old ) override final { |
---|
916 | auto stmt = new ast::CompoundStmt( |
---|
917 | old->location, |
---|
918 | to<std::list>::from( GET_ACCEPT_V(kids, Stmt) ), |
---|
919 | GET_LABELS_V(old->labels) |
---|
920 | ); |
---|
921 | |
---|
922 | this->node = stmt; |
---|
923 | } |
---|
924 | |
---|
925 | virtual void visit( ExprStmt * old ) override final { |
---|
926 | this->node = new ast::ExprStmt( |
---|
927 | old->location, |
---|
928 | GET_ACCEPT_1(expr, Expr), |
---|
929 | GET_LABELS_V(old->labels) |
---|
930 | ); |
---|
931 | } |
---|
932 | |
---|
933 | virtual void visit( AsmStmt * old ) override final { |
---|
934 | this->node = new ast::AsmStmt( |
---|
935 | old->location, |
---|
936 | old->voltile, |
---|
937 | GET_ACCEPT_1(instruction, Expr), |
---|
938 | GET_ACCEPT_V(output, Expr), |
---|
939 | GET_ACCEPT_V(input, Expr), |
---|
940 | GET_ACCEPT_V(clobber, ConstantExpr), |
---|
941 | GET_LABELS_V(old->gotolabels), |
---|
942 | GET_LABELS_V(old->labels) |
---|
943 | ); |
---|
944 | } |
---|
945 | |
---|
946 | virtual void visit( DirectiveStmt * old ) override final { |
---|
947 | this->node = new ast::DirectiveStmt( |
---|
948 | old->location, |
---|
949 | old->directive, |
---|
950 | GET_LABELS_V(old->labels) |
---|
951 | ); |
---|
952 | } |
---|
953 | |
---|
954 | virtual void visit( IfStmt * old ) override final { |
---|
955 | this->node = new ast::IfStmt( |
---|
956 | old->location, |
---|
957 | GET_ACCEPT_1(condition, Expr), |
---|
958 | GET_ACCEPT_1(thenPart, Stmt), |
---|
959 | GET_ACCEPT_1(elsePart, Stmt), |
---|
960 | GET_ACCEPT_V(initialization, Stmt), |
---|
961 | GET_LABELS_V(old->labels) |
---|
962 | ); |
---|
963 | } |
---|
964 | |
---|
965 | virtual void visit( SwitchStmt * old ) override final { |
---|
966 | this->node = new ast::SwitchStmt( |
---|
967 | old->location, |
---|
968 | GET_ACCEPT_1(condition, Expr), |
---|
969 | GET_ACCEPT_V(statements, Stmt), |
---|
970 | GET_LABELS_V(old->labels) |
---|
971 | ); |
---|
972 | } |
---|
973 | |
---|
974 | virtual void visit( CaseStmt * old ) override final { |
---|
975 | this->node = new ast::CaseStmt( |
---|
976 | old->location, |
---|
977 | GET_ACCEPT_1(condition, Expr), |
---|
978 | GET_ACCEPT_V(stmts, Stmt), |
---|
979 | GET_LABELS_V(old->labels) |
---|
980 | ); |
---|
981 | } |
---|
982 | |
---|
983 | virtual void visit( WhileStmt * old ) override final { |
---|
984 | this->node = new ast::WhileStmt( |
---|
985 | old->location, |
---|
986 | GET_ACCEPT_1(condition, Expr), |
---|
987 | GET_ACCEPT_1(body, Stmt), |
---|
988 | GET_ACCEPT_V(initialization, Stmt), |
---|
989 | old->isDoWhile, |
---|
990 | GET_LABELS_V(old->labels) |
---|
991 | ); |
---|
992 | } |
---|
993 | |
---|
994 | virtual void visit( ForStmt * old ) override final { |
---|
995 | this->node = new ast::ForStmt( |
---|
996 | old->location, |
---|
997 | GET_ACCEPT_V(initialization, Stmt), |
---|
998 | GET_ACCEPT_1(condition, Expr), |
---|
999 | GET_ACCEPT_1(increment, Expr), |
---|
1000 | GET_ACCEPT_1(body, Stmt), |
---|
1001 | GET_LABELS_V(old->labels) |
---|
1002 | ); |
---|
1003 | } |
---|
1004 | |
---|
1005 | virtual void visit( BranchStmt * old ) override final { |
---|
1006 | if (old->computedTarget) { |
---|
1007 | this->node = new ast::BranchStmt( |
---|
1008 | old->location, |
---|
1009 | GET_ACCEPT_1(computedTarget, Expr), |
---|
1010 | GET_LABELS_V(old->labels) |
---|
1011 | ); |
---|
1012 | } else { |
---|
1013 | ast::BranchStmt::Kind kind; |
---|
1014 | switch (old->type) { |
---|
1015 | #define CASE(n) \ |
---|
1016 | case BranchStmt::n: \ |
---|
1017 | kind = ast::BranchStmt::n; \ |
---|
1018 | break |
---|
1019 | CASE(Goto); |
---|
1020 | CASE(Break); |
---|
1021 | CASE(Continue); |
---|
1022 | CASE(FallThrough); |
---|
1023 | CASE(FallThroughDefault); |
---|
1024 | #undef CASE |
---|
1025 | default: |
---|
1026 | assertf(false, "Invalid BranchStmt::Type %d\n", old->type); |
---|
1027 | } |
---|
1028 | |
---|
1029 | Label label = old->originalTarget; |
---|
1030 | auto stmt = new ast::BranchStmt( |
---|
1031 | old->location, |
---|
1032 | kind, |
---|
1033 | make_label(&label), |
---|
1034 | GET_LABELS_V(old->labels) |
---|
1035 | ); |
---|
1036 | stmt->target = make_label(&old->target); |
---|
1037 | this->node = stmt; |
---|
1038 | } |
---|
1039 | } |
---|
1040 | |
---|
1041 | virtual void visit( ReturnStmt * old ) override final { |
---|
1042 | this->node = new ast::ReturnStmt( |
---|
1043 | old->location, |
---|
1044 | GET_ACCEPT_1(expr, Expr), |
---|
1045 | GET_LABELS_V(old->labels) |
---|
1046 | ); |
---|
1047 | } |
---|
1048 | |
---|
1049 | virtual void visit( ThrowStmt * old ) override final { |
---|
1050 | ast::ThrowStmt::Kind kind; |
---|
1051 | switch (old->kind) { |
---|
1052 | case ThrowStmt::Terminate: |
---|
1053 | kind = ast::ThrowStmt::Terminate; |
---|
1054 | break; |
---|
1055 | case ThrowStmt::Resume: |
---|
1056 | kind = ast::ThrowStmt::Resume; |
---|
1057 | break; |
---|
1058 | default: |
---|
1059 | assertf(false, "Invalid ThrowStmt::Kind %d\n", old->kind); |
---|
1060 | } |
---|
1061 | |
---|
1062 | this->node = new ast::ThrowStmt( |
---|
1063 | old->location, |
---|
1064 | kind, |
---|
1065 | GET_ACCEPT_1(expr, Expr), |
---|
1066 | GET_ACCEPT_1(target, Expr), |
---|
1067 | GET_LABELS_V(old->labels) |
---|
1068 | ); |
---|
1069 | } |
---|
1070 | |
---|
1071 | virtual void visit( TryStmt * old ) override final { |
---|
1072 | this->node = new ast::TryStmt( |
---|
1073 | old->location, |
---|
1074 | GET_ACCEPT_1(block, CompoundStmt), |
---|
1075 | GET_ACCEPT_V(handlers, CatchStmt), |
---|
1076 | GET_ACCEPT_1(finallyBlock, FinallyStmt), |
---|
1077 | GET_LABELS_V(old->labels) |
---|
1078 | ); |
---|
1079 | } |
---|
1080 | |
---|
1081 | virtual void visit( CatchStmt * old ) override final { |
---|
1082 | ast::CatchStmt::Kind kind; |
---|
1083 | switch (old->kind) { |
---|
1084 | case CatchStmt::Terminate: |
---|
1085 | kind = ast::CatchStmt::Terminate; |
---|
1086 | break; |
---|
1087 | case CatchStmt::Resume: |
---|
1088 | kind = ast::CatchStmt::Resume; |
---|
1089 | break; |
---|
1090 | default: |
---|
1091 | assertf(false, "Invalid CatchStmt::Kind %d\n", old->kind); |
---|
1092 | } |
---|
1093 | |
---|
1094 | this->node = new ast::CatchStmt( |
---|
1095 | old->location, |
---|
1096 | kind, |
---|
1097 | GET_ACCEPT_1(decl, Decl), |
---|
1098 | GET_ACCEPT_1(cond, Expr), |
---|
1099 | GET_ACCEPT_1(body, Stmt), |
---|
1100 | GET_LABELS_V(old->labels) |
---|
1101 | ); |
---|
1102 | } |
---|
1103 | |
---|
1104 | virtual void visit( FinallyStmt * old ) override final { |
---|
1105 | this->node = new ast::FinallyStmt( |
---|
1106 | old->location, |
---|
1107 | GET_ACCEPT_1(block, CompoundStmt), |
---|
1108 | GET_LABELS_V(old->labels) |
---|
1109 | ); |
---|
1110 | } |
---|
1111 | |
---|
1112 | virtual void visit( WaitForStmt * old ) override final { |
---|
1113 | ast::WaitForStmt * stmt = new ast::WaitForStmt( |
---|
1114 | old->location, |
---|
1115 | GET_LABELS_V(old->labels) |
---|
1116 | ); |
---|
1117 | |
---|
1118 | stmt->clauses.reserve( old->clauses.size() ); |
---|
1119 | for (size_t i = 0 ; i < old->clauses.size() ; ++i) { |
---|
1120 | stmt->clauses.push_back({ |
---|
1121 | ast::WaitForStmt::Target{ |
---|
1122 | GET_ACCEPT_1(clauses[i].target.function, Expr), |
---|
1123 | GET_ACCEPT_V(clauses[i].target.arguments, Expr) |
---|
1124 | }, |
---|
1125 | GET_ACCEPT_1(clauses[i].statement, Stmt), |
---|
1126 | GET_ACCEPT_1(clauses[i].condition, Expr) |
---|
1127 | }); |
---|
1128 | } |
---|
1129 | stmt->timeout = { |
---|
1130 | GET_ACCEPT_1(timeout.time, Expr), |
---|
1131 | GET_ACCEPT_1(timeout.statement, Stmt), |
---|
1132 | GET_ACCEPT_1(timeout.condition, Expr), |
---|
1133 | }; |
---|
1134 | stmt->orElse = { |
---|
1135 | GET_ACCEPT_1(timeout.statement, Stmt), |
---|
1136 | GET_ACCEPT_1(timeout.condition, Expr), |
---|
1137 | }; |
---|
1138 | |
---|
1139 | this->node = stmt; |
---|
1140 | } |
---|
1141 | |
---|
1142 | virtual void visit( WithStmt * old ) override final { |
---|
1143 | this->node = new ast::WithStmt( |
---|
1144 | old->location, |
---|
1145 | GET_ACCEPT_V(exprs, Expr), |
---|
1146 | GET_ACCEPT_1(stmt, Stmt), |
---|
1147 | GET_LABELS_V(old->labels) |
---|
1148 | ); |
---|
1149 | } |
---|
1150 | |
---|
1151 | virtual void visit( NullStmt * old ) override final { |
---|
1152 | this->node = new ast::NullStmt( |
---|
1153 | old->location, |
---|
1154 | GET_LABELS_V(old->labels) |
---|
1155 | ); |
---|
1156 | } |
---|
1157 | |
---|
1158 | virtual void visit( DeclStmt * old ) override final { |
---|
1159 | this->node = new ast::DeclStmt( |
---|
1160 | old->location, |
---|
1161 | GET_ACCEPT_1(decl, Decl), |
---|
1162 | GET_LABELS_V(old->labels) |
---|
1163 | ); |
---|
1164 | } |
---|
1165 | |
---|
1166 | virtual void visit( ImplicitCtorDtorStmt * old ) override final { |
---|
1167 | this->node = new ast::ImplicitCtorDtorStmt( |
---|
1168 | old->location, |
---|
1169 | GET_ACCEPT_1(callStmt, Stmt), |
---|
1170 | GET_LABELS_V(old->labels) |
---|
1171 | ); |
---|
1172 | } |
---|
1173 | |
---|
1174 | virtual void visit( ApplicationExpr * ) override final { |
---|
1175 | |
---|
1176 | } |
---|
1177 | |
---|
1178 | virtual void visit( UntypedExpr * ) override final { |
---|
1179 | |
---|
1180 | } |
---|
1181 | |
---|
1182 | virtual void visit( NameExpr * ) override final { |
---|
1183 | |
---|
1184 | } |
---|
1185 | |
---|
1186 | virtual void visit( CastExpr * ) override final { |
---|
1187 | |
---|
1188 | } |
---|
1189 | |
---|
1190 | virtual void visit( KeywordCastExpr * ) override final { |
---|
1191 | |
---|
1192 | } |
---|
1193 | |
---|
1194 | virtual void visit( VirtualCastExpr * ) override final { |
---|
1195 | |
---|
1196 | } |
---|
1197 | |
---|
1198 | virtual void visit( AddressExpr * ) override final { |
---|
1199 | |
---|
1200 | } |
---|
1201 | |
---|
1202 | virtual void visit( LabelAddressExpr * ) override final { |
---|
1203 | |
---|
1204 | } |
---|
1205 | |
---|
1206 | virtual void visit( UntypedMemberExpr * ) override final { |
---|
1207 | |
---|
1208 | } |
---|
1209 | |
---|
1210 | virtual void visit( MemberExpr * ) override final { |
---|
1211 | |
---|
1212 | } |
---|
1213 | |
---|
1214 | virtual void visit( VariableExpr * ) override final { |
---|
1215 | |
---|
1216 | } |
---|
1217 | |
---|
1218 | virtual void visit( ConstantExpr * ) override final { |
---|
1219 | |
---|
1220 | } |
---|
1221 | |
---|
1222 | virtual void visit( SizeofExpr * ) override final { |
---|
1223 | |
---|
1224 | } |
---|
1225 | |
---|
1226 | virtual void visit( AlignofExpr * ) override final { |
---|
1227 | |
---|
1228 | } |
---|
1229 | |
---|
1230 | virtual void visit( UntypedOffsetofExpr * ) override final { |
---|
1231 | |
---|
1232 | } |
---|
1233 | |
---|
1234 | virtual void visit( OffsetofExpr * ) override final { |
---|
1235 | |
---|
1236 | } |
---|
1237 | |
---|
1238 | virtual void visit( OffsetPackExpr * ) override final { |
---|
1239 | |
---|
1240 | } |
---|
1241 | |
---|
1242 | virtual void visit( LogicalExpr * ) override final { |
---|
1243 | |
---|
1244 | } |
---|
1245 | |
---|
1246 | virtual void visit( ConditionalExpr * ) override final { |
---|
1247 | |
---|
1248 | } |
---|
1249 | |
---|
1250 | virtual void visit( CommaExpr * ) override final { |
---|
1251 | |
---|
1252 | } |
---|
1253 | |
---|
1254 | virtual void visit( TypeExpr * ) override final { |
---|
1255 | |
---|
1256 | } |
---|
1257 | |
---|
1258 | virtual void visit( AsmExpr * ) override final { |
---|
1259 | |
---|
1260 | } |
---|
1261 | |
---|
1262 | virtual void visit( ImplicitCopyCtorExpr * ) override final { |
---|
1263 | |
---|
1264 | } |
---|
1265 | |
---|
1266 | virtual void visit( ConstructorExpr * ) override final { |
---|
1267 | |
---|
1268 | } |
---|
1269 | |
---|
1270 | virtual void visit( CompoundLiteralExpr * ) override final { |
---|
1271 | |
---|
1272 | } |
---|
1273 | |
---|
1274 | virtual void visit( RangeExpr * ) override final { |
---|
1275 | |
---|
1276 | } |
---|
1277 | |
---|
1278 | virtual void visit( UntypedTupleExpr * ) override final { |
---|
1279 | |
---|
1280 | } |
---|
1281 | |
---|
1282 | virtual void visit( TupleExpr * ) override final { |
---|
1283 | |
---|
1284 | } |
---|
1285 | |
---|
1286 | virtual void visit( TupleIndexExpr * ) override final { |
---|
1287 | |
---|
1288 | } |
---|
1289 | |
---|
1290 | virtual void visit( TupleAssignExpr * ) override final { |
---|
1291 | |
---|
1292 | } |
---|
1293 | |
---|
1294 | virtual void visit( StmtExpr * ) override final { |
---|
1295 | |
---|
1296 | } |
---|
1297 | |
---|
1298 | virtual void visit( UniqueExpr * ) override final { |
---|
1299 | |
---|
1300 | } |
---|
1301 | |
---|
1302 | virtual void visit( UntypedInitExpr * ) override final { |
---|
1303 | |
---|
1304 | } |
---|
1305 | |
---|
1306 | virtual void visit( InitExpr * ) override final { |
---|
1307 | |
---|
1308 | } |
---|
1309 | |
---|
1310 | virtual void visit( DeletedExpr * ) override final { |
---|
1311 | |
---|
1312 | } |
---|
1313 | |
---|
1314 | virtual void visit( DefaultArgExpr * ) override final { |
---|
1315 | |
---|
1316 | } |
---|
1317 | |
---|
1318 | virtual void visit( GenericExpr * ) override final { |
---|
1319 | |
---|
1320 | } |
---|
1321 | |
---|
1322 | virtual void visit( VoidType * ) override final { |
---|
1323 | |
---|
1324 | } |
---|
1325 | |
---|
1326 | virtual void visit( BasicType * ) override final { |
---|
1327 | |
---|
1328 | } |
---|
1329 | |
---|
1330 | virtual void visit( PointerType * ) override final { |
---|
1331 | |
---|
1332 | } |
---|
1333 | |
---|
1334 | virtual void visit( ArrayType * ) override final { |
---|
1335 | |
---|
1336 | } |
---|
1337 | |
---|
1338 | virtual void visit( ReferenceType * ) override final { |
---|
1339 | |
---|
1340 | } |
---|
1341 | |
---|
1342 | virtual void visit( QualifiedType * ) override final { |
---|
1343 | |
---|
1344 | } |
---|
1345 | |
---|
1346 | virtual void visit( FunctionType * ) override final { |
---|
1347 | |
---|
1348 | } |
---|
1349 | |
---|
1350 | virtual void visit( StructInstType * ) override final { |
---|
1351 | |
---|
1352 | } |
---|
1353 | |
---|
1354 | virtual void visit( UnionInstType * ) override final { |
---|
1355 | |
---|
1356 | } |
---|
1357 | |
---|
1358 | virtual void visit( EnumInstType * ) override final { |
---|
1359 | |
---|
1360 | } |
---|
1361 | |
---|
1362 | virtual void visit( TraitInstType * ) override final { |
---|
1363 | |
---|
1364 | } |
---|
1365 | |
---|
1366 | virtual void visit( TypeInstType * ) override final { |
---|
1367 | |
---|
1368 | } |
---|
1369 | |
---|
1370 | virtual void visit( TupleType * ) override final { |
---|
1371 | |
---|
1372 | } |
---|
1373 | |
---|
1374 | virtual void visit( TypeofType * ) override final { |
---|
1375 | |
---|
1376 | } |
---|
1377 | |
---|
1378 | virtual void visit( AttrType * ) override final { |
---|
1379 | |
---|
1380 | } |
---|
1381 | |
---|
1382 | virtual void visit( VarArgsType * ) override final { |
---|
1383 | |
---|
1384 | } |
---|
1385 | |
---|
1386 | virtual void visit( ZeroType * ) override final { |
---|
1387 | |
---|
1388 | } |
---|
1389 | |
---|
1390 | virtual void visit( OneType * ) override final { |
---|
1391 | |
---|
1392 | } |
---|
1393 | |
---|
1394 | virtual void visit( GlobalScopeType * ) override final { |
---|
1395 | |
---|
1396 | } |
---|
1397 | |
---|
1398 | virtual void visit( Designation * ) override final { |
---|
1399 | |
---|
1400 | } |
---|
1401 | |
---|
1402 | virtual void visit( SingleInit * ) override final { |
---|
1403 | |
---|
1404 | } |
---|
1405 | |
---|
1406 | virtual void visit( ListInit * ) override final { |
---|
1407 | |
---|
1408 | } |
---|
1409 | |
---|
1410 | virtual void visit( ConstructorInit * ) override final { |
---|
1411 | |
---|
1412 | } |
---|
1413 | |
---|
1414 | virtual void visit( Constant * ) override final { |
---|
1415 | |
---|
1416 | } |
---|
1417 | |
---|
1418 | virtual void visit( Attribute * ) override final { |
---|
1419 | |
---|
1420 | } |
---|
1421 | |
---|
1422 | virtual void visit( AttrExpr * ) override final { |
---|
1423 | |
---|
1424 | assert( 0 ); |
---|
1425 | } |
---|
1426 | }; |
---|
1427 | |
---|
1428 | #undef GET_LABELS_V |
---|
1429 | #undef GET_ACCEPT_V |
---|
1430 | #undef GET_ACCEPT_1 |
---|
1431 | |
---|
1432 | std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > && translationUnit ) { |
---|
1433 | ConverterOldToNew c; |
---|
1434 | std::list< ast::ptr< ast::Decl > > decls; |
---|
1435 | for(auto d : translationUnit) { |
---|
1436 | d->accept( c ); |
---|
1437 | decls.emplace_back( c.decl() ); |
---|
1438 | delete d; |
---|
1439 | } |
---|
1440 | return decls; |
---|
1441 | } |
---|