Changeset 400b8be


Ignore:
Timestamp:
Mar 28, 2022, 10:41:45 AM (6 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
enum, master, pthread-emulation, qualifiedEnum
Children:
8e819a9
Parents:
f5bace8
Message:

Added StmtClause? and converted the existing nodes that should be clauses.

Location:
src
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rf5bace8 r400b8be  
    353353        }
    354354
     355        void clausePostamble( Statement * stmt, const ast::StmtClause * node ) {
     356                stmt->location = node->location;
     357                this->node = stmt;
     358        }
     359
    355360        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
    356361                if ( inCache( node ) ) return nullptr;
     
    401406                auto stmt = new SwitchStmt(
    402407                        get<Expression>().accept1( node->cond ),
    403                         get<Statement>().acceptL( node->stmts )
     408                        get<Statement>().acceptL( node->cases )
    404409                );
    405410                return stmtPostamble( stmt, node );
    406411        }
    407412
    408         const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
     413        const ast::CaseClause * visit( const ast::CaseClause * node ) override final {
    409414                if ( inCache( node ) ) return nullptr;
    410415                auto stmt = new CaseStmt(
     
    413418                        node->isDefault()
    414419                );
    415                 return stmtPostamble( stmt, node );
     420                clausePostamble( stmt, node );
     421                return nullptr;
    416422        }
    417423
     
    509515        }
    510516
    511         const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
     517        const ast::CatchClause * visit( const ast::CatchClause * node ) override final {
    512518                if ( inCache( node ) ) return nullptr;
    513519                CatchStmt::Kind kind;
     
    520526                        break;
    521527                default:
    522                         assertf(false, "Invalid ast::CatchStmt::Kind: %d\n", node->kind);
     528                        assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind);
    523529                }
    524530                auto stmt = new CatchStmt(
     
    528534                        get<Statement>().accept1( node->body )
    529535                );
    530                 return stmtPostamble( stmt, node );
    531         }
    532 
    533         const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
     536                return clausePostamble( stmt, node ), nullptr;
     537        }
     538
     539        const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final {
    534540                if ( inCache( node ) ) return nullptr;
    535541                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    536                 return stmtPostamble( stmt, node );
     542                return clausePostamble( stmt, node ), nullptr;
    537543        }
    538544
     
    18841890                        old->location,
    18851891                        GET_ACCEPT_1(condition, Expr),
    1886                         GET_ACCEPT_V(statements, Stmt),
     1892                        GET_ACCEPT_V(statements, CaseClause),
    18871893                        GET_LABELS_V(old->labels)
    18881894                );
     
    18921898        virtual void visit( const CaseStmt * old ) override final {
    18931899                if ( inCache( old ) ) return;
    1894                 this->node = new ast::CaseStmt(
     1900                this->node = new ast::CaseClause(
    18951901                        old->location,
    18961902                        GET_ACCEPT_1(condition, Expr),
    1897                         GET_ACCEPT_V(stmts, Stmt),
    1898                         GET_LABELS_V(old->labels)
    1899                 );
     1903                        GET_ACCEPT_V(stmts, Stmt)
     1904                );
     1905                auto labels = GET_LABELS_V(old->labels);
     1906                assertf(labels.empty(), "Labels found on CaseStmt.");
    19001907                cache.emplace( old, this->node );
    19011908        }
     
    20052012                        old->location,
    20062013                        GET_ACCEPT_1(block, CompoundStmt),
    2007                         GET_ACCEPT_V(handlers, CatchStmt),
    2008                         GET_ACCEPT_1(finallyBlock, FinallyStmt),
     2014                        GET_ACCEPT_V(handlers, CatchClause),
     2015                        GET_ACCEPT_1(finallyBlock, FinallyClause),
    20092016                        GET_LABELS_V(old->labels)
    20102017                );
     
    20262033                }
    20272034
    2028                 this->node = new ast::CatchStmt(
     2035                this->node = new ast::CatchClause(
    20292036                        old->location,
    20302037                        kind,
    20312038                        GET_ACCEPT_1(decl, Decl),
    20322039                        GET_ACCEPT_1(cond, Expr),
    2033                         GET_ACCEPT_1(body, Stmt),
    2034                         GET_LABELS_V(old->labels)
    2035                 );
     2040                        GET_ACCEPT_1(body, Stmt)
     2041                );
     2042                auto labels = GET_LABELS_V(old->labels);
     2043                assertf(labels.empty(), "Labels found on CatchStmt.");
    20362044                cache.emplace( old, this->node );
    20372045        }
     
    20392047        virtual void visit( const FinallyStmt * old ) override final {
    20402048                if ( inCache( old ) ) return;
    2041                 this->node = new ast::FinallyStmt(
    2042                         old->location,
    2043                         GET_ACCEPT_1(block, CompoundStmt),
    2044                         GET_LABELS_V(old->labels)
    2045                 );
     2049                this->node = new ast::FinallyClause(
     2050                        old->location,
     2051                        GET_ACCEPT_1(block, CompoundStmt)
     2052                );
     2053                auto labels = GET_LABELS_V(old->labels);
     2054                assertf(labels.empty(), "Labels found on FinallyStmt.");
    20462055                cache.emplace( old, this->node );
    20472056        }
  • src/AST/Fwd.hpp

    rf5bace8 r400b8be  
    4747class ForStmt;
    4848class SwitchStmt;
    49 class CaseStmt;
     49class CaseClause;
    5050class BranchStmt;
    5151class ReturnStmt;
    5252class ThrowStmt;
    5353class TryStmt;
    54 class CatchStmt;
    55 class FinallyStmt;
     54class CatchClause;
     55class FinallyClause;
    5656class SuspendStmt;
    5757class WaitForStmt;
  • src/AST/Node.cpp

    rf5bace8 r400b8be  
    160160template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::weak >;
    161161template class ast::ptr_base< ast::SwitchStmt, ast::Node::ref_type::strong >;
    162 template class ast::ptr_base< ast::CaseStmt, ast::Node::ref_type::weak >;
    163 template class ast::ptr_base< ast::CaseStmt, ast::Node::ref_type::strong >;
     162template class ast::ptr_base< ast::CaseClause, ast::Node::ref_type::weak >;
     163template class ast::ptr_base< ast::CaseClause, ast::Node::ref_type::strong >;
    164164template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::weak >;
    165165template class ast::ptr_base< ast::BranchStmt, ast::Node::ref_type::strong >;
     
    170170template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::weak >;
    171171template class ast::ptr_base< ast::TryStmt, ast::Node::ref_type::strong >;
    172 template class ast::ptr_base< ast::CatchStmt, ast::Node::ref_type::weak >;
    173 template class ast::ptr_base< ast::CatchStmt, ast::Node::ref_type::strong >;
    174 template class ast::ptr_base< ast::FinallyStmt, ast::Node::ref_type::weak >;
    175 template class ast::ptr_base< ast::FinallyStmt, ast::Node::ref_type::strong >;
     172template class ast::ptr_base< ast::CatchClause, ast::Node::ref_type::weak >;
     173template class ast::ptr_base< ast::CatchClause, ast::Node::ref_type::strong >;
     174template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::weak >;
     175template class ast::ptr_base< ast::FinallyClause, ast::Node::ref_type::strong >;
    176176template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::weak >;
    177177template class ast::ptr_base< ast::WaitForStmt, ast::Node::ref_type::strong >;
  • src/AST/Pass.hpp

    rf5bace8 r400b8be  
    149149        const ast::Stmt *             visit( const ast::ForStmt              * ) override final;
    150150        const ast::Stmt *             visit( const ast::SwitchStmt           * ) override final;
    151         const ast::Stmt *             visit( const ast::CaseStmt             * ) override final;
     151        const ast::CaseClause *       visit( const ast::CaseClause           * ) override final;
    152152        const ast::Stmt *             visit( const ast::BranchStmt           * ) override final;
    153153        const ast::Stmt *             visit( const ast::ReturnStmt           * ) override final;
    154154        const ast::Stmt *             visit( const ast::ThrowStmt            * ) override final;
    155155        const ast::Stmt *             visit( const ast::TryStmt              * ) override final;
    156         const ast::Stmt *             visit( const ast::CatchStmt            * ) override final;
    157         const ast::Stmt *             visit( const ast::FinallyStmt          * ) override final;
     156        const ast::CatchClause *      visit( const ast::CatchClause          * ) override final;
     157        const ast::FinallyClause *    visit( const ast::FinallyClause        * ) override final;
    158158        const ast::Stmt *             visit( const ast::SuspendStmt          * ) override final;
    159159        const ast::Stmt *             visit( const ast::WaitForStmt          * ) override final;
  • src/AST/Pass.impl.hpp

    rf5bace8 r400b8be  
    893893        if ( __visit_children() ) {
    894894                maybe_accept( node, &SwitchStmt::cond  );
    895                 maybe_accept( node, &SwitchStmt::stmts );
     895                maybe_accept( node, &SwitchStmt::cases );
    896896        }
    897897
     
    900900
    901901//--------------------------------------------------------------------------
    902 // CaseStmt
    903 template< typename core_t >
    904 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CaseStmt * node ) {
    905         VISIT_START( node );
    906 
    907         if ( __visit_children() ) {
    908                 maybe_accept( node, &CaseStmt::cond  );
    909                 maybe_accept( node, &CaseStmt::stmts );
    910         }
    911 
    912         VISIT_END( Stmt, node );
     902// CaseClause
     903template< typename core_t >
     904const ast::CaseClause * ast::Pass< core_t >::visit( const ast::CaseClause * node ) {
     905        VISIT_START( node );
     906
     907        if ( __visit_children() ) {
     908                maybe_accept( node, &CaseClause::cond  );
     909                maybe_accept( node, &CaseClause::stmts );
     910        }
     911
     912        VISIT_END( CaseClause, node );
    913913}
    914914
     
    964964
    965965//--------------------------------------------------------------------------
    966 // CatchStmt
    967 template< typename core_t >
    968 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CatchStmt * node ) {
     966// CatchClause
     967template< typename core_t >
     968const ast::CatchClause * ast::Pass< core_t >::visit( const ast::CatchClause * node ) {
    969969        VISIT_START( node );
    970970
     
    972972                // catch statements introduce a level of scope (for the caught exception)
    973973                guard_symtab guard { *this };
    974                 maybe_accept( node, &CatchStmt::decl );
    975                 maybe_accept( node, &CatchStmt::cond );
    976                 maybe_accept_as_compound( node, &CatchStmt::body );
    977         }
    978 
    979         VISIT_END( Stmt, node );
    980 }
    981 
    982 //--------------------------------------------------------------------------
    983 // FinallyStmt
    984 template< typename core_t >
    985 const ast::Stmt * ast::Pass< core_t >::visit( const ast::FinallyStmt * node ) {
    986         VISIT_START( node );
    987 
    988         if ( __visit_children() ) {
    989                 maybe_accept( node, &FinallyStmt::body );
    990         }
    991 
    992         VISIT_END( Stmt, node );
     974                maybe_accept( node, &CatchClause::decl );
     975                maybe_accept( node, &CatchClause::cond );
     976                maybe_accept_as_compound( node, &CatchClause::body );
     977        }
     978
     979        VISIT_END( CatchClause, node );
     980}
     981
     982//--------------------------------------------------------------------------
     983// FinallyClause
     984template< typename core_t >
     985const ast::FinallyClause * ast::Pass< core_t >::visit( const ast::FinallyClause * node ) {
     986        VISIT_START( node );
     987
     988        if ( __visit_children() ) {
     989                maybe_accept( node, &FinallyClause::body );
     990        }
     991
     992        VISIT_END( FinallyClause, node );
    993993}
    994994
  • src/AST/Print.cpp

    rf5bace8 r400b8be  
    589589
    590590                ++indent;
    591                 for ( const ast::Stmt * stmt : node->stmts ) {
     591                for ( const ast::CaseClause * stmt : node->cases ) {
    592592                        stmt->accept( *this );
    593593                }
     
    597597        }
    598598
    599         virtual const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
     599        virtual const ast::CaseClause * visit( const ast::CaseClause * node ) override final {
    600600                if ( node->isDefault() ) {
    601601                        os << indent << "Default ";
     
    679679
    680680                os << indent-1 << "... and handlers:" << endl;
    681                 for ( const ast::CatchStmt * stmt : node->handlers ) {
     681                for ( const ast::CatchClause * stmt : node->handlers ) {
    682682                        os << indent;
    683683                        stmt->accept( *this );
     
    693693        }
    694694
    695         virtual const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
     695        virtual const ast::CatchClause * visit( const ast::CatchClause * node ) override final {
    696696                os << "Catch ";
    697697                switch ( node->kind ) {
     
    718718        }
    719719
    720         virtual const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
     720        virtual const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final {
    721721                os << "Finally Statement" << endl;
    722722                os << indent << "... with block:" << endl;
  • src/AST/Stmt.hpp

    rf5bace8 r400b8be  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May  8 13:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  2 20:06:41 2022
    13 // Update Count     : 34
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Mar 28  9:50:00 2022
     13// Update Count     : 35
    1414//
    1515
     
    4747  private:
    4848        Stmt * clone() const override = 0;
     49        MUTATE_FRIEND
     50};
     51
     52// Base statement component node (only serves to group them).
     53class StmtClause : public ParseNode {
     54  public:
     55        // This is for non-statements that still belong with the statements,
     56        // but are not statements, usually some sort of clause. Often these can
     57        // (and should) be folded into the approprate parent node, but if they
     58        // cannot be, they are sub-types of this type, for organization.
     59
     60    StmtClause( const CodeLocation & loc )
     61                : ParseNode(loc) {}
     62
     63  private:
     64        StmtClause * clone() const override = 0;
    4965        MUTATE_FRIEND
    5066};
     
    158174  public:
    159175        ptr<Expr> cond;
     176        std::vector<ptr<CaseClause>> cases;
     177
     178        SwitchStmt( const CodeLocation & loc, const Expr * cond,
     179                                const std::vector<ptr<CaseClause>> && cases,
     180                                const std::vector<Label> && labels = {} )
     181                : Stmt(loc, std::move(labels)), cond(cond), cases(std::move(cases)) {}
     182
     183        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     184  private:
     185        SwitchStmt * clone() const override { return new SwitchStmt{ *this }; }
     186        MUTATE_FRIEND
     187};
     188
     189// Case label: case ...: or default:
     190class CaseClause final : public StmtClause {
     191  public:
     192        // Null for the default label.
     193        ptr<Expr> cond;
    160194        std::vector<ptr<Stmt>> stmts;
    161195
    162         SwitchStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts,
    163                                 const std::vector<Label> && labels = {} )
    164                 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
    165 
    166         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    167   private:
    168         SwitchStmt * clone() const override { return new SwitchStmt{ *this }; }
    169         MUTATE_FRIEND
    170 };
    171 
    172 // Case label: case ...: or default:
    173 class CaseStmt final : public Stmt {
    174   public:
    175         // Null for the default label.
    176         ptr<Expr> cond;
    177         std::vector<ptr<Stmt>> stmts;
    178 
    179         CaseStmt( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts,
    180                           const std::vector<Label> && labels = {} )
    181                 : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
     196        CaseClause( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts )
     197                : StmtClause(loc), cond(cond), stmts(std::move(stmts)) {}
    182198
    183199        bool isDefault() const { return !cond; }
    184200
    185         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    186   private:
    187         CaseStmt * clone() const override { return new CaseStmt{ *this }; }
     201        const CaseClause * accept( Visitor & v ) const override { return v.visit( this ); }
     202  private:
     203        CaseClause * clone() const override { return new CaseClause{ *this }; }
    188204        MUTATE_FRIEND
    189205};
     
    298314  public:
    299315        ptr<CompoundStmt> body;
    300         std::vector<ptr<CatchStmt>> handlers;
    301         ptr<FinallyStmt> finally;
     316        std::vector<ptr<CatchClause>> handlers;
     317        ptr<FinallyClause> finally;
    302318
    303319        TryStmt( const CodeLocation & loc, const CompoundStmt * body,
    304                          const std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally,
     320                         const std::vector<ptr<CatchClause>> && handlers, const FinallyClause * finally,
    305321                         const std::vector<Label> && labels = {} )
    306322                : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {}
     
    313329
    314330// Catch clause of try statement
    315 class CatchStmt final : public Stmt {
     331class CatchClause final : public StmtClause {
    316332  public:
    317333        ptr<Decl> decl;
     
    320336        ExceptionKind kind;
    321337
    322         CatchStmt( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,
    323                            const Stmt * body, const std::vector<Label> && labels = {} )
    324                 : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}
    325 
    326         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    327   private:
    328         CatchStmt * clone() const override { return new CatchStmt{ *this }; }
     338        CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,
     339                           const Stmt * body )
     340                : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {}
     341
     342        const CatchClause * accept( Visitor & v ) const override { return v.visit( this ); }
     343  private:
     344        CatchClause * clone() const override { return new CatchClause{ *this }; }
    329345        MUTATE_FRIEND
    330346};
    331347
    332348// Finally clause of try statement
    333 class FinallyStmt final : public Stmt {
     349class FinallyClause final : public StmtClause {
    334350  public:
    335351        ptr<CompoundStmt> body;
    336352
    337         FinallyStmt( const CodeLocation & loc, const CompoundStmt * body,
    338                                  std::vector<Label> && labels = {} )
    339                 : Stmt(loc, std::move(labels)), body(body) {}
    340 
    341         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    342   private:
    343         FinallyStmt * clone() const override { return new FinallyStmt{ *this }; }
     353        FinallyClause( const CodeLocation & loc, const CompoundStmt * body )
     354                : StmtClause(loc), body(body) {}
     355
     356        const FinallyClause * accept( Visitor & v ) const override { return v.visit( this ); }
     357  private:
     358        FinallyClause * clone() const override { return new FinallyClause{ *this }; }
    344359        MUTATE_FRIEND
    345360};
  • src/AST/Visitor.hpp

    rf5bace8 r400b8be  
    4141    virtual const ast::Stmt *             visit( const ast::ForStmt              * ) = 0;
    4242    virtual const ast::Stmt *             visit( const ast::SwitchStmt           * ) = 0;
    43     virtual const ast::Stmt *             visit( const ast::CaseStmt             * ) = 0;
     43    virtual const ast::CaseClause *       visit( const ast::CaseClause           * ) = 0;
    4444    virtual const ast::Stmt *             visit( const ast::BranchStmt           * ) = 0;
    4545    virtual const ast::Stmt *             visit( const ast::ReturnStmt           * ) = 0;
    4646    virtual const ast::Stmt *             visit( const ast::ThrowStmt            * ) = 0;
    4747    virtual const ast::Stmt *             visit( const ast::TryStmt              * ) = 0;
    48     virtual const ast::Stmt *             visit( const ast::CatchStmt            * ) = 0;
    49     virtual const ast::Stmt *             visit( const ast::FinallyStmt          * ) = 0;
     48    virtual const ast::CatchClause *      visit( const ast::CatchClause          * ) = 0;
     49    virtual const ast::FinallyClause *    visit( const ast::FinallyClause        * ) = 0;
    5050    virtual const ast::Stmt *             visit( const ast::SuspendStmt          * ) = 0;
    5151    virtual const ast::Stmt *             visit( const ast::WaitForStmt          * ) = 0;
  • src/Common/CodeLocationTools.cpp

    rf5bace8 r400b8be  
    112112    macro(ForStmt, Stmt) \
    113113    macro(SwitchStmt, Stmt) \
    114     macro(CaseStmt, Stmt) \
     114    macro(CaseClause, CaseClause) \
    115115    macro(BranchStmt, Stmt) \
    116116    macro(ReturnStmt, Stmt) \
    117117    macro(ThrowStmt, Stmt) \
    118118    macro(TryStmt, Stmt) \
    119     macro(CatchStmt, Stmt) \
    120     macro(FinallyStmt, Stmt) \
     119    macro(CatchClause, CatchClause) \
     120    macro(FinallyClause, FinallyClause) \
    121121    macro(SuspendStmt, Stmt) \
    122122    macro(WaitForStmt, Stmt) \
  • src/Concurrency/KeywordsNew.cpp

    rf5bace8 r400b8be  
    13331333
    13341334                // construct the current try
    1335                 currentTry = new ast::TryStmt( 
    1336                         location, 
    1337                         currTryBody, 
    1338                         {}, 
    1339                         new ast::FinallyStmt( location, currFinallyBody )
     1335                currentTry = new ast::TryStmt(
     1336                        location,
     1337                        currTryBody,
     1338                        {},
     1339                        new ast::FinallyClause( location, currFinallyBody )
    13401340                );
    13411341                if ( i == 0 ) outerTry = currentTry;
     
    13511351                lastBody->push_back( body );
    13521352                newBody->push_front( outerTry );
    1353         }       
     1353        }
    13541354
    13551355        // monitor_guard_t __guard = { __monitors, # };
  • src/ControlStruct/ExceptTranslateNew.cpp

    rf5bace8 r400b8be  
    2626namespace {
    2727
    28         typedef std::list<ast::CatchStmt*> CatchList;
     28        typedef std::list<ast::CatchClause*> CatchList;
    2929
    3030        void appendDeclStmt( ast::CompoundStmt * block, ast::DeclWithType * item ) {
     
    4545        {}
    4646
    47         void previsit( const ast::CatchStmt * stmt );
     47        void previsit( const ast::CatchClause * stmt );
    4848        const ast::Stmt * postvisit( const ast::ThrowStmt * stmt );
    4949};
     
    8888}
    8989
    90 void TranslateThrowsCore::previsit( const ast::CatchStmt * stmt ) {
     90void TranslateThrowsCore::previsit( const ast::CatchClause * stmt ) {
    9191        // Validate the statement's form.
    9292        const ast::ObjectDecl * decl = stmt->decl.as<ast::ObjectDecl>();
     
    147147        ast::FunctionDecl * create_terminate_catch( CatchList &handlers );
    148148        ast::CompoundStmt * create_single_matcher(
    149                 const ast::DeclWithType * except_obj, ast::CatchStmt * modded_handler );
     149                const ast::DeclWithType * except_obj, ast::CatchClause * modded_handler );
    150150        ast::FunctionDecl * create_terminate_match( CatchList &handlers );
    151151        ast::CompoundStmt * create_terminate_caller( CodeLocation loc, ast::FunctionDecl * try_wrapper,
     
    338338ast::FunctionDecl * TryMutatorCore::create_terminate_catch(
    339339                CatchList &handlers ) {
    340         std::vector<ast::ptr<ast::Stmt>> handler_wrappers;
     340        std::vector<ast::ptr<ast::CaseClause>> handler_wrappers;
    341341
    342342        assert (!handlers.empty());
     
    352352        for ( ; it != handlers.end() ; ++it ) {
    353353                ++index;
    354                 ast::CatchStmt * handler = *it;
     354                ast::CatchClause * handler = *it;
    355355                const CodeLocation loc = handler->location;
    356356
     
    390390                // handler->body = nullptr;
    391391
    392                 handler_wrappers.push_back( new ast::CaseStmt(loc,
     392                handler_wrappers.push_back( new ast::CaseClause(loc,
    393393                        ast::ConstantExpr::from_int(loc, index) ,
    394394                        { block, new ast::ReturnStmt( loc, nullptr ) }
     
    410410// except_obj is referenced, modded_handler will be freed.
    411411ast::CompoundStmt * TryMutatorCore::create_single_matcher(
    412                 const ast::DeclWithType * except_obj, ast::CatchStmt * modded_handler ) {
     412                const ast::DeclWithType * except_obj, ast::CatchClause * modded_handler ) {
    413413        // {
    414414        //     `modded_handler.decl`
     
    465465        for ( it = handlers.begin() ; it != handlers.end() ; ++it ) {
    466466                ++index;
    467                 ast::CatchStmt * handler = *it;
     467                ast::CatchClause * handler = *it;
    468468
    469469                // Body should have been taken by create_terminate_catch.
     
    520520        CatchList::iterator it;
    521521        for ( it = handlers.begin() ; it != handlers.end() ; ++it ) {
    522                 ast::CatchStmt * handler = *it;
     522                ast::CatchClause * handler = *it;
    523523                const CodeLocation loc = handler->location;
    524524                // Modifiy body.
     
    587587                ast::TryStmt * tryStmt ) {
    588588        // void finally() { `finally->block` }
    589         const ast::FinallyStmt * finally = tryStmt->finally;
     589        const ast::FinallyClause * finally = tryStmt->finally;
    590590        const ast::CompoundStmt * body = finally->body;
    591591
  • src/ControlStruct/LabelGeneratorNew.cpp

    rf5bace8 r400b8be  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // LabelGenerator.cc --
     7// LabelGeneratorNew.cpp --
    88//
    99// Author           : Peter A. Buhr
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  2 09:11:17 2022
    13 // Update Count     : 72
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Mar 28 10:03:00 2022
     13// Update Count     : 73
    1414//
    1515
     
    2525namespace ControlStruct {
    2626
    27 Label newLabel( const string & suffix, const Stmt * stmt ) {
     27enum { size = 128 };
     28
     29static int newLabelPre( char buf[size], const string & suffix ) {
    2830        static int current = 0;
    2931
    30         assertf( stmt, "CFA internal error: parameter statement cannot be null pointer" );
    31 
    32         enum { size = 128 };
    33         char buf[size];                                                                         // space to build label
    3432        int len = snprintf( buf, size, "__L%d__%s", current++, suffix.c_str() );
    3533        assertf( len < size, "CFA Internal error: buffer overflow creating label" );
     34        return len;
     35}
     36
     37static Label newLabelPost( char buf[size], const CodeLocation & location ) {
     38        Label ret_label( location, buf );
     39        ret_label.attributes.push_back( new Attribute( "unused" ) );
     40        return ret_label;
     41}
     42
     43Label newLabel( const string & suffix, const Stmt * stmt ) {
     44        // Buffer for string manipulation.
     45        char buf[size];
     46
     47        assertf( stmt, "CFA internal error: parameter statement cannot be null pointer" );
     48        int len = newLabelPre( buf, suffix );
    3649
    3750        // What does this do?
     
    4154        } // if
    4255
    43         Label ret_label( stmt->location, buf );
    44         ret_label.attributes.push_back( new Attribute( "unused" ) );
    45         return ret_label;
     56        return newLabelPost( buf, stmt->location );
     57}
     58
     59Label newLabel( const string & suffix, const CodeLocation & location ) {
     60        // Buffer for string manipulation.
     61        char buf[size];
     62
     63        newLabelPre( buf, suffix );
     64        return newLabelPost( buf, location );
    4665}
    4766
  • src/ControlStruct/LabelGeneratorNew.hpp

    rf5bace8 r400b8be  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 18:03:09 2022
    13 // Update Count     : 27
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fir Mar 25 15:40:00 2022
     13// Update Count     : 28
    1414//
    1515
     
    1818#include <string>                                                                               // for string
    1919
    20 class Statement;
     20class CodeLocation;
    2121
    2222namespace ast {
     23        class Label;
    2324        class Stmt;
    24         class Label;
    2525} // namespace ast
    2626
    2727namespace ControlStruct {
    2828        ast::Label newLabel( const std::string &, const ast::Stmt * );
     29        ast::Label newLabel( const std::string &, const CodeLocation & );
    2930} // namespace ControlStruct
    3031
  • src/ControlStruct/MultiLevelExit.cpp

    rf5bace8 r400b8be  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Nov  1 13:48:00 2021
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  2 23:07:54 2022
    13 // Update Count     : 33
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Mar 28  9:42:00 2022
     13// Update Count     : 34
    1414//
    1515
     
    4040
    4141        enum Kind {
    42                 ForStmtK, WhileDoStmtK, CompoundStmtK, IfStmtK, CaseStmtK, SwitchStmtK, TryStmtK
     42                ForStmtK, WhileDoStmtK, CompoundStmtK, IfStmtK, CaseClauseK, SwitchStmtK, TryStmtK
    4343        } kind;
    4444
     
    5858        Entry( const IfStmt *stmt, Label breakExit ) :
    5959                stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( IfStmtK ) {}
    60         Entry( const CaseStmt *stmt, Label fallExit ) :
    61                 stmt( stmt ), firstTarget( fallExit ), secondTarget(), kind( CaseStmtK ) {}
     60        Entry( const CaseClause *, const CompoundStmt *stmt, Label fallExit ) :
     61                stmt( stmt ), firstTarget( fallExit ), secondTarget(), kind( CaseClauseK ) {}
    6262        Entry( const SwitchStmt *stmt, Label breakExit, Label fallDefaultExit ) :
    6363                stmt( stmt ), firstTarget( breakExit ), secondTarget( fallDefaultExit ), kind( SwitchStmtK ) {}
     
    6666
    6767        bool isContTarget() const { return kind <= WhileDoStmtK; }
    68         bool isBreakTarget() const { return kind != CaseStmtK; }
    69         bool isFallTarget() const { return kind == CaseStmtK; }
     68        bool isBreakTarget() const { return kind != CaseClauseK; }
     69        bool isFallTarget() const { return kind == CaseClauseK; }
    7070        bool isFallDefaultTarget() const { return kind == SwitchStmtK; }
    7171
    7272        // These routines set a target as being "used" by a BranchStmt
    7373        Label useContExit() { assert( kind <= WhileDoStmtK ); return useTarget(secondTarget); }
    74         Label useBreakExit() { assert( kind != CaseStmtK ); return useTarget(firstTarget); }
    75         Label useFallExit() { assert( kind == CaseStmtK );  return useTarget(firstTarget); }
     74        Label useBreakExit() { assert( kind != CaseClauseK ); return useTarget(firstTarget); }
     75        Label useFallExit() { assert( kind == CaseClauseK );  return useTarget(firstTarget); }
    7676        Label useFallDefaultExit() { assert( kind == SwitchStmtK ); return useTarget(secondTarget); }
    7777
    7878        // These routines check if a specific label for a statement is used by a BranchStmt
    7979        bool isContUsed() const { assert( kind <= WhileDoStmtK ); return secondTarget.used; }
    80         bool isBreakUsed() const { assert( kind != CaseStmtK ); return firstTarget.used; }
    81         bool isFallUsed() const { assert( kind == CaseStmtK ); return firstTarget.used; }
     80        bool isBreakUsed() const { assert( kind != CaseClauseK ); return firstTarget.used; }
     81        bool isFallUsed() const { assert( kind == CaseClauseK ); return firstTarget.used; }
    8282        bool isFallDefaultUsed() const { assert( kind == SwitchStmtK ); return secondTarget.used; }
    8383        void seenDefault() { fallDefaultValid = false; }
     
    115115        void previsit( const ForStmt * );
    116116        const ForStmt * postvisit( const ForStmt * );
    117         const CaseStmt * previsit( const CaseStmt * );
     117        const CaseClause * previsit( const CaseClause * );
    118118        void previsit( const IfStmt * );
    119119        const IfStmt * postvisit( const IfStmt * );
     
    123123        void previsit( const TryStmt * );
    124124        void postvisit( const TryStmt * );
    125         void previsit( const FinallyStmt * );
     125        void previsit( const FinallyClause * );
    126126
    127127        const Stmt * mutateLoop( const Stmt * body, Entry& );
     
    288288                  auto switchStmt = strict_dynamic_cast< const SwitchStmt * >( targetEntry->stmt );
    289289                  bool foundDefault = false;
    290                   for ( auto subStmt : switchStmt->stmts ) {
    291                           const CaseStmt * caseStmt = subStmt.strict_as<CaseStmt>();
     290                  for ( auto caseStmt : switchStmt->cases ) {
    292291                          if ( caseStmt->isDefault() ) {
    293292                                  foundDefault = true;
     
    365364}
    366365
    367 const CaseStmt * MultiLevelExitCore::previsit( const CaseStmt * stmt ) {
     366const CaseClause * MultiLevelExitCore::previsit( const CaseClause * stmt ) {
    368367        visit_children = false;
    369368
     
    375374
    376375        // The cond may not exist, but if it does update it now.
    377         visitor->maybe_accept( stmt, &CaseStmt::cond );
     376        visitor->maybe_accept( stmt, &CaseClause::cond );
    378377
    379378        // Just save the mutated node for simplicity.
    380         CaseStmt * mutStmt = mutate( stmt );
    381 
    382         Label fallLabel = newLabel( "fallThrough", stmt );
     379        CaseClause * mutStmt = mutate( stmt );
     380
     381        Label fallLabel = newLabel( "fallThrough", stmt->location );
    383382        if ( ! mutStmt->stmts.empty() ) {
     383                // These should already be in a block.
     384                auto first = mutStmt->stmts.front().get_and_mutate();
     385                auto block = strict_dynamic_cast<CompoundStmt *>( first );
     386
    384387                // Ensure that the stack isn't corrupted by exceptions in fixBlock.
    385388                auto guard = makeFuncGuard(
    386                         [&](){ enclosing_control_structures.emplace_back( mutStmt, fallLabel ); },
     389                        [&](){ enclosing_control_structures.emplace_back( mutStmt, block, fallLabel ); },
    387390                        [this](){ enclosing_control_structures.pop_back(); }
    388391                        );
    389392
    390                 // These should already be in a block.
    391                 auto block = mutate( mutStmt->stmts.front().strict_as<CompoundStmt>() );
    392393                block->kids = fixBlock( block->kids, true );
    393394
     
    396397                Entry & entry = enclosing_control_structures.back();
    397398                if ( entry.isFallUsed() ) {
    398                         mutStmt->stmts.push_back( labelledNullStmt( mutStmt->location, entry.useFallExit() ) );
     399                        mutStmt->stmts.push_back( labelledNullStmt( block->location, entry.useFallExit() ) );
    399400                }
    400401        }
     
    433434}
    434435
    435 bool isDefaultCase( const ptr<Stmt> & stmt ) {
    436         const CaseStmt * caseStmt = stmt.strict_as<CaseStmt>();
    437         return caseStmt->isDefault();
     436static bool isDefaultCase( const ptr<CaseClause> & caseClause ) {
     437        return caseClause->isDefault();
    438438}
    439439
    440440void MultiLevelExitCore::previsit( const SwitchStmt * stmt ) {
    441441        Label label = newLabel( "switchBreak", stmt );
    442         auto it = find_if( stmt->stmts.rbegin(), stmt->stmts.rend(), isDefaultCase );
    443 
    444         const CaseStmt * defaultCase = it != stmt->stmts.rend() ? (it)->strict_as<CaseStmt>() : nullptr;
    445         Label defaultLabel = defaultCase ? newLabel( "fallThroughDefault", defaultCase ) : Label( stmt->location, "" );
     442        auto it = find_if( stmt->cases.rbegin(), stmt->cases.rend(), isDefaultCase );
     443
     444        const CaseClause * defaultCase = it != stmt->cases.rend() ? (*it) : nullptr;
     445        Label defaultLabel = defaultCase ? newLabel( "fallThroughDefault", defaultCase->location ) : Label( stmt->location, "" );
    446446        enclosing_control_structures.emplace_back( stmt, label, defaultLabel );
    447447        GuardAction( [this]() { enclosing_control_structures.pop_back(); } );
     
    449449        // Collect valid labels for fallthrough. It starts with all labels at this level, then remove as each is seen during
    450450        // traversal.
    451         for ( const Stmt * stmt : stmt->stmts ) {
    452                 auto * caseStmt = strict_dynamic_cast< const CaseStmt * >( stmt );
     451        for ( const CaseClause * caseStmt : stmt->cases ) {
    453452                if ( caseStmt->stmts.empty() ) continue;
    454453                auto block = caseStmt->stmts.front().strict_as<CompoundStmt>();
     
    471470                // exit label and break to the last case, create a default case if no cases.
    472471                SwitchStmt * mutStmt = mutate( stmt );
    473                 if ( mutStmt->stmts.empty() ) {
    474                         mutStmt->stmts.push_back( new CaseStmt( mutStmt->location, nullptr, {} ) );
    475                 }
    476 
    477                 auto caseStmt = mutStmt->stmts.back().strict_as<CaseStmt>();
     472                if ( mutStmt->cases.empty() ) {
     473                        mutStmt->cases.push_back( new CaseClause( mutStmt->location, nullptr, {} ) );
     474                }
     475
     476                auto caseStmt = mutStmt->cases.back().get();
    478477                auto mutCase = mutate( caseStmt );
    479                 mutStmt->stmts.back() = mutCase;
     478                mutStmt->cases.back() = mutCase;
    480479
    481480                Label label( mutCase->location, "breakLabel" );
     
    514513}
    515514
    516 void MultiLevelExitCore::previsit( const FinallyStmt * ) {
     515void MultiLevelExitCore::previsit( const FinallyClause * ) {
    517516        GuardAction([this, old = move( enclosing_control_structures)](){ enclosing_control_structures = move(old); });
    518517        enclosing_control_structures = vector<Entry>();
  • src/InitTweak/InitTweak.cc

    rf5bace8 r400b8be  
    423423                                loc, targetLabel.newName(), { new ast::Attribute{ "unused" } } };
    424424
    425                         std::vector< ast::ptr< ast::Stmt > > branches;
     425                        std::vector< ast::ptr< ast::CaseClause > > branches;
    426426                        for ( const ast::Init * init : *listInit ) {
    427427                                auto condition = ast::ConstantExpr::from_ulong( loc, cond );
     
    432432                                stmts.emplace_back(
    433433                                        new ast::BranchStmt{ loc, ast::BranchStmt::Break, switchLabel } );
    434                                 branches.emplace_back( new ast::CaseStmt{ loc, condition, std::move( stmts ) } );
     434                                branches.emplace_back( new ast::CaseClause{ loc, condition, std::move( stmts ) } );
    435435                        }
    436436                        out.emplace_back( new ast::SwitchStmt{ loc, index, std::move( branches ) } );
  • src/ResolvExpr/Resolver.cc

    rf5bace8 r400b8be  
    12811281                const ast::ForStmt *         previsit( const ast::ForStmt * );
    12821282                const ast::SwitchStmt *      previsit( const ast::SwitchStmt * );
    1283                 const ast::CaseStmt *        previsit( const ast::CaseStmt * );
     1283                const ast::CaseClause *      previsit( const ast::CaseClause * );
    12841284                const ast::BranchStmt *      previsit( const ast::BranchStmt * );
    12851285                const ast::ReturnStmt *      previsit( const ast::ReturnStmt * );
    12861286                const ast::ThrowStmt *       previsit( const ast::ThrowStmt * );
    1287                 const ast::CatchStmt *       previsit( const ast::CatchStmt * );
    1288                 const ast::CatchStmt *       postvisit( const ast::CatchStmt * );
     1287                const ast::CatchClause *     previsit( const ast::CatchClause * );
     1288                const ast::CatchClause *     postvisit( const ast::CatchClause * );
    12891289                const ast::WaitForStmt *     previsit( const ast::WaitForStmt * );
    12901290                const ast::WithStmt *        previsit( const ast::WithStmt * );
     
    16151615        }
    16161616
    1617         const ast::CaseStmt * Resolver_new::previsit( const ast::CaseStmt * caseStmt ) {
     1617        const ast::CaseClause * Resolver_new::previsit( const ast::CaseClause * caseStmt ) {
    16181618                if ( caseStmt->cond ) {
    16191619                        std::deque< ast::InitAlternative > initAlts = currentObject.getOptions();
     
    16311631                        }
    16321632
    1633                         caseStmt = ast::mutate_field( caseStmt, &ast::CaseStmt::cond, newExpr );
     1633                        caseStmt = ast::mutate_field( caseStmt, &ast::CaseClause::cond, newExpr );
    16341634                }
    16351635                return caseStmt;
     
    16741674        }
    16751675
    1676         const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) {
     1676        const ast::CatchClause * Resolver_new::previsit( const ast::CatchClause * catchClause ) {
    16771677                // Until we are very sure this invarent (ifs that move between passes have then)
    16781678                // holds, check it. This allows a check for when to decode the mangling.
    1679                 if ( auto ifStmt = catchStmt->body.as<ast::IfStmt>() ) {
     1679                if ( auto ifStmt = catchClause->body.as<ast::IfStmt>() ) {
    16801680                        assert( ifStmt->then );
    16811681                }
    16821682                // Encode the catchStmt so the condition can see the declaration.
    1683                 if ( catchStmt->cond ) {
    1684                         ast::CatchStmt * stmt = mutate( catchStmt );
    1685                         stmt->body = new ast::IfStmt( stmt->location, stmt->cond, nullptr, stmt->body );
    1686                         stmt->cond = nullptr;
    1687                         return stmt;
    1688                 }
    1689                 return catchStmt;
    1690         }
    1691 
    1692         const ast::CatchStmt * Resolver_new::postvisit( const ast::CatchStmt * catchStmt ) {
     1683                if ( catchClause->cond ) {
     1684                        ast::CatchClause * clause = mutate( catchClause );
     1685                        clause->body = new ast::IfStmt( clause->location, clause->cond, nullptr, clause->body );
     1686                        clause->cond = nullptr;
     1687                        return clause;
     1688                }
     1689                return catchClause;
     1690        }
     1691
     1692        const ast::CatchClause * Resolver_new::postvisit( const ast::CatchClause * catchClause ) {
    16931693                // Decode the catchStmt so everything is stored properly.
    1694                 const ast::IfStmt * ifStmt = catchStmt->body.as<ast::IfStmt>();
     1694                const ast::IfStmt * ifStmt = catchClause->body.as<ast::IfStmt>();
    16951695                if ( nullptr != ifStmt && nullptr == ifStmt->then ) {
    16961696                        assert( ifStmt->cond );
    16971697                        assert( ifStmt->else_ );
    1698                         ast::CatchStmt * stmt = ast::mutate( catchStmt );
    1699                         stmt->cond = ifStmt->cond;
    1700                         stmt->body = ifStmt->else_;
     1698                        ast::CatchClause * clause = ast::mutate( catchClause );
     1699                        clause->cond = ifStmt->cond;
     1700                        clause->body = ifStmt->else_;
    17011701                        // ifStmt should be implicately deleted here.
    1702                         return stmt;
    1703                 }
    1704                 return catchStmt;
     1702                        return clause;
     1703                }
     1704                return catchClause;
    17051705        }
    17061706
Note: See TracChangeset for help on using the changeset viewer.