Ignore:
Timestamp:
Feb 1, 2022, 8:22:12 PM (2 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_

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Statement.cc

    r729c991 r3b0bc16  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jan 20 16:03:00 2020
    13 // Update Count     : 71
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Feb  1 17:55:29 2022
     13// Update Count     : 79
    1414//
    1515
     
    145145}
    146146
    147 IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, std::list<Statement *> initialization ):
    148         Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
     147IfStmt::IfStmt( Expression * condition, Statement * then, Statement * else_, std::list<Statement *> initialization ):
     148        Statement(), condition( condition ), then( then ), else_( else_ ), initialization( initialization ) {}
    149149
    150150IfStmt::IfStmt( const IfStmt & other ) :
    151         Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {
     151        Statement( other ), condition( maybeClone( other.condition ) ), then( maybeClone( other.then ) ), else_( maybeClone( other.else_ ) ) {
    152152        cloneAll( other.initialization, initialization );
    153153}
     
    156156        deleteAll( initialization );
    157157        delete condition;
    158         delete thenPart;
    159         delete elsePart;
     158        delete then;
     159        delete else_;
    160160}
    161161
     
    177177
    178178        os << indent+1;
    179         thenPart->print( os, indent+1 );
    180 
    181         if ( elsePart != nullptr ) {
     179        then->print( os, indent+1 );
     180
     181        if ( else_ != nullptr ) {
    182182                os << indent << "... else: " << endl;
    183183                os << indent+1;
    184                 elsePart->print( os, indent+1 );
     184                else_->print( os, indent+1 );
    185185        } // if
    186186}
     
    246246}
    247247
    248 WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ):
    249         Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) {
    250 }
    251 
    252 WhileStmt::WhileStmt( const WhileStmt & other ):
     248WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ):
     249        Statement(), condition( condition ), body( body ), else_( nullptr ), initialization( initialization ), isDoWhile( isDoWhile) {
     250}
     251
     252WhileDoStmt::WhileDoStmt( Expression * condition, Statement * body, Statement * else_, std::list< Statement * > & initialization, bool isDoWhile ):
     253        Statement(), condition( condition), body( body ), else_( else_ ), initialization( initialization ), isDoWhile( isDoWhile) {
     254}
     255
     256WhileDoStmt::WhileDoStmt( const WhileDoStmt & other ):
    253257        Statement( other ), condition( maybeClone( other.condition ) ), body( maybeClone( other.body ) ), isDoWhile( other.isDoWhile ) {
    254258}
    255259
    256 WhileStmt::~WhileStmt() {
     260WhileDoStmt::~WhileDoStmt() {
    257261        delete body;
    258262        delete condition;
    259263}
    260264
    261 void WhileStmt::print( std::ostream & os, Indenter indent ) const {
     265void WhileDoStmt::print( std::ostream & os, Indenter indent ) const {
    262266        os << "While on condition: " << endl ;
    263267        condition->print( os, indent+1 );
     
    268272}
    269273
    270 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ):
    271         Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
     274ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body, Statement * else_ ):
     275        Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ), else_( else_ ) {
    272276}
    273277
    274278ForStmt::ForStmt( const ForStmt & other ):
    275         Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ) {
     279        Statement( other ), condition( maybeClone( other.condition ) ), increment( maybeClone( other.increment ) ), body( maybeClone( other.body ) ), else_( maybeClone( other.else_ ) ) {
    276280                cloneAll( other.initialization, initialization );
    277281
     
    283287        delete increment;
    284288        delete body;
     289        delete else_;
    285290}
    286291
     
    311316                os << "\n" << indent << "... with body: \n" << indent+1;
    312317                body->print( os, indent+1 );
     318        }
     319
     320        if ( else_ != nullptr ) {
     321                os << "\n" << indent << "... with body: \n" << indent+1;
     322                else_->print( os, indent+1 );
    313323        }
    314324        os << endl;
Note: See TracChangeset for help on using the changeset viewer.