Changeset 3b0bc16 for src/AST


Ignore:
Timestamp:
Feb 1, 2022, 8:22:12 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
fde0a58
Parents:
729c991
Message:

change class name WhileStmt to WhileDoStmt, add else clause to WhileDoStmt and ForStmt, change names thenPart/ElsePart to then/else_

Location:
src/AST
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r729c991 r3b0bc16  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 14 16:15:00 2021
    13 // Update Count     : 37
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Feb  1 16:27:15 2022
     13// Update Count     : 39
    1414//
    1515
     
    393393                auto stmt = new IfStmt(
    394394                        get<Expression>().accept1( node->cond ),
    395                         get<Statement>().accept1( node->thenPart ),
    396                         get<Statement>().accept1( node->elsePart ),
     395                        get<Statement>().accept1( node->then ),
     396                        get<Statement>().accept1( node->else_ ),
    397397                        get<Statement>().acceptL( node->inits )
    398398                );
     
    419419        }
    420420
    421         const ast::Stmt * visit( const ast::WhileStmt * node ) override final {
     421        const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final {
    422422                if ( inCache( node ) ) return nullptr;
    423423                auto inits = get<Statement>().acceptL( node->inits );
    424                 auto stmt = new WhileStmt(
     424                auto stmt = new WhileDoStmt(
    425425                        get<Expression>().accept1( node->cond ),
    426426                        get<Statement>().accept1( node->body ),
     
    18721872                        old->location,
    18731873                        GET_ACCEPT_1(condition, Expr),
    1874                         GET_ACCEPT_1(thenPart, Stmt),
    1875                         GET_ACCEPT_1(elsePart, Stmt),
     1874                        GET_ACCEPT_1(then, Stmt),
     1875                        GET_ACCEPT_1(else_, Stmt),
    18761876                        GET_ACCEPT_V(initialization, Stmt),
    18771877                        GET_LABELS_V(old->labels)
     
    19021902        }
    19031903
    1904         virtual void visit( const WhileStmt * old ) override final {
     1904        virtual void visit( const WhileDoStmt * old ) override final {
    19051905                if ( inCache( old ) ) return;
    1906                 this->node = new ast::WhileStmt(
     1906                this->node = new ast::WhileDoStmt(
    19071907                        old->location,
    19081908                        GET_ACCEPT_1(condition, Expr),
  • src/AST/Fwd.hpp

    r729c991 r3b0bc16  
    1010// Created On       : Wed May  8 16:05:00 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 12 18:37:39 2021
    13 // Update Count     : 4
     12// Last Modified On : Tue Feb  1 09:08:33 2022
     13// Update Count     : 5
    1414//
    1515
     
    4444class DirectiveStmt;
    4545class IfStmt;
    46 class WhileStmt;
     46class WhileDoStmt;
    4747class ForStmt;
    4848class SwitchStmt;
  • src/AST/Node.cpp

    r729c991 r3b0bc16  
    1010// Created On       : Thu May 16 14:16:00 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 12 18:25:06 2021
    13 // Update Count     : 2
     12// Last Modified On : Tue Feb  1 09:09:39 2022
     13// Update Count     : 3
    1414//
    1515
     
    146146template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::weak >;
    147147template class ast::ptr_base< ast::IfStmt, ast::Node::ref_type::strong >;
    148 template class ast::ptr_base< ast::WhileStmt, ast::Node::ref_type::weak >;
    149 template class ast::ptr_base< ast::WhileStmt, ast::Node::ref_type::strong >;
     148template class ast::ptr_base< ast::WhileDoStmt, ast::Node::ref_type::weak >;
     149template class ast::ptr_base< ast::WhileDoStmt, ast::Node::ref_type::strong >;
    150150template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::weak >;
    151151template class ast::ptr_base< ast::ForStmt, ast::Node::ref_type::strong >;
  • src/AST/Pass.hpp

    r729c991 r3b0bc16  
    146146        const ast::Stmt *             visit( const ast::DirectiveStmt        * ) override final;
    147147        const ast::Stmt *             visit( const ast::IfStmt               * ) override final;
    148         const ast::Stmt *             visit( const ast::WhileStmt            * ) override final;
     148        const ast::Stmt *             visit( const ast::WhileDoStmt          * ) override final;
    149149        const ast::Stmt *             visit( const ast::ForStmt              * ) override final;
    150150        const ast::Stmt *             visit( const ast::SwitchStmt           * ) override final;
  • src/AST/Pass.impl.hpp

    r729c991 r3b0bc16  
    756756                maybe_accept( node, &IfStmt::inits    );
    757757                maybe_accept( node, &IfStmt::cond     );
    758                 maybe_accept_as_compound( node, &IfStmt::thenPart );
    759                 maybe_accept_as_compound( node, &IfStmt::elsePart );
     758                maybe_accept_as_compound( node, &IfStmt::then );
     759                maybe_accept_as_compound( node, &IfStmt::else_ );
    760760        }
    761761
     
    764764
    765765//--------------------------------------------------------------------------
    766 // WhileStmt
    767 template< typename core_t >
    768 const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileStmt * node ) {
     766// WhileDoStmt
     767template< typename core_t >
     768const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileDoStmt * node ) {
    769769        VISIT_START( node );
    770770
     
    772772                // while statements introduce a level of scope (for the initialization)
    773773                guard_symtab guard { *this };
    774                 maybe_accept( node, &WhileStmt::inits );
    775                 maybe_accept( node, &WhileStmt::cond  );
    776                 maybe_accept_as_compound( node, &WhileStmt::body  );
     774                maybe_accept( node, &WhileDoStmt::inits );
     775                maybe_accept( node, &WhileDoStmt::cond  );
     776                maybe_accept_as_compound( node, &WhileDoStmt::body  );
    777777        }
    778778
  • src/AST/Print.cpp

    r729c991 r3b0bc16  
    511511                ++indent;
    512512                os << indent;
    513                 safe_print( node->thenPart );
    514                 --indent;
    515 
    516                 if ( node->elsePart != 0 ) {
     513                safe_print( node->then );
     514                --indent;
     515
     516                if ( node->else_ != 0 ) {
    517517                        os << indent << "... else:" << endl;
    518518                        ++indent;
    519519                        os << indent;
    520                         node->elsePart->accept( *this );
     520                        node->else_->accept( *this );
    521521                        --indent;
    522522                } // if
     
    524524        }
    525525
    526         virtual const ast::Stmt * visit( const ast::WhileStmt * node ) override final {
     526        virtual const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final {
    527527                if ( node->isDoWhile ) { os << "Do-"; }
    528528                os << "While on condition:" << endl;
  • src/AST/Stmt.hpp

    r729c991 r3b0bc16  
    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 ); }
  • src/AST/Visitor.hpp

    r729c991 r3b0bc16  
    1010// Created On       : Thr May 9 15:28:00 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 12 18:25:07 2021
    13 // Update Count     : 1
     12// Last Modified On : Tue Feb  1 09:09:34 2022
     13// Update Count     : 2
    1414//
    1515
     
    3838    virtual const ast::Stmt *             visit( const ast::DirectiveStmt        * ) = 0;
    3939    virtual const ast::Stmt *             visit( const ast::IfStmt               * ) = 0;
    40     virtual const ast::Stmt *             visit( const ast::WhileStmt            * ) = 0;
     40    virtual const ast::Stmt *             visit( const ast::WhileDoStmt          * ) = 0;
    4141    virtual const ast::Stmt *             visit( const ast::ForStmt              * ) = 0;
    4242    virtual const ast::Stmt *             visit( const ast::SwitchStmt           * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.