Changeset 2d11663 for src/InitTweak/InitTweak.cc
- Timestamp:
- Jun 10, 2019, 1:48:19 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:
- f9a7cf0
- Parents:
- 05d55ff
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r05d55ff r2d11663 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // InitTweak.cc -- 8 // 9 // Author : Rob Schluntz 10 // Created On : Fri May 13 11:26:36 2016 11 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 10 13:30:00 2019 13 // Update Count : 5 14 // 15 1 16 #include <algorithm> // for find, all_of 2 17 #include <cassert> // for assertf, assert, strict_dynamic_cast … … 4 19 #include <iterator> // for back_insert_iterator, back_inserter 5 20 #include <memory> // for __shared_ptr 21 #include <vector> 6 22 7 23 #include "AST/Expr.hpp" … … 307 323 } 308 324 309 struct CallFinder {310 CallFinder ( const std::list< std::string > & names ) : names( names ) {}325 struct CallFinder_old { 326 CallFinder_old( const std::list< std::string > & names ) : names( names ) {} 311 327 312 328 void postvisit( ApplicationExpr * appExpr ) { … … 331 347 }; 332 348 349 struct CallFinder_new final { 350 std::vector< ast::ptr< ast::Expr > > matches; 351 const std::vector< std::string > names; 352 353 CallFinder_new( std::vector< std::string > && ns ) : matches(), names( std::move(ns) ) {} 354 355 void handleCallExpr( const ast::Expr * expr ) { 356 std::string fname = getFunctionName( expr ); 357 if ( std::find( names.begin(), names.end(), fname ) != names.end() ) { 358 matches.emplace_back( expr ); 359 } 360 } 361 362 void postvisit( const ast::ApplicationExpr * expr ) { handleCallExpr( expr ); } 363 void postvisit( const ast::UntypedExpr * expr ) { handleCallExpr( expr ); } 364 }; 365 333 366 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) { 334 static PassVisitor<CallFinder > finder( std::list< std::string >{ "?{}", "^?{}" } );367 static PassVisitor<CallFinder_old> finder( std::list< std::string >{ "?{}", "^?{}" } ); 335 368 finder.pass.matches = &matches; 336 369 maybeAccept( stmt, finder ); 370 } 371 372 std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt ) { 373 ast::Pass< CallFinder_new > finder{ std::vector< std::string >{ "?{}", "^?{}" } }; 374 maybe_accept( stmt, finder ); 375 return std::move( finder.pass.matches ); 337 376 } 338 377 … … 436 475 } 437 476 477 const ast::ApplicationExpr * isIntrinsicCallExpr( const ast::Expr * expr ) { 478 auto appExpr = dynamic_cast< const ast::ApplicationExpr * >( expr ); 479 if ( ! appExpr ) return nullptr; 480 481 const ast::DeclWithType * func = getCalledFunction( appExpr->func ); 482 assertf( func, 483 "getCalledFunction returned nullptr: %s", toString( appExpr->func ).c_str() ); 484 485 // check for Intrinsic only -- don't want to remove all overridable ctor/dtor because 486 // autogenerated ctor/dtor will call all member dtors, and some members may have a 487 // user-defined dtor 488 return func->linkage == ast::Linkage::Intrinsic ? appExpr : nullptr; 489 } 490 438 491 namespace { 439 492 template <typename Predicate> … … 444 497 return std::all_of( callExprs.begin(), callExprs.end(), pred); 445 498 } 499 500 template <typename Predicate> 501 bool allofCtorDtor( const ast::Stmt * stmt, const Predicate & pred ) { 502 std::vector< ast::ptr< ast::Expr > > callExprs = collectCtorDtorCalls( stmt ); 503 return std::all_of( callExprs.begin(), callExprs.end(), pred ); 504 } 446 505 } 447 506 … … 452 511 assert( funcType ); 453 512 return funcType->get_parameters().size() == 1; 513 } 514 return false; 515 }); 516 } 517 518 bool isIntrinsicSingleArgCallStmt( const ast::Stmt * stmt ) { 519 return allofCtorDtor( stmt, []( const ast::Expr * callExpr ){ 520 if ( const ast::ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) { 521 const ast::FunctionType * funcType = 522 GenPoly::getFunctionType( appExpr->func->result ); 523 assert( funcType ); 524 return funcType->params.size() == 1; 454 525 } 455 526 return false;
Note: See TracChangeset
for help on using the changeset viewer.