source: src/AST/Convert.cpp@ 74dbbf6

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 74dbbf6 was 74dbbf6, checked in by Andrew Beach <ajbeach@…>, 7 years ago

ConverterNewToOld boiler-plate code.

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