Changeset 23b6f4d7


Ignore:
Timestamp:
Jun 23, 2016, 12:16:45 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, 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, with_gc
Children:
71a145de
Parents:
0caaa6a
git-author:
Rob Schluntz <rschlunt@…> (06/23/16 11:34:11)
git-committer:
Rob Schluntz <rschlunt@…> (06/23/16 12:16:45)
Message:

change Label type from std::string to a custom Label class, link label to its statement

Location:
src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/LabelFixer.cc

    r0caaa6a r23b6f4d7  
    9595
    9696                for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ ) {
    97                         if ( labelTable.find( *i ) == labelTable.end() ) {
     97                        Label & l = *i;
     98                        l.set_statement( definition ); // attach statement to the label to be used later
     99                        if ( labelTable.find( l ) == labelTable.end() ) {
    98100                                // all labels on this statement need to use the same entry, so this should only be created once
    99101                                // undefined and unused until now, add an entry
    100                                 labelTable[ *i ] =  e;
    101                         } else if ( labelTable[ *i ]->defined() ) {
     102                                labelTable[ l ] =  e;
     103                        } else if ( labelTable[ l ]->defined() ) {
    102104                                // defined twice, error
    103                                 throw SemanticError( "Duplicate definition of label: " + (*i).get_name() );
     105                                throw SemanticError( "Duplicate definition of label: " + l.get_name() );
    104106                        }       else {
    105107                                // used previously, but undefined until now -> link with this entry
    106                                 delete labelTable[ *i ];
    107                                 labelTable[ *i ] = e;
     108                                delete labelTable[ l ];
     109                                labelTable[ l ] = e;
    108110                        } // if
    109111                } // for
     
    114116        }
    115117
    116         // A label was used, add it ot the table if it isn't already there
     118        // A label was used, add it to the table if it isn't already there
    117119        template< typename UsageNode >
    118120        void LabelFixer::setLabelsUsg( Label orgValue, UsageNode *use ) {
  • src/ControlStruct/MLEMutator.cc

    r0caaa6a r23b6f4d7  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // MLEMutator.cc -- 
     7// MLEMutator.cc --
    88//
    99// Author           : Rodolfo G. Esteves
     
    1414//
    1515
    16 // NOTE: There are two known subtle differences from the code that uC++ 
     16// NOTE: There are two known subtle differences from the code that uC++
    1717// generates for the same input
    1818// -CFA puts the break label inside at the end of a switch, uC++ puts it after
     
    3434        }
    3535
    36         // break labels have to come after the statement they break out of, 
     36        // break labels have to come after the statement they break out of,
    3737        // so mutate a statement, then if they inform us through the breakLabel field
    38         // tha they need a place to jump to on a break statement, add the break label 
     38        // tha they need a place to jump to on a break statement, add the break label
    3939        // to the body of statements
    4040        void MLEMutator::fixBlock( std::list< Statement * > &kids ) {
     
    4444                        if ( ! get_breakLabel().empty() ) {
    4545                                std::list< Statement * >::iterator next = k+1;
     46                                Statement * stmt = 0;
    4647                                if ( next == kids.end() ) {
    4748                                        std::list<Label> ls; ls.push_back( get_breakLabel() );
    48                                         kids.push_back( new NullStmt( ls ) );
     49                                        kids.push_back( stmt = new NullStmt( ls ) );
    4950                                } else {
    50                                         (*next)->get_labels().push_back( get_breakLabel() );
     51                                        (stmt = *next)->get_labels().push_back( get_breakLabel() );
    5152                                }
     53                                stmt->get_labels().front().set_statement( stmt );
    5254
    5355                                set_breakLabel("");
     
    8183        template< typename LoopClass >
    8284        Statement *MLEMutator::handleLoopStmt( LoopClass *loopStmt ) {
    83                 // remember this as the most recent enclosing loop, then mutate 
     85                // remember this as the most recent enclosing loop, then mutate
    8486                // the body of the loop -- this will determine whether brkLabel
    8587                // and contLabel are used with branch statements
     
    111113        template< typename SwitchClass >
    112114        Statement *MLEMutator::handleSwitchStmt( SwitchClass *switchStmt ) {
    113                 // generate a label for breaking out of a labeled switch 
     115                // generate a label for breaking out of a labeled switch
    114116                Label brkLabel = generator->newLabel("switchBreak");
    115117                enclosingSwitches.push_back( Entry(switchStmt, brkLabel) );
    116                 mutateAll( switchStmt->get_branches(), *this ); 
     118                mutateAll( switchStmt->get_branches(), *this );
    117119
    118120                Entry &e = enclosingSwitches.back();
     
    121123                // only generate break label if labeled break is used
    122124                if (e.isBreakUsed()) {
    123                         // for the purposes of keeping switch statements uniform (i.e. all statements that are 
    124                         // direct children of a switch should be CastStmts), append the exit label + break to the 
     125                        // for the purposes of keeping switch statements uniform (i.e. all statements that are
     126                        // direct children of a switch should be CastStmts), append the exit label + break to the
    125127                        // last case statement; create a default case if there are no cases
    126128                        std::list< Statement * > &branches = switchStmt->get_branches();
     
    131133                        if ( CaseStmt * c = dynamic_cast< CaseStmt * >( branches.back() ) ) {
    132134                                std::list<Label> temp; temp.push_back( brkLabel );
    133                                 c->get_statements().push_back( new BranchStmt( temp, Label(""), BranchStmt::Break ) );
     135                                Statement * stmt = new BranchStmt( temp, Label(""), BranchStmt::Break );
     136                                stmt->get_labels().front().set_statement( stmt );
     137                                c->get_statements().push_back( stmt );
    134138                        } else assert(0); // as of this point, all branches of a switch are still CaseStmts
    135139                }
     
    206210                        // continue label goes in the body as the last statement
    207211                        std::list< Label > labels; labels.push_back( e.useContExit() );
    208                         newBody->get_kids().push_back( new NullStmt( labels ) );                       
     212                        Statement * stmt = new NullStmt( labels );
     213                        stmt->get_labels().front().set_statement( stmt );
     214                        newBody->get_kids().push_back( stmt );
    209215                }
    210216
    211217                if ( e.isBreakUsed() ) {
    212                         // break label goes after the loop -- it'll get set by the 
     218                        // break label goes after the loop -- it'll get set by the
    213219                        // outer mutator if we do this
    214                         set_breakLabel( e.useBreakExit() );                     
     220                        set_breakLabel( e.useBreakExit() );
    215221                }
    216222
     
    231237
    232238        Statement *MLEMutator::mutate( ChooseStmt *switchStmt ) {
    233                 return handleSwitchStmt( switchStmt );         
     239                return handleSwitchStmt( switchStmt );
    234240        }
    235241
Note: See TracChangeset for help on using the changeset viewer.