source: src/AST/Print.cpp@ 97f8f0f

Last change on this file since 97f8f0f was 88bc876, checked in by Andrew Beach <ajbeach@…>, 14 months ago

Breaks (and some other control flow) in a loop else clause now work. I also implemented else clauses in printing and code generation.

  • Property mode set to 100644
File size: 41.7 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 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// Print.cpp -- Print an AST (or sub-tree) to a stream.
8//
9// Author : Thierry Delisle
10// Created On : Tue May 21 16:20:15 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count :
14//
15
16#include "Print.hpp"
17
18#include "Attribute.hpp"
19#include "Decl.hpp"
20#include "Expr.hpp"
21#include "Init.hpp"
22#include "Stmt.hpp"
23#include "Type.hpp"
24#include "TypeSubstitution.hpp"
25#include "CompilationState.hpp"
26#include "Common/Iterate.hpp"
27
28using namespace std;
29
30namespace ast {
31
32namespace {
33
34template<typename C, typename... T>
35constexpr array<C, sizeof...(T)> make_array( T&&... values ) {
36 return array<C, sizeof...(T)>{ std::forward<T>( values )... };
37}
38
39namespace Names {
40 static constexpr auto FuncSpecifiers = make_array<const char*>(
41 "inline", "_Noreturn", "fortran"
42 );
43
44 static constexpr auto StorageClasses = make_array<const char*>(
45 "extern", "static", "auto", "register", "__thread", "_Thread_local"
46 );
47
48 static constexpr auto Qualifiers = make_array<const char*>(
49 "const", "restrict", "volatile", "mutex", "_Atomic"
50 );
51}
52
53template<typename bits_t, size_t N>
54void print( ostream & os, const bits_t & bits,
55 const array<const char *, N> & names ) {
56 if ( !bits.any() ) return;
57 for ( size_t i = 0 ; i < N ; i += 1 ) {
58 if ( bits[i] ) {
59 os << names[i] << ' ';
60 }
61 }
62}
63
64class Printer final : public Visitor {
65public:
66 ostream & os;
67 Indenter indent;
68 bool short_mode;
69
70 Printer(ostream & os, Indenter indent, bool short_mode) : os( os ), indent( indent ), short_mode(short_mode) {}
71
72private:
73 template< typename C >
74 void printAll( const C & c ) {
75 for ( const auto & i : c ) {
76 if ( i ) {
77 os << indent;
78 i->accept( *this );
79 // need an endl after each element because it's not
80 // easy to know when each individual item should end
81 os << endl;
82 } // if
83 } // for
84 }
85
86 /// call if mandatory field is missing
87 void undefined() {
88 os << "UNDEFINED";
89 }
90
91 /// call for fields that should be mandatory
92 void safe_print( const ast::Node * n ) {
93 if ( n ) n->accept( *this );
94 else undefined();
95 }
96
97 /// call to print short form. Incorporates features of safe_print()
98 void short_print( const ast::Decl * n ) {
99 if ( ! n ) { undefined(); return; }
100 bool old_short = short_mode; short_mode = true;
101 n->accept( *this );
102 short_mode = old_short;
103 }
104
105 void print( const std::vector<ast::Label> & labels ) {
106 if ( labels.empty() ) return;
107 os << indent << "... Labels: {";
108 bool isFirst = true;
109 for ( const Label & l : labels ) {
110 if ( isFirst ) { isFirst = false; } else { os << ","; }
111 os << l;
112 }
113 os << "}" << endl;
114 }
115
116 void print( const ast::Expr::InferUnion & inferred, unsigned level = 0 ) {
117 if (inferred.data.resnSlots && !inferred.data.resnSlots->empty()) {
118 os << indent << "with " << inferred.data.resnSlots->size()
119 << " pending inference slots" << endl;
120 }
121 if (inferred.data.inferParams && !inferred.data.inferParams->empty()) {
122 os << indent << "with inferred parameters " << level << ":" << endl;
123 ++indent;
124 for ( const auto & i : *inferred.data.inferParams ) {
125 os << indent;
126 short_print( i.second.declptr );
127 os << endl;
128 print( i.second.expr->inferred, level+1 );
129 }
130 --indent;
131 }
132 }
133
134 void print( const ast::FunctionType::ForallList & forall ) {
135 if ( forall.empty() ) return;
136 os << "forall" << endl;
137 ++indent;
138 printAll( forall );
139 os << indent;
140 --indent;
141 }
142
143 void print( const ast::FunctionType::AssertionList & assts ) {
144 if (assts.empty()) return;
145 os << "with assertions" << endl;
146 ++indent;
147 printAll(assts);
148 os << indent;
149 --indent;
150 }
151
152 void print( const std::vector<ptr<Attribute>> & attrs ) {
153 if ( attrs.empty() ) return;
154 os << "with attributes" << endl;
155 ++indent;
156 printAll( attrs );
157 --indent;
158 }
159
160 void print( const std::vector<ptr<Expr>> & params ) {
161 if ( params.empty() ) return;
162 os << endl << indent << "... with parameters" << endl;
163 ++indent;
164 printAll( params );
165 --indent;
166 }
167
168 void print( const ast::AggregateDecl * node ) {
169 os << node->typeString() << " " << node->name;
170
171 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
172 os << " " << Linkage::name( node->linkage );
173 }
174
175 auto ptrToEnum = dynamic_cast<const ast::EnumDecl *>(node);
176 if ( ! short_mode && ptrToEnum && ptrToEnum->base ) {
177 os << endl << indent << "... with base type" << endl;
178 ++indent;
179 os << indent;
180 ptrToEnum->base->accept( *this );
181 --indent;
182 }
183
184 os << " " << (node->body ? "with" : "without") << " body";
185
186 if ( ! node->params.empty() ) {
187 os << endl << indent << "... with parameters" << endl;
188 ++indent;
189 printAll( node->params );
190 --indent;
191 }
192
193 if ( ! short_mode && ! node->members.empty() ) {
194 os << endl << indent << "... with members" << endl;
195 ++indent;
196 printAll( node->members );
197 --indent;
198 }
199
200 if ( ! short_mode && ! node->attributes.empty() ) {
201 os << endl << indent << "... with attributes" << endl;
202 ++indent;
203 printAll( node->attributes );
204 --indent;
205 }
206
207
208
209 os << endl;
210 }
211
212 void print( const ast::WaitStmt * node ) {
213 if ( node->timeout_time ) {
214 os << indent-1 << "timeout of:" << endl;
215 node->timeout_time->accept( *this );
216
217 if ( node->timeout_stmt ) {
218 os << indent-1 << "... with statment:" << endl;
219 node->timeout_stmt->accept( *this );
220 }
221
222 if ( node->timeout_cond ) {
223 os << indent-1 << "... with condition:" << endl;
224 node->timeout_cond->accept( *this );
225 }
226 }
227
228 if ( node->else_stmt ) {
229 os << indent-1 << "else:" << endl;
230 node->else_stmt->accept( *this );
231
232 if ( node->else_cond ) {
233 os << indent-1 << "... with condition:" << endl;
234 node->else_cond->accept( *this );
235 }
236 }
237 }
238
239 void preprint( const ast::NamedTypeDecl * node ) {
240 if ( ! node->name.empty() ) {
241 os << node->name << ": ";
242 }
243
244 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
245 os << Linkage::name( node->linkage ) << " ";
246 }
247
248 ast::print( os, node->storage );
249 os << node->typeString();
250
251 if ( node->base ) {
252 os << " for ";
253 ++indent;
254 node->base->accept( *this );
255 --indent;
256 }
257
258 if ( ! node->assertions.empty() ) {
259 os << endl << indent << "... with assertions" << endl;
260 ++indent;
261 printAll( node->assertions );
262 --indent;
263 }
264 }
265
266 void postprint( const ast::Expr * node ) {
267 print( node->inferred );
268
269 if ( node->result ) {
270 os << endl << indent << "... with resolved type:" << endl;
271 ++indent;
272 os << indent;
273 node->result->accept( *this );
274 --indent;
275 }
276
277 if ( node->env ) {
278 os << endl << indent << "... with environment:" << endl;
279 ++indent;
280 node->env->accept( *this );
281 --indent;
282 }
283
284 if ( node->extension ) {
285 os << endl << indent << "... with extension";
286 }
287 }
288
289 void preprint( const ast::Type * node ) {
290 ast::print( os, node->qualifiers );
291 }
292
293 void preprint( const ast::FunctionType * node ) {
294 print( node->forall );
295 print( node->assertions );
296 ast::print( os, node->qualifiers );
297 }
298
299 void preprint( const ast::BaseInstType * node ) {
300 print( node->attributes );
301 ast::print( os, node->qualifiers );
302 }
303
304public:
305 virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
306 if ( ! node->name.empty() ) os << node->name << ": ";
307
308 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
309 os << Linkage::name( node->linkage ) << " ";
310 }
311
312 ast::print( os, node->storage );
313
314 if ( node->type ) {
315 node->type->accept( *this );
316 } else {
317 os << "untyped entity";
318 }
319
320 if ( ! short_mode && node->init ) {
321 ++indent;
322 os << " with initializer (" << (
323 node->init->maybeConstructed
324 ? "maybe constructed"
325 : "not constructed"
326 ) << ")" << endl << indent;
327 node->init->accept( *this );
328 --indent;
329 os << endl;
330 }
331
332 if ( ! short_mode && ! node->attributes.empty() ) {
333 os << endl << indent << "... with attributes:" << endl;
334 ++indent;
335 printAll( node->attributes );
336 --indent;
337 }
338
339 if ( node->bitfieldWidth ) {
340 os << indent << " with bitfield width ";
341 node->bitfieldWidth->accept( *this );
342 }
343
344 return node;
345 }
346
347 virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
348 if ( !node->name.empty() ) os << node->name << ": ";
349
350 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
351 os << Linkage::name( node->linkage ) << " ";
352 }
353
354 if ( ! short_mode ) printAll( node->attributes );
355
356 ast::print( os, node->storage );
357 ast::print( os, node->funcSpec );
358
359 if ( node->type && node->isTypeFixed ) {
360 node->type->accept( *this );
361 } else {
362 if (!node->type_params.empty()) {
363 os << "forall" << endl;
364 ++indent;
365 printAll(node->type_params);
366 os << indent;
367 --indent;
368
369 if (!node->assertions.empty()) {
370 os << "with assertions" << endl;
371 ++indent;
372 printAll(node->assertions);
373 os << indent;
374 --indent;
375 }
376 }
377
378 os << "function" << endl;
379 if ( ! node->params.empty() ) {
380 os << indent << "... with parameters" << endl;
381 ++indent;
382 printAll( node->params );
383 if ( node->type->isVarArgs ) {
384 os << indent << "and a variable number of other arguments" << endl;
385 }
386 --indent;
387 } else if ( node->type->isVarArgs ) {
388 os << indent+1 << "accepting unspecified arguments" << endl;
389 }
390
391 os << indent << "... returning";
392 if ( node->returns.empty() ) {
393 os << " nothing" << endl;
394 } else {
395 os << endl;
396 ++indent;
397 printAll( node->returns );
398 --indent;
399 }
400 }
401
402 if ( ! node->withExprs.empty() ) {
403 // Not with a clause, but the 'with clause'.
404 ++indent;
405 os << " with clause" << endl << indent;
406 printAll( node->withExprs );
407 --indent;
408 }
409
410 if ( ! short_mode && node->stmts ) {
411 ++indent;
412 os << " with body" << endl << indent;
413 node->stmts->accept( *this );
414 --indent;
415 }
416
417 return node;
418 }
419
420 virtual const ast::Decl * visit( const ast::StructDecl * node ) override final {
421 print(node);
422 return node;
423 }
424
425 virtual const ast::DeclWithType * visit( const ast::InlineMemberDecl * node ) override final {
426 os << "inline ";
427 if ( ! node->name.empty() ) os << node->name;
428
429 return node;
430 }
431
432 virtual const ast::Decl * visit( const ast::UnionDecl * node ) override final {
433 print(node);
434 return node;
435 }
436
437 virtual const ast::Decl * visit( const ast::EnumDecl * node ) override final {
438 print(node);
439 return node;
440 }
441
442 virtual const ast::Decl * visit( const ast::TraitDecl * node ) override final {
443 print(node);
444 return node;
445 }
446
447 virtual const ast::Decl * visit( const ast::TypeDecl * node ) override final {
448 preprint( node );
449 if ( ! short_mode && node->init ) {
450 os << endl << indent << "with type initializer: ";
451 ++indent;
452 node->init->accept( *this );
453 --indent;
454 }
455
456 return node;
457 }
458
459 virtual const ast::Decl * visit( const ast::TypedefDecl * node ) override final {
460 preprint( node );
461 return node;
462 }
463
464 virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final {
465 safe_print( node->stmt );
466 return node;
467 }
468
469 virtual const ast::DirectiveDecl * visit( const ast::DirectiveDecl * node ) override final {
470 safe_print( node->stmt );
471 return node;
472 }
473
474 virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final {
475 os << "Static Assert with condition: ";
476 ++indent;
477 safe_print( node->cond );
478 os << endl << indent-1 << "and message: ";
479 safe_print( node->msg );
480 --indent;
481 os << endl;
482
483 return node;
484 }
485
486 virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
487 os << "Compound Statement:" << endl;
488 ++indent;
489 printAll( node->kids );
490 --indent;
491 return node;
492 }
493
494 virtual const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
495 ++indent;
496 os << "Expression Statement:" << endl << indent;
497 safe_print( node->expr );
498 --indent;
499 return node;
500 }
501
502 virtual const ast::Stmt * visit( const ast::AsmStmt * node ) override final {
503 os << "Assembler Statement:" << endl;
504 ++indent;
505 os << indent-1 << "instruction:" << endl << indent;
506 safe_print( node->instruction );
507 if ( ! node->output.empty() ) {
508 os << endl << indent << "output:" << endl;
509 printAll( node->output );
510 } // if
511 if ( ! node->input.empty() ) {
512 os << indent << "input:" << endl;
513 printAll( node->input );
514 } // if
515 if ( ! node->clobber.empty() ) {
516 os << indent << "clobber:" << endl;
517 printAll( node->clobber );
518 } // if
519 --indent;
520 return node;
521 }
522
523 virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
524 os << "GCC Directive: " << node->directive << endl;
525 return node;
526 }
527
528 virtual const ast::Stmt * visit( const ast::IfStmt * node ) override final {
529 os << "If on condition:" << endl;
530 ++indent;
531 os << indent;
532 safe_print( node->cond );
533 --indent;
534
535 if ( ! node->inits.empty() ) {
536 os << indent << "... with initialization:" << endl;
537 ++indent;
538 for ( const ast::Stmt * stmt : node->inits ) {
539 os << indent;
540 safe_print( stmt );
541 }
542 --indent;
543 os << endl;
544 }
545
546 os << indent << "... then:" << endl;
547
548 ++indent;
549 os << indent;
550 safe_print( node->then );
551 --indent;
552
553 if ( node->else_ != 0 ) {
554 os << indent << "... else:" << endl;
555 ++indent;
556 os << indent;
557 node->else_->accept( *this );
558 --indent;
559 } // if
560 return node;
561 }
562
563 virtual const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final {
564 if ( node->isDoWhile ) { os << "Do-"; }
565 os << "While on condition:" << endl;
566 ++indent;
567 safe_print( node->cond );
568
569 if ( ! node->inits.empty() ) {
570 os << indent-1 << "... with inits:" << endl;
571 printAll( node->inits );
572 }
573
574 os << indent-1 << "... with body:" << endl;
575 safe_print( node->body );
576
577 if ( node->else_ ) {
578 os << indent-1 << "... with else:" << endl;
579 os << indent;
580 node->else_->accept( *this );
581 }
582
583 --indent;
584
585 return node;
586 }
587
588 virtual const ast::Stmt * visit( const ast::ForStmt * node ) override final {
589 os << "For Statement" << endl;
590
591 if ( ! node->inits.empty() ) {
592 os << indent << "... initialization:" << endl;
593 ++indent;
594 for ( const ast::Stmt * stmt : node->inits ) {
595 os << indent+1;
596 safe_print( stmt );
597 }
598 --indent;
599 }
600
601 if ( node->cond ) {
602 os << indent << "... condition:" << endl;
603 ++indent;
604 os << indent;
605 node->cond->accept( *this );
606 --indent;
607 }
608
609 if ( node->inc ) {
610 os << indent << "... increment:" << endl;
611 ++indent;
612 os << indent;
613 node->inc->accept( *this );
614 --indent;
615 }
616
617 if ( node->body ) {
618 os << indent << "... with body:" << endl;
619 ++indent;
620 os << indent;
621 node->body->accept( *this );
622 --indent;
623 }
624
625 if ( node->else_ ) {
626 os << indent << "... with else:" << endl;
627 ++indent;
628 os << indent;
629 node->else_->accept( *this );
630 --indent;
631 }
632
633 os << endl;
634 print( node->labels );
635
636 return node;
637 }
638
639 virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) override final {
640 os << "Switch on condition: ";
641 safe_print( node->cond );
642 os << endl;
643
644 ++indent;
645 for ( const ast::CaseClause * stmt : node->cases ) {
646 stmt->accept( *this );
647 }
648 --indent;
649
650 return node;
651 }
652
653 virtual const ast::CaseClause * visit( const ast::CaseClause * node ) override final {
654 if ( node->isDefault() ) {
655 os << indent << "Default ";
656 } else {
657 os << indent << "Case ";
658 safe_print( node->cond );
659 } // if
660 os << endl;
661
662 ++indent;
663 for ( const ast::Stmt * stmt : node->stmts ) {
664 os << indent;
665 stmt->accept( *this );
666 }
667 --indent;
668
669 return node;
670 }
671
672 virtual const ast::Stmt * visit( const ast::BranchStmt * node ) override final {
673 os << "Branch (" << node->kindName() << ")" << endl;
674 ++indent;
675 if ( ! node->target.empty() ) {
676 os << indent << "with target: " << node->target << endl;
677 }
678
679 if ( ! node->originalTarget.empty() ) {
680 os << indent << "with original target: " << node->originalTarget << endl;
681 }
682
683 if ( node->computedTarget ) {
684 os << indent << "with computed target: ";
685 node->computedTarget->accept( *this );
686 os << endl;
687 }
688 --indent;
689
690 return node;
691 }
692
693 virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
694 os << "Return Statement, returning";
695 if ( node->expr ) {
696 ++indent;
697 os << ":" << endl << indent;
698 node->expr->accept( *this );
699 --indent;
700 } else {
701 os << " void";
702 }
703 os << endl;
704
705 return node;
706 }
707
708 virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) override final {
709 if ( node->target ) os << "Non-Local ";
710
711 switch( node->kind ) {
712 case ast::ExceptionKind::Terminate: os << "Terminate "; break;
713 case ast::ExceptionKind::Resume: os << "Resume "; break;
714 }
715
716 ++indent;
717 os << "Throw Statement, raising: ";
718 safe_print( node->expr );
719 if ( node->target ) {
720 os << "... at: ";
721 node->target->accept( *this );
722 }
723 --indent;
724
725 return node;
726 }
727
728 virtual const ast::Stmt * visit( const ast::TryStmt * node ) override final {
729 ++indent;
730 os << "Try Statement" << endl << indent-1
731 << "... with block:" << endl << indent;
732 safe_print( node->body );
733
734 os << indent-1 << "... and handlers:" << endl;
735 for ( const ast::CatchClause * stmt : node->handlers ) {
736 os << indent;
737 stmt->accept( *this );
738 }
739
740 if ( node->finally ) {
741 os << indent-1 << "... and finally:" << endl << indent;
742 node->finally->accept( *this );
743 }
744 --indent;
745
746 return node;
747 }
748
749 virtual const ast::CatchClause * visit( const ast::CatchClause * node ) override final {
750 os << "Catch ";
751 switch ( node->kind ) {
752 case ast::ExceptionKind::Terminate: os << "Terminate "; break;
753 case ast::ExceptionKind::Resume: os << "Resume "; break;
754 }
755 os << "Statement" << endl << indent;
756
757 ++indent;
758 os << "... catching: ";
759 short_print( node->decl );
760 os << endl;
761
762 if ( node->cond ) {
763 os << indent-1 << "... with conditional:" << endl << indent;
764 node->cond->accept( *this );
765 }
766
767 os << indent-1 << "... with block:" << endl << indent;
768 safe_print( node->body );
769 --indent;
770
771 return node;
772 }
773
774 virtual const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final {
775 os << "Finally Statement" << endl;
776 os << indent << "... with block:" << endl;
777 ++indent;
778 os << indent;
779 safe_print( node->body );
780 --indent;
781
782 return node;
783 }
784
785 virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final {
786 os << "Suspend Statement";
787 switch (node->kind) {
788 case ast::SuspendStmt::None : os << " with implicit target"; break;
789 case ast::SuspendStmt::Generator: os << " for generator"; break;
790 case ast::SuspendStmt::Coroutine: os << " for coroutine"; break;
791 }
792 os << endl;
793
794 ++indent;
795 if(node->then) {
796 os << indent << " with post statement :" << endl;
797 safe_print( node->then );
798 }
799 ++indent;
800
801 return node;
802 }
803
804 virtual const ast::WhenClause * visit( const ast::WhenClause * node ) override final {
805 os << indent-1 << "target: ";
806 safe_print( node->target );
807
808 if ( node->stmt ) {
809 os << indent-1 << "... with statment:" << endl;
810 node->stmt->accept( *this );
811 }
812
813 if ( node->when_cond ) {
814 os << indent-1 << "... with when condition:" << endl;
815 node->when_cond->accept( *this );
816 }
817
818 return node;
819 }
820
821 virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
822 os << "Waitfor Statement" << endl;
823 indent += 2;
824 for( const auto & clause : node->clauses ) {
825 clause->accept( *this );
826 }
827
828 if ( node->timeout_time ) {
829 os << indent-1 << "timeout of:" << endl;
830 node->timeout_time->accept( *this );
831
832 if ( node->timeout_stmt ) {
833 os << indent-1 << "... with statment:" << endl;
834 node->timeout_stmt->accept( *this );
835 }
836
837 if ( node->timeout_cond ) {
838 os << indent-1 << "... with condition:" << endl;
839 node->timeout_cond->accept( *this );
840 }
841 }
842
843 if ( node->else_stmt ) {
844 os << indent-1 << "else:" << endl;
845 node->else_stmt->accept( *this );
846
847 if ( node->else_cond ) {
848 os << indent-1 << "... with condition:" << endl;
849 node->else_cond->accept( *this );
850 }
851 }
852
853 return node;
854 }
855
856 virtual const ast::WaitForClause * visit( const ast::WaitForClause * node ) override final {
857 os << indent-1 << "target function: ";
858 safe_print( node->target );
859
860 if ( !node->target_args.empty() ) {
861 os << endl << indent-1 << "... with arguments:" << endl;
862 for( const ast::Expr * arg : node->target_args ) {
863 arg->accept( *this );
864 }
865 }
866
867 if ( node->stmt ) {
868 os << indent-1 << "... with statment:" << endl;
869 node->stmt->accept( *this );
870 }
871
872 if ( node->when_cond ) {
873 os << indent-1 << "... with condition:" << endl;
874 node->when_cond->accept( *this );
875 }
876
877 return node;
878 }
879
880 virtual const ast::Stmt * visit( const ast::WaitUntilStmt * node ) override final {
881 os << "Waituntil Statement" << endl;
882 indent += 2;
883 for( const auto & clause : node->clauses ) {
884 clause->accept( *this );
885 }
886 // calls print( const ast::WaitStmt * node )
887 print(node);
888 return node;
889 }
890
891 virtual const ast::Decl * visit( const ast::WithStmt * node ) override final {
892 os << "With statement" << endl;
893 os << indent << "... with expressions:" << endl;
894 ++indent;
895 printAll( node->exprs );
896 os << indent-1 << "... with statement:" << endl << indent;
897 safe_print( node->stmt );
898 --indent;
899
900 return node;
901 }
902
903 virtual const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
904 os << "Null Statement" << endl;
905 print( node->labels );
906
907 return node;
908 }
909
910 virtual const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
911 os << "Declaration of ";
912 safe_print( node->decl );
913
914 return node;
915 }
916
917 virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final {
918 os << "Implicit Ctor Dtor Statement" << endl;
919 os << indent << "... with Ctor/Dtor: ";
920 ++indent;
921 safe_print( node->callStmt );
922 --indent;
923 os << endl;
924
925 return node;
926 }
927
928 virtual const ast::Stmt * visit( const ast::MutexStmt * node ) override final {
929 os << "Mutex Statement" << endl;
930 os << indent << "... with Mutex Parameters: ";
931 ++indent;
932 printAll( node->mutexObjs );
933 --indent;
934 os << indent << "... with Statement: ";
935 ++indent;
936 safe_print( node->stmt );
937 --indent;
938 os << endl;
939
940 return node;
941 }
942
943 virtual const ast::Stmt * visit( const ast::CorunStmt * node ) override final {
944 os << "Corun Statement" << endl;
945 os << indent << "... with Statement: ";
946 ++indent;
947 safe_print( node->stmt );
948 --indent;
949 os << endl;
950
951 return node;
952 }
953
954 virtual const ast::Stmt * visit( const ast::CoforStmt * node ) override final {
955 os << "Cofor Statement" << endl;
956
957 if ( ! node->inits.empty() ) {
958 os << indent << "... initialization:" << endl;
959 ++indent;
960 for ( const ast::Stmt * stmt : node->inits ) {
961 os << indent+1;
962 safe_print( stmt );
963 }
964 --indent;
965 }
966
967 if ( node->cond ) {
968 os << indent << "... condition:" << endl;
969 ++indent;
970 os << indent;
971 node->cond->accept( *this );
972 --indent;
973 }
974
975 if ( node->inc ) {
976 os << indent << "... increment:" << endl;
977 ++indent;
978 os << indent;
979 node->inc->accept( *this );
980 --indent;
981 }
982
983 if ( node->body ) {
984 os << indent << "... with body:" << endl;
985 ++indent;
986 os << indent;
987 node->body->accept( *this );
988 --indent;
989 }
990 os << endl;
991 print( node->labels );
992
993 return node;
994 }
995
996 virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {
997 ++indent;
998 os << "Application of" << endl << indent;
999 safe_print( node->func );
1000 os << endl;
1001 if ( ! node->args.empty() ) {
1002 os << indent << "... to arguments" << endl;
1003 printAll( node->args );
1004 }
1005 --indent;
1006 postprint( node );
1007
1008 return node;
1009 }
1010
1011 virtual const ast::Expr * visit( const ast::UntypedExpr * node ) override final {
1012 ++indent;
1013 os << "Applying untyped:" << endl;
1014 os << indent;
1015 safe_print( node->func );
1016 os << endl << indent-1 << "...to:" << endl;
1017 printAll( node->args );
1018 --indent;
1019 postprint( node );
1020
1021 return node;
1022 }
1023
1024 virtual const ast::Expr * visit( const ast::NameExpr * node ) override final {
1025 os << "Name: " << node->name;
1026 postprint( node );
1027
1028 return node;
1029 }
1030
1031 virtual const ast::Expr * visit( const ast::QualifiedNameExpr * node ) override final {
1032 os << "QualifiedNameExpr: " << std::endl;
1033 os << ++indent << "Type: ";
1034 safe_print( node->type_decl );
1035 os << std::endl;
1036 os << indent << "Name: " << node->name << std::endl;
1037 --indent;
1038 postprint( node );
1039 return node;
1040 }
1041
1042 virtual const ast::Expr * visit( const ast::AddressExpr * node ) override final {
1043 os << "Address of:" << endl;
1044 ++indent;
1045 os << indent;
1046 safe_print( node->arg );
1047
1048 --indent;
1049
1050 return node;
1051 }
1052
1053 virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {
1054 os << "Address of label:" << node->arg;
1055
1056 return node;
1057 }
1058
1059 virtual const ast::Expr * visit( const ast::CastExpr * node ) override final {
1060 ++indent;
1061 os << (node->isGenerated ? "Generated" : "Explicit") << " Cast of:" << endl << indent;
1062 safe_print( node->arg );
1063 os << endl << indent-1 << "... to:";
1064 if ( ! node->result ) {
1065 os << " ";
1066 undefined();
1067 } else if ( node->result->isVoid() ) {
1068 os << " nothing";
1069 } else {
1070 os << endl << indent;
1071 node->result->accept( *this );
1072 } // if
1073 --indent;
1074 postprint( node );
1075
1076 return node;
1077 }
1078
1079 virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
1080 ++indent;
1081 os << "Keyword Cast of:" << endl << indent;
1082 safe_print( node->arg );
1083 --indent;
1084 os << endl << indent << "... to: " << node->targetString();
1085 postprint( node );
1086
1087 return node;
1088 }
1089
1090 virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
1091 ++indent;
1092 os << "Virtual Cast of:" << endl << indent;
1093 safe_print( node->arg );
1094 os << endl << indent-1 << "... to:";
1095 if ( ! node->result ) {
1096 os << " unknown";
1097 } else {
1098 os << endl << indent;
1099 node->result->accept( *this );
1100 }
1101 --indent;
1102 postprint( node );
1103
1104 return node;
1105 }
1106
1107 virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {
1108 ++indent;
1109 os << "Untyped Member Expression, with field: " << endl << indent;
1110 safe_print( node->member );
1111 os << indent-1 << "... from aggregate:" << endl << indent;
1112 safe_print( node->aggregate );
1113 --indent;
1114 postprint( node );
1115
1116 return node;
1117 }
1118
1119 virtual const ast::Expr * visit( const ast::MemberExpr * node ) override final {
1120 ++indent;
1121 os << "Member Expression, with field:" << endl << indent;
1122 safe_print( node->member );
1123 os << endl << indent-1 << "... from aggregate:" << endl << indent;
1124 safe_print( node->aggregate );
1125 --indent;
1126 postprint( node );
1127
1128 return node;
1129 }
1130
1131 virtual const ast::Expr * visit( const ast::VariableExpr * node ) override final {
1132 os << "Variable Expression: ";
1133 short_print( node->var );
1134 postprint( node );
1135
1136 return node;
1137 }
1138
1139 virtual const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
1140 os << "Constant Expression (" << node->rep;
1141 if ( node->result ) {
1142 os << ": ";
1143 node->result->accept( *this );
1144 }
1145 os << ")";
1146 postprint( node );
1147
1148 return node;
1149 }
1150
1151 virtual const ast::Expr * visit( const ast::SizeofExpr * node ) override final {
1152 os << "Sizeof Expression on: ";
1153 ++indent;
1154 if ( node->type ) node->type->accept( *this );
1155 else safe_print( node->expr );
1156 --indent;
1157 postprint( node );
1158
1159 return node;
1160 }
1161
1162 virtual const ast::Expr * visit( const ast::CountExpr * node ) override final {
1163 os << "Count Expression on: ";
1164 ++indent;
1165 if ( node->type ) node->type->accept( *this );
1166 else safe_print( node->expr );
1167 --indent;
1168 postprint( node );
1169 return node;
1170 }
1171
1172 virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
1173 os << "Alignof Expression on: ";
1174 ++indent;
1175 if ( node->type ) node->type->accept( *this );
1176 else safe_print( node->expr );
1177 --indent;
1178 postprint( node );
1179
1180 return node;
1181 }
1182
1183 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {
1184 os << "Untyped Offsetof Expression on member " << node->member << " of ";
1185 ++indent;
1186 safe_print( node->type );
1187 --indent;
1188 postprint( node );
1189
1190 return node;
1191 }
1192
1193 virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {
1194 os << "Offsetof Expression on member " << node->member->name << " of ";
1195 ++indent;
1196 safe_print( node->type );
1197 --indent;
1198 postprint( node );
1199
1200 return node;
1201 }
1202
1203 virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {
1204 os << "Offset Pack Expression on: ";
1205 ++indent;
1206 safe_print( node->type );
1207 --indent;
1208 postprint( node );
1209
1210 return node;
1211 }
1212
1213 virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
1214 os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: ";
1215 safe_print( node->arg1 );
1216 os << " and ";
1217 safe_print( node->arg2 );
1218 postprint( node );
1219
1220 return node;
1221 }
1222
1223 virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
1224 ++indent;
1225 os << "Conditional expression on:" << endl << indent;
1226 safe_print( node->arg1 );
1227 os << indent-1 << "First alternative:" << endl << indent;
1228 safe_print( node->arg2 );
1229 os << indent-1 << "Second alternative:" << endl << indent;
1230 safe_print( node->arg3 );
1231 --indent;
1232 postprint( node );
1233
1234 return node;
1235 }
1236
1237 virtual const ast::Expr * visit( const ast::CommaExpr * node ) override final {
1238 ++indent;
1239 os << "Comma Expression:" << endl << indent;
1240 safe_print( node->arg1 );
1241 os << endl << indent;
1242 safe_print( node->arg2 );
1243 --indent;
1244 postprint( node );
1245
1246 return node;
1247 }
1248
1249 virtual const ast::Expr * visit( const ast::TypeExpr * node ) override final {
1250 safe_print( node->type );
1251 postprint( node );
1252
1253 return node;
1254 }
1255
1256 virtual const ast::Expr * visit( const ast::DimensionExpr * node ) override final {
1257 os << "Type-Sys Value: " << node->name;
1258 postprint( node );
1259
1260 return node;
1261 }
1262
1263 virtual const ast::Expr * visit( const ast::AsmExpr * node ) override final {
1264 os << "Asm Expression:" << endl;
1265 ++indent;
1266 if ( !node->inout.empty() ) os << "[" << node->inout << "] ";
1267 if ( node->constraint ) node->constraint->accept( *this );
1268 if ( node->operand ) node->operand->accept( *this );
1269 --indent;
1270
1271 return node;
1272 }
1273
1274 virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
1275 ++indent;
1276 os << "Implicit Copy Constructor Expression:" << endl << indent;
1277 safe_print( node->callExpr );
1278 --indent;
1279 postprint( node );
1280
1281 return node;
1282 }
1283
1284 virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
1285 os << "Constructor Expression:" << endl << indent+1;
1286 indent += 2;
1287 safe_print( node->callExpr );
1288 indent -= 2;
1289 postprint( node );
1290
1291 return node;
1292 }
1293
1294 virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
1295 ++indent;
1296 os << "Compound Literal Expression: " << endl << indent;
1297 safe_print( node->result );
1298 os << indent;
1299 safe_print( node->init );
1300 --indent;
1301 postprint( node );
1302
1303 return node;
1304 }
1305
1306 virtual const ast::Expr * visit( const ast::RangeExpr * node ) override final {
1307 os << "Range Expression: ";
1308 safe_print( node->low );
1309 os << " ... ";
1310 safe_print( node->high );
1311 postprint( node );
1312
1313 return node;
1314 }
1315
1316 virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
1317 os << "Untyped Tuple:" << endl;
1318 ++indent;
1319 printAll( node->exprs );
1320 --indent;
1321 postprint( node );
1322
1323 return node;
1324 }
1325
1326 virtual const ast::Expr * visit( const ast::TupleExpr * node ) override final {
1327 os << "Tuple:" << endl;
1328 ++indent;
1329 printAll( node->exprs );
1330 --indent;
1331 postprint( node );
1332
1333 return node;
1334 }
1335
1336 virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
1337 os << "Tuple Index Expression, with tuple:" << endl;
1338 ++indent;
1339 os << indent;
1340 safe_print( node->tuple );
1341 os << indent << "with index: " << node->index << endl;
1342 --indent;
1343 postprint( node );
1344
1345 return node;
1346 }
1347
1348 virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
1349 os << "Tuple Assignment Expression, with stmt expr:" << endl;
1350 ++indent;
1351 os << indent;
1352 safe_print( node->stmtExpr );
1353 --indent;
1354 postprint( node );
1355
1356 return node;
1357 }
1358
1359 virtual const ast::Expr * visit( const ast::StmtExpr * node ) override final {
1360 ++indent;
1361 os << "Statement Expression:" << endl << indent;
1362 safe_print( node->stmts );
1363 if ( ! node->returnDecls.empty() ) {
1364 os << indent << "... with returnDecls: ";
1365 printAll( node->returnDecls );
1366 }
1367 if ( ! node->dtors.empty() ) {
1368 os << indent << "... with dtors: ";
1369 printAll( node->dtors );
1370 }
1371 --indent;
1372 postprint( node );
1373
1374 return node;
1375 }
1376
1377 virtual const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
1378 ++indent;
1379 os << "Unique Expression with id: " << node->id << endl << indent;
1380 safe_print( node->expr );
1381 if ( node->object ) {
1382 os << indent-1 << "... with decl: ";
1383 short_print( node->object );
1384 }
1385 --indent;
1386 postprint( node );
1387
1388 return node;
1389 }
1390
1391 virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
1392 ++indent;
1393 os << "Untyped Init Expression" << endl << indent;
1394 safe_print( node->expr );
1395 if ( ! node->initAlts.empty() ) {
1396 for ( const InitAlternative & alt : node->initAlts ) {
1397 os << indent << "InitAlternative: ";
1398 safe_print( alt.type );
1399 safe_print( alt.designation );
1400 }
1401 }
1402 --indent;
1403
1404 return node;
1405 }
1406
1407 virtual const ast::Expr * visit( const ast::InitExpr * node ) override final {
1408 ++indent;
1409 os << "Init Expression" << endl << indent;
1410 safe_print( node->expr );
1411 os << indent << "... with designation: ";
1412 safe_print( node->designation );
1413 --indent;
1414
1415 return node;
1416 }
1417
1418 virtual const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
1419 ++indent;
1420 os << "Deleted Expression" << endl << indent;
1421 safe_print( node->expr );
1422 os << endl << indent << "... deleted by: ";
1423 safe_print( node->deleteStmt );
1424 --indent;
1425
1426 return node;
1427 }
1428
1429 virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
1430 ++indent;
1431 os << "Default Argument Expression" << endl << indent;
1432 safe_print( node->expr );
1433 --indent;
1434
1435 return node;
1436 }
1437
1438 virtual const ast::Expr * visit( const ast::GenericExpr * node ) override final {
1439 ++indent;
1440 os << "C11 _Generic Expression" << endl << indent;
1441 safe_print( node->control );
1442 os << endl << indent << "... with associations:" << endl;
1443 for ( const auto & assoc : node->associations ) {
1444 os << indent;
1445 if ( assoc.type ) {
1446 os << "... type: ";
1447 assoc.type->accept( *this );
1448 os << endl << indent << "... expression: ";
1449 safe_print( assoc.expr );
1450 } else {
1451 os << "... default: ";
1452 safe_print( assoc.expr );
1453 }
1454 os << endl;
1455 }
1456 --indent;
1457
1458 return node;
1459 }
1460
1461 virtual const ast::Type * visit( const ast::VoidType * node ) override final {
1462 preprint( node );
1463 os << "void";
1464 return node;
1465 }
1466
1467 virtual const ast::Type * visit( const ast::BasicType * node ) override final {
1468 preprint( node );
1469 os << ast::BasicType::typeNames[ node->kind ];
1470 return node;
1471 }
1472
1473 virtual const ast::Type * visit( const ast::PointerType * node ) override final {
1474 preprint( node );
1475 if ( ! node->isArray() ) {
1476 os << "pointer to ";
1477 } else {
1478 os << "decayed ";
1479 if ( node->isStatic ) {
1480 os << "static ";
1481 }
1482
1483 if ( node->isVarLen ) {
1484 os << "variable length array of ";
1485 } else if ( node->dimension ) {
1486 os << "array of ";
1487 node->dimension->accept( *this );
1488 os << " ";
1489 }
1490 }
1491 safe_print( node->base );
1492
1493 return node;
1494 }
1495
1496 virtual const ast::Type * visit( const ast::ArrayType * node ) override final {
1497 preprint( node );
1498 if ( node->isStatic ) {
1499 os << "static ";
1500 }
1501
1502 if ( node->isVarLen ) {
1503 os << "variable length array of ";
1504 } else if ( node->dimension ) {
1505 os << "array of ";
1506 } else {
1507 os << "open array of ";
1508 }
1509
1510 safe_print( node->base );
1511
1512 if ( node->dimension ) {
1513 os << " with dimension of ";
1514 node->dimension->accept( *this );
1515 }
1516
1517 return node;
1518 }
1519
1520 virtual const ast::Type * visit( const ast::ReferenceType * node ) override final {
1521 preprint( node );
1522 os << "reference to ";
1523 safe_print( node->base );
1524
1525 return node;
1526 }
1527
1528 virtual const ast::Type * visit( const ast::QualifiedType * node ) override final {
1529 preprint( node );
1530 ++indent;
1531 os << "Qualified Type:" << endl << indent;
1532 safe_print( node->parent );
1533 os << endl << indent;
1534 safe_print( node->child );
1535 os << endl;
1536 --indent;
1537
1538 return node;
1539 }
1540
1541 virtual const ast::Type * visit( const ast::FunctionType * node ) override final {
1542 preprint( node );
1543
1544 os << "function" << endl;
1545 if ( ! node->params.empty() ) {
1546 os << indent << "... with parameters" << endl;
1547 ++indent;
1548 printAll( node->params );
1549 if ( node->isVarArgs ) {
1550 os << indent << "and a variable number of other arguments" << endl;
1551 }
1552 --indent;
1553 } else if ( node->isVarArgs ) {
1554 os << indent+1 << "accepting unspecified arguments" << endl;
1555 }
1556
1557 os << indent << "... returning";
1558 if ( node->returns.empty() ) {
1559 os << " nothing" << endl;
1560 } else {
1561 os << endl;
1562 ++indent;
1563 printAll( node->returns );
1564 --indent;
1565 }
1566
1567 return node;
1568 }
1569
1570 virtual const ast::Type * visit( const ast::StructInstType * node ) override final {
1571 preprint( node );
1572 os << "instance of struct " << node->name;
1573 if ( node->base ) {
1574 os << " " << ( node->base->body ? "with" : "without" ) << " body";
1575 }
1576 print( node->params );
1577
1578 return node;
1579 }
1580
1581 virtual const ast::Type * visit( const ast::UnionInstType * node ) override final {
1582 preprint( node );
1583 os << "instance of union " << node->name;
1584 if ( node->base ) {
1585 os << " " << ( node->base->body ? "with" : "without" ) << " body";
1586 }
1587 print( node->params );
1588
1589 return node;
1590 }
1591
1592 virtual const ast::Type * visit( const ast::EnumInstType * node ) override final {
1593 preprint( node );
1594 os << "instance of enum " << node->name;
1595 if ( node->base ) {
1596 os << " " << ( node->base->body ? "with" : "without" ) << " body";
1597 }
1598 print( node->params );
1599
1600 return node;
1601 }
1602
1603 virtual const ast::Type * visit( const ast::TraitInstType * node ) override final {
1604 preprint( node );
1605 os << "instance of trait " << node->name;
1606 print( node->params );
1607
1608 return node;
1609 }
1610
1611 virtual const ast::Type * visit( const ast::TypeInstType * node ) override final {
1612 preprint( node );
1613 const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->typeString();
1614 os << "instance of type " << _name
1615 << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)";
1616 print( node->params );
1617
1618 return node;
1619 }
1620
1621 virtual const ast::Type * visit( const ast::TupleType * node ) override final {
1622 preprint( node );
1623 os << "tuple of types" << endl;
1624 ++indent;
1625 printAll( node->types );
1626 --indent;
1627
1628 return node;
1629 }
1630
1631 virtual const ast::Type * visit( const ast::TypeofType * node ) override final {
1632 preprint( node );
1633 if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }
1634 os << "type-of expression ";
1635 safe_print( node->expr );
1636
1637 return node;
1638 }
1639
1640 virtual const ast::Type * visit( const ast::VTableType * node ) override final {
1641 preprint( node );
1642 os << "vtable for ";
1643 safe_print( node->base );
1644
1645 return node;
1646 }
1647
1648 virtual const ast::Type * visit( const ast::VarArgsType * node ) override final {
1649 preprint( node );
1650 os << "builtin var args pack";
1651 return node;
1652 }
1653
1654 virtual const ast::Type * visit( const ast::ZeroType * node ) override final {
1655 preprint( node );
1656 os << "zero_t";
1657 return node;
1658 }
1659
1660 virtual const ast::Type * visit( const ast::OneType * node ) override final {
1661 preprint( node );
1662 os << "one_t";
1663 return node;
1664 }
1665
1666 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
1667 preprint( node );
1668 os << "Global Scope Type";
1669 return node;
1670 }
1671
1672 virtual const ast::Designation * visit( const ast::Designation * node ) override final {
1673 if ( node->designators.empty() ) return node;
1674 os << "... designated by: " << endl;
1675 ++indent;
1676 for ( const ast::Expr * d : node->designators ) {
1677 os << indent;
1678 d->accept( *this );
1679 os << endl;
1680 }
1681 --indent;
1682 return node;
1683 }
1684
1685 virtual const ast::Init * visit( const ast::SingleInit * node ) override final {
1686 os << "Simple Initializer: ";
1687 safe_print( node->value );
1688 return node;
1689 }
1690
1691 virtual const ast::Init * visit( const ast::ListInit * node ) override final {
1692 os << "Compound initializer: " << endl;
1693 ++indent;
1694 for ( auto p : group_iterate( node->designations, node->initializers ) ) {
1695 const ast::Designation * d = std::get<0>(p);
1696 const ast::Init * init = std::get<1>(p);
1697 os << indent;
1698 init->accept( *this );
1699 os << endl;
1700 if ( ! d->designators.empty() ) {
1701 os << indent;
1702 d->accept( *this );
1703 }
1704 }
1705 --indent;
1706 return node;
1707 }
1708
1709 virtual const ast::Init * visit( const ast::ConstructorInit * node ) override final {
1710 os << "Constructor initializer: " << endl;
1711 if ( node->ctor ) {
1712 os << indent << "... initially constructed with ";
1713 ++indent;
1714 node->ctor->accept( *this );
1715 --indent;
1716 }
1717
1718 if ( node->dtor ) {
1719 os << indent << "... destructed with ";
1720 ++indent;
1721 node->dtor->accept( *this );
1722 --indent;
1723 }
1724
1725 if ( node->init ) {
1726 os << indent << "... with fallback C-style initializer: ";
1727 ++indent;
1728 node->init->accept( *this );
1729 --indent;
1730 }
1731 return node;
1732 }
1733
1734 virtual const ast::Attribute * visit( const ast::Attribute * node ) override final {
1735 if ( node->empty() ) return node;
1736 os << "Attribute with name: " << node->name;
1737 if ( node->params.empty() ) return node;
1738 os << " with parameters: " << endl;
1739 ++indent;
1740 printAll( node->params );
1741 --indent;
1742 return node;
1743 }
1744
1745 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
1746 os << indent << "Types:" << endl;
1747 for ( const auto& i : *node ) {
1748 os << indent+1 << i.first.typeString() << " -> ";
1749 indent += 2;
1750 safe_print( i.second );
1751 indent -= 2;
1752 os << endl;
1753 }
1754 return node;
1755 }
1756
1757};
1758
1759} // namespace
1760
1761void print( ostream & os, const ast::Node * node, Indenter indent ) {
1762 Printer printer { os, indent, false };
1763 node->accept(printer);
1764}
1765
1766void printShort( ostream & os, const ast::Decl * node, Indenter indent ) {
1767 Printer printer { os, indent, true };
1768 node->accept(printer);
1769}
1770
1771void print( ostream & os, Function::Specs specs ) {
1772 print( os, specs, Names::FuncSpecifiers );
1773}
1774
1775void print( ostream & os, Storage::Classes storage ) {
1776 print( os, storage, Names::StorageClasses );
1777}
1778
1779void print( ostream & os, CV::Qualifiers qualifiers ) {
1780 print( os, qualifiers, Names::Qualifiers );
1781}
1782
1783} // namespace ast
Note: See TracBrowser for help on using the repository browser.