Changes in / [1259c35:0c6900b]


Ignore:
Location:
src/AST
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r1259c35 r0c6900b  
    397397                ThrowStmt::Kind kind;
    398398                switch (node->kind) {
    399                 case ast::ExceptionKind::Terminate:
     399                case ast::ThrowStmt::Terminate:
    400400                        kind = ThrowStmt::Terminate;
    401401                        break;
    402                 case ast::ExceptionKind::Resume:
     402                case ast::ThrowStmt::Resume:
    403403                        kind = ThrowStmt::Resume;
    404404                        break;
     
    429429                CatchStmt::Kind kind;
    430430                switch (node->kind) {
    431                 case ast::ExceptionKind::Terminate:
     431                case ast::CatchStmt::Terminate:
    432432                        kind = CatchStmt::Terminate;
    433433                        break;
    434                 case ast::ExceptionKind::Resume:
     434                case ast::CatchStmt::Resume:
    435435                        kind = CatchStmt::Resume;
    436436                        break;
     
    17351735        virtual void visit( ThrowStmt * old ) override final {
    17361736                if ( inCache( old ) ) return;
    1737                 ast::ExceptionKind kind;
     1737                ast::ThrowStmt::Kind kind;
    17381738                switch (old->kind) {
    17391739                case ThrowStmt::Terminate:
    1740                         kind = ast::ExceptionKind::Terminate;
     1740                        kind = ast::ThrowStmt::Terminate;
    17411741                        break;
    17421742                case ThrowStmt::Resume:
    1743                         kind = ast::ExceptionKind::Resume;
     1743                        kind = ast::ThrowStmt::Resume;
    17441744                        break;
    17451745                default:
     
    17711771        virtual void visit( CatchStmt * old ) override final {
    17721772                if ( inCache( old ) ) return;
    1773                 ast::ExceptionKind kind;
     1773                ast::CatchStmt::Kind kind;
    17741774                switch (old->kind) {
    17751775                case CatchStmt::Terminate:
    1776                         kind = ast::ExceptionKind::Terminate;
     1776                        kind = ast::CatchStmt::Terminate;
    17771777                        break;
    17781778                case CatchStmt::Resume:
    1779                         kind = ast::ExceptionKind::Resume;
     1779                        kind = ast::CatchStmt::Resume;
    17801780                        break;
    17811781                default:
  • src/AST/Print.cpp

    r1259c35 r0c6900b  
    7171
    7272        /// call to print short form. Incorporates features of safe_print()
    73         void short_print( const ast::Decl * n ) {
     73        void short_print( const ast::Node * n ) {
    7474                if ( ! n ) { undefined(); return; }
    7575                bool old_short = short_mode; short_mode = true;
     
    7777                short_mode = old_short;
    7878        }
     79
    7980
    8081        static const char* Names[];
     
    177178
    178179        void print( const ast::AggregateDecl * node ) {
    179                 os << node->typeString() << " " << node->name;
    180 
    181                 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
     180                os << node->typeString() << " " << node->name << ":";
     181                if ( node->linkage != Linkage::Cforall ) {
    182182                        os << " " << Linkage::name( node->linkage );
    183                 }
    184 
    185                 os << " " << (node->body ? "with" : "without") << " body";
     183                } // if
     184                os << " with body : " << (node->body ? "yes " : "no ");
    186185
    187186                if ( ! node->params.empty() ) {
     
    190189                        printAll( node->params );
    191190                        --indent;
    192                 }
    193 
    194                 if ( ! short_mode && ! node->members.empty() ) {
     191                } // if
     192                if ( ! node->members.empty() ) {
    195193                        os << endl << indent << "... with members" << endl;
    196194                        ++indent;
    197195                        printAll( node->members );
    198196                        --indent;
    199                 }
    200 
    201                 if ( ! short_mode && ! node->attributes.empty() ) {
     197                } // if
     198                if ( ! node->attributes.empty() ) {
    202199                        os << endl << indent << "... with attributes" << endl;
    203200                        ++indent;
    204201                        printAll( node->attributes );
    205202                        --indent;
    206                 }
    207 
     203                } // if
    208204                os << endl;
    209205        }
    210206
    211         void preprint( const ast::NamedTypeDecl * node ) {
    212                 if ( ! node->name.empty() ) os << node->name << ": ";
    213 
    214                 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
     207        void print( const ast::NamedTypeDecl * node ) {
     208                if ( !node->name.empty() ) os << node->name << ": ";
     209
     210                if ( node->linkage != Linkage::Cforall ) {
    215211                        os << Linkage::name( node->linkage ) << " ";
    216                 }
    217 
     212                } // if
    218213                print( node->storage );
    219214                os << node->typeString();
    220 
    221215                if ( node->base ) {
    222216                        os << " for ";
     
    224218                        node->base->accept( *this );
    225219                        --indent;
    226                 }
    227 
     220                } // if
    228221                if ( ! node->params.empty() ) {
    229222                        os << endl << indent << "... with parameters" << endl;
     
    231224                        printAll( node->params );
    232225                        --indent;
    233                 }
    234 
    235                 if ( ! short_mode && ! node->assertions.empty() ) {
     226                } // if
     227                if ( ! node->assertions.empty() ) {
    236228                        os << endl << indent << "... with assertions" << endl;
    237229                        ++indent;
    238230                        printAll( node->assertions );
    239231                        --indent;
    240                 }
     232                } // if
    241233        }
    242234
     
    273265public:
    274266        virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) {
    275                 if ( ! node->name.empty() ) os << node->name << ": ";
    276 
    277                 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
     267                if ( !node->name.empty() ) os << node->name << ": ";
     268
     269                if ( node->linkage != Linkage::Cforall ) {
    278270                        os << Linkage::name( node->linkage ) << " ";
    279                 }
     271                } // if
    280272
    281273                print( node->storage );
     
    285277                } else {
    286278                        os << "untyped entity";
    287                 }
    288 
    289                 if ( ! short_mode && node->init ) {
    290                         ++indent;
     279                } // if
     280
     281                if ( node->init ) {
    291282                        os << " with initializer (" << (
    292283                                node->init->maybeConstructed
    293284                                        ? "maybe constructed"
    294285                                        : "not constructed"
    295                                 ) << ")" << endl << indent;
     286                                ) << ")" << endl << indent+1;
     287
     288                        ++indent;
    296289                        node->init->accept( *this );
    297290                        --indent;
    298291                        os << endl;
    299                 }
    300 
    301                 if ( ! short_mode && ! node->attributes.empty() ) {
     292                } // if
     293
     294                if ( ! node->attributes.empty() ) {
    302295                        os << endl << indent << "... with attributes:" << endl;
    303296                        ++indent;
     
    309302                        os << indent << " with bitfield width ";
    310303                        node->bitfieldWidth->accept( *this );
    311                 }
    312 
     304                } // if
    313305                return node;
    314306        }
    315307
    316308        virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) {
    317                 if ( !node->name.empty() ) os << node->name << ": ";
    318 
    319                 if ( ! short_mode && node->linkage != Linkage::Cforall ) {
     309                if ( !node->name.empty() ) {
     310                        os << node->name << ": ";
     311                } // if
     312                if ( node->linkage != Linkage::Cforall ) {
    320313                        os << Linkage::name( node->linkage ) << " ";
    321                 }
    322 
    323                 if ( ! short_mode ) printAll( node->attributes );
     314                } // if
     315
     316                printAll( node->attributes );
    324317
    325318                print( node->storage );
     
    330323                } else {
    331324                        os << "untyped entity";
    332                 }
    333 
    334                 if ( ! short_mode && node->stmts ) {
    335                         ++indent;
    336                         os << " with body" << endl << indent;
     325                } // if
     326
     327                if ( node->stmts ) {
     328                        os << indent << "... with body" << endl << indent+1;
     329                        ++indent;
    337330                        node->stmts->accept( *this );
    338331                        --indent;
    339                 }
    340 
     332                } // if
    341333                return node;
    342334        }
     
    363355
    364356        virtual const ast::Decl * visit( const ast::TypeDecl * node ) {
    365                 preprint( node );
    366                 if ( ! short_mode && node->init ) {
     357                print( node );
     358                if ( node->init ) {
    367359                        os << endl << indent << "with type initializer: ";
    368360                        ++indent;
     
    370362                        --indent;
    371363                }
    372 
    373364                return node;
    374365        }
    375366
    376367        virtual const ast::Decl * visit( const ast::TypedefDecl * node ) {
    377                 preprint( node );
     368                print( node );
    378369                return node;
    379370        }
    380371
    381372        virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) {
    382                 safe_print( node->stmt );
     373                node->stmt->accept( *this );
    383374                return node;
    384375        }
     
    387378                os << "Static Assert with condition: ";
    388379                ++indent;
    389                 safe_print( node->cond );
    390                 os << endl << indent-1 << "and message: ";
    391                 safe_print( node->msg );
     380                node->cond->accept( *this );
     381                --indent;
     382                os << endl << indent << "and message: ";
     383                ++indent;
     384                node->msg->accept( *this );
    392385                --indent;
    393386                os << endl;
    394 
    395387                return node;
    396388        }
     
    602594
    603595        virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) {
    604                 if ( node->target ) os << "Non-Local ";
    605 
    606                 switch( node->kind ) {
    607                 case ast::ExceptionKind::Terminate: os << "Terminate "; break;
    608                 case ast::ExceptionKind::Resume:    os << "Resume ";    break;
    609                 }
    610 
    611                 ++indent;
    612                 os << "Throw Statement, raising: ";
    613                 safe_print( node->expr );
    614                 if ( node->target ) {
    615                         os << "... at: ";
    616                         node->target->accept( *this );
    617                 }
    618                 --indent;
    619 
    620596                return node;
    621597        }
    622598
    623599        virtual const ast::Stmt * visit( const ast::TryStmt * node ) {
    624                 ++indent;
    625                 os << "Try Statement" << endl << indent-1
    626                    << "... with block:" << endl << indent;
    627                 safe_print( node->body );
    628 
    629                 os << indent-1 << "... and handlers:" << endl;
    630                 for ( const ast::CatchStmt * stmt : node->handlers ) {
    631                         os << indent;
    632                         stmt->accept( *this );
    633                 }
    634 
    635                 if ( node->finally ) {
    636                         os << indent-1 << "... and finally:" << endl << indent;
    637                         node->finally->accept( *this );
    638                 }
    639                 --indent;
    640 
    641600                return node;
    642601        }
    643602
    644603        virtual const ast::Stmt * visit( const ast::CatchStmt * node ) {
    645                 os << "Catch ";
    646                 switch ( node->kind ) {
    647                 case ast::ExceptionKind::Terminate: os << "Terminate "; break;
    648                 case ast::ExceptionKind::Resume:    os << "Resume ";    break;
    649                 }
    650                 os << "Statement" << endl << indent;
    651 
    652                 ++indent;
    653                 os << "... catching: ";
    654                 short_print( node->decl );
    655                 os << endl;
    656 
    657                 if ( node->cond ) {
    658                         os << indent-1 << "... with conditional:" << endl << indent;
    659                         node->cond->accept( *this );
    660                 }
    661 
    662                 os << indent-1 << "... with block:" << endl << indent;
    663                 safe_print( node->body );
    664                 --indent;
    665 
    666604                return node;
    667605        }
    668606
    669607        virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) {
    670                 os << "Finally Statement" << endl;
    671                 os << indent << "... with block:" << endl;
    672                 ++indent;
    673                 os << indent;
    674                 safe_print( node->body );
    675                 --indent;
    676 
    677608                return node;
    678609        }
    679610
    680611        virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) {
    681                 os << "Waitfor Statement" << endl;
    682                 indent += 2;
    683                 for( const auto & clause : node->clauses ) {
    684                         os << indent-1 << "target function: ";
    685                         safe_print( clause.target.func );
    686 
    687                         if ( ! clause.target.args.empty() ) {
    688                                 os << endl << indent-1 << "... with arguments:" << endl;
    689                                 for( const ast::Expr * arg : clause.target.args ) {
    690                                         arg->accept( *this );
    691                                 }
    692                         }
    693 
    694                         if ( clause.stmt ) {
    695                                 os << indent-1 << "... with statment:" << endl;
    696                                 clause.stmt->accept( *this );
    697                         }
    698 
    699                         if ( clause.cond ) {
    700                                 os << indent-1 << "... with condition:" << endl;
    701                                 clause.cond->accept( *this );
    702                         }
    703                 }
    704 
    705                 if ( node->timeout.time ) {
    706                         os << indent-1 << "timeout of:" << endl;
    707                         node->timeout.time->accept( *this );
    708 
    709                         if ( node->timeout.stmt ) {
    710                                 os << indent-1 << "... with statment:" << endl;
    711                                 node->timeout.stmt->accept( *this );
    712                         }
    713 
    714                         if ( node->timeout.cond ) {
    715                                 os << indent-1 << "... with condition:" << endl;
    716                                 node->timeout.cond->accept( *this );
    717                         }
    718                 }
    719 
    720                 if ( node->orElse.stmt ) {
    721                         os << indent-1 << "else:" << endl;
    722                         node->orElse.stmt->accept( *this );
    723 
    724                         if ( node->orElse.cond ) {
    725                                 os << indent-1 << "... with condition:" << endl;
    726                                 node->orElse.cond->accept( *this );
    727                         }
    728                 }
    729                 indent -= 2;
    730 
    731612                return node;
    732613        }
    733614
    734615        virtual const ast::Stmt * visit( const ast::WithStmt * node ) {
    735                 os << "With statement" << endl;
    736                 os << indent << "... with expressions:" << endl;
    737                 ++indent;
    738                 printAll( node->exprs );
    739                 os << indent-1 << "... with statement:" << endl << indent;
    740                 safe_print( node->stmt );
    741                 --indent;
    742 
    743616                return node;
    744617        }
     
    752625
    753626        virtual const ast::Stmt * visit( const ast::DeclStmt * node ) {
    754                 os << "Declaration of ";
    755                 safe_print( node->decl );
    756 
    757627                return node;
    758628        }
    759629
    760630        virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) {
    761                 os << "Implicit Ctor Dtor Statement" << endl;
    762                 os << indent << "... with Ctor/Dtor: ";
    763                 ++indent;
    764                 safe_print( node->callStmt );
    765                 --indent;
    766                 os << endl;
    767 
    768631                return node;
    769632        }
     
    15081371}
    15091372
    1510 void printShort( ostream & os, const ast::Decl * node, Indenter indent ) {
     1373void printShort( ostream & os, const ast::Node * node, Indenter indent ) {
    15111374        Printer printer { os, indent, true };
    15121375        node->accept(printer);
  • src/AST/Print.hpp

    r1259c35 r0c6900b  
    2323namespace ast {
    2424
    25 class Decl;
    26 
    27 /// Print a node with the given indenter
    2825void print( std::ostream & os, const ast::Node * node, Indenter indent = {} );
    2926
     
    3229}
    3330
    34 /// Print a declaration in its short form
    35 void printShort( std::ostream & os, const ast::Decl * node, Indenter indent = {} );
    36 
    37 inline void printShort( std::ostream & os, const ast::Decl * node, unsigned int indent ) {
    38     printShort( os, node, Indenter{ Indenter::tabsize, indent } );
    3931}
    40 
    41 }
  • src/AST/Stmt.hpp

    r1259c35 r0c6900b  
    268268};
    269269
    270 /// Kind of exception
    271 enum ExceptionKind { Terminate, Resume };
    272 
    273270/// Throw statement `throw ...`
    274271class ThrowStmt final : public Stmt {
    275272public:
     273        enum Kind { Terminate, Resume };
     274
    276275        ptr<Expr> expr;
    277276        ptr<Expr> target;
    278         ExceptionKind kind;
    279 
    280         ThrowStmt(
    281                 const CodeLocation & loc, ExceptionKind kind, const Expr * expr, const Expr * target,
     277        Kind kind;
     278
     279        ThrowStmt( const CodeLocation & loc, Kind kind, const Expr * expr, const Expr * target,
    282280                std::vector<Label> && labels = {} )
    283281        : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {}
     
    296294        ptr<FinallyStmt> finally;
    297295
    298         TryStmt(
    299                 const CodeLocation & loc, const CompoundStmt * body,
     296        TryStmt( const CodeLocation & loc, const CompoundStmt * body,
    300297                std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally,
    301298                std::vector<Label> && labels = {} )
     
    311308class CatchStmt final : public Stmt {
    312309public:
     310        enum Kind { Terminate, Resume };
     311
    313312        ptr<Decl> decl;
    314313        ptr<Expr> cond;
    315314        ptr<Stmt> body;
    316         ExceptionKind kind;
    317 
    318         CatchStmt(
    319                 const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,
     315        Kind kind;
     316
     317        CatchStmt( const CodeLocation & loc, Kind kind, const Decl * decl, const Expr * cond,
    320318                const Stmt * body, std::vector<Label> && labels = {} )
    321319        : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}
  • src/AST/porting.md

    r1259c35 r0c6900b  
    3737  * all subclass constructors must fill it; by convention, from their first argument
    3838
    39 `N->print(std::ostream&)` is a visitor now
    40 * `Declaration::printShort` is also integrated
     39`N->print(std::ostream&)` is a visitor now, port these methods to `ast::Print` class
     40* **TODO** `Declaration::printShort` should also be integrated
    4141
    4242`clone` is private to `Node` now
     
    137137* `parameters` => `params`
    138138
     139`EnumDecl`
     140* **TODO** rebuild `eval` for new AST (re: `valueOf` implementation)
     141
    139142`Expr`
    140143* Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version
     
    148151* `function` => `func`
    149152* removed `begin_args()` in favour of `args.begin()`
     153
     154`MemberExpr`
     155* **TODO** port setup of `result` in constructor
    150156
    151157`ConstantExpr`
     
    198204`TryStmt`
    199205* `block` -> `body` and `finallyBlock` -> `finally`
    200 
    201 `ThrowStmt` `CatchStmt`
    202 * moved `Kind` enums to shared `ast::ExceptionKind` enum
    203206
    204207`FinallyStmt`
Note: See TracChangeset for help on using the changeset viewer.