Changeset 2e9b59b for src/AST/Stmt.hpp


Ignore:
Timestamp:
Apr 19, 2022, 3:00:04 PM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
5b84a321
Parents:
ba897d21 (diff), bb7c77d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

added benchmark and evaluations chapter to thesis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Stmt.hpp

    rba897d21 r2e9b59b  
    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};
Note: See TracChangeset for help on using the changeset viewer.