Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    r2d11663 rd76c588  
    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 
    161#include <algorithm>               // for find, all_of
    172#include <cassert>                 // for assertf, assert, strict_dynamic_cast
     
    194#include <iterator>                // for back_insert_iterator, back_inserter
    205#include <memory>                  // for __shared_ptr
    21 #include <vector>
    226
    237#include "AST/Expr.hpp"
     
    323307        }
    324308
    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 ) {}
    327311
    328312                void postvisit( ApplicationExpr * appExpr ) {
     
    347331        };
    348332
    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 
    366333        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 >{ "?{}", "^?{}" } );
    368335                finder.pass.matches = &matches;
    369336                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 );
    376337        }
    377338
     
    379340                std::list< Expression * > matches;
    380341                collectCtorDtorCalls( stmt, matches );
    381                 assertf( matches.size() <= 1, "%zd constructor/destructors found in %s", matches.size(), toString( stmt ).c_str() );
     342                assert( matches.size() <= 1 );
    382343                return matches.size() == 1 ? matches.front() : nullptr;
    383344        }
     
    475436        }
    476437
    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 
    491438        namespace {
    492439                template <typename Predicate>
     
    497444                        return std::all_of( callExprs.begin(), callExprs.end(), pred);
    498445                }
    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                 }
    505446        }
    506447
     
    511452                                assert( funcType );
    512453                                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;
    525454                        }
    526455                        return false;
Note: See TracChangeset for help on using the changeset viewer.