Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    re6cf857f r16ba4a6f  
    2121
    2222#include "AST/Decl.hpp"
     23#include "AST/Eval.hpp"
    2324#include "AST/Expr.hpp"
    2425#include "AST/Init.hpp"
     
    7071        template< typename OutIter >
    7172        ast::ptr< ast::Stmt > genCall(
    72                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
    73                 const CodeLocation & loc, const std::string & fname, OutIter && out,
     73                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
     74                const CodeLocation & loc, const std::string & fname, OutIter && out, 
    7475                const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward );
    7576
     
    127128        }
    128129
    129         /// inserts into out a generated call expression to function fname with arguments dstParam and
     130        /// inserts into out a generated call expression to function fname with arguments dstParam and 
    130131        /// srcParam. Should only be called with non-array types.
    131         /// optionally returns a statement which must be inserted prior to the containing loop, if
     132        /// optionally returns a statement which must be inserted prior to the containing loop, if 
    132133        /// there is one
    133134        template< typename OutIter >
    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,
     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, 
    137138                const ast::Type * addCast = nullptr
    138139        ) {
     
    152153
    153154                if ( addCast ) {
    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
     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 
    157158                        // lvalue-qualified type, so remove all qualifiers except lvalue.
    158159                        // xxx -- old code actually removed lvalue too...
    159160                        ast::ptr< ast::Type > guard = addCast;  // prevent castType from mutating addCast
    160161                        ast::ptr< ast::Type > castType = addCast;
    161                         ast::remove_qualifiers(
    162                                 castType,
     162                        ast::remove_qualifiers( 
     163                                castType, 
    163164                                ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Atomic );
    164165                        dstParam = new ast::CastExpr{ dstParam, new ast::ReferenceType{ castType } };
     
    180181
    181182                srcParam.clearArrayIndices();
    182 
     183               
    183184                return listInit;
    184185        }
     
    248249        }
    249250
    250         /// Store in out a loop which calls fname on each element of the array with srcParam and
     251        /// Store in out a loop which calls fname on each element of the array with srcParam and 
    251252        /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0
    252253        template< typename OutIter >
    253254        void genArrayCall(
    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
     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 
    258259        ) {
    259260                static UniqueName indexName( "_index" );
     
    278279                } else {
    279280                        // generate: for ( int i = N-1; i >= 0; --i )
    280                         begin = ast::UntypedExpr::createCall( loc, "?-?",
    281                                 { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) } );
     281                        begin = ast::call(
     282                                loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ) );
    282283                        end = ast::ConstantExpr::from_int( loc, 0 );
    283284                        cmp = "?>=?";
     
    285286                }
    286287
    287                 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{
    288                         loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt },
     288                ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 
     289                        loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 
    289290                        new ast::SingleInit{ loc, begin } };
    290291                ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index };
    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
     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
    302300                // array list initializer
    303301                srcParam.addArrayIndex( indexVar, array->dimension );
     
    305303                // for stmt's body, eventually containing call
    306304                ast::CompoundStmt * body = new ast::CompoundStmt{ loc };
    307                 ast::ptr< ast::Stmt > listInit = genCall(
    308                         srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast,
     305                ast::ptr< ast::Stmt > listInit = genCall( 
     306                        srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 
    309307                        forward );
    310 
     308               
    311309                // block containing the stmt and index variable
    312310                ast::CompoundStmt * block = new ast::CompoundStmt{ loc };
     
    330328        template< typename OutIter >
    331329        ast::ptr< ast::Stmt > genCall(
    332                 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam,
    333                 const CodeLocation & loc, const std::string & fname, OutIter && out,
     330                InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 
     331                const CodeLocation & loc, const std::string & fname, OutIter && out, 
    334332                const ast::Type * type, const ast::Type * addCast, LoopDirection forward
    335333        ) {
    336334                if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) {
    337                         genArrayCall(
    338                                 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast,
     335                        genArrayCall( 
     336                                srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 
    339337                                forward );
    340338                        return {};
    341339                } else {
    342                         return genScalarCall(
     340                        return genScalarCall( 
    343341                                srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast );
    344342                }
     
    379377        }
    380378
    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
     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 
    385383        ) {
    386384                // unnamed bit fields are not copied as they cannot be accessed
     
    394392
    395393                std::vector< ast::ptr< ast::Stmt > > stmts;
    396                 genCall(
     394                genCall( 
    397395                        srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward );
    398396
     
    402400                        const ast::Stmt * callStmt = stmts.front();
    403401                        if ( addCast ) {
    404                                 // implicitly generated ctor/dtor calls should be wrapped so that later passes are
     402                                // implicitly generated ctor/dtor calls should be wrapped so that later passes are 
    405403                                // aware they were generated.
    406404                                callStmt = new ast::ImplicitCtorDtorStmt{ callStmt->location, callStmt };
     
    419417// compile-command: "make install" //
    420418// End: //
     419
Note: See TracChangeset for help on using the changeset viewer.