Ignore:
Timestamp:
Jan 19, 2015, 6:29:10 PM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
f7f6785
Parents:
0b8cd722
Message:

add list initializer, formatting changes

Location:
translator/ControlStruct
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • translator/ControlStruct/LabelFixer.cc

    r0b8cd722 r6c3744e  
    2424    }
    2525
    26     void LabelFixer::visit(FunctionDecl *functionDecl) {
     26    void LabelFixer::visit( FunctionDecl *functionDecl ) {
    2727        if ( functionDecl->get_statements() != 0 )
    2828            functionDecl->get_statements()->accept( *this );
     
    3232    }
    3333
    34     void LabelFixer::visit(Statement *stmt ) {
     34    void LabelFixer::visit( Statement *stmt ) {
    3535        std::list< Label > &labels = stmt->get_labels();
    3636
     
    4242    }
    4343
    44     void LabelFixer::visit(BranchStmt *branchStmt) {
     44    void LabelFixer::visit( BranchStmt *branchStmt ) {
    4545        visit ( ( Statement * )branchStmt );  // the labels this statement might have
    4646
     
    5050        } //else       /* computed goto or normal exit-loop statements */
    5151    }
    52 
    5352
    5453    Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) {
     
    6160                { used = true; labelTable[ *i ] = entry; } // undefined and unused
    6261            else
    63                 if( labelTable[ *i ]->defined() )
    64                     throw SemanticError("Duplicate definition of label: " + *i );
     62                if ( labelTable[ *i ]->defined() )
     63                    throw SemanticError( "Duplicate definition of label: " + *i );
    6564                else
    6665                    labelTable[ *i ]->set_definition( definition );
     
    8281    }
    8382
    84     std::map < Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {
    85         std::map < Statement *, Entry * > def_us;
     83    std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {
     84        std::map< Statement *, Entry * > def_us;
    8685
    87         for ( std::map < Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) {
     86        for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) {
    8887            Entry *e = i->second;
    8988
     
    9190                def_us[ e->get_definition() ] = e;
    9291            else
    93                 if(e->used())
     92                if ( e->used() )
    9493                    def_us[ e->get_definition() ]->add_uses( e->get_uses() );
    9594        }
    9695
    9796        // get rid of labelTable
    98         for ( std::map < Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) {
     97        for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) {
    9998            Statement *to = (*i).first;
    100             std::list < Statement *> &from = (*i).second->get_uses();
     99            std::list< Statement *> &from = (*i).second->get_uses();
    101100            Label finalLabel = generator->newLabel();
    102101            (*i).second->set_label( finalLabel );
     
    114113
    115114            for ( std::list< Statement *>::iterator j = from.begin(); j != from.end(); j++ ) {
    116                 BranchStmt *jumpTo = dynamic_cast < BranchStmt * > ( *j );
     115                BranchStmt *jumpTo = dynamic_cast< BranchStmt * > ( *j );
    117116                assert( jumpTo != 0 );
    118117                jumpTo->set_target( finalLabel );
     
    121120
    122121        // reverse table
    123         std::map < Label, Statement * > *ret = new std::map < Label, Statement * >();
    124         for (std::map < Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ )
     122        std::map< Label, Statement * > *ret = new std::map< Label, Statement * >();
     123        for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ )
    125124            (*ret)[ (*i).second->get_label() ] = (*i).first;
    126125
  • translator/ControlStruct/MLEMutator.cc

    r0b8cd722 r6c3744e  
    1212    }
    1313
    14     CompoundStmt* MLEMutator::mutate(CompoundStmt *cmpndStmt) {
     14    CompoundStmt* MLEMutator::mutate( CompoundStmt *cmpndStmt ) {
    1515        bool labeledBlock = false;
    1616        if ( !((cmpndStmt->get_labels()).empty()) ) {
     
    2727                if ( next == kids.end() ) {
    2828                    std::list<Label> ls; ls.push_back( get_breakLabel() );
    29                     kids.push_back( new NullStmt(ls) );
     29                    kids.push_back( new NullStmt( ls ) );
    3030                } else
    3131                    (*next)->get_labels().push_back( get_breakLabel() );
     
    8888        std::list< Entry >::iterator check;
    8989        if ( ( check = std::find( enclosingLoops.begin(), enclosingLoops.end(), (*targetTable)[branchStmt->get_target()] ) ) == enclosingLoops.end() )
    90             // not in loop, checking if in switch/choose
     90            // not in loop, checking if in block
    9191            if ( (check = std::find( enclosingBlocks.begin(), enclosingBlocks.end(), (*targetTable)[branchStmt->get_target()] )) == enclosingBlocks.end() )
    9292                // neither in loop nor in block, checking if in switch/choose
     
    9595
    9696        if ( enclosingLoops.back() == (*check) )
    97             return branchStmt;                      // exit the innermost loop (labels not necessary)
     97            return branchStmt;                          // exit the innermost loop (labels unnecessary)
    9898
    9999        Label newLabel;
     
    102102            if ( check->get_breakExit() != "" )
    103103                newLabel = check->get_breakExit();
    104             else { newLabel = generator->newLabel(); check->set_breakExit( newLabel ); }
     104            else {
     105                newLabel = generator->newLabel();
     106                check->set_breakExit( newLabel );
     107            } // if
    105108            break;
    106109          case BranchStmt::Continue:
    107110            if ( check->get_contExit() != "" )
    108111                newLabel = check->get_contExit();
    109             else { newLabel = generator->newLabel(); check->set_contExit( newLabel ); }
     112            else {
     113                newLabel = generator->newLabel();
     114                check->set_contExit( newLabel );
     115            } // if
    110116            break;
    111117          default:
    112             // shouldn't be here
    113             return 0;
     118            return 0;                                   // shouldn't be here
    114119        } // switch
    115120
    116         return new BranchStmt(std::list<Label>(), newLabel, BranchStmt::Goto );
     121        return new BranchStmt( std::list<Label>(), newLabel, BranchStmt::Goto );
    117122    }
    118123
    119124
    120     Statement *MLEMutator::mutate(SwitchStmt *switchStmt) {
     125    Statement *MLEMutator::mutate( SwitchStmt *switchStmt ) {
    121126        Label brkLabel = generator->newLabel();
    122127        enclosingSwitches.push_back( Entry(switchStmt, "", brkLabel) );
     
    131136    }
    132137
    133     Statement *MLEMutator::mutate(ChooseStmt *switchStmt) {
     138    Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) {
    134139        Label brkLabel = generator->newLabel();
    135140        enclosingSwitches.push_back( Entry(switchStmt,"", brkLabel) );
  • translator/ControlStruct/MLEMutator.h

    r0b8cd722 r6c3744e  
    1515        class Entry;
    1616      public:
    17         MLEMutator( std::map <Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
     17        MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {}
    1818        ~MLEMutator();
    1919
     
    5656        };
    5757
    58         std::map <Label, Statement *> *targetTable;
    59         std::list < Entry > enclosingBlocks,enclosingLoops,enclosingSwitches;
     58        std::map< Label, Statement * > *targetTable;
     59        std::list< Entry > enclosingBlocks, enclosingLoops, enclosingSwitches;
    6060        Label breakLabel;
    6161        LabelGenerator *generator;
Note: See TracChangeset for help on using the changeset viewer.