Ignore:
Timestamp:
Jun 12, 2019, 4:06:37 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
462a7c7, d60780c
Parents:
aaeacf4 (diff), 6625727 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    raaeacf4 r21300d7  
     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
    116#include <algorithm>               // for find, all_of
    217#include <cassert>                 // for assertf, assert, strict_dynamic_cast
     
    419#include <iterator>                // for back_insert_iterator, back_inserter
    520#include <memory>                  // for __shared_ptr
     21#include <vector>
    622
    723#include "AST/Expr.hpp"
     
    307323        }
    308324
    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 ) {}
    311327
    312328                void postvisit( ApplicationExpr * appExpr ) {
     
    331347        };
    332348
     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
    333366        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 >{ "?{}", "^?{}" } );
    335368                finder.pass.matches = &matches;
    336369                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 );
    337376        }
    338377
     
    436475        }
    437476
     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
    438491        namespace {
    439492                template <typename Predicate>
     
    444497                        return std::all_of( callExprs.begin(), callExprs.end(), pred);
    445498                }
     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                }
    446505        }
    447506
     
    452511                                assert( funcType );
    453512                                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;
    454525                        }
    455526                        return false;
Note: See TracChangeset for help on using the changeset viewer.