Changeset ec79847 for src/InitTweak
- Timestamp:
- May 9, 2016, 12:41:50 PM (9 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, with_gc
- Children:
- fb24492
- Parents:
- 9e2c1f0
- Location:
- src/InitTweak
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r9e2c1f0 rec79847 10 10 // Created On : Mon May 04 15:14:56 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri May 06 16:14:13201612 // Last Modified On : Mon May 09 11:44:29 2016 13 13 // Update Count : 2 14 14 // … … 92 92 GlobalFixer fixer( name, inLibrary ); 93 93 acceptAll( translationUnit, fixer ); 94 translationUnit.push_back( fixer.initFunction ); 95 translationUnit.push_back( fixer.destroyFunction ); 94 // don't need to include function if it's empty 95 if ( fixer.initFunction->get_statements()->get_kids().empty() ) { 96 delete fixer.initFunction; 97 } else { 98 translationUnit.push_back( fixer.initFunction ); 99 } 100 if ( fixer.destroyFunction->get_statements()->get_kids().empty() ) { 101 delete fixer.destroyFunction; 102 } else { 103 translationUnit.push_back( fixer.destroyFunction ); 104 } 96 105 } 97 106 -
src/InitTweak/FixInit.cc
r9e2c1f0 rec79847 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed May 04 14:51:33201612 // Last Modified On : Mon May 09 12:36:02 2016 13 13 // Update Count : 30 14 14 // … … 398 398 } 399 399 400 template<typename Iterator, typename OutputIterator> 401 void insertDtors( Iterator begin, Iterator end, OutputIterator out ) { 402 for ( Iterator it = begin ; it != end ; ++it ) { 403 // remove if instrinsic destructor statement. Note that this is only called 404 // on lists of implicit dtors, so if the user manually calls an intrinsic 405 // dtor then the call will still be generated 406 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( *it ) ) { 407 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() ); 408 assert( appExpr ); 409 VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() ); 410 assert( function ); 411 // check for Intrinsic only - don't want to remove all overridable dtors because autogenerated dtor 412 // will call all member dtors, and some members may have a user defined dtor. 413 if ( function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) { 414 // don't need to call intrinsic dtor, because it does nothing 415 } else { 400 bool isInstrinsicSingleArgCallStmt( Statement * stmt ) { 401 if ( stmt == NULL ) return false; 402 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( stmt ) ) { 403 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() ); 404 assert( appExpr ); 405 VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() ); 406 assert( function ); 407 // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor 408 // will call all member dtors, and some members may have a user defined dtor. 409 FunctionType * funcType = GenPoly::getFunctionType( function->get_var()->get_type() ); 410 assert( funcType ); 411 return function->get_var()->get_linkage() == LinkageSpec::Intrinsic && funcType->get_parameters().size() == 1; 412 } else if ( CompoundStmt * compoundStmt = dynamic_cast< CompoundStmt * >( stmt ) ) { 413 // could also be a compound statement with a loop, in the case of an array 414 assert( compoundStmt->get_kids().size() == 2 ); // loop variable and loop 415 ForStmt * forStmt = dynamic_cast< ForStmt * >( compoundStmt->get_kids().back() ); 416 assert( forStmt && forStmt->get_body() ); 417 return isInstrinsicSingleArgCallStmt( forStmt->get_body() ); 418 } else { 419 // should never get here 420 assert( false && "encountered unknown call statement" ); 421 } 422 } 423 424 namespace { 425 template<typename Iterator, typename OutputIterator> 426 void insertDtors( Iterator begin, Iterator end, OutputIterator out ) { 427 for ( Iterator it = begin ; it != end ; ++it ) { 428 // remove if instrinsic destructor statement. Note that this is only called 429 // on lists of implicit dtors, so if the user manually calls an intrinsic 430 // dtor then the call will still be generated 431 if ( ! isInstrinsicSingleArgCallStmt( *it ) ) { 432 // don't need to call intrinsic dtor, because it does nothing, but 416 433 // non-intrinsic dtors must be called 417 434 *out++ = (*it)->clone(); 418 435 } 419 } else {420 // could also be a compound statement with a loop, in the case of an array421 // xxx - write code to remove loop calling intrinsic dtor.422 *out++ = (*it)->clone();423 436 } 424 437 } 425 438 } 426 427 439 428 440 CompoundStmt * FixInit::mutate( CompoundStmt * compoundStmt ) { -
src/InitTweak/FixInit.h
r9e2c1f0 rec79847 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jan 13 16:31:13201612 // Last Modified On : Mon May 09 12:08:11 2016 13 13 // Update Count : 5 14 14 // … … 28 28 /// and unwrap basic C-style initializers 29 29 void fix( std::list< Declaration * > & translationUnit ); 30 31 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. 32 /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. 33 /// Currently has assertions that make it less than fully general. 34 bool isInstrinsicSingleArgCallStmt( Statement * expr ); 30 35 } // namespace 31 36
Note: See TracChangeset
for help on using the changeset viewer.