Changeset e6cf857f for src


Ignore:
Timestamp:
May 18, 2022, 2:24:48 PM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
288927f
Parents:
767a8ef
Message:

call -> createCall: The template wrapper has been removed and now it is beside similar helper functions.

Location:
src
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r767a8ef re6cf857f  
    1010// Created On       : Wed May 15 17:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Created On       : Tue Nov 30 14:23:00 2021
    13 // Update Count     : 7
     12// Created On       : Wed May 18 13:56:00 2022
     13// Update Count     : 8
    1414//
    1515
     
    2121
    2222#include "Copy.hpp"                // for shallowCopy
    23 #include "Eval.hpp"                // for call
    2423#include "GenericSubstitution.hpp"
    2524#include "LinkageSpec.hpp"
     
    6766// --- UntypedExpr
    6867
     68bool UntypedExpr::get_lvalue() const {
     69        std::string fname = InitTweak::getFunctionName( this );
     70        return lvalueFunctionNames.count( fname );
     71}
     72
    6973UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, const Expr * arg ) {
    7074        assert( arg );
    7175
    72         UntypedExpr * ret = call( loc, "*?", arg );
     76        UntypedExpr * ret = createCall( loc, "*?", { arg } );
    7377        if ( const Type * ty = arg->result ) {
    7478                const Type * base = InitTweak::getPointerBase( ty );
     
    8791}
    8892
    89 bool UntypedExpr::get_lvalue() const {
    90         std::string fname = InitTweak::getFunctionName( this );
    91         return lvalueFunctionNames.count( fname );
    92 }
    93 
    9493UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs ) {
    9594        assert( lhs && rhs );
    9695
    97         UntypedExpr * ret = call( loc, "?=?", lhs, rhs );
     96        UntypedExpr * ret = createCall( loc, "?=?", { lhs, rhs } );
    9897        if ( lhs->result && rhs->result ) {
    9998                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
     
    102101        }
    103102        return ret;
     103}
     104
     105UntypedExpr * UntypedExpr::createCall( const CodeLocation & loc,
     106                const std::string & name, std::vector<ptr<Expr>> && args ) {
     107        return new UntypedExpr( loc,
     108                        new NameExpr( loc, name ), std::move( args ) );
    104109}
    105110
  • src/AST/Expr.hpp

    r767a8ef re6cf857f  
    230230        /// Creates a new assignment expression
    231231        static UntypedExpr * createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs );
     232        /// Creates a new call of a variable.
     233        static UntypedExpr * createCall( const CodeLocation & loc,
     234                const std::string & name, std::vector<ptr<Expr>> && args );
    232235
    233236        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/module.mk

    r767a8ef re6cf857f  
    2929        AST/DeclReplacer.cpp \
    3030        AST/DeclReplacer.hpp \
    31         AST/Eval.hpp \
    3231        AST/Expr.cpp \
    3332        AST/Expr.hpp \
  • src/SymTab/Autogen.h

    r767a8ef re6cf857f  
    2121
    2222#include "AST/Decl.hpp"
    23 #include "AST/Eval.hpp"
    2423#include "AST/Expr.hpp"
    2524#include "AST/Init.hpp"
     
    7170        template< typename OutIter >
    7271        ast::ptr< ast::Stmt > genCall(
    73                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    74                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
     72                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     73                const CodeLocation & loc, const std::string & fname, OutIter && out,
    7574                const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward );
    7675
     
    128127        }
    129128
    130         /// inserts into out a generated call expression to function fname with arguments dstParam and 
     129        /// inserts into out a generated call expression to function fname with arguments dstParam and
    131130        /// srcParam. Should only be called with non-array types.
    132         /// optionally returns a statement which must be inserted prior to the containing loop, if 
     131        /// optionally returns a statement which must be inserted prior to the containing loop, if
    133132        /// there is one
    134133        template< typename OutIter >
    135         ast::ptr< ast::Stmt > genScalarCall( 
    136                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    137                 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 
     134        ast::ptr< ast::Stmt > genScalarCall(
     135                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     136                const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type,
    138137                const ast::Type * addCast = nullptr
    139138        ) {
     
    153152
    154153                if ( addCast ) {
    155                         // cast to T& with qualifiers removed, so that qualified objects can be constructed and 
    156                         // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 
    157                         // is considered a qualifier - for AddressExpr to resolve, its argument must have an 
     154                        // cast to T& with qualifiers removed, so that qualified objects can be constructed and
     155                        // destructed with the same functions as non-qualified objects. Unfortunately, lvalue
     156                        // is considered a qualifier - for AddressExpr to resolve, its argument must have an
    158157                        // lvalue-qualified type, so remove all qualifiers except lvalue.
    159158                        // xxx -- old code actually removed lvalue too...
    160159                        ast::ptr< ast::Type > guard = addCast;  // prevent castType from mutating addCast
    161160                        ast::ptr< ast::Type > castType = addCast;
    162                         ast::remove_qualifiers( 
    163                                 castType, 
     161                        ast::remove_qualifiers(
     162                                castType,
    164163                                ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Atomic );
    165164                        dstParam = new ast::CastExpr{ dstParam, new ast::ReferenceType{ castType } };
     
    181180
    182181                srcParam.clearArrayIndices();
    183                
     182
    184183                return listInit;
    185184        }
     
    249248        }
    250249
    251         /// Store in out a loop which calls fname on each element of the array with srcParam and 
     250        /// Store in out a loop which calls fname on each element of the array with srcParam and
    252251        /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0
    253252        template< typename OutIter >
    254253        void genArrayCall(
    255                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    256                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
    257                 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 
    258                 LoopDirection forward = LoopForward 
     254                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     255                const CodeLocation & loc, const std::string & fname, OutIter && out,
     256                const ast::ArrayType * array, const ast::Type * addCast = nullptr,
     257                LoopDirection forward = LoopForward
    259258        ) {
    260259                static UniqueName indexName( "_index" );
     
    279278                } else {
    280279                        // generate: for ( int i = N-1; i >= 0; --i )
    281                         begin = ast::call(
    282                                 loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ) );
     280                        begin = ast::UntypedExpr::createCall( loc, "?-?",
     281                                { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) } );
    283282                        end = ast::ConstantExpr::from_int( loc, 0 );
    284283                        cmp = "?>=?";
     
    286285                }
    287286
    288                 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 
    289                         loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 
     287                ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{
     288                        loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt },
    290289                        new ast::SingleInit{ loc, begin } };
    291290                ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index };
    292                
    293                 ast::ptr< ast::Expr > cond = ast::call( loc, cmp, indexVar, end );
    294                
    295                 ast::ptr< ast::Expr > inc = ast::call( loc, update, indexVar );
    296                
    297                 ast::ptr< ast::Expr > dstIndex = ast::call( loc, "?[?]", dstParam, indexVar );
    298                
    299                 // srcParam must keep track of the array indices to build the source parameter and/or
     291
     292                ast::ptr< ast::Expr > cond = ast::UntypedExpr::createCall(
     293                        loc, cmp, { indexVar, end } );
     294
     295                ast::ptr< ast::Expr > inc = ast::UntypedExpr::createCall(
     296                        loc, update, { indexVar } );
     297
     298                ast::ptr< ast::Expr > dstIndex = ast::UntypedExpr::createCall(
     299                        loc, "?[?]", { dstParam, indexVar } );
     300
     301                // srcParam must keep track of the array indices to build the source parameter and/or
    300302                // array list initializer
    301303                srcParam.addArrayIndex( indexVar, array->dimension );
     
    303305                // for stmt's body, eventually containing call
    304306                ast::CompoundStmt * body = new ast::CompoundStmt{ loc };
    305                 ast::ptr< ast::Stmt > listInit = genCall( 
    306                         srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 
     307                ast::ptr< ast::Stmt > listInit = genCall(
     308                        srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast,
    307309                        forward );
    308                
     310
    309311                // block containing the stmt and index variable
    310312                ast::CompoundStmt * block = new ast::CompoundStmt{ loc };
     
    328330        template< typename OutIter >
    329331        ast::ptr< ast::Stmt > genCall(
    330                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    331                 const CodeLocation & loc, const std::string & fname, OutIter && out, 
     332                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     333                const CodeLocation & loc, const std::string & fname, OutIter && out,
    332334                const ast::Type * type, const ast::Type * addCast, LoopDirection forward
    333335        ) {
    334336                if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
    335                         genArrayCall( 
    336                                 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 
     337                        genArrayCall(
     338                                srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast,
    337339                                forward );
    338340                        return {};
    339341                } else {
    340                         return genScalarCall( 
     342                        return genScalarCall(
    341343                                srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast );
    342344                }
     
    377379        }
    378380
    379         static inline ast::ptr< ast::Stmt > genImplicitCall( 
    380                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
    381                 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 
    382                 LoopDirection forward = LoopForward 
     381        static inline ast::ptr< ast::Stmt > genImplicitCall(
     382                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
     383                const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj,
     384                LoopDirection forward = LoopForward
    383385        ) {
    384386                // unnamed bit fields are not copied as they cannot be accessed
     
    392394
    393395                std::vector< ast::ptr< ast::Stmt > > stmts;
    394                 genCall( 
     396                genCall(
    395397                        srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward );
    396398
     
    400402                        const ast::Stmt * callStmt = stmts.front();
    401403                        if ( addCast ) {
    402                                 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 
     404                                // implicitly generated ctor/dtor calls should be wrapped so that later passes are
    403405                                // aware they were generated.
    404406                                callStmt = new ast::ImplicitCtorDtorStmt{ callStmt->location, callStmt };
     
    417419// compile-command: "make install" //
    418420// End: //
    419 
Note: See TracChangeset for help on using the changeset viewer.