Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Print.cpp

    r20a5977 rb0ec971  
    2222#include "TypeSubstitution.hpp"
    2323
    24 #include "Common/utility.h" // for group_iterate
    25 
    26 using namespace std;
     24#include "Common/utility.h"      // for group_iterate
    2725
    2826namespace ast {
     
    3028template <typename C, typename... T>
    3129constexpr auto make_array(T&&... values) ->
    32         array<C,sizeof...(T)>
     30        std::array<C,sizeof...(T)>
    3331{
    34         return array<C,sizeof...(T)>{
    35                 forward<T>(values)...
     32        return std::array<C,sizeof...(T)>{
     33                std::forward<T>(values)...
    3634        };
    3735}
     
    3937class Printer : public Visitor {
    4038public:
    41         ostream & os;
     39        std::ostream & os;
    4240        Indenter indent;
    43         bool short_mode;
    44 
    45         Printer(ostream & os, Indenter indent, bool short_mode) : os( os ), indent( indent ), short_mode(short_mode) {}
     41
     42        Printer(std::ostream & os, Indenter indent) : os( os ), indent( indent ) {}
    4643
    4744private:
     
    5451                                // need an endl after each element because it's not
    5552                                // easy to know when each individual item should end
    56                                 os << endl;
     53                                os << std::endl;
    5754                        } // if
    5855                } // for
    59         }
    60 
    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()
    73         void short_print( const ast::Node * n ) {
    74                 if ( ! n ) { undefined(); return; }
    75                 bool old_short = short_mode; short_mode = true;
    76                 n->accept( *this );
    77                 short_mode = old_short;
    7856        }
    7957
     
    9674
    9775        template<typename storage_t, size_t N>
    98         void print(const storage_t & storage, const array<const char *, N> & Names ) {
     76        void print(const storage_t & storage, const std::array<const char *, N> & Names ) {
    9977                if ( storage.any() ) {
    10078                        for ( size_t i = 0; i < Names.size(); i += 1 ) {
     
    11694        void print( const ast::CV::Qualifiers & qualifiers ) {
    11795                print(qualifiers, Names::Qualifiers);
    118         }
    119 
    120         void print( const ast::Expr::InferUnion & inferred, unsigned level = 0 ) {
    121                 switch ( inferred.mode ) {
    122                 case ast::Expr::InferUnion::Empty: return;
    123                 case ast::Expr::InferUnion::Slots: {
    124                         os << indent << "with " << inferred.data.resnSlots.size() << " pending inference slots"
    125                            << std::endl;
    126                         return;
    127                 }
    128                 case ast::Expr::InferUnion::Params: {
    129                         os << indent << "with inferred parameters " << level << ":" << std::endl;
    130                         ++indent;
    131                         for ( const auto & i : inferred.data.inferParams ) {
    132                                 os << indent;
    133                                 short_print( Decl::fromId( i.second.decl ) );
    134                                 os << std::endl;
    135                                 print( i.second.expr->inferred, level+1 );
    136                         }
    137                         --indent;
    138                         return;
    139                 }
    140                 }
    14196        }
    14297
     
    166121        }
    167122
    168         void print( const ast::AggregateDecl * node ) {
    169                 os << node->typeString() << " " << node->name << ":";
    170                 if ( node->linkage != Linkage::Cforall ) {
    171                         os << " " << Linkage::name( node->linkage );
    172                 } // if
    173                 os << " with body : " << (node->body ? "yes " : "no ");
    174 
    175                 if ( ! node->params.empty() ) {
    176                         os << endl << indent << "... with parameters" << endl;
    177                         ++indent;
    178                         printAll( node->params );
    179                         --indent;
    180                 } // if
    181                 if ( ! node->members.empty() ) {
    182                         os << endl << indent << "... with members" << endl;
    183                         ++indent;
    184                         printAll( node->members );
    185                         --indent;
    186                 } // if
    187                 if ( ! node->attributes.empty() ) {
    188                         os << endl << indent << "... with attributes" << endl;
    189                         ++indent;
    190                         printAll( node->attributes );
    191                         --indent;
    192                 } // if
    193                 os << endl;
    194         }
    195 
    196         void print( const ast::NamedTypeDecl * node ) {
    197                 if ( !node->name.empty() ) os << node->name << ": ";
    198 
    199                 if ( node->linkage != Linkage::Cforall ) {
    200                         os << Linkage::name( node->linkage ) << " ";
    201                 } // if
    202                 print( node->storage );
    203                 os << node->typeString();
    204                 if ( node->base ) {
    205                         os << " for ";
    206                         ++indent;
    207                         node->base->accept( *this );
    208                         --indent;
    209                 } // if
    210                 if ( ! node->params.empty() ) {
    211                         os << endl << indent << "... with parameters" << endl;
    212                         ++indent;
    213                         printAll( node->params );
    214                         --indent;
    215                 } // if
    216                 if ( ! node->assertions.empty() ) {
    217                         os << endl << indent << "... with assertions" << endl;
    218                         ++indent;
    219                         printAll( node->assertions );
    220                         --indent;
    221                 } // if
    222         }
    223 
    224         void postprint( const ast::Expr * node ) {
    225                 print( node->inferred );
    226 
    227                 if ( node->env ) {
    228                         os << std::endl << indent << "... with environment:" << std::endl;
    229                         ++indent;
    230                         node->env->accept( *this );
    231                         --indent;
    232                 }
    233                
    234                 if ( node->extension ) {
    235                         os << std::endl << indent << "... with extension";
    236                 }
    237         }
    238 
    239123        void preprint( const ast::Type * node ) {
    240124                print( node->qualifiers );
     
    253137
    254138public:
    255         virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) {
    256                 if ( !node->name.empty() ) os << node->name << ": ";
     139        virtual const ast::DeclWithType *     visit( const ast::ObjectDecl          * node ) {
     140                if ( node->name != "" ) os << node->name << ": ";
    257141
    258142                if ( node->linkage != Linkage::Cforall ) {
     
    265149                        node->type->accept( *this );
    266150                } else {
    267                         os << "untyped entity";
     151                        os << " untyped entity ";
    268152                } // if
    269153
     
    273157                                        ? "maybe constructed"
    274158                                        : "not constructed"
    275                                 ) << ")" << endl << indent+1;
     159                                ) << ")" << std::endl << indent+1;
    276160
    277161                        ++indent;
    278162                        node->init->accept( *this );
    279163                        --indent;
    280                         os << endl;
     164                        os << std::endl;
    281165                } // if
    282166
    283167                if ( ! node->attributes.empty() ) {
    284                         os << endl << indent << "... with attributes:" << endl;
     168                        os << std::endl << indent << "... with attributes:" << std::endl;
    285169                        ++indent;
    286170                        printAll( node->attributes );
     
    295179        }
    296180
    297         virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) {
    298                 if ( !node->name.empty() ) {
    299                         os << node->name << ": ";
    300                 } // if
    301                 if ( node->linkage != Linkage::Cforall ) {
    302                         os << Linkage::name( node->linkage ) << " ";
    303                 } // if
    304 
    305                 printAll( node->attributes );
    306 
    307                 print( node->storage );
    308                 print( node->funcSpec );
    309 
    310                 if ( node->type ) {
    311                         node->type->accept( *this );
    312                 } else {
    313                         os << "untyped entity";
    314                 } // if
    315 
    316                 if ( node->stmts ) {
    317                         os << indent << "... with body" << endl << indent+1;
    318                         ++indent;
    319                         node->stmts->accept( *this );
    320                         --indent;
    321                 } // if
    322                 return node;
    323         }
    324 
    325         virtual const ast::Decl * visit( const ast::StructDecl * node ) {
    326                 print(node);
    327                 return node;
    328         }
    329 
    330         virtual const ast::Decl * visit( const ast::UnionDecl * node ) {
    331                 print(node);
    332                 return node;
    333         }
    334 
    335         virtual const ast::Decl * visit( const ast::EnumDecl * node ) {
    336                 print(node);
    337                 return node;
    338         }
    339 
    340         virtual const ast::Decl * visit( const ast::TraitDecl * node ) {
    341                 print(node);
    342                 return node;
    343         }
    344 
    345         virtual const ast::Decl * visit( const ast::TypeDecl * node ) {
    346                 print( node );
    347                 if ( node->init ) {
    348                         os << endl << indent << "with type initializer: ";
    349                         ++indent;
    350                         node->init->accept( *this );
    351                         --indent;
    352                 }
    353                 return node;
    354         }
    355 
    356         virtual const ast::Decl * visit( const ast::TypedefDecl * node ) {
    357                 print( node );
    358                 return node;
    359         }
    360 
    361         virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) {
    362                 node->stmt->accept( *this );
    363                 return node;
    364         }
    365 
    366         virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) {
    367                 os << "Static Assert with condition: ";
    368                 ++indent;
    369                 node->cond->accept( *this );
    370                 --indent;
    371                 os << endl << indent << "and message: ";
    372                 ++indent;
    373                 node->msg->accept( *this );
    374                 --indent;
    375                 os << endl;
    376                 return node;
    377         }
    378 
    379         virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) {
    380                 os << "CompoundStmt" << endl;
    381                 ++indent;
    382                 printAll( node->kids );
    383                 --indent;
    384                 return node;
    385         }
    386 
    387         virtual const ast::Stmt * visit( const ast::ExprStmt * node ) {
    388                 ++indent;
    389                 os << "Expression Statement:" << endl << indent;
    390                 safe_print( node->expr );
    391                 --indent;
    392                 return node;
    393         }
    394 
    395         virtual const ast::Stmt * visit( const ast::AsmStmt * node ) {
    396                 os << "Assembler Statement:" << endl;
    397                 ++indent;
    398                 os << indent << "instruction: " << endl << indent;
    399                 node->instruction->accept( *this );
    400                 if ( ! node->output.empty() ) {
    401                         os << endl << indent+1 << "output: " << endl;
    402                         printAll( node->output );
    403                 } // if
    404                 if ( ! node->input.empty() ) {
    405                         os << indent+1 << "input: " << endl;
    406                         printAll( node->input );
    407                 } // if
    408                 if ( ! node->clobber.empty() ) {
    409                         os << indent+1 << "clobber: " << endl;
    410                         printAll( node->clobber );
    411                 } // if
    412                 --indent;
    413                 return node;
    414         }
    415 
    416         virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) {
    417                 os << "GCC Directive:" << node->directive << endl;
    418                 return node;
    419         }
    420 
    421         virtual const ast::Stmt * visit( const ast::IfStmt * node ) {
    422                 os << "If on condition: " << endl;
    423                 os << indent+1;
    424                 ++indent;
    425                 safe_print( node->cond );
    426                 --indent;
    427 
    428                 if ( !node->inits.empty() ) {
    429                         os << indent << "... with initialization: \n";
    430                         ++indent;
    431                         for ( const Stmt * stmt : node->inits ) {
    432                                 os << indent;
    433                                 stmt->accept( *this );
    434                         }
    435                         --indent;
    436                         os << endl;
    437                 }
    438 
    439                 os << indent << "... then: " << endl;
    440 
    441                 ++indent;
    442                 os << indent;
    443                 safe_print( node->thenPart );
    444                 --indent;
    445 
    446                 if ( node->elsePart != 0 ) {
    447                         os << indent << "... else: " << endl;
    448                         ++indent;
    449                         os << indent;
    450                         node->elsePart->accept( *this );
    451                         --indent;
    452                 } // if
    453                 return node;
    454         }
    455 
    456         virtual const ast::Stmt * visit( const ast::WhileStmt * node ) {
    457                 return node;
    458         }
    459 
    460         virtual const ast::Stmt * visit( const ast::ForStmt * node ) {
    461                 return node;
    462         }
    463 
    464         virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) {
    465                 return node;
    466         }
    467 
    468         virtual const ast::Stmt * visit( const ast::CaseStmt * node ) {
    469                 return node;
    470         }
    471 
    472         virtual const ast::Stmt * visit( const ast::BranchStmt * node ) {
    473                 return node;
    474         }
    475 
    476         virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) {
    477                 return node;
    478         }
    479 
    480         virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) {
    481                 return node;
    482         }
    483 
    484         virtual const ast::Stmt * visit( const ast::TryStmt * node ) {
    485                 return node;
    486         }
    487 
    488         virtual const ast::Stmt * visit( const ast::CatchStmt * node ) {
    489                 return node;
    490         }
    491 
    492         virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) {
    493                 return node;
    494         }
    495 
    496         virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) {
    497                 return node;
    498         }
    499 
    500         virtual const ast::Stmt * visit( const ast::WithStmt * node ) {
    501                 return node;
    502         }
    503 
    504         virtual const ast::NullStmt * visit( const ast::NullStmt * node ) {
    505                 return node;
    506         }
    507 
    508         virtual const ast::Stmt * visit( const ast::DeclStmt * node ) {
    509                 return node;
    510         }
    511 
    512         virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) {
    513                 return node;
    514         }
    515 
    516         virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) {
    517                 ++indent;
    518                 os << "Application of" << std::endl << indent;
    519                 safe_print( node->func );
    520                 os << std::endl;
    521                 if ( ! node->args.empty() ) {
    522                         os << indent << "... to arguments" << std::endl;
    523                         printAll( node->args );
    524                 }
    525                 --indent;
    526                 postprint( node );
    527 
    528                 return node;
    529         }
    530 
    531         virtual const ast::Expr * visit( const ast::UntypedExpr * node ) {
    532                 ++indent;
    533                 os << "Applying untyped:" << std::endl;
    534                 os << indent;
    535                 safe_print( node->func );
    536                 os << std::endl << indent-1 << "...to:" << std::endl;
    537                 printAll( node->args );
    538                 --indent;
    539                 postprint( node );
    540 
    541                 return node;
    542         }
    543 
    544         virtual const ast::Expr * visit( const ast::NameExpr * node ) {
    545                 os << "Name: " << node->name;
    546                 postprint( node );
    547                
    548                 return node;
    549         }
    550 
    551         virtual const ast::Expr * visit( const ast::AddressExpr * node ) {
    552                 os << "Address of:" << std::endl;
    553                 ++indent;
    554                 os << indent;
    555                 safe_print( node->arg );
    556 
    557                 --indent;
    558 
    559                 return node;
    560         }
    561 
    562         virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) {
    563                 os << "Address of label:" << node->arg;
    564 
    565                 return node;
    566         }
    567 
    568         virtual const ast::Expr * visit( const ast::CastExpr * node ) {
    569                 ++indent;
    570                 os << (node->isGenerated ? "Generated" : "Explicit") << " cast of:" << std::endl << indent;
    571                 safe_print( node->arg );
    572                 os << std::endl << indent-1 << "... to:";
    573                 if ( ! node->result ) {
    574                         os << " ";
    575                         undefined();
    576                 } else if ( node->result->isVoid() ) {
    577                         os << " nothing";
    578                 } else {
    579                         os << std::endl << indent;
    580                         node->result->accept( *this );
    581                 } // if
    582                 --indent;
    583                 postprint( node );
    584 
    585                 return node;
    586         }
    587 
    588         virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) {
    589                 ++indent;
    590                 os << "Keyword Cast of:" << std::endl << indent;
    591                 safe_print( node->arg );
    592                 --indent;
    593                 os << std::endl << indent << "... to: " << node->targetString();
    594                 postprint( node );
    595 
    596                 return node;
    597         }
    598 
    599         virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) {
    600                 ++indent;
    601                 os << "Virtual Cast of:" << std::endl << indent;
    602                 safe_print( node->arg );
    603                 os << std::endl << indent-1 << "... to:";
    604                 if ( ! node->result ) {
    605                         os << " unknown";
    606                 } else {
    607                         os << std::endl << indent;
    608                         node->result->accept( *this );
    609                 }
    610                 --indent;
    611                 postprint( node );
    612 
    613                 return node;
    614         }
    615 
    616         virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) {
    617                 ++indent;
    618                 os << "Untyped Member Expression, with field: " << std::endl << indent;
    619                 safe_print( node->member );
    620                 os << indent-1 << "... from aggregate:" << std::endl << indent;
    621                 safe_print( node->aggregate );
    622                 --indent;
    623                 postprint( node );
    624 
    625                 return node;
    626         }
    627 
    628         virtual const ast::Expr * visit( const ast::MemberExpr * node ) {
    629                 ++indent;
    630                 os << "Member Expression, with field:" << std::endl << indent;
    631                 safe_print( node->member );
    632                 os << std::endl << indent-1 << "... from aggregate:" << std::endl << indent;
    633                 safe_print( node->aggregate );
    634                 --indent;
    635                 postprint( node );
    636 
    637                 return node;
    638         }
    639 
    640         virtual const ast::Expr * visit( const ast::VariableExpr * node ) {
    641                 os << "Variable Expression: ";
    642                 short_print( node->var );
    643                 postprint( node );
    644 
    645                 return node;
    646         }
    647 
    648         virtual const ast::Expr * visit( const ast::ConstantExpr * node ) {
    649                 os << "Constant Expression (" << node->rep;
    650                 if ( node->result ) {
    651                         os << ": ";
    652                         node->result->accept( *this );
    653                 }
    654                 os << ")";
    655                 postprint( node );
    656 
    657                 return node;
    658         }
    659 
    660         virtual const ast::Expr * visit( const ast::SizeofExpr * node ) {
    661                 return node;
    662         }
    663 
    664         virtual const ast::Expr * visit( const ast::AlignofExpr * node ) {
    665                 return node;
    666         }
    667 
    668         virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) {
    669                 return node;
    670         }
    671 
    672         virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) {
    673                 return node;
    674         }
    675 
    676         virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) {
    677                 return node;
    678         }
    679 
    680         virtual const ast::Expr * visit( const ast::LogicalExpr * node ) {
    681                 return node;
    682         }
    683 
    684         virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) {
    685                 return node;
    686         }
    687 
    688         virtual const ast::Expr * visit( const ast::CommaExpr * node ) {
    689                 return node;
    690         }
    691 
    692         virtual const ast::Expr * visit( const ast::TypeExpr * node ) {
    693                 return node;
    694         }
    695 
    696         virtual const ast::Expr * visit( const ast::AsmExpr * node ) {
    697                 return node;
    698         }
    699 
    700         virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) {
    701                 return node;
    702         }
    703 
    704         virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) {
    705                 return node;
    706         }
    707 
    708         virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) {
    709                 return node;
    710         }
    711 
    712         virtual const ast::Expr * visit( const ast::RangeExpr * node ) {
    713                 return node;
    714         }
    715 
    716         virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) {
    717                 return node;
    718         }
    719 
    720         virtual const ast::Expr * visit( const ast::TupleExpr * node ) {
    721                 return node;
    722         }
    723 
    724         virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) {
    725                 return node;
    726         }
    727 
    728         virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) {
    729                 return node;
    730         }
    731 
    732         virtual const ast::Expr * visit( const ast::StmtExpr * node ) {
    733                 return node;
    734         }
    735 
    736         virtual const ast::Expr * visit( const ast::UniqueExpr * node ) {
    737                 return node;
    738         }
    739 
    740         virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) {
    741                 return node;
    742         }
    743 
    744         virtual const ast::Expr * visit( const ast::InitExpr * node ) {
    745                 return node;
    746         }
    747 
    748         virtual const ast::Expr * visit( const ast::DeletedExpr * node ) {
    749                 return node;
    750         }
    751 
    752         virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) {
    753                 return node;
    754         }
    755 
    756         virtual const ast::Expr * visit( const ast::GenericExpr * node ) {
    757                 return node;
    758         }
    759 
    760         virtual const ast::Type * visit( const ast::VoidType * node ) {
     181        virtual const ast::DeclWithType *     visit( const ast::FunctionDecl         * node ) {
     182                return node;
     183        }
     184
     185        virtual const ast::Decl *             visit( const ast::StructDecl           * node ) {
     186                return node;
     187        }
     188
     189        virtual const ast::Decl *             visit( const ast::UnionDecl            * node ) {
     190                return node;
     191        }
     192
     193        virtual const ast::Decl *             visit( const ast::EnumDecl             * node ) {
     194                return node;
     195        }
     196
     197        virtual const ast::Decl *             visit( const ast::TraitDecl            * node ) {
     198                return node;
     199        }
     200
     201        virtual const ast::Decl *             visit( const ast::TypeDecl             * node ) {
     202                return node;
     203        }
     204
     205        virtual const ast::Decl *             visit( const ast::TypedefDecl          * node ) {
     206                return node;
     207        }
     208
     209        virtual const ast::AsmDecl *          visit( const ast::AsmDecl              * node ) {
     210                return node;
     211        }
     212
     213        virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl     * node ) {
     214                return node;
     215        }
     216
     217        virtual const ast::CompoundStmt *     visit( const ast::CompoundStmt         * node ) {
     218                return node;
     219        }
     220
     221        virtual const ast::Stmt *             visit( const ast::ExprStmt             * node ) {
     222                return node;
     223        }
     224
     225        virtual const ast::Stmt *             visit( const ast::AsmStmt              * node ) {
     226                return node;
     227        }
     228
     229        virtual const ast::Stmt *             visit( const ast::DirectiveStmt        * node ) {
     230                return node;
     231        }
     232
     233        virtual const ast::Stmt *             visit( const ast::IfStmt               * node ) {
     234                return node;
     235        }
     236
     237        virtual const ast::Stmt *             visit( const ast::WhileStmt            * node ) {
     238                return node;
     239        }
     240
     241        virtual const ast::Stmt *             visit( const ast::ForStmt              * node ) {
     242                return node;
     243        }
     244
     245        virtual const ast::Stmt *             visit( const ast::SwitchStmt           * node ) {
     246                return node;
     247        }
     248
     249        virtual const ast::Stmt *             visit( const ast::CaseStmt             * node ) {
     250                return node;
     251        }
     252
     253        virtual const ast::Stmt *             visit( const ast::BranchStmt           * node ) {
     254                return node;
     255        }
     256
     257        virtual const ast::Stmt *             visit( const ast::ReturnStmt           * node ) {
     258                return node;
     259        }
     260
     261        virtual const ast::Stmt *             visit( const ast::ThrowStmt            * node ) {
     262                return node;
     263        }
     264
     265        virtual const ast::Stmt *             visit( const ast::TryStmt              * node ) {
     266                return node;
     267        }
     268
     269        virtual const ast::Stmt *             visit( const ast::CatchStmt            * node ) {
     270                return node;
     271        }
     272
     273        virtual const ast::Stmt *             visit( const ast::FinallyStmt          * node ) {
     274                return node;
     275        }
     276
     277        virtual const ast::Stmt *             visit( const ast::WaitForStmt          * node ) {
     278                return node;
     279        }
     280
     281        virtual const ast::Stmt *             visit( const ast::WithStmt             * node ) {
     282                return node;
     283        }
     284
     285        virtual const ast::NullStmt *         visit( const ast::NullStmt             * node ) {
     286                return node;
     287        }
     288
     289        virtual const ast::Stmt *             visit( const ast::DeclStmt             * node ) {
     290                return node;
     291        }
     292
     293        virtual const ast::Stmt *             visit( const ast::ImplicitCtorDtorStmt * node ) {
     294                return node;
     295        }
     296
     297        virtual const ast::Expr *             visit( const ast::ApplicationExpr      * node ) {
     298                return node;
     299        }
     300
     301        virtual const ast::Expr *             visit( const ast::UntypedExpr          * node ) {
     302                return node;
     303        }
     304
     305        virtual const ast::Expr *             visit( const ast::NameExpr             * node ) {
     306                return node;
     307        }
     308
     309        virtual const ast::Expr *             visit( const ast::AddressExpr          * node ) {
     310                return node;
     311        }
     312
     313        virtual const ast::Expr *             visit( const ast::LabelAddressExpr     * node ) {
     314                return node;
     315        }
     316
     317        virtual const ast::Expr *             visit( const ast::CastExpr             * node ) {
     318                return node;
     319        }
     320
     321        virtual const ast::Expr *             visit( const ast::KeywordCastExpr      * node ) {
     322                return node;
     323        }
     324
     325        virtual const ast::Expr *             visit( const ast::VirtualCastExpr      * node ) {
     326                return node;
     327        }
     328
     329        virtual const ast::Expr *             visit( const ast::UntypedMemberExpr    * node ) {
     330                return node;
     331        }
     332
     333        virtual const ast::Expr *             visit( const ast::MemberExpr           * node ) {
     334                return node;
     335        }
     336
     337        virtual const ast::Expr *             visit( const ast::VariableExpr         * node ) {
     338                return node;
     339        }
     340
     341        virtual const ast::Expr *             visit( const ast::ConstantExpr         * node ) {
     342                return node;
     343        }
     344
     345        virtual const ast::Expr *             visit( const ast::SizeofExpr           * node ) {
     346                return node;
     347        }
     348
     349        virtual const ast::Expr *             visit( const ast::AlignofExpr          * node ) {
     350                return node;
     351        }
     352
     353        virtual const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * node ) {
     354                return node;
     355        }
     356
     357        virtual const ast::Expr *             visit( const ast::OffsetofExpr         * node ) {
     358                return node;
     359        }
     360
     361        virtual const ast::Expr *             visit( const ast::OffsetPackExpr       * node ) {
     362                return node;
     363        }
     364
     365        virtual const ast::Expr *             visit( const ast::LogicalExpr          * node ) {
     366                return node;
     367        }
     368
     369        virtual const ast::Expr *             visit( const ast::ConditionalExpr      * node ) {
     370                return node;
     371        }
     372
     373        virtual const ast::Expr *             visit( const ast::CommaExpr            * node ) {
     374                return node;
     375        }
     376
     377        virtual const ast::Expr *             visit( const ast::TypeExpr             * node ) {
     378                return node;
     379        }
     380
     381        virtual const ast::Expr *             visit( const ast::AsmExpr              * node ) {
     382                return node;
     383        }
     384
     385        virtual const ast::Expr *             visit( const ast::ImplicitCopyCtorExpr * node ) {
     386                return node;
     387        }
     388
     389        virtual const ast::Expr *             visit( const ast::ConstructorExpr      * node ) {
     390                return node;
     391        }
     392
     393        virtual const ast::Expr *             visit( const ast::CompoundLiteralExpr  * node ) {
     394                return node;
     395        }
     396
     397        virtual const ast::Expr *             visit( const ast::RangeExpr            * node ) {
     398                return node;
     399        }
     400
     401        virtual const ast::Expr *             visit( const ast::UntypedTupleExpr     * node ) {
     402                return node;
     403        }
     404
     405        virtual const ast::Expr *             visit( const ast::TupleExpr            * node ) {
     406                return node;
     407        }
     408
     409        virtual const ast::Expr *             visit( const ast::TupleIndexExpr       * node ) {
     410                return node;
     411        }
     412
     413        virtual const ast::Expr *             visit( const ast::TupleAssignExpr      * node ) {
     414                return node;
     415        }
     416
     417        virtual const ast::Expr *             visit( const ast::StmtExpr             * node ) {
     418                return node;
     419        }
     420
     421        virtual const ast::Expr *             visit( const ast::UniqueExpr           * node ) {
     422                return node;
     423        }
     424
     425        virtual const ast::Expr *             visit( const ast::UntypedInitExpr      * node ) {
     426                return node;
     427        }
     428
     429        virtual const ast::Expr *             visit( const ast::InitExpr             * node ) {
     430                return node;
     431        }
     432
     433        virtual const ast::Expr *             visit( const ast::DeletedExpr          * node ) {
     434                return node;
     435        }
     436
     437        virtual const ast::Expr *             visit( const ast::DefaultArgExpr       * node ) {
     438                return node;
     439        }
     440
     441        virtual const ast::Expr *             visit( const ast::GenericExpr          * node ) {
     442                return node;
     443        }
     444
     445        virtual const ast::Type *             visit( const ast::VoidType             * node ) {
    761446                preprint( node );
    762447                os << "void";
     
    764449        }
    765450
    766         virtual const ast::Type * visit( const ast::BasicType * node ) {
     451        virtual const ast::Type *             visit( const ast::BasicType            * node ) {
    767452                preprint( node );
    768453                os << ast::BasicType::typeNames[ node->kind ];
     
    770455        }
    771456
    772         virtual const ast::Type * visit( const ast::PointerType * node ) {
     457        virtual const ast::Type *             visit( const ast::PointerType          * node ) {
    773458                preprint( node );
    774459                if ( ! node->isArray() ) {
     
    788473                        }
    789474                }
    790                 safe_print( node->base );
    791 
    792                 return node;
    793         }
    794 
    795         virtual const ast::Type * visit( const ast::ArrayType * node ) {
     475
     476                if ( node->base ) {
     477                        node->base->accept( *this );
     478                } else {
     479                        os << "UNDEFINED";
     480                }
     481                return node;
     482        }
     483
     484        virtual const ast::Type *             visit( const ast::ArrayType            * node ) {
    796485                preprint( node );
    797486                if ( node->isStatic ) {
     
    807496                }
    808497
    809                 safe_print( node->base );
     498                if ( node->base ) {
     499                        node->base->accept( *this );
     500                } else {
     501                        os << "UNDEFINED";
     502                }
    810503
    811504                if ( node->dimension ) {
     
    817510        }
    818511
    819         virtual const ast::Type * visit( const ast::ReferenceType * node ) {
    820                 preprint( node );
     512        virtual const ast::Type *             visit( const ast::ReferenceType        * node ) {
     513                preprint( node );
     514
    821515                os << "reference to ";
    822                 safe_print( node->base );
    823 
    824                 return node;
    825         }
    826 
    827         virtual const ast::Type * visit( const ast::QualifiedType * node ) {
    828                 preprint( node );
     516                if ( node->base ) {
     517                        node->base->accept( *this );
     518                } else {
     519                        os << "UNDEFINED";
     520                }
     521
     522                return node;
     523        }
     524
     525        virtual const ast::Type *             visit( const ast::QualifiedType        * node ) {
     526                preprint( node );
     527
    829528                ++indent;
    830529                os << "Qualified Type:" << std::endl << indent;
    831                 safe_print( node->parent );
     530                node->parent->accept( *this );
    832531                os << std::endl << indent;
    833                 safe_print( node->child );
     532                node->child->accept( *this );
    834533                os << std::endl;
    835534                --indent;
     
    838537        }
    839538
    840         virtual const ast::Type * visit( const ast::FunctionType * node ) {
    841                 preprint( node );
    842                
     539        virtual const ast::Type *             visit( const ast::FunctionType        * node ) {
     540                preprint( node );
     541
    843542                os << "function" << std::endl;
    844543                if ( ! node->params.empty() ) {
     
    867566        }
    868567
    869         virtual const ast::Type * visit( const ast::StructInstType * node ) {
    870                 preprint( node );
     568        virtual const ast::Type *             visit( const ast::StructInstType       * node ) {
     569                preprint( node );
     570
    871571                os << "instance of struct " << node->name;
    872572                if ( node->base ) {
     
    878578        }
    879579
    880         virtual const ast::Type * visit( const ast::UnionInstType * node ) {
    881                 preprint( node );
     580        virtual const ast::Type *             visit( const ast::UnionInstType        * node ) {
     581                preprint( node );
     582
    882583                os << "instance of union " << node->name;
    883584                if ( node->base ) {
     
    889590        }
    890591
    891         virtual const ast::Type * visit( const ast::EnumInstType * node ) {
    892                 preprint( node );
     592        virtual const ast::Type *             visit( const ast::EnumInstType         * node ) {
     593                preprint( node );
     594
    893595                os << "instance of enum " << node->name;
    894596                if ( node->base ) {
     
    900602        }
    901603
    902         virtual const ast::Type * visit( const ast::TraitInstType * node ) {
    903                 preprint( node );
     604        virtual const ast::Type *             visit( const ast::TraitInstType        * node ) {
     605                preprint( node );
     606
    904607                os << "instance of trait " << node->name;
    905608                print( node->params );
     
    908611        }
    909612
    910         virtual const ast::Type * visit( const ast::TypeInstType * node ) {
    911                 preprint( node );
     613        virtual const ast::Type *             visit( const ast::TypeInstType         * node ) {
     614                preprint( node );
     615
    912616                os << "instance of type " << node->name
    913617                   << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)";
     
    917621        }
    918622
    919         virtual const ast::Type * visit( const ast::TupleType * node ) {
    920                 preprint( node );
     623        virtual const ast::Type *             visit( const ast::TupleType            * node ) {
     624                preprint( node );
     625
    921626                os << "tuple of types" << std::endl;
    922627                ++indent;
     
    927632        }
    928633
    929         virtual const ast::Type * visit( const ast::TypeofType * node ) {
    930                 preprint( node );
     634        virtual const ast::Type *             visit( const ast::TypeofType           * node ) {
     635                preprint( node );
     636
    931637                if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }
    932638                os << "type-of expression ";
    933                 safe_print( node->expr );
    934 
    935                 return node;
    936         }
    937 
    938         virtual const ast::Type * visit( const ast::VarArgsType * node ) {
     639                if ( node->expr ) {
     640                        node->expr->accept( *this );
     641                } else {
     642                        os << "UNDEFINED";
     643                }
     644
     645                return node;
     646        }
     647
     648        virtual const ast::Type *             visit( const ast::VarArgsType          * node ) {
    939649                preprint( node );
    940650                os << "builtin var args pack";
     
    942652        }
    943653
    944         virtual const ast::Type * visit( const ast::ZeroType * node ) {
     654        virtual const ast::Type *             visit( const ast::ZeroType            * node ) {
    945655                preprint( node );
    946656                os << "zero_t";
     
    948658        }
    949659
    950         virtual const ast::Type * visit( const ast::OneType * node ) {
     660        virtual const ast::Type *             visit( const ast::OneType              * node ) {
    951661                preprint( node );
    952662                os << "one_t";
     
    954664        }
    955665
    956         virtual const ast::Type * visit( const ast::GlobalScopeType * node ) {
     666        virtual const ast::Type *             visit( const ast::GlobalScopeType      * node ) {
    957667                preprint( node );
    958668                os << "Global Scope Type";
     
    960670        }
    961671
    962         virtual const ast::Designation * visit( const ast::Designation * node ) {
     672        virtual const ast::Designation *      visit( const ast::Designation          * node ) {
    963673                if ( node->designators.empty() ) return node;
    964674                os << "... designated by: " << std::endl;
     
    973683        }
    974684
    975         virtual const ast::Init * visit( const ast::SingleInit * node ) {
     685        virtual const ast::Init *             visit( const ast::SingleInit          * node ) {
    976686                os << "Simple Initializer: ";
    977                 safe_print( node->value );
    978                 return node;
    979         }
    980 
    981         virtual const ast::Init * visit( const ast::ListInit * node ) {
     687                node->value->accept( *this );
     688                return node;
     689        }
     690
     691        virtual const ast::Init *             visit( const ast::ListInit            * node ) {
    982692                os << "Compound initializer: " << std::endl;
    983693                ++indent;
     
    997707        }
    998708
    999         virtual const ast::Init * visit( const ast::ConstructorInit * node ) {
     709        virtual const ast::Init *             visit( const ast::ConstructorInit      * node ) {
    1000710                os << "Constructor initializer: " << std::endl;
    1001711                if ( node->ctor ) {
     
    1022732        }
    1023733
    1024         virtual const ast::Attribute * visit( const ast::Attribute * node ) {
     734        virtual const ast::Attribute *        visit( const ast::Attribute            * node ) {
    1025735                if ( node->empty() ) return node;
    1026736                os << "Attribute with name: " << node->name;
     
    1033743        }
    1034744
    1035         virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) {
     745        virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * node ) {
    1036746                os << indent << "Types:" << std::endl;
    1037747                for ( const auto& i : *node ) {
    1038748                        os << indent+1 << i.first << " -> ";
    1039749                        indent += 2;
    1040                         safe_print( i.second );
     750                        i.second->accept( *this );
    1041751                        indent -= 2;
    1042752                        os << std::endl;
     
    1046756                        os << indent+1 << i->first << " -> ";
    1047757                        indent += 2;
    1048                         safe_print( i->second );
     758                        i->second->accept( *this );
    1049759                        indent -= 2;
    1050760                        os << std::endl;
     
    1055765};
    1056766
    1057 void print( ostream & os, const ast::Node * node, Indenter indent ) {
    1058         Printer printer { os, indent, false };
    1059         node->accept(printer);
    1060 }
    1061 
    1062 void printShort( ostream & os, const ast::Node * node, Indenter indent ) {
    1063         Printer printer { os, indent, true };
     767void print( std::ostream & os, const ast::Node * node, Indenter indent ) {
     768        Printer printer { os, indent };
    1064769        node->accept(printer);
    1065770}
     
    1068773// The size here needs to be explicit but at least the compiler will produce an error
    1069774// if the wrong size is specified
    1070 constexpr array<const char*, 3> Printer::Names::FuncSpecifiers;
    1071 constexpr array<const char*, 5> Printer::Names::StorageClasses;
    1072 constexpr array<const char*, 6> Printer::Names::Qualifiers;
     775constexpr std::array<const char*, 3> Printer::Names::FuncSpecifiers;
     776constexpr std::array<const char*, 5> Printer::Names::StorageClasses;
     777constexpr std::array<const char*, 6> Printer::Names::Qualifiers;
    1073778}
Note: See TracChangeset for help on using the changeset viewer.