Changeset 65660bd for src/InitTweak/FixInit.cc
- Timestamp:
- Sep 22, 2016, 8:14:56 AM (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:
- ac9ca96
- Parents:
- 1132b62
- git-author:
- Rob Schluntz <rschlunt@…> (09/21/16 23:43:37)
- git-committer:
- Rob Schluntz <rschlunt@…> (09/22/16 08:14:56)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r1132b62 r65660bd 69 69 70 70 /// create and resolve ctor/dtor expression: fname(var, [cpArg]) 71 ApplicationExpr* makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg = NULL );72 ApplicationExpr* makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg = NULL );71 Expression * makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg = NULL ); 72 Expression * makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg = NULL ); 73 73 /// true if type does not need to be copy constructed to ensure correctness 74 74 bool skipCopyConstruct( Type * type ); … … 360 360 } 361 361 362 ApplicationExpr* ResolveCopyCtors::makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg ) {362 Expression * ResolveCopyCtors::makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg ) { 363 363 assert( var ); 364 364 return makeCtorDtor( fname, new AddressExpr( new VariableExpr( var ) ), cpArg ); 365 365 } 366 366 367 ApplicationExpr* ResolveCopyCtors::makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg ) {367 Expression * ResolveCopyCtors::makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg ) { 368 368 assert( thisArg ); 369 369 UntypedExpr * untyped = new UntypedExpr( new NameExpr( fname ) ); … … 375 375 // (VariableExpr and already resolved expression) 376 376 CP_CTOR_PRINT( std::cerr << "ResolvingCtorDtor " << untyped << std::endl; ) 377 ApplicationExpr * resolved = dynamic_cast< ApplicationExpr * >( ResolvExpr::findVoidExpression( untyped, *this ) ); 377 Expression * resolved = ResolvExpr::findVoidExpression( untyped, *this ); 378 assert( resolved ); 378 379 if ( resolved->get_env() ) { 379 380 env->add( *resolved->get_env() ); 380 381 } // if 381 382 382 assert( resolved );383 383 delete untyped; 384 384 return resolved; … … 392 392 if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types 393 393 394 if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( arg ) ) {395 for ( Expression * & expr : tupleExpr->get_exprs() ) {396 copyConstructArg( expr, impCpCtorExpr );397 }398 return;399 }400 401 394 // type may involve type variables, so apply type substitution to get temporary variable's actual type 402 395 result = result->clone(); … … 407 400 // create and resolve copy constructor 408 401 CP_CTOR_PRINT( std::cerr << "makeCtorDtor for an argument" << std::endl; ) 409 ApplicationExpr * cpCtor = makeCtorDtor( "?{}", tmp, arg ); 410 411 // if the chosen constructor is intrinsic, the copy is unnecessary, so 412 // don't create the temporary and don't call the copy constructor 413 VariableExpr * function = dynamic_cast< VariableExpr * >( cpCtor->get_function() ); 414 assert( function ); 415 if ( function->get_var()->get_linkage() != LinkageSpec::Intrinsic ) { 416 // replace argument to function call with temporary 417 arg = new CommaExpr( cpCtor, new VariableExpr( tmp ) ); 418 impCpCtorExpr->get_tempDecls().push_back( tmp ); 419 impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", tmp ) ); 420 } // if 402 Expression * cpCtor = makeCtorDtor( "?{}", tmp, arg ); 403 404 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( cpCtor ) ) { 405 // if the chosen constructor is intrinsic, the copy is unnecessary, so 406 // don't create the temporary and don't call the copy constructor 407 VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() ); 408 assert( function ); 409 if ( function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) return; 410 } 411 412 // replace argument to function call with temporary 413 arg = new CommaExpr( cpCtor, new VariableExpr( tmp ) ); 414 impCpCtorExpr->get_tempDecls().push_back( tmp ); 415 impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", tmp ) ); 421 416 } 422 417 423 418 void ResolveCopyCtors::destructRet( Expression * ret, ImplicitCopyCtorExpr * impCpCtorExpr ) { 424 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( ret->get_result() ) ) {425 int idx = 0;426 for ( Type *& t : tupleType->get_types() ) {427 (void)t;428 destructRet( new TupleIndexExpr( ret->clone(), idx++ ), impCpCtorExpr );429 }430 return;431 }432 419 impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", new AddressExpr( ret ) ) ); 433 420 }
Note: See TracChangeset
for help on using the changeset viewer.