Changes in src/InitTweak/InitTweak.cc [2d11663:d76c588]
- File:
-
- 1 edited
-
src/InitTweak/InitTweak.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r2d11663 rd76c588 1 //2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo3 //4 // The contents of this file are covered under the licence agreement in the5 // file "LICENCE" distributed with Cforall.6 //7 // InitTweak.cc --8 //9 // Author : Rob Schluntz10 // Created On : Fri May 13 11:26:36 201611 // Last Modified By : Aaron B. Moss12 // Last Modified On : Mon Jun 10 13:30:00 201913 // Update Count : 514 //15 16 1 #include <algorithm> // for find, all_of 17 2 #include <cassert> // for assertf, assert, strict_dynamic_cast … … 19 4 #include <iterator> // for back_insert_iterator, back_inserter 20 5 #include <memory> // for __shared_ptr 21 #include <vector>22 6 23 7 #include "AST/Expr.hpp" … … 323 307 } 324 308 325 struct CallFinder _old{326 CallFinder _old( const std::list< std::string > & names ) : names( names ) {}309 struct CallFinder { 310 CallFinder( const std::list< std::string > & names ) : names( names ) {} 327 311 328 312 void postvisit( ApplicationExpr * appExpr ) { … … 347 331 }; 348 332 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 366 333 void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) { 367 static PassVisitor<CallFinder _old> finder( std::list< std::string >{ "?{}", "^?{}" } );334 static PassVisitor<CallFinder> finder( std::list< std::string >{ "?{}", "^?{}" } ); 368 335 finder.pass.matches = &matches; 369 336 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 );376 337 } 377 338 … … 379 340 std::list< Expression * > matches; 380 341 collectCtorDtorCalls( stmt, matches ); 381 assert f( matches.size() <= 1, "%zd constructor/destructors found in %s", matches.size(), toString( stmt ).c_str());342 assert( matches.size() <= 1 ); 382 343 return matches.size() == 1 ? matches.front() : nullptr; 383 344 } … … 475 436 } 476 437 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 because486 // autogenerated ctor/dtor will call all member dtors, and some members may have a487 // user-defined dtor488 return func->linkage == ast::Linkage::Intrinsic ? appExpr : nullptr;489 }490 491 438 namespace { 492 439 template <typename Predicate> … … 497 444 return std::all_of( callExprs.begin(), callExprs.end(), pred); 498 445 } 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 }505 446 } 506 447 … … 511 452 assert( funcType ); 512 453 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;525 454 } 526 455 return false;
Note:
See TracChangeset
for help on using the changeset viewer.