Changeset 66f8528 for src/InitTweak
- Timestamp:
- Dec 15, 2016, 5:16:42 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:
- 43385ca, f7ff3fb
- Parents:
- 5802a4f (diff), 596f987b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r5802a4f r66f8528 346 346 347 347 if ( VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() ) ) { 348 if ( function->get_var()->get_linkage() == LinkageSpec::Intrinsic) {348 if ( LinkageSpec::isBuiltin( function->get_var()->get_linkage() ) ) { 349 349 // optimization: don't need to copy construct in order to call intrinsic functions 350 350 return appExpr; -
src/InitTweak/InitTweak.cc
r5802a4f r66f8528 304 304 305 305 namespace { 306 DeclarationWithType * getCalledFunction( Expression * expr ); 307 308 template<typename CallExpr> 309 DeclarationWithType * handleDerefCalledFunction( CallExpr * expr ) { 310 // (*f)(x) => should get "f" 311 std::string name = getFunctionName( expr ); 312 assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() ); 313 assertf( ! expr->get_args().empty(), "Can't get called function from dereference with no arguments" ); 314 return getCalledFunction( expr->get_args().front() ); 315 } 316 306 317 DeclarationWithType * getCalledFunction( Expression * expr ) { 307 318 assert( expr ); … … 312 323 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 313 324 return getCalledFunction( castExpr->get_arg() ); 325 } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( expr ) ) { 326 return handleDerefCalledFunction( untypedExpr ); 327 } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) { 328 return handleDerefCalledFunction( appExpr ); 314 329 } 315 330 return nullptr; … … 377 392 378 393 namespace { 394 std::string funcName( Expression * func ); 395 396 template<typename CallExpr> 397 std::string handleDerefName( CallExpr * expr ) { 398 // (*f)(x) => should get name "f" 399 std::string name = getFunctionName( expr ); 400 assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() ); 401 assertf( ! expr->get_args().empty(), "Can't get function name from dereference with no arguments" ); 402 return funcName( expr->get_args().front() ); 403 } 404 379 405 std::string funcName( Expression * func ) { 380 406 if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( func ) ) { … … 388 414 } else if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * > ( func ) ) { 389 415 return funcName( memberExpr->get_member() ); 416 } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( func ) ) { 417 return handleDerefName( untypedExpr ); 418 } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( func ) ) { 419 return handleDerefName( appExpr ); 390 420 } else { 391 421 assertf( false, "Unexpected expression type being called as a function in call expression" ); … … 395 425 396 426 std::string getFunctionName( Expression * expr ) { 427 // there's some unforunate overlap here with getCalledFunction. Ideally this would be able to use getCalledFunction and 428 // return the name of the DeclarationWithType, but this needs to work for NameExpr and UntypedMemberExpr, where getCalledFunction 429 // can't possibly do anything reasonable. 397 430 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ) ) { 398 431 return funcName( appExpr->get_function() );
Note: See TracChangeset
for help on using the changeset viewer.