Changeset 4e2f1b2


Ignore:
Timestamp:
Feb 23, 2024, 3:59:35 PM (5 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
1761046
Parents:
d06273c
Message:

Clean-up of GenImplicitCall? module. Changing the return type for consistency spilled out into some other files, but that should also saves some operations. The other big one is the template instances were reduced to one and then the templates removed.

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cpp

    rd06273c r4e2f1b2  
    11341134                        ast::Expr * thisExpr = new ast::CastExpr(funcDecl->location, new ast::VariableExpr(funcDecl->location, thisParam ), thisParam->get_type()->stripReferences());
    11351135                        ast::Expr * memberDest = new ast::MemberExpr(funcDecl->location, field, thisExpr );
    1136                         ast::ptr<ast::Stmt> callStmt = SymTab::genImplicitCall( srcParam, memberDest, loc, function->name, field, static_cast<SymTab::LoopDirection>(isCtor) );
     1136                        const ast::Stmt * callStmt = SymTab::genImplicitCall( srcParam, memberDest, loc, function->name, field, static_cast<SymTab::LoopDirection>(isCtor) );
    11371137
    11381138                        if ( callStmt ) {
  • src/InitTweak/GenInit.cc

    rd06273c r4e2f1b2  
    239239                                        if ( varExpr->var == retVal ) return stmt;
    240240                                }
    241                                 ast::ptr<ast::Stmt> ctorStmt = genCtorDtor(
     241                                const ast::Stmt * ctorStmt = genCtorDtor(
    242242                                        retVal->location, "?{}", retVal, stmt->expr );
    243243                                assertf( ctorStmt,
     
    327327void ManagedTypes::endScope() { managedTypes.endScope(); }
    328328
    329 ast::ptr<ast::Stmt> genCtorDtor (const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg) {
     329const ast::Stmt * genCtorDtor( const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg ) {
    330330        assertf(objDecl, "genCtorDtor passed null objDecl");
    331331        InitExpander srcParam(arg);
  • src/InitTweak/GenInit.h

    rd06273c r4e2f1b2  
    3333
    3434/// generates a single ctor/dtor statement using objDecl as the 'this' parameter and arg as the optional argument
    35 ast::ptr<ast::Stmt> genCtorDtor (const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg = nullptr);
     35const ast::Stmt * genCtorDtor( const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * objDecl, const ast::Expr * arg = nullptr );
    3636
    3737/// creates an appropriate ConstructorInit node which contains a constructor, destructor, and C-initializer
  • src/SymTab/GenImplicitCall.cpp

    rd06273c r4e2f1b2  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // GenImplicitCall.hpp --
     7// GenImplicitCall.cpp -- Generate code for implicit operator calls.
    88//
    99// Author           : Andrew Beach
     
    3131namespace {
    3232
    33 template< typename OutIter >
     33using Inserter = std::back_insert_iterator<std::list<ast::ptr<ast::Stmt>>>;
     34
    3435ast::ptr< ast::Stmt > genCall(
    3536        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    36         const CodeLocation & loc, const std::string & fname, OutIter && out,
     37        const CodeLocation & loc, const std::string & fname, Inserter && out,
    3738        const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward );
    3839
     
    4142/// optionally returns a statement which must be inserted prior to the containing loop, if
    4243/// there is one
    43 template< typename OutIter >
    4444ast::ptr< ast::Stmt > genScalarCall(
    4545        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    46         const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type,
     46        const CodeLocation & loc, std::string fname, Inserter && 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
    99 template< typename OutIter >
    10099void genArrayCall(
    101100        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    102         const CodeLocation & loc, const std::string & fname, OutIter && out,
     101        const CodeLocation & loc, const std::string & fname, Inserter && out,
    103102        const ast::ArrayType * array, const ast::Type * addCast = nullptr,
    104103        LoopDirection forward = LoopForward
     
    166165}
    167166
    168 template< typename OutIter >
    169167ast::ptr< ast::Stmt > genCall(
    170168        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    171         const CodeLocation & loc, const std::string & fname, OutIter && out,
     169        const CodeLocation & loc, const std::string & fname, Inserter && out,
    172170        const ast::Type * type, const ast::Type * addCast, LoopDirection forward
    173171) {
    174172        if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
    175173                genArrayCall(
    176                         srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast,
     174                        srcParam, dstParam, loc, fname, std::forward< Inserter&& >( out ), at, addCast,
    177175                        forward );
    178176                return {};
    179177        } else {
    180178                return genScalarCall(
    181                         srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast );
     179                        srcParam, dstParam, loc, fname, std::forward< Inserter&& >( out ), type, addCast );
    182180        }
    183181}
     
    185183} // namespace
    186184
    187 ast::ptr< ast::Stmt > genImplicitCall(
     185const ast::Stmt * genImplicitCall(
    188186        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    189187        const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
     
    191189) {
    192190        // unnamed bit fields are not copied as they cannot be accessed
    193         if ( isUnnamedBitfield( obj ) ) return {};
     191        if ( isUnnamedBitfield( obj ) ) return nullptr;
    194192
    195193        ast::ptr< ast::Type > addCast;
     
    199197        }
    200198
    201         std::vector< ast::ptr< ast::Stmt > > stmts;
     199        std::list< ast::ptr< ast::Stmt > > stmts;
    202200        genCall(
    203201                srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward );
    204202
    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         }
     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;
    219213}
    220214
     
    226220// compile-command: "make install" //
    227221// End: //
    228 
    229 
  • src/SymTab/GenImplicitCall.hpp

    rd06273c r4e2f1b2  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // GenImplicitCall.hpp --
     7// GenImplicitCall.hpp -- Generate code for implicit operator calls.
    88//
    99// Author           : Andrew Beach
     
    2525/// Returns a generated call expression to function fname with srcParam and
    2626/// dstParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
    27 ast::ptr<ast::Stmt> genImplicitCall(
     27const ast::Stmt * genImplicitCall(
    2828        InitTweak::InitExpander & srcParam, const ast::Expr * dstParam,
    2929        const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
  • src/Validate/Autogen.cpp

    rd06273c r4e2f1b2  
    134134        /// (constructor call, destructor call, assignment call)
    135135        // This is managed because it uses another helper that returns a ast::ptr.
    136         ast::ptr<ast::Stmt> makeMemberOp(
     136        const ast::Stmt * makeMemberOp(
    137137                const CodeLocation& location,
    138138                const ast::ObjectDecl * dstParam, const ast::Expr * src,
     
    524524}
    525525
    526 ast::ptr<ast::Stmt> StructFuncGenerator::makeMemberOp(
     526const ast::Stmt * StructFuncGenerator::makeMemberOp(
    527527                const CodeLocation& location, const ast::ObjectDecl * dstParam,
    528528                const ast::Expr * src, const ast::ObjectDecl * field,
     
    539539                )
    540540        );
    541         auto stmt = genImplicitCall(
     541        const ast::Stmt * stmt = genImplicitCall(
    542542                srcParam, dstSelect, location, func->name,
    543543                field, direction
     
    597597                        location, field, new ast::VariableExpr( location, srcParam )
    598598                ) : nullptr;
    599                 ast::ptr<ast::Stmt> stmt =
     599                const ast::Stmt * stmt =
    600600                        makeMemberOp( location, dstParam, srcSelect, field, func, direction );
    601601
    602602                if ( nullptr != stmt ) {
    603                         stmts->kids.push_back( stmt );
     603                        stmts->kids.emplace_back( stmt );
    604604                }
    605605        }
     
    622622        for ( auto param = params.begin() + 1 ; current != end ; ++current ) {
    623623                const ast::ptr<ast::Decl> & member = *current;
    624                 ast::ptr<ast::Stmt> stmt = nullptr;
     624                const ast::Stmt * stmt = nullptr;
    625625                auto field = member.as<ast::ObjectDecl>();
    626626                // Not sure why it could be null.
     
    640640
    641641                if ( nullptr != stmt ) {
    642                         stmts->kids.push_back( stmt );
     642                        stmts->kids.emplace_back( stmt );
    643643                }
    644644        }
Note: See TracChangeset for help on using the changeset viewer.