Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Print.cpp

    rb0ec971 r335f2d8  
    2222#include "TypeSubstitution.hpp"
    2323
    24 #include "Common/utility.h"      // for group_iterate
     24#include "Common/utility.h" // for group_iterate
     25
     26using namespace std;
    2527
    2628namespace ast {
     
    2830template <typename C, typename... T>
    2931constexpr auto make_array(T&&... values) ->
    30         std::array<C,sizeof...(T)>
     32        array<C,sizeof...(T)>
    3133{
    32         return std::array<C,sizeof...(T)>{
    33                 std::forward<T>(values)...
     34        return array<C,sizeof...(T)>{
     35                forward<T>(values)...
    3436        };
    3537}
     
    3739class Printer : public Visitor {
    3840public:
    39         std::ostream & os;
     41        ostream & os;
    4042        Indenter indent;
    41 
    42         Printer(std::ostream & os, Indenter indent) : os( os ), indent( indent ) {}
     43        bool short_mode;
     44
     45        Printer(ostream & os, Indenter indent, bool short_mode) : os( os ), indent( indent ), short_mode(short_mode) {}
    4346
    4447private:
     
    5154                                // need an endl after each element because it's not
    5255                                // easy to know when each individual item should end
    53                                 os << std::endl;
     56                                os << endl;
    5457                        } // if
    5558                } // for
     
    7477
    7578        template<typename storage_t, size_t N>
    76         void print(const storage_t & storage, const std::array<const char *, N> & Names ) {
     79        void print(const storage_t & storage, const array<const char *, N> & Names ) {
    7780                if ( storage.any() ) {
    7881                        for ( size_t i = 0; i < Names.size(); i += 1 ) {
     
    9699        }
    97100
    98         void print( const ast::ParameterizedType::ForallList & forall ) {
    99                 if ( forall.empty() ) return;   
    100                 os << "forall" << std::endl;
    101                 ++indent;
    102                 printAll( forall );
    103                 os << indent;
    104                 --indent;
    105         }
    106 
    107         void print( const std::vector<ptr<Attribute>> & attrs ) {
    108                 if ( attrs.empty() ) return;
    109                 os << "with attributes" << std::endl;
    110                 ++indent;
    111                 printAll( attrs );
    112                 --indent;
    113         }
    114 
    115         void print( const std::vector<ptr<Expr>> & params ) {
    116                 if ( params.empty() ) return;
    117                 os << std::endl << indent << "... with parameters" << std::endl;
    118                 ++indent;
    119                 printAll( params );
    120                 --indent;
    121         }
    122 
    123         void preprint( const ast::Type * node ) {
    124                 print( node->qualifiers );
    125         }
    126 
    127         void preprint( const ast::ParameterizedType * node ) {
    128                 print( node->forall );
    129                 print( node->qualifiers );
    130         }
    131 
    132         void preprint( const ast::ReferenceToType * node ) {
    133                 print( node->forall );
    134                 print( node->attributes );
    135                 print( node->qualifiers );
     101        void print( const ast::AggregateDecl * node ) {
     102                os << node->typeString() << " " << node->name << ":";
     103                if ( node->linkage != Linkage::Cforall ) {
     104                        os << " " << Linkage::name( node->linkage );
     105                } // if
     106                os << " with body : " << (node->body ? "yes " : "no ");
     107
     108                if ( ! node->params.empty() ) {
     109                        os << endl << indent << "... with parameters" << endl;
     110                        ++indent;
     111                        printAll( node->params );
     112                        --indent;
     113                } // if
     114                if ( ! node->members.empty() ) {
     115                        os << endl << indent << "... with members" << endl;
     116                        ++indent;
     117                        printAll( node->members );
     118                        --indent;
     119                } // if
     120                if ( ! node->attributes.empty() ) {
     121                        os << endl << indent << "... with attributes" << endl;
     122                        ++indent;
     123                        printAll( node->attributes );
     124                        --indent;
     125                } // if
     126                os << endl;
     127        }
     128
     129        void print( const ast::NamedTypeDecl * node ) {
     130                if ( !node->name.empty() ) os << node->name << ": ";
     131
     132                if ( node->linkage != Linkage::Cforall ) {
     133                        os << Linkage::name( node->linkage ) << " ";
     134                } // if
     135                print( node->storage );
     136                os << node->typeString();
     137                if ( node->base ) {
     138                        os << " for ";
     139                        ++indent;
     140                        node->base->accept( *this );
     141                        --indent;
     142                } // if
     143                if ( ! node->params.empty() ) {
     144                        os << endl << indent << "... with parameters" << endl;
     145                        ++indent;
     146                        printAll( node->params );
     147                        --indent;
     148                } // if
     149                if ( ! node->assertions.empty() ) {
     150                        os << endl << indent << "... with assertions" << endl;
     151                        ++indent;
     152                        printAll( node->assertions );
     153                        --indent;
     154                } // if
    136155        }
    137156
    138157public:
    139         virtual const ast::DeclWithType *     visit( const ast::ObjectDecl          * node ) {
    140                 if ( node->name != "" ) os << node->name << ": ";
     158        virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) {
     159                if ( !node->name.empty() ) os << node->name << ": ";
    141160
    142161                if ( node->linkage != Linkage::Cforall ) {
     
    157176                                        ? "maybe constructed"
    158177                                        : "not constructed"
    159                                 ) << ")" << std::endl << indent+1;
     178                                ) << ")" << endl << indent+1;
    160179
    161180                        ++indent;
    162181                        node->init->accept( *this );
    163182                        --indent;
    164                         os << std::endl;
     183                        os << endl;
    165184                } // if
    166185
    167186                if ( ! node->attributes.empty() ) {
    168                         os << std::endl << indent << "... with attributes:" << std::endl;
     187                        os << endl << indent << "... with attributes:" << endl;
    169188                        ++indent;
    170189                        printAll( node->attributes );
     
    179198        }
    180199
    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 ) {
    446                 preprint( node );
    447                 os << "void";
    448                 return node;
    449         }
    450 
    451         virtual const ast::Type *             visit( const ast::BasicType            * node ) {
    452                 preprint( node );
    453                 os << ast::BasicType::typeNames[ node->kind ];
    454                 return node;
    455         }
    456 
    457         virtual const ast::Type *             visit( const ast::PointerType          * node ) {
    458                 preprint( node );
    459                 if ( ! node->isArray() ) {
    460                         os << "pointer to ";
     200        virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) {
     201                if ( !node->name.empty() ) {
     202                        os << node->name << ": ";
     203                } // if
     204                if ( node->linkage != Linkage::Cforall ) {
     205                        os << Linkage::name( node->linkage ) << " ";
     206                } // if
     207
     208                printAll( node->attributes );
     209
     210                print( node->storage );
     211                print( node->funcSpec );
     212
     213                if ( node->type ) {
     214                        node->type->accept( *this );
    461215                } else {
    462                         os << "decayed ";
    463                         if ( node->isStatic ) {
    464                                 os << "static ";
     216                        os << "untyped entity ";
     217                } // if
     218
     219                if ( node->stmts ) {
     220                        os << indent << "... with body" << endl << indent+1;
     221                        ++indent;
     222                        node->stmts->accept( *this );
     223                        --indent;
     224                } // if
     225                return node;
     226        }
     227
     228        virtual const ast::Decl * visit( const ast::StructDecl * node ) {
     229                print(node);
     230                return node;
     231        }
     232
     233        virtual const ast::Decl * visit( const ast::UnionDecl * node ) {
     234                print(node);
     235                return node;
     236        }
     237
     238        virtual const ast::Decl * visit( const ast::EnumDecl * node ) {
     239                print(node);
     240                return node;
     241        }
     242
     243        virtual const ast::Decl * visit( const ast::TraitDecl * node ) {
     244                print(node);
     245                return node;
     246        }
     247
     248        virtual const ast::Decl * visit( const ast::TypeDecl * node ) {
     249                print( node );
     250                if ( node->init ) {
     251                        os << endl << indent << "with type initializer: ";
     252                        ++indent;
     253                        node->init->accept( *this );
     254                        --indent;
     255                }
     256                return node;
     257        }
     258
     259        virtual const ast::Decl * visit( const ast::TypedefDecl * node ) {
     260                print( node );
     261                return node;
     262        }
     263
     264        virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) {
     265                node->stmt->accept( *this );
     266                return node;
     267        }
     268
     269        virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) {
     270                os << "Static Assert with condition: ";
     271                ++indent;
     272                node->cond->accept( *this );
     273                --indent;
     274                os << endl << indent << "and message: ";
     275                ++indent;
     276                node->msg->accept( *this );
     277                --indent;
     278                os << endl;
     279                return node;
     280        }
     281
     282        virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) {
     283                os << "CompoundStmt" << endl;
     284                ++indent;
     285                printAll( node->kids );
     286                --indent;
     287                return node;
     288        }
     289
     290        virtual const ast::Stmt * visit( const ast::ExprStmt * node ) {
     291                ++indent;
     292                os << "Expression Statement:" << endl << indent;
     293                node->expr->accept( *this );
     294                --indent;
     295                return node;
     296        }
     297
     298        virtual const ast::Stmt * visit( const ast::AsmStmt * node ) {
     299                os << "Assembler Statement:" << endl;
     300                ++indent;
     301                os << indent << "instruction: " << endl << indent;
     302                node->instruction->accept( *this );
     303                if ( ! node->output.empty() ) {
     304                        os << endl << indent+1 << "output: " << endl;
     305                        printAll( node->output );
     306                } // if
     307                if ( ! node->input.empty() ) {
     308                        os << indent+1 << "input: " << endl;
     309                        printAll( node->input );
     310                } // if
     311                if ( ! node->clobber.empty() ) {
     312                        os << indent+1 << "clobber: " << endl;
     313                        printAll( node->clobber );
     314                } // if
     315                --indent;
     316                return node;
     317        }
     318
     319        virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) {
     320                os << "GCC Directive:" << node->directive << endl;
     321                return node;
     322        }
     323
     324        virtual const ast::Stmt * visit( const ast::IfStmt * node ) {
     325                os << "If on condition: " << endl;
     326                os << indent+1;
     327                ++indent;
     328                node->cond->accept( *this );
     329                --indent;
     330
     331                if ( !node->inits.empty() ) {
     332                        os << indent << "... with initialization: \n";
     333                        ++indent;
     334                        for ( const Stmt * stmt : node->inits ) {
     335                                os << indent;
     336                                stmt->accept( *this );
    465337                        }
    466 
    467                         if ( node->isVarLen ) {
    468                                 os << "variable length array of ";
    469                         } else if ( node->dimension ) {
    470                                 os << "array of ";
    471                                 node->dimension->accept( *this );
    472                                 os << " ";
    473                         }
    474                 }
    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 ) {
    485                 preprint( node );
    486                 if ( node->isStatic ) {
    487                         os << "static ";
    488                 }
    489 
    490                 if ( node->isVarLen ) {
    491                         os << "variable length array of ";
    492                 } else if ( node->dimension ) {
    493                         os << "array of ";
    494                 } else {
    495                         os << "open array of ";
    496                 }
    497 
    498                 if ( node->base ) {
    499                         node->base->accept( *this );
    500                 } else {
    501                         os << "UNDEFINED";
    502                 }
    503 
    504                 if ( node->dimension ) {
    505                         os << " with dimension of ";
    506                         node->dimension->accept( *this );
    507                 }
    508 
    509                 return node;
    510         }
    511 
    512         virtual const ast::Type *             visit( const ast::ReferenceType        * node ) {
    513                 preprint( node );
    514 
    515                 os << "reference to ";
    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 
    528                 ++indent;
    529                 os << "Qualified Type:" << std::endl << indent;
    530                 node->parent->accept( *this );
    531                 os << std::endl << indent;
    532                 node->child->accept( *this );
    533                 os << std::endl;
    534                 --indent;
    535 
    536                 return node;
    537         }
    538 
    539         virtual const ast::Type *             visit( const ast::FunctionType         * node ) {
    540                 preprint( node );
    541 
    542                 os << "function" << std::endl;
    543                 if ( ! node->params.empty() ) {
    544                         os << indent << "... with parameters" << std::endl;
    545                         ++indent;
    546                         printAll( node->params );
    547                         if ( node->isVarArgs ) {
    548                                 os << indent << "and a variable number of other arguments" << std::endl;
    549                         }
    550                         --indent;
    551                 } else if ( node->isVarArgs ) {
    552                         os << indent+1 << "accepting unspecified arguments" << std::endl;
    553                 }
    554 
    555                 os << indent << "... returning";
    556                 if ( node->returns.empty() ) {
    557                         os << " nothing" << std::endl;
    558                 } else {
    559                         os << std::endl;
    560                         ++indent;
    561                         printAll( node->returns );
    562                         --indent;
    563                 }
    564 
    565                 return node;
    566         }
    567 
    568         virtual const ast::Type *             visit( const ast::StructInstType       * node ) {
    569                 preprint( node );
    570 
    571                 os << "instance of struct " << node->name;
    572                 if ( node->base ) {
    573                         os << " " << ( node->base->body ? "with" : "without" ) << " body";
    574                 }
    575                 print( node->params );
    576 
    577                 return node;
    578         }
    579 
    580         virtual const ast::Type *             visit( const ast::UnionInstType        * node ) {
    581                 preprint( node );
    582 
    583                 os << "instance of union " << node->name;
    584                 if ( node->base ) {
    585                         os << " " << ( node->base->body ? "with" : "without" ) << " body";
    586                 }
    587                 print( node->params );
    588 
    589                 return node;
    590         }
    591 
    592         virtual const ast::Type *             visit( const ast::EnumInstType         * node ) {
    593                 preprint( node );
    594 
    595                 os << "instance of enum " << node->name;
    596                 if ( node->base ) {
    597                         os << " " << ( node->base->body ? "with" : "without" ) << " body";
    598                 }
    599                 print( node->params );
    600 
    601                 return node;
    602         }
    603 
    604         virtual const ast::Type *             visit( const ast::TraitInstType        * node ) {
    605                 preprint( node );
    606 
    607                 os << "instance of trait " << node->name;
    608                 print( node->params );
    609 
    610                 return node;
    611         }
    612 
    613         virtual const ast::Type *             visit( const ast::TypeInstType         * node ) {
    614                 preprint( node );
    615 
    616                 os << "instance of type " << node->name
    617                    << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)";
    618                 print( node->params );
    619 
    620                 return node;
    621         }
    622 
    623         virtual const ast::Type *             visit( const ast::TupleType            * node ) {
    624                 preprint( node );
    625 
    626                 os << "tuple of types" << std::endl;
    627                 ++indent;
    628                 printAll( node->types );
    629                 --indent;
    630 
    631                 return node;
    632         }
    633 
    634         virtual const ast::Type *             visit( const ast::TypeofType           * node ) {
    635                 preprint( node );
    636 
    637                 if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; }
    638                 os << "type-of expression ";
    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 ) {
    649                 preprint( node );
    650                 os << "builtin var args pack";
    651                 return node;
    652         }
    653 
    654         virtual const ast::Type *             visit( const ast::ZeroType             * node ) {
    655                 preprint( node );
    656                 os << "zero_t";
    657                 return node;
    658         }
    659 
    660         virtual const ast::Type *             visit( const ast::OneType              * node ) {
    661                 preprint( node );
    662                 os << "one_t";
    663                 return node;
    664         }
    665 
    666         virtual const ast::Type *             visit( const ast::GlobalScopeType      * node ) {
    667                 preprint( node );
    668                 os << "Global Scope Type";
    669                 return node;
    670         }
    671 
    672         virtual const ast::Designation *      visit( const ast::Designation          * node ) {
     338                        --indent;
     339                        os << endl;
     340                }
     341
     342                os << indent << "... then: " << endl;
     343
     344                ++indent;
     345                os << indent;
     346                node->thenPart->accept( *this );
     347                --indent;
     348
     349                if ( node->elsePart != 0 ) {
     350                        os << indent << "... else: " << endl;
     351                        ++indent;
     352                        os << indent;
     353                        node->elsePart->accept( *this );
     354                        --indent;
     355                } // if
     356                return node;
     357        }
     358
     359        virtual const ast::Stmt * visit( const ast::WhileStmt * node ) {
     360                return node;
     361        }
     362
     363        virtual const ast::Stmt * visit( const ast::ForStmt * node ) {
     364                return node;
     365        }
     366
     367        virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) {
     368                return node;
     369        }
     370
     371        virtual const ast::Stmt * visit( const ast::CaseStmt * node ) {
     372                return node;
     373        }
     374
     375        virtual const ast::Stmt * visit( const ast::BranchStmt * node ) {
     376                return node;
     377        }
     378
     379        virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) {
     380                return node;
     381        }
     382
     383        virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) {
     384                return node;
     385        }
     386
     387        virtual const ast::Stmt * visit( const ast::TryStmt * node ) {
     388                return node;
     389        }
     390
     391        virtual const ast::Stmt * visit( const ast::CatchStmt * node ) {
     392                return node;
     393        }
     394
     395        virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) {
     396                return node;
     397        }
     398
     399        virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) {
     400                return node;
     401        }
     402
     403        virtual const ast::Stmt * visit( const ast::WithStmt * node ) {
     404                return node;
     405        }
     406
     407        virtual const ast::NullStmt * visit( const ast::NullStmt * node ) {
     408                return node;
     409        }
     410
     411        virtual const ast::Stmt * visit( const ast::DeclStmt * node ) {
     412                return node;
     413        }
     414
     415        virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) {
     416                return node;
     417        }
     418
     419        virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) {
     420                return node;
     421        }
     422
     423        virtual const ast::Expr * visit( const ast::UntypedExpr * node ) {
     424                return node;
     425        }
     426
     427        virtual const ast::Expr * visit( const ast::NameExpr * node ) {
     428                return node;
     429        }
     430
     431        virtual const ast::Expr * visit( const ast::AddressExpr * node ) {
     432                return node;
     433        }
     434
     435        virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) {
     436                return node;
     437        }
     438
     439        virtual const ast::Expr * visit( const ast::CastExpr * node ) {
     440                return node;
     441        }
     442
     443        virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) {
     444                return node;
     445        }
     446
     447        virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) {
     448                return node;
     449        }
     450
     451        virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) {
     452                return node;
     453        }
     454
     455        virtual const ast::Expr * visit( const ast::MemberExpr * node ) {
     456                return node;
     457        }
     458
     459        virtual const ast::Expr * visit( const ast::VariableExpr * node ) {
     460                return node;
     461        }
     462
     463        virtual const ast::Expr * visit( const ast::ConstantExpr * node ) {
     464                return node;
     465        }
     466
     467        virtual const ast::Expr * visit( const ast::SizeofExpr * node ) {
     468                return node;
     469        }
     470
     471        virtual const ast::Expr * visit( const ast::AlignofExpr * node ) {
     472                return node;
     473        }
     474
     475        virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) {
     476                return node;
     477        }
     478
     479        virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) {
     480                return node;
     481        }
     482
     483        virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) {
     484                return node;
     485        }
     486
     487        virtual const ast::Expr * visit( const ast::LogicalExpr * node ) {
     488                return node;
     489        }
     490
     491        virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) {
     492                return node;
     493        }
     494
     495        virtual const ast::Expr * visit( const ast::CommaExpr * node ) {
     496                return node;
     497        }
     498
     499        virtual const ast::Expr * visit( const ast::TypeExpr * node ) {
     500                return node;
     501        }
     502
     503        virtual const ast::Expr * visit( const ast::AsmExpr * node ) {
     504                return node;
     505        }
     506
     507        virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) {
     508                return node;
     509        }
     510
     511        virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) {
     512                return node;
     513        }
     514
     515        virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) {
     516                return node;
     517        }
     518
     519        virtual const ast::Expr * visit( const ast::RangeExpr * node ) {
     520                return node;
     521        }
     522
     523        virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) {
     524                return node;
     525        }
     526
     527        virtual const ast::Expr * visit( const ast::TupleExpr * node ) {
     528                return node;
     529        }
     530
     531        virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) {
     532                return node;
     533        }
     534
     535        virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) {
     536                return node;
     537        }
     538
     539        virtual const ast::Expr * visit( const ast::StmtExpr * node ) {
     540                return node;
     541        }
     542
     543        virtual const ast::Expr * visit( const ast::UniqueExpr * node ) {
     544                return node;
     545        }
     546
     547        virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) {
     548                return node;
     549        }
     550
     551        virtual const ast::Expr * visit( const ast::InitExpr * node ) {
     552                return node;
     553        }
     554
     555        virtual const ast::Expr * visit( const ast::DeletedExpr * node ) {
     556                return node;
     557        }
     558
     559        virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) {
     560                return node;
     561        }
     562
     563        virtual const ast::Expr * visit( const ast::GenericExpr * node ) {
     564                return node;
     565        }
     566
     567        virtual const ast::Type * visit( const ast::VoidType * node ) {
     568                return node;
     569        }
     570
     571        virtual const ast::Type * visit( const ast::BasicType * node ) {
     572                return node;
     573        }
     574
     575        virtual const ast::Type * visit( const ast::PointerType * node ) {
     576                return node;
     577        }
     578
     579        virtual const ast::Type * visit( const ast::ArrayType * node ) {
     580                return node;
     581        }
     582
     583        virtual const ast::Type * visit( const ast::ReferenceType * node ) {
     584                return node;
     585        }
     586
     587        virtual const ast::Type * visit( const ast::QualifiedType * node ) {
     588                return node;
     589        }
     590
     591        virtual const ast::Type * visit( const ast::FunctionType * node ) {
     592                return node;
     593        }
     594
     595        virtual const ast::Type * visit( const ast::StructInstType * node ) {
     596                return node;
     597        }
     598
     599        virtual const ast::Type * visit( const ast::UnionInstType * node ) {
     600                return node;
     601        }
     602
     603        virtual const ast::Type * visit( const ast::EnumInstType * node ) {
     604                return node;
     605        }
     606
     607        virtual const ast::Type * visit( const ast::TraitInstType * node ) {
     608                return node;
     609        }
     610
     611        virtual const ast::Type * visit( const ast::TypeInstType * node ) {
     612                return node;
     613        }
     614
     615        virtual const ast::Type * visit( const ast::TupleType * node ) {
     616                return node;
     617        }
     618
     619        virtual const ast::Type * visit( const ast::TypeofType * node ) {
     620                return node;
     621        }
     622
     623        virtual const ast::Type * visit( const ast::VarArgsType * node ) {
     624                return node;
     625        }
     626
     627        virtual const ast::Type * visit( const ast::ZeroType * node ) {
     628                return node;
     629        }
     630
     631        virtual const ast::Type * visit( const ast::OneType * node ) {
     632                return node;
     633        }
     634
     635        virtual const ast::Type * visit( const ast::GlobalScopeType * node ) {
     636                return node;
     637        }
     638
     639        virtual const ast::Designation * visit( const ast::Designation * node ) {
    673640                if ( node->designators.empty() ) return node;
    674641                os << "... designated by: " << std::endl;
     
    683650        }
    684651
    685         virtual const ast::Init *             visit( const ast::SingleInit          * node ) {
     652        virtual const ast::Init * visit( const ast::SingleInit * node ) {
    686653                os << "Simple Initializer: ";
    687654                node->value->accept( *this );
     
    689656        }
    690657
    691         virtual const ast::Init *             visit( const ast::ListInit            * node ) {
     658        virtual const ast::Init * visit( const ast::ListInit * node ) {
    692659                os << "Compound initializer: " << std::endl;
    693660                ++indent;
     
    707674        }
    708675
    709         virtual const ast::Init *             visit( const ast::ConstructorInit      * node ) {
     676        virtual const ast::Init * visit( const ast::ConstructorInit * node ) {
    710677                os << "Constructor initializer: " << std::endl;
    711678                if ( node->ctor ) {
     
    732699        }
    733700
    734         virtual const ast::Attribute *        visit( const ast::Attribute            * node ) {
     701        virtual const ast::Attribute * visit( const ast::Attribute * node ) {
    735702                if ( node->empty() ) return node;
    736703                os << "Attribute with name: " << node->name;
     
    743710        }
    744711
    745         virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * node ) {
     712        virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) {
    746713                os << indent << "Types:" << std::endl;
    747714                for ( const auto& i : *node ) {
     
    765732};
    766733
    767 void print( std::ostream & os, const ast::Node * node, Indenter indent ) {
    768         Printer printer { os, indent };
     734void print( ostream & os, const ast::Node * node, Indenter indent ) {
     735        Printer printer { os, indent, false };
     736        node->accept(printer);
     737}
     738
     739void printShort( ostream & os, const ast::Node * node, Indenter indent ) {
     740        Printer printer { os, indent, true };
    769741        node->accept(printer);
    770742}
     
    773745// The size here needs to be explicit but at least the compiler will produce an error
    774746// if the wrong size is specified
    775 constexpr std::array<const char*, 3> Printer::Names::FuncSpecifiers;
    776 constexpr std::array<const char*, 5> Printer::Names::StorageClasses;
    777 constexpr std::array<const char*, 6> Printer::Names::Qualifiers;
     747constexpr array<const char*, 3> Printer::Names::FuncSpecifiers;
     748constexpr array<const char*, 5> Printer::Names::StorageClasses;
     749constexpr array<const char*, 6> Printer::Names::Qualifiers;
    778750}
Note: See TracChangeset for help on using the changeset viewer.