Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/MLEMutator.cc

    rbe5aa1b rd939274  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed May 27 16:19:32 2015
    13 // Update Count     : 44
     12// Last Modified On : Tue Jun 02 13:43:01 2015
     13// Update Count     : 92
    1414//
    1515
     
    3333                } // if
    3434
     35                // a child statement may set the break label
     36                // - if they do, attach it to the next statement
    3537                std::list< Statement * > &kids = cmpndStmt->get_kids();
    3638                for ( std::list< Statement * >::iterator k = kids.begin(); k != kids.end(); k++ ) {
     
    3840
    3941                        if ( ! get_breakLabel().empty() ) {
    40                                 std::list< Statement * >::iterator next = k; next++;
     42                                std::list< Statement * >::iterator next = k+1;
    4143                                if ( next == kids.end() ) {
    4244                                        std::list<Label> ls; ls.push_back( get_breakLabel() );
     
    5860                } // if
    5961
    60                 //mutateAll( cmpndStmt->get_kids(), *this );
    6162                return cmpndStmt;
    6263        }
     
    7677        Statement *MLEMutator::mutate( ForStmt *forStmt ) {
    7778                enclosingLoops.push_back( Entry( forStmt ) );
    78                 maybeMutate( forStmt->get_body(), *this );
     79                forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) );
    7980
    8081                Entry &e = enclosingLoops.back();
     
    154155                Label brkLabel = generator->newLabel();
    155156                enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) );
    156                 mutateAll( switchStmt->get_branches(), mutator ); {
     157                mutateAll( switchStmt->get_branches(), mutator );
     158                {
    157159                        // check if this is necessary (if there is a break to this point, otherwise do not generate
    158                         std::list<Label> temp; temp.push_back( brkLabel );
    159                         switchStmt->get_branches().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );
     160
     161                        // for the purposes of keeping switch statements uniform (i.e. all statements that are
     162                        // direct children of a switch should be CastStmts), append the exit label + break to the
     163                        // last case statement; create a default case if there are no cases
     164                        std::list< Statement * > &branches = switchStmt->get_branches();
     165                        if ( branches.empty() ) {
     166                                branches.push_back( CaseStmt::makeDefault() );
     167                        }
     168
     169                        if ( CaseStmt * c = dynamic_cast< CaseStmt * >( branches.back() ) ) {
     170                                std::list<Label> temp; temp.push_back( brkLabel );
     171                                c->get_statements().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );
     172                        } else assert(0);
    160173                }
    161174                assert ( enclosingSwitches.back() == switchStmt );
     
    173186
    174187        Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) {
     188                // ensure loop body is a block
    175189                CompoundStmt *newBody;
    176190                if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) {
     
    204218        }
    205219
    206         //*** Entry's methods
     220        //*** Entry's methods - ensure these labels can be set at most once
    207221        void MLEMutator::Entry::set_contExit( Label l ) {
    208222                assert ( contExit == "" || contExit == l );
Note: See TracChangeset for help on using the changeset viewer.