Changeset a465caf
- Timestamp:
- Aug 8, 2016, 4:20:29 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, cleanup-dtors, ctor, 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:
- 0853178
- Parents:
- 242d458
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r242d458 ra465caf 291 291 } 292 292 293 namespace { 294 template <typename Predicate> 295 bool allofCtorDtor( Statement * stmt, const Predicate & pred ) { 296 std::list< Expression * > callExprs; 297 collectCtorDtorCalls( stmt, callExprs ); 298 // if ( callExprs.empty() ) return false; // xxx - do I still need this check? 299 return std::all_of( callExprs.begin(), callExprs.end(), pred); 300 } 301 } 302 293 303 bool isIntrinsicSingleArgCallStmt( Statement * stmt ) { 294 std::list< Expression * > callExprs; 295 collectCtorDtorCalls( stmt, callExprs ); 296 // if ( callExprs.empty() ) return false; // xxx - do I still need this check? 297 return std::all_of( callExprs.begin(), callExprs.end(), []( Expression * callExpr ){ 304 return allofCtorDtor( stmt, []( Expression * callExpr ){ 298 305 if ( ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) { 299 306 assert( ! appExpr->get_function()->get_results().empty() ); … … 303 310 } 304 311 return false; 312 }); 313 } 314 315 bool isIntrinsicCallStmt( Statement * stmt ) { 316 return allofCtorDtor( stmt, []( Expression * callExpr ) { 317 return isIntrinsicCallExpr( callExpr ); 305 318 }); 306 319 } -
src/InitTweak/InitTweak.h
r242d458 ra465caf 41 41 /// Intended to be used for default ctor/dtor calls, but might have use elsewhere. 42 42 /// Currently has assertions that make it less than fully general. 43 bool isIntrinsicSingleArgCallStmt( Statement * expr ); 43 bool isIntrinsicSingleArgCallStmt( Statement * stmt ); 44 45 /// True if stmt is a call statement where the function called is intrinsic. 46 bool isIntrinsicCallStmt( Statement * stmt ); 44 47 45 48 /// get all Ctor/Dtor call expressions from a Statement -
src/ResolvExpr/Resolver.cc
r242d458 ra465caf 550 550 } 551 551 552 // xxx - todo553 // if ( InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {554 // // can reduce the constructor down to a SingleInit using the555 // // second argument from the ctor call556 // }557 558 552 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) { 559 553 delete ctorInit->get_dtor(); 560 554 ctorInit->set_dtor( NULL ); 561 555 } 556 557 // xxx - todo -- what about arrays? 558 // if ( dtor == NULL && InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) { 559 // // can reduce the constructor down to a SingleInit using the 560 // // second argument from the ctor call, since 561 // delete ctorInit->get_ctor(); 562 // ctorInit->set_ctor( NULL ); 563 564 // Expression * arg = 565 // ctorInit->set_init( new SingleInit( arg ) ); 566 // } 562 567 } 563 568 } // namespace ResolvExpr -
src/SymTab/Autogen.cc
r242d458 ra465caf 68 68 copy->get_args().push_back( new VariableExpr( dstParam ) ); 69 69 copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) ); 70 copy->get_args().push_back( new SizeofExpr( unionType) );70 copy->get_args().push_back( new SizeofExpr( srcParam->get_type()->clone() ) ); 71 71 72 72 *out++ = new ExprStmt( noLabels, copy ); … … 421 421 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 422 422 if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) ); 423 424 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 423 else assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); 425 424 426 425 // body of assignment and copy ctor is the same 427 426 copyCtorDecl->set_statements( assignDecl->get_statements()->clone() ); 427 428 // create a constructor which takes the first member type as a parameter. 429 // for example, for Union A { int x; double y; }; generate 430 // void ?{}(A *, int) 431 // This is to mimic C's behaviour which initializes the first member of the union. 432 std::list<Declaration *> memCtors; 433 for ( Declaration * member : aggregateDecl->get_members() ) { 434 if ( DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ) ) { 435 ObjectDecl * srcParam = new ObjectDecl( "src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, field->get_type()->clone(), 0 ); 436 437 FunctionType * memCtorType = ctorType->clone(); 438 memCtorType->get_parameters().push_back( srcParam ); 439 FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType, new CompoundStmt( noLabels ), true, false ); 440 ctor->fixUniqueId(); 441 442 makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( ctor->get_statements()->get_kids() ) ); 443 memCtors.push_back( ctor ); 444 // only generate a ctor for the first field 445 break; 446 } 447 } 428 448 429 449 declsToAdd.push_back( assignDecl ); … … 431 451 declsToAdd.push_back( copyCtorDecl ); 432 452 declsToAdd.push_back( dtorDecl ); 453 declsToAdd.splice( declsToAdd.end(), memCtors ); 433 454 } 434 455
Note: See TracChangeset
for help on using the changeset viewer.