Changeset ee1635c8 for src/InitTweak
- Timestamp:
- Sep 8, 2016, 4:49:57 PM (8 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:
- 4563a95
- Parents:
- 24670d2
- Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r24670d2 ree1635c8 304 304 305 305 namespace { 306 VariableExpr * getCalledFunction( ApplicationExpr * appExpr ) { 307 assert( appExpr ); 308 // xxx - it's possible this can be other things, e.g. MemberExpr, so this is insufficient 309 return dynamic_cast< VariableExpr * >( appExpr->get_function() ); 306 DeclarationWithType * getCalledFunction( Expression * expr ) { 307 assert( expr ); 308 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 309 return varExpr->get_var(); 310 } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( expr ) ) { 311 return memberExpr->get_member(); 312 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 313 return getCalledFunction( castExpr->get_arg() ); 314 } 315 return nullptr; 310 316 } 311 317 } … … 314 320 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ); 315 321 if ( ! appExpr ) return NULL; 316 VariableExpr * function = getCalledFunction( appExpr);322 DeclarationWithType * function = getCalledFunction( appExpr->get_function() ); 317 323 assert( function ); 318 324 // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor 319 325 // will call all member dtors, and some members may have a user defined dtor. 320 return function->get_ var()->get_linkage() == LinkageSpec::Intrinsic ? appExpr : NULL;326 return function->get_linkage() == LinkageSpec::Intrinsic ? appExpr : NULL; 321 327 } 322 328 … … 379 385 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( func ) ) { 380 386 return funcName( castExpr->get_arg() ); 387 } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( func ) ) { 388 return memberExpr->get_member()->get_name(); 381 389 } else { 382 390 assert( false && "Unexpected expression type being called as a function in call expression" ); … … 472 480 bool isConstructor( const std::string & str ) { return str == "?{}"; } 473 481 bool isDestructor( const std::string & str ) { return str == "^?{}"; } 482 bool isAssignment( const std::string & str ) { return str == "?=?"; } 474 483 bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); } 475 476 FunctionDecl * isCopyConstructor( Declaration * decl ) { 484 bool isCtorDtorAssign( const std::string & str ) { return isCtorDtor( str ) || isAssignment( str ); } 485 486 FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ) { 477 487 FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ); 478 488 if ( ! function ) return 0; 479 if ( ! isConstructor( function->get_name() )) return 0;489 if ( function->get_name() != fname ) return 0; 480 490 FunctionType * ftype = function->get_functionType(); 481 491 if ( ftype->get_parameters().size() != 2 ) return 0; … … 486 496 assert( ptrType ); 487 497 488 if ( ResolvExpr::typesCompatible ( ptrType->get_base(), t2, SymTab::Indexer() ) ) {498 if ( ResolvExpr::typesCompatibleIgnoreQualifiers( ptrType->get_base(), t2, SymTab::Indexer() ) ) { 489 499 return function; 490 500 } else { 491 return 0; 492 } 501 return nullptr; 502 } 503 } 504 505 FunctionDecl * isCopyConstructor( Declaration * decl ) { 506 return isCopyFunction( decl, "?{}" ); 493 507 } 494 508 } -
src/InitTweak/InitTweak.h
r24670d2 ree1635c8 28 28 bool isConstructor( const std::string & ); 29 29 bool isDestructor( const std::string & ); 30 bool isAssignment( const std::string & ); 30 31 bool isCtorDtor( const std::string & ); 32 bool isCtorDtorAssign( const std::string & ); 31 33 32 34 FunctionDecl * isCopyConstructor( Declaration * decl ); 35 FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ); 33 36 34 37 /// transform Initializer into an argument list that can be passed to a call expression
Note: See TracChangeset
for help on using the changeset viewer.