source: src/AST/Print.cpp @ 3cc1111

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 3cc1111 was 6cebfef, checked in by caparsons <caparson@…>, 3 years ago

added mutex stmt monitor

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