source: src/AST/Print.cpp@ 496ffc17

Last change on this file since 496ffc17 was 16afb2a, checked in by JiadaL <j82liang@…>, 23 months ago

Fix the print for enum with type

  • 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::EnumPosExpr * node ) override final {
1189 os << "Enum Position Expression on: ";
1190 ++indent;
1191 safe_print( node->type );
1192 --indent;
1193 postprint( node );
1194 return node;
1195 }
1196
1197 virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
1198 os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: ";
1199 safe_print( node->arg1 );
1200 os << " and ";
1201 safe_print( node->arg2 );
1202 postprint( node );
1203
1204 return node;
1205 }
1206
1207 virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
1208 ++indent;
1209 os << "Conditional expression on:" << endl << indent;
1210 safe_print( node->arg1 );
1211 os << indent-1 << "First alternative:" << endl << indent;
1212 safe_print( node->arg2 );
1213 os << indent-1 << "Second alternative:" << endl << indent;
1214 safe_print( node->arg3 );
1215 --indent;
1216 postprint( node );
1217
1218 return node;
1219 }
1220
1221 virtual const ast::Expr * visit( const ast::CommaExpr * node ) override final {
1222 ++indent;
1223 os << "Comma Expression:" << endl << indent;
1224 safe_print( node->arg1 );
1225 os << endl << indent;
1226 safe_print( node->arg2 );
1227 --indent;
1228 postprint( node );
1229
1230 return node;
1231 }
1232
1233 virtual const ast::Expr * visit( const ast::TypeExpr * node ) override final {
1234 safe_print( node->type );
1235 postprint( node );
1236
1237 return node;
1238 }
1239
1240 virtual const ast::Expr * visit( const ast::DimensionExpr * node ) override final {
1241 os << "Type-Sys Value: " << node->name;
1242 postprint( node );
1243
1244 return node;
1245 }
1246
1247 virtual const ast::Expr * visit( const ast::AsmExpr * node ) override final {
1248 os << "Asm Expression:" << endl;
1249 ++indent;
1250 if ( !node->inout.empty() ) os << "[" << node->inout << "] ";
1251 if ( node->constraint ) node->constraint->accept( *this );
1252 if ( node->operand ) node->operand->accept( *this );
1253 --indent;
1254
1255 return node;
1256 }
1257
1258 virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
1259 ++indent;
1260 os << "Implicit Copy Constructor Expression:" << endl << indent;
1261 safe_print( node->callExpr );
1262 --indent;
1263 postprint( node );
1264
1265 return node;
1266 }
1267
1268 virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
1269 os << "Constructor Expression:" << endl << indent+1;
1270 indent += 2;
1271 safe_print( node->callExpr );
1272 indent -= 2;
1273 postprint( node );
1274
1275 return node;
1276 }
1277
1278 virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
1279 ++indent;
1280 os << "Compound Literal Expression: " << endl << indent;
1281 safe_print( node->result );
1282 os << indent;
1283 safe_print( node->init );
1284 --indent;
1285 postprint( node );
1286
1287 return node;
1288 }
1289
1290 virtual const ast::Expr * visit( const ast::RangeExpr * node ) override final {
1291 os << "Range Expression: ";
1292 safe_print( node->low );
1293 os << " ... ";
1294 safe_print( node->high );
1295 postprint( node );
1296
1297 return node;
1298 }
1299
1300 virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
1301 os << "Untyped Tuple:" << endl;
1302 ++indent;
1303 printAll( node->exprs );
1304 --indent;
1305 postprint( node );
1306
1307 return node;
1308 }
1309
1310 virtual const ast::Expr * visit( const ast::TupleExpr * node ) override final {
1311 os << "Tuple:" << endl;
1312 ++indent;
1313 printAll( node->exprs );
1314 --indent;
1315 postprint( node );
1316
1317 return node;
1318 }
1319
1320 virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
1321 os << "Tuple Index Expression, with tuple:" << endl;
1322 ++indent;
1323 os << indent;
1324 safe_print( node->tuple );
1325 os << indent << "with index: " << node->index << endl;
1326 --indent;
1327 postprint( node );
1328
1329 return node;
1330 }
1331
1332 virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
1333 os << "Tuple Assignment Expression, with stmt expr:" << endl;
1334 ++indent;
1335 os << indent;
1336 safe_print( node->stmtExpr );
1337 --indent;
1338 postprint( node );
1339
1340 return node;
1341 }
1342
1343 virtual const ast::Expr * visit( const ast::StmtExpr * node ) override final {
1344 ++indent;
1345 os << "Statement Expression:" << endl << indent;
1346 safe_print( node->stmts );
1347 if ( ! node->returnDecls.empty() ) {
1348 os << indent << "... with returnDecls: ";
1349 printAll( node->returnDecls );
1350 }
1351 if ( ! node->dtors.empty() ) {
1352 os << indent << "... with dtors: ";
1353 printAll( node->dtors );
1354 }
1355 --indent;
1356 postprint( node );
1357
1358 return node;
1359 }
1360
1361 virtual const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
1362 ++indent;
1363 os << "Unique Expression with id: " << node->id << endl << indent;
1364 safe_print( node->expr );
1365 if ( node->object ) {
1366 os << indent-1 << "... with decl: ";
1367 short_print( node->object );
1368 }
1369 --indent;
1370 postprint( node );
1371
1372 return node;
1373 }
1374
1375 virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
1376 ++indent;
1377 os << "Untyped Init Expression" << endl << indent;
1378 safe_print( node->expr );
1379 if ( ! node->initAlts.empty() ) {
1380 for ( const InitAlternative & alt : node->initAlts ) {
1381 os << indent << "InitAlternative: ";
1382 safe_print( alt.type );
1383 safe_print( alt.designation );
1384 }
1385 }
1386 --indent;
1387
1388 return node;
1389 }
1390
1391 virtual const ast::Expr * visit( const ast::InitExpr * node ) override final {
1392 ++indent;
1393 os << "Init Expression" << endl << indent;
1394 safe_print( node->expr );
1395 os << indent << "... with designation: ";
1396 safe_print( node->designation );
1397 --indent;
1398
1399 return node;
1400 }
1401
1402 virtual const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
1403 ++indent;
1404 os << "Deleted Expression" << endl << indent;
1405 safe_print( node->expr );
1406 os << endl << indent << "... deleted by: ";
1407 safe_print( node->deleteStmt );
1408 --indent;
1409
1410 return node;
1411 }
1412
1413 virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
1414 ++indent;
1415 os << "Default Argument Expression" << endl << indent;
1416 safe_print( node->expr );
1417 --indent;
1418
1419 return node;
1420 }
1421
1422 virtual const ast::Expr * visit( const ast::GenericExpr * node ) override final {
1423 ++indent;
1424 os << "C11 _Generic Expression" << endl << indent;
1425 safe_print( node->control );
1426 os << endl << indent << "... with associations:" << endl;
1427 for ( const auto & assoc : node->associations ) {
1428 os << indent;
1429 if ( assoc.type ) {
1430 os << "... type: ";
1431 assoc.type->accept( *this );
1432 os << endl << indent << "... expression: ";
1433 safe_print( assoc.expr );
1434 } else {
1435 os << "... default: ";
1436 safe_print( assoc.expr );
1437 }
1438 os << endl;
1439 }
1440 --indent;
1441
1442 return node;
1443 }
1444
1445 virtual const ast::Type * visit( const ast::VoidType * node ) override final {
1446 preprint( node );
1447 os << "void";
1448 return node;
1449 }
1450
1451 virtual const ast::Type * visit( const ast::BasicType * node ) override final {
1452 preprint( node );
1453 os << ast::BasicType::typeNames[ node->kind ];
1454 return node;
1455 }
1456
1457 virtual const ast::Type * visit( const ast::PointerType * node ) override final {
1458 preprint( node );
1459 if ( ! node->isArray() ) {
1460 os << "pointer to ";
1461 } else {
1462 os << "decayed ";
1463 if ( node->isStatic ) {
1464 os << "static ";
1465 }
1466
1467 if ( node->isVarLen ) {
1468 os << "variable length array of ";
1469 } else if ( node->dimension ) {
1470 os << "array of ";
1471 node->dimension->accept( *this );
1472 os << " ";
1473 }
1474 }
1475 safe_print( node->base );
1476
1477 return node;
1478 }
1479
1480 virtual const ast::Type * visit( const ast::ArrayType * node ) override final {
1481 preprint( node );
1482 if ( node->isStatic ) {
1483 os << "static ";
1484 }
1485
1486 if ( node->isVarLen ) {
1487 os << "variable length array of ";
1488 } else if ( node->dimension ) {
1489 os << "array of ";
1490 } else {
1491 os << "open array of ";
1492 }
1493
1494 safe_print( node->base );
1495
1496 if ( node->dimension ) {
1497 os << " with dimension of ";
1498 node->dimension->accept( *this );
1499 }
1500
1501 return node;
1502 }
1503
1504 virtual const ast::Type * visit( const ast::ReferenceType * node ) override final {
1505 preprint( node );
1506 os << "reference to ";
1507 safe_print( node->base );
1508
1509 return node;
1510 }
1511
1512 virtual const ast::Type * visit( const ast::QualifiedType * node ) override final {
1513 preprint( node );
1514 ++indent;
1515 os << "Qualified Type:" << endl << indent;
1516 safe_print( node->parent );
1517 os << endl << indent;
1518 safe_print( node->child );
1519 os << endl;
1520 --indent;
1521
1522 return node;
1523 }
1524
1525 virtual const ast::Type * visit( const ast::FunctionType * node ) override final {
1526 preprint( node );
1527
1528 os << "function" << endl;
1529 if ( ! node->params.empty() ) {
1530 os << indent << "... with parameters" << endl;
1531 ++indent;
1532 printAll( node->params );
1533 if ( node->isVarArgs ) {
1534 os << indent << "and a variable number of other arguments" << endl;
1535 }
1536 --indent;
1537 } else if ( node->isVarArgs ) {
1538 os << indent+1 << "accepting unspecified arguments" << endl;
1539 }
1540
1541 os << indent << "... returning";
1542 if ( node->returns.empty() ) {
1543 os << " nothing" << endl;
1544 } else {
1545 os << endl;
1546 ++indent;
1547 printAll( node->returns );
1548 --indent;
1549 }
1550
1551 return node;
1552 }
1553
1554 virtual const ast::Type * visit( const ast::StructInstType * node ) override final {
1555 preprint( node );
1556 os << "instance of struct " << node->name;
1557 if ( node->base ) {
1558 os << " " << ( node->base->body ? "with" : "without" ) << " body";
1559 }
1560 print( node->params );
1561
1562 return node;
1563 }
1564
1565 virtual const ast::Type * visit( const ast::UnionInstType * node ) override final {
1566 preprint( node );
1567 os << "instance of union " << node->name;
1568 if ( node->base ) {
1569 os << " " << ( node->base->body ? "with" : "without" ) << " body";
1570 }
1571 print( node->params );
1572
1573 return node;
1574 }
1575
1576 virtual const ast::Type * visit( const ast::EnumInstType * node ) override final {
1577 preprint( node );
1578 os << "instance of enum " << node->name;
1579 if ( node->base ) {
1580 os << " " << ( node->base->body ? "with" : "without" ) << " body";
1581 }
1582 print( node->params );
1583
1584 return node;
1585 }
1586
1587 virtual const ast::Type * visit( const ast::TraitInstType * node ) override final {
1588 preprint( node );
1589 os << "instance of trait " << node->name;
1590 print( node->params );
1591
1592 return node;
1593 }
1594
1595 virtual const ast::Type * visit( const ast::TypeInstType * node ) override final {
1596 preprint( node );
1597 const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->typeString();
1598 os << "instance of type " << _name
1599 << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)";
1600 print( node->params );
1601
1602 return node;
1603 }
1604
1605 virtual const ast::Type * visit( const ast::TupleType * node ) override final {
1606 preprint( node );
1607 os << "tuple of types" << endl;
1608 ++indent;
1609 printAll( node->types );
1610 --indent;
1611
1612 return node;
1613 }
1614
1615 virtual const ast::Type * visit( const ast::TypeofType * node ) override final {
1616 preprint( node );
1617 if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }
1618 os << "type-of expression ";
1619 safe_print( node->expr );
1620
1621 return node;
1622 }
1623
1624 virtual const ast::Type * visit( const ast::VTableType * node ) override final {
1625 preprint( node );
1626 os << "vtable for ";
1627 safe_print( node->base );
1628
1629 return node;
1630 }
1631
1632 virtual const ast::Type * visit( const ast::VarArgsType * node ) override final {
1633 preprint( node );
1634 os << "builtin var args pack";
1635 return node;
1636 }
1637
1638 virtual const ast::Type * visit( const ast::ZeroType * node ) override final {
1639 preprint( node );
1640 os << "zero_t";
1641 return node;
1642 }
1643
1644 virtual const ast::Type * visit( const ast::OneType * node ) override final {
1645 preprint( node );
1646 os << "one_t";
1647 return node;
1648 }
1649
1650 virtual const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
1651 preprint( node );
1652 os << "Global Scope Type";
1653 return node;
1654 }
1655
1656 virtual const ast::Designation * visit( const ast::Designation * node ) override final {
1657 if ( node->designators.empty() ) return node;
1658 os << "... designated by: " << endl;
1659 ++indent;
1660 for ( const ast::Expr * d : node->designators ) {
1661 os << indent;
1662 d->accept( *this );
1663 os << endl;
1664 }
1665 --indent;
1666 return node;
1667 }
1668
1669 virtual const ast::Init * visit( const ast::SingleInit * node ) override final {
1670 os << "Simple Initializer: ";
1671 safe_print( node->value );
1672 return node;
1673 }
1674
1675 virtual const ast::Init * visit( const ast::ListInit * node ) override final {
1676 os << "Compound initializer: " << endl;
1677 ++indent;
1678 for ( auto p : group_iterate( node->designations, node->initializers ) ) {
1679 const ast::Designation * d = std::get<0>(p);
1680 const ast::Init * init = std::get<1>(p);
1681 os << indent;
1682 init->accept( *this );
1683 os << endl;
1684 if ( ! d->designators.empty() ) {
1685 os << indent;
1686 d->accept( *this );
1687 }
1688 }
1689 --indent;
1690 return node;
1691 }
1692
1693 virtual const ast::Init * visit( const ast::ConstructorInit * node ) override final {
1694 os << "Constructor initializer: " << endl;
1695 if ( node->ctor ) {
1696 os << indent << "... initially constructed with ";
1697 ++indent;
1698 node->ctor->accept( *this );
1699 --indent;
1700 }
1701
1702 if ( node->dtor ) {
1703 os << indent << "... destructed with ";
1704 ++indent;
1705 node->dtor->accept( *this );
1706 --indent;
1707 }
1708
1709 if ( node->init ) {
1710 os << indent << "... with fallback C-style initializer: ";
1711 ++indent;
1712 node->init->accept( *this );
1713 --indent;
1714 }
1715 return node;
1716 }
1717
1718 virtual const ast::Attribute * visit( const ast::Attribute * node ) override final {
1719 if ( node->empty() ) return node;
1720 os << "Attribute with name: " << node->name;
1721 if ( node->params.empty() ) return node;
1722 os << " with parameters: " << endl;
1723 ++indent;
1724 printAll( node->params );
1725 --indent;
1726 return node;
1727 }
1728
1729 virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
1730 os << indent << "Types:" << endl;
1731 for ( const auto& i : *node ) {
1732 os << indent+1 << i.first.typeString() << " -> ";
1733 indent += 2;
1734 safe_print( i.second );
1735 indent -= 2;
1736 os << endl;
1737 }
1738 return node;
1739 }
1740
1741};
1742
1743} // namespace
1744
1745void print( ostream & os, const ast::Node * node, Indenter indent ) {
1746 Printer printer { os, indent, false };
1747 node->accept(printer);
1748}
1749
1750void printShort( ostream & os, const ast::Decl * node, Indenter indent ) {
1751 Printer printer { os, indent, true };
1752 node->accept(printer);
1753}
1754
1755void print( ostream & os, Function::Specs specs ) {
1756 print( os, specs, Names::FuncSpecifiers );
1757}
1758
1759void print( ostream & os, Storage::Classes storage ) {
1760 print( os, storage, Names::StorageClasses );
1761}
1762
1763void print( ostream & os, CV::Qualifiers qualifiers ) {
1764 print( os, qualifiers, Names::Qualifiers );
1765}
1766
1767} // namespace ast
Note: See TracBrowser for help on using the repository browser.