source: src/AST/Print.cpp @ 624ba3a5

Last change on this file since 624ba3a5 was 9ddcee1, checked in by JiadaL <j82liang@…>, 5 months ago

Remove EnumPosExpr?, an early design that no longer used. The implementation of the feature has been replaced by ReplacePseudoFunc?

  • Property mode set to 100644
File size: 41.2 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::TraitInstType * node ) override final {
1579                preprint( node );
1580                os << "instance of trait " << node->name;
1581                print( node->params );
1582
1583                return node;
1584        }
1585
1586        virtual const ast::Type * visit( const ast::TypeInstType * node ) override final {
1587                preprint( node );
1588                const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->typeString();
1589                os << "instance of type " << _name
1590                   << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)";
1591                print( node->params );
1592
1593                return node;
1594        }
1595
1596        virtual const ast::Type * visit( const ast::TupleType * node ) override final {
1597                preprint( node );
1598                os << "tuple of types" << endl;
1599                ++indent;
1600                printAll( node->types );
1601                --indent;
1602
1603                return node;
1604        }
1605
1606        virtual const ast::Type * visit( const ast::TypeofType * node ) override final {
1607                preprint( node );
1608                if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }
1609                os << "type-of expression ";
1610                safe_print( node->expr );
1611
1612                return node;
1613        }
1614
1615        virtual const ast::Type * visit( const ast::VTableType * node ) override final {
1616                preprint( node );
1617                os << "vtable for ";
1618                safe_print( node->base );
1619
1620                return node;
1621        }
1622
1623        virtual const ast::Type * visit( const ast::VarArgsType * node ) override final {
1624                preprint( node );
1625                os << "builtin var args pack";
1626                return node;
1627        }
1628
1629        virtual const ast::Type * visit( const ast::ZeroType * node ) override final {
1630                preprint( node );
1631                os << "zero_t";
1632                return node;
1633        }
1634
1635        virtual const ast::Type * visit( const ast::OneType * node ) override final {
1636                preprint( node );
1637                os << "one_t";
1638                return node;
1639        }
1640
1641        virtual const ast::Type * visit( const ast::GlobalScopeType * node ) override final {
1642                preprint( node );
1643                os << "Global Scope Type";
1644                return node;
1645        }
1646
1647        virtual const ast::Designation * visit( const ast::Designation * node ) override final {
1648                if ( node->designators.empty() ) return node;
1649                os << "... designated by: " << endl;
1650                ++indent;
1651                for ( const ast::Expr * d : node->designators ) {
1652                        os << indent;
1653                        d->accept( *this );
1654                        os << endl;
1655                }
1656                --indent;
1657                return node;
1658        }
1659
1660        virtual const ast::Init * visit( const ast::SingleInit * node ) override final {
1661                os << "Simple Initializer: ";
1662                safe_print( node->value );
1663                return node;
1664        }
1665
1666        virtual const ast::Init * visit( const ast::ListInit * node ) override final {
1667                os << "Compound initializer: " << endl;
1668                ++indent;
1669                for ( auto p : group_iterate( node->designations, node->initializers ) ) {
1670                        const ast::Designation * d = std::get<0>(p);
1671                        const ast::Init * init = std::get<1>(p);
1672                        os << indent;
1673                        init->accept( *this );
1674                        os << endl;
1675                        if ( ! d->designators.empty() ) {
1676                                os << indent;
1677                                d->accept( *this );
1678                        }
1679                }
1680                --indent;
1681                return node;
1682        }
1683
1684        virtual const ast::Init * visit( const ast::ConstructorInit * node ) override final {
1685                os << "Constructor initializer: " << endl;
1686                if ( node->ctor ) {
1687                        os << indent << "... initially constructed with ";
1688                        ++indent;
1689                        node->ctor->accept( *this );
1690                        --indent;
1691                }
1692
1693                if ( node->dtor ) {
1694                        os << indent << "... destructed with ";
1695                        ++indent;
1696                        node->dtor->accept( *this );
1697                        --indent;
1698                }
1699
1700                if ( node->init ) {
1701                        os << indent << "... with fallback C-style initializer: ";
1702                        ++indent;
1703                        node->init->accept( *this );
1704                        --indent;
1705                }
1706                return node;
1707        }
1708
1709        virtual const ast::Attribute * visit( const ast::Attribute * node ) override final {
1710                if ( node->empty() ) return node;
1711                os << "Attribute with name: " << node->name;
1712                if ( node->params.empty() ) return node;
1713                os << " with parameters: " << endl;
1714                ++indent;
1715                printAll( node->params );
1716                --indent;
1717                return node;
1718        }
1719
1720        virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
1721                os << indent << "Types:" << endl;
1722                for ( const auto& i : *node ) {
1723                        os << indent+1 << i.first.typeString() << " -> ";
1724                        indent += 2;
1725                        safe_print( i.second );
1726                        indent -= 2;
1727                        os << endl;
1728                }
1729                return node;
1730        }
1731
1732};
1733
1734} // namespace
1735
1736void print( ostream & os, const ast::Node * node, Indenter indent ) {
1737        Printer printer { os, indent, false };
1738        node->accept(printer);
1739}
1740
1741void printShort( ostream & os, const ast::Decl * node, Indenter indent ) {
1742        Printer printer { os, indent, true };
1743        node->accept(printer);
1744}
1745
1746void print( ostream & os, Function::Specs specs ) {
1747        print( os, specs, Names::FuncSpecifiers );
1748}
1749
1750void print( ostream & os, Storage::Classes storage ) {
1751        print( os, storage, Names::StorageClasses );
1752}
1753
1754void print( ostream & os, CV::Qualifiers qualifiers ) {
1755        print( os, qualifiers, Names::Qualifiers );
1756}
1757
1758} // namespace ast
Note: See TracBrowser for help on using the repository browser.