Changeset 6c3744e for translator/ControlStruct/LabelFixer.cc
- Timestamp:
- Jan 19, 2015, 6:29:10 PM (10 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ControlStruct/LabelFixer.cc
r0b8cd722 r6c3744e 24 24 } 25 25 26 void LabelFixer::visit( FunctionDecl *functionDecl) {26 void LabelFixer::visit( FunctionDecl *functionDecl ) { 27 27 if ( functionDecl->get_statements() != 0 ) 28 28 functionDecl->get_statements()->accept( *this ); … … 32 32 } 33 33 34 void LabelFixer::visit( Statement *stmt ) {34 void LabelFixer::visit( Statement *stmt ) { 35 35 std::list< Label > &labels = stmt->get_labels(); 36 36 … … 42 42 } 43 43 44 void LabelFixer::visit( BranchStmt *branchStmt) {44 void LabelFixer::visit( BranchStmt *branchStmt ) { 45 45 visit ( ( Statement * )branchStmt ); // the labels this statement might have 46 46 … … 50 50 } //else /* computed goto or normal exit-loop statements */ 51 51 } 52 53 52 54 53 Label LabelFixer::setLabelsDef( std::list< Label > &llabel, Statement *definition ) { … … 61 60 { used = true; labelTable[ *i ] = entry; } // undefined and unused 62 61 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 ); 65 64 else 66 65 labelTable[ *i ]->set_definition( definition ); … … 82 81 } 83 82 84 std::map <Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {85 std::map 83 std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) { 84 std::map< Statement *, Entry * > def_us; 86 85 87 for ( std::map 86 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); i++ ) { 88 87 Entry *e = i->second; 89 88 … … 91 90 def_us[ e->get_definition() ] = e; 92 91 else 93 if (e->used())92 if ( e->used() ) 94 93 def_us[ e->get_definition() ]->add_uses( e->get_uses() ); 95 94 } 96 95 97 96 // get rid of labelTable 98 for ( std::map 97 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); i++ ) { 99 98 Statement *to = (*i).first; 100 std::list 99 std::list< Statement *> &from = (*i).second->get_uses(); 101 100 Label finalLabel = generator->newLabel(); 102 101 (*i).second->set_label( finalLabel ); … … 114 113 115 114 for ( std::list< Statement *>::iterator j = from.begin(); j != from.end(); j++ ) { 116 BranchStmt *jumpTo = dynamic_cast 115 BranchStmt *jumpTo = dynamic_cast< BranchStmt * > ( *j ); 117 116 assert( jumpTo != 0 ); 118 117 jumpTo->set_target( finalLabel ); … … 121 120 122 121 // 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++ ) 125 124 (*ret)[ (*i).second->get_label() ] = (*i).first; 126 125
Note: See TracChangeset
for help on using the changeset viewer.