Changeset 8cb149f for src/AST/Stmt.hpp


Ignore:
Timestamp:
Feb 2, 2022, 2:50:46 PM (4 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
21a99cc
Parents:
4de48c5 (diff), 4e7171f (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Stmt.hpp

    r4de48c5 r8cb149f  
    1010// Created On       : Wed May  8 13:00:00 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 31 22:38:53 2022
    13 // Update Count     : 12
     12// Last Modified On : Tue Feb  1 17:44:46 2022
     13// Update Count     : 24
    1414//
    1515
     
    4242                : ParseNode(loc), labels(std::move(labels)) {}
    4343
    44         Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {}
     44        Stmt(const Stmt & o) : ParseNode(o), labels(o.labels) {}
    4545
    4646        const Stmt * accept( Visitor & v ) const override = 0;
     
    5656
    5757        CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {},
    58                                  std::vector<Label>&& labels = {} )
     58                                 std::vector<Label> && labels = {} )
    5959                : Stmt(loc, std::move(labels)), kids(std::move(ks)) {}
    6060
    61         CompoundStmt( const CompoundStmt& o );
    62         CompoundStmt( CompoundStmt&& o ) = default;
     61        CompoundStmt( const CompoundStmt & o );
     62        CompoundStmt( CompoundStmt && o ) = default;
    6363
    6464        void push_back( const Stmt * s ) { kids.emplace_back( s ); }
     
    8888        ptr<Expr> expr;
    8989
    90         ExprStmt( const CodeLocation& loc, const Expr* e, std::vector<Label>&& labels = {} )
     90        ExprStmt( const CodeLocation & loc, const Expr* e, std::vector<Label> && labels = {} )
    9191                : Stmt(loc, std::move(labels)), expr(e) {}
    9292
     
    139139  public:
    140140        ptr<Expr> cond;
    141         ptr<Stmt> thenPart;
    142         ptr<Stmt> elsePart;
     141        ptr<Stmt> then;
     142        ptr<Stmt> else_;
    143143        std::vector<ptr<Stmt>> inits;
    144144
    145         IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * thenPart,
    146                         const Stmt * elsePart = nullptr, std::vector<ptr<Stmt>> && inits = {},
     145        IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * then,
     146                        const Stmt * else_ = nullptr, std::vector<ptr<Stmt>> && inits = {},
    147147                        std::vector<Label> && labels = {} )
    148                 : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart),
     148                : Stmt(loc, std::move(labels)), cond(cond), then(then), else_(else_),
    149149                  inits(std::move(inits)) {}
    150150
     
    191191
    192192// While loop: while (...) ... else ... or do ... while (...) else ...;
    193 class WhileStmt final : public Stmt {
     193class WhileDoStmt final : public Stmt {
    194194  public:
    195195        ptr<Expr> cond;
    196196        ptr<Stmt> body;
    197         ptr<Stmt> elsePart;
     197        ptr<Stmt> else_;
    198198        std::vector<ptr<Stmt>> inits;
    199199        bool isDoWhile;
    200200
    201         WhileStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body,
     201        WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body,
    202202                           std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} )
    203                 : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)), isDoWhile(isDoWhile) {}
    204 
    205         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    206   private:
    207         WhileStmt * clone() const override { return new WhileStmt{ *this }; }
     203                : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(nullptr), inits(std::move(inits)), isDoWhile(isDoWhile) {}
     204
     205        WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, const Stmt * else_,
     206                           std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} )
     207                : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(else_), inits(std::move(inits)), isDoWhile(isDoWhile) {}
     208
     209        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     210  private:
     211        WhileDoStmt * clone() const override { return new WhileDoStmt{ *this }; }
    208212        MUTATE_FRIEND
    209213};
     
    216220        ptr<Expr> inc;
    217221        ptr<Stmt> body;
    218         ptr<Stmt> elsePart;
     222        ptr<Stmt> else_;
    219223
    220224        ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond,
    221                          const Expr * inc, const Stmt * body, std::vector<Label> && labels = {} )
    222                 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body) {}
     225                         const Expr * inc, const Stmt * body, std::vector<Label> && label = {} )
     226                : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {}
     227
     228        ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond,
     229                         const Expr * inc, const Stmt * body, const Stmt * else_, std::vector<Label> && labels = {} )
     230                : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {}
    223231
    224232        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
Note: See TracChangeset for help on using the changeset viewer.