Changeset 2bf9c37
- Timestamp:
- Sep 1, 2017, 2:39:52 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- a984e65
- Parents:
- 9b18044
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r9b18044 r2bf9c37 172 172 auto filter(Args&&... args) -> decltype(std::copy_if(std::forward<Args>(args)...)) { 173 173 return std::copy_if(std::forward<Args>(args)...); 174 } 175 176 template <typename E, typename UnaryPredicate, template< typename, typename...> class Container, typename... Args > 177 void filter( Container< E *, Args... > & container, UnaryPredicate pred, bool doDelete ) { 178 auto i = begin( container ); 179 while ( i != end( container ) ) { 180 auto it = next( i ); 181 if ( pred( *i ) ) { 182 if ( doDelete ) { 183 delete *i; 184 } // if 185 container.erase( i ); 186 } // if 187 i = it; 188 } // while 174 189 } 175 190 -
src/SymTab/Validate.cc
r9b18044 r2bf9c37 291 291 292 292 HoistStruct::HoistStruct() : inStruct( false ) { 293 }294 295 void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {296 std::list< Declaration * >::iterator i = declList.begin();297 while ( i != declList.end() ) {298 std::list< Declaration * >::iterator next = i;299 ++next;300 if ( pred( *i ) ) {301 if ( doDelete ) {302 delete *i;303 } // if304 declList.erase( i );305 } // if306 i = next;307 } // while308 293 } 309 294 … … 797 782 CompoundStmt *ret = Mutator::mutate( compoundStmt ); 798 783 scopeLevel -= 1; 799 std::list< Statement * >::iterator i = compoundStmt->get_kids().begin(); 800 while ( i != compoundStmt->get_kids().end() ) { 801 std::list< Statement * >::iterator next = i+1; 802 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) { 784 // remove and delete decl stmts 785 filter( compoundStmt->kids, [](Statement * stmt) { 786 if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( stmt ) ) { 803 787 if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) { 804 delete *i; 805 compoundStmt->get_kids().erase( i ); 788 return true; 806 789 } // if 807 790 } // if 808 i = next;809 } // while791 return false; 792 }, true); 810 793 typedefNames.endScope(); 811 794 return ret; … … 816 799 template<typename AggDecl> 817 800 AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) { 818 std::list<Declaration *>::iterator it = aggDecl->get_members().begin(); 819 for ( ; it != aggDecl->get_members().end(); ) { 820 std::list< Declaration * >::iterator next = it+1; 821 if ( dynamic_cast< TypedefDecl * >( *it ) ) { 822 delete *it; 823 aggDecl->get_members().erase( it ); 824 } // if 825 it = next; 826 } 801 filter( aggDecl->members, isTypedef, true ); 827 802 return aggDecl; 828 803 }
Note: See TracChangeset
for help on using the changeset viewer.