source: src/AST/Print.cpp@ f5212ca

Last change on this file since f5212ca was 0522ebe, checked in by JiadaL <j82liang@…>, 19 months ago

Add EnumPosType to type system

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