Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/GenImplicitCall.cpp

    r4e2f1b2 r5bf685f  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // GenImplicitCall.cpp -- Generate code for implicit operator calls.
     7// GenImplicitCall.hpp --
    88//
    99// Author           : Andrew Beach
     
    3131namespace {
    3232
    33 using Inserter = std::back_insert_iterator<std::list<ast::ptr<ast::Stmt>>>;
    34 
     33template< typename OutIter >
    3534ast::ptr< ast::Stmt > genCall(
    3635        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    37         const CodeLocation & loc, const std::string & fname, Inserter && out,
     36        const CodeLocation & loc, const std::string & fname, OutIter && out,
    3837        const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward );
    3938
     
    4241/// optionally returns a statement which must be inserted prior to the containing loop, if
    4342/// there is one
     43template< typename OutIter >
    4444ast::ptr< ast::Stmt > genScalarCall(
    4545        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    46         const CodeLocation & loc, std::string fname, Inserter && out, const ast::Type * type,
     46        const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type,
    4747        const ast::Type * addCast = nullptr
    4848) {
     
    9797/// Store in out a loop which calls fname on each element of the array with srcParam and
    9898/// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0
     99template< typename OutIter >
    99100void genArrayCall(
    100101        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    101         const CodeLocation & loc, const std::string & fname, Inserter && out,
     102        const CodeLocation & loc, const std::string & fname, OutIter && out,
    102103        const ast::ArrayType * array, const ast::Type * addCast = nullptr,
    103104        LoopDirection forward = LoopForward
     
    165166}
    166167
     168template< typename OutIter >
    167169ast::ptr< ast::Stmt > genCall(
    168170        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    169         const CodeLocation & loc, const std::string & fname, Inserter && out,
     171        const CodeLocation & loc, const std::string & fname, OutIter && out,
    170172        const ast::Type * type, const ast::Type * addCast, LoopDirection forward
    171173) {
    172174        if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
    173175                genArrayCall(
    174                         srcParam, dstParam, loc, fname, std::forward< Inserter&& >( out ), at, addCast,
     176                        srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast,
    175177                        forward );
    176178                return {};
    177179        } else {
    178180                return genScalarCall(
    179                         srcParam, dstParam, loc, fname, std::forward< Inserter&& >( out ), type, addCast );
     181                        srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast );
    180182        }
    181183}
     
    183185} // namespace
    184186
    185 const ast::Stmt * genImplicitCall(
     187ast::ptr< ast::Stmt > genImplicitCall(
    186188        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    187189        const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
     
    189191) {
    190192        // unnamed bit fields are not copied as they cannot be accessed
    191         if ( isUnnamedBitfield( obj ) ) return nullptr;
     193        if ( isUnnamedBitfield( obj ) ) return {};
    192194
    193195        ast::ptr< ast::Type > addCast;
     
    197199        }
    198200
    199         std::list< ast::ptr< ast::Stmt > > stmts;
     201        std::vector< ast::ptr< ast::Stmt > > stmts;
    200202        genCall(
    201203                srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward );
    202204
    203         if ( stmts.empty() ) return nullptr;
    204         assert( stmts.size() == 1 );
    205 
    206         const ast::Stmt * callStmt = stmts.front().release();
    207         // Implicitly generated ctor/dtor calls should be wrapped so that
    208         // later passes are aware they were generated.
    209         if ( addCast ) {
    210                 callStmt = new ast::ImplicitCtorDtorStmt( callStmt->location, callStmt );
    211         }
    212         return callStmt;
     205        if ( stmts.empty() ) {
     206                return {};
     207        } else if ( stmts.size() == 1 ) {
     208                const ast::Stmt * callStmt = stmts.front();
     209                if ( addCast ) {
     210                        // implicitly generated ctor/dtor calls should be wrapped so that later passes are
     211                        // aware they were generated.
     212                        callStmt = new ast::ImplicitCtorDtorStmt( callStmt->location, callStmt );
     213                }
     214                return callStmt;
     215        } else {
     216                assert( false );
     217                return {};
     218        }
    213219}
    214220
     
    220226// compile-command: "make install" //
    221227// End: //
     228
     229
Note: See TracChangeset for help on using the changeset viewer.