source: src/AST/Print.cpp @ f988834

Last change on this file since f988834 was 59c8dff, checked in by JiadaL <j82liang@…>, 9 months ago

Draft Implementation for enum position pesudo function (posE). EnumPosExpr? is mostly irrelevant for now. It is used in development/code probing and will be removed later

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