Changeset 6f096d2 for src/InitTweak/InitTweak.cc
- Timestamp:
- Jul 12, 2019, 4:34:56 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e3d7f9f
- Parents:
- 8fd52e9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r8fd52e9 r6f096d2 318 318 virtual ~ExpanderImpl() = default; 319 319 virtual std::vector< ast::ptr< ast::Expr > > next( IndexList & indices ) = 0; 320 virtual ast::ptr< ast::Stmt > buildListInit( 320 virtual ast::ptr< ast::Stmt > buildListInit( 321 321 ast::UntypedExpr * callExpr, IndexList & indices ) = 0; 322 322 }; … … 324 324 namespace { 325 325 template< typename Out > 326 void buildCallExpr( 327 ast::UntypedExpr * callExpr, const ast::Expr * index, const ast::Expr * dimension, 326 void buildCallExpr( 327 ast::UntypedExpr * callExpr, const ast::Expr * index, const ast::Expr * dimension, 328 328 const ast::Init * init, Out & out 329 329 ) { 330 330 const CodeLocation & loc = init->location; 331 331 332 auto cond = new ast::UntypedExpr{ 332 auto cond = new ast::UntypedExpr{ 333 333 loc, new ast::NameExpr{ loc, "?<?" }, { index, dimension } }; 334 334 335 335 std::vector< ast::ptr< ast::Expr > > args = makeInitList( init ); 336 336 splice( callExpr->args, args ); … … 338 338 out.emplace_back( new ast::IfStmt{ loc, cond, new ast::ExprStmt{ loc, callExpr } } ); 339 339 340 out.emplace_back( new ast::ExprStmt{ 340 out.emplace_back( new ast::ExprStmt{ 341 341 loc, new ast::UntypedExpr{ loc, new ast::NameExpr{ loc, "++?" }, { index } } } ); 342 342 } … … 344 344 template< typename Out > 345 345 void build( 346 ast::UntypedExpr * callExpr, const InitExpander_new::IndexList & indices, 346 ast::UntypedExpr * callExpr, const InitExpander_new::IndexList & indices, 347 347 const ast::Init * init, Out & out 348 348 ) { … … 371 371 372 372 static UniqueName targetLabel( "L__autogen__" ); 373 ast::Label switchLabel{ 373 ast::Label switchLabel{ 374 374 loc, targetLabel.newName(), { new ast::Attribute{ "unused" } } }; 375 375 376 376 std::vector< ast::ptr< ast::Stmt > > branches; 377 377 for ( const ast::Init * init : *listInit ) { … … 381 381 std::vector< ast::ptr< ast::Stmt > > stmts; 382 382 build( callExpr, indices, init, stmts ); 383 stmts.emplace_back( 383 stmts.emplace_back( 384 384 new ast::BranchStmt{ loc, ast::BranchStmt::Break, switchLabel } ); 385 385 branches.emplace_back( new ast::CaseStmt{ loc, condition, std::move( stmts ) } ); … … 398 398 return makeInitList( init ); 399 399 } 400 401 ast::ptr< ast::Stmt > buildListInit( 402 ast::UntypedExpr * callExpr, InitExpander_new::IndexList & indices 400 401 ast::ptr< ast::Stmt > buildListInit( 402 ast::UntypedExpr * callExpr, InitExpander_new::IndexList & indices 403 403 ) override { 404 // If array came with an initializer list, initialize each element. We may have more 405 // initializers than elements of the array; need to check at each index that we have 406 // not exceeded size. We may have fewer initializers than elements in the array; need 407 // to default-construct remaining elements. To accomplish this, generate switch 404 // If array came with an initializer list, initialize each element. We may have more 405 // initializers than elements of the array; need to check at each index that we have 406 // not exceeded size. We may have fewer initializers than elements in the array; need 407 // to default-construct remaining elements. To accomplish this, generate switch 408 408 // statement consuming all of expander's elements 409 409 … … 427 427 ExprImpl_new( const ast::Expr * a ) : arg( a ) {} 428 428 429 std::vector< ast::ptr< ast::Expr > > next( 430 InitExpander_new::IndexList & indices 429 std::vector< ast::ptr< ast::Expr > > next( 430 InitExpander_new::IndexList & indices 431 431 ) override { 432 432 if ( ! arg ) return {}; … … 437 437 // go through indices and layer on subscript exprs ?[?] 438 438 ++it; 439 expr = new ast::UntypedExpr{ 439 expr = new ast::UntypedExpr{ 440 440 loc, new ast::NameExpr{ loc, "?[?]" }, { expr, *it } }; 441 441 } 442 442 return { expr }; 443 443 } 444 445 ast::ptr< ast::Stmt > buildListInit( 446 ast::UntypedExpr *, InitExpander_new::IndexList & 447 ) override { 444 445 ast::ptr< ast::Stmt > buildListInit( 446 ast::UntypedExpr *, InitExpander_new::IndexList & 447 ) override { 448 448 return {}; 449 449 } … … 464 464 } 465 465 466 /// builds statement which has the same semantics as a C-style list initializer (for array 466 /// builds statement which has the same semantics as a C-style list initializer (for array 467 467 /// initializers) using callExpr as the base expression to perform initialization 468 468 ast::ptr< ast::Stmt > InitExpander_new::buildListInit( ast::UntypedExpr * callExpr ) { … … 668 668 669 669 const ast::DeclWithType * func = getCalledFunction( appExpr->func ); 670 assertf( func, 670 assertf( func, 671 671 "getCalledFunction returned nullptr: %s", toString( appExpr->func ).c_str() ); 672 673 // check for Intrinsic only -- don't want to remove all overridable ctor/dtor because 674 // autogenerated ctor/dtor will call all member dtors, and some members may have a 672 673 // check for Intrinsic only -- don't want to remove all overridable ctor/dtor because 674 // autogenerated ctor/dtor will call all member dtors, and some members may have a 675 675 // user-defined dtor 676 676 return func->linkage == ast::Linkage::Intrinsic ? appExpr : nullptr; … … 707 707 return allofCtorDtor( stmt, []( const ast::Expr * callExpr ){ 708 708 if ( const ast::ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) { 709 const ast::FunctionType * funcType = 709 const ast::FunctionType * funcType = 710 710 GenPoly::getFunctionType( appExpr->func->result ); 711 711 assert( funcType ); … … 997 997 bool isCtorDtorAssign( const std::string & str ) { return isCtorDtor( str ) || isAssignment( str ); } 998 998 999 FunctionDecl * isCopyFunction(Declaration * decl, const std::string & fname ) {1000 FunctionDecl * function = dynamic_cast<FunctionDecl * >( decl );999 const FunctionDecl * isCopyFunction( const Declaration * decl, const std::string & fname ) { 1000 const FunctionDecl * function = dynamic_cast< const FunctionDecl * >( decl ); 1001 1001 if ( ! function ) return nullptr; 1002 1002 if ( function->name != fname ) return nullptr; … … 1022 1022 if ( ! t1 ) return false; 1023 1023 const ast::Type * t2 = ftype->params.back()->get_type(); 1024 1024 1025 1025 return ResolvExpr::typesCompatibleIgnoreQualifiers( t1, t2, ast::SymbolTable{} ); 1026 1026 } 1027 1027 1028 FunctionDecl * isAssignment(Declaration * decl ) {1028 const FunctionDecl * isAssignment( const Declaration * decl ) { 1029 1029 return isCopyFunction( decl, "?=?" ); 1030 1030 } 1031 FunctionDecl * isDestructor(Declaration * decl ) {1032 if ( isDestructor( decl-> get_name()) ) {1033 return dynamic_cast< FunctionDecl * >( decl );1031 const FunctionDecl * isDestructor( const Declaration * decl ) { 1032 if ( isDestructor( decl->name ) ) { 1033 return dynamic_cast< const FunctionDecl * >( decl ); 1034 1034 } 1035 1035 return nullptr; 1036 1036 } 1037 FunctionDecl * isDefaultConstructor(Declaration * decl ) {1037 const FunctionDecl * isDefaultConstructor( const Declaration * decl ) { 1038 1038 if ( isConstructor( decl->name ) ) { 1039 if ( FunctionDecl * func = dynamic_cast<FunctionDecl * >( decl ) ) {1039 if ( const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl ) ) { 1040 1040 if ( func->type->parameters.size() == 1 ) { 1041 1041 return func; … … 1045 1045 return nullptr; 1046 1046 } 1047 FunctionDecl * isCopyConstructor(Declaration * decl ) {1047 const FunctionDecl * isCopyConstructor( const Declaration * decl ) { 1048 1048 return isCopyFunction( decl, "?{}" ); 1049 1049 }
Note: See TracChangeset
for help on using the changeset viewer.