Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    r1a5ad8c ra4477db  
    1919#include <string>                 // for string
    2020
    21 #include "CodeGen/OperatorTable.h"
    2221#include "Common/UniqueName.h"    // for UniqueName
    2322#include "InitTweak/InitTweak.h"  // for InitExpander
     
    5251
    5352        // generate the type of a copy constructor for paramType
    54         FunctionType * genCopyType( Type * paramType );
     53        FunctionType * genDefaultType( Type * paramType );
    5554
    5655        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
     
    6160        /// optionally returns a statement which must be inserted prior to the containing loop, if there is one
    6261        template< typename OutputIterator >
    63         Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, bool addCast = false ) {
    64                 bool isReferenceCtorDtor = false;
    65                 if ( dynamic_cast< ReferenceType * >( type ) && CodeGen::isCtorDtor( fname ) ) {
    66                         // reference constructors are essentially application of the rebind operator.
    67                         // apply & to both arguments, do not need a cast
    68                         fname = "?=?";
    69                         dstParam = new AddressExpr( dstParam );
    70                         addCast = false;
    71                         isReferenceCtorDtor = true;
    72                 }
    73 
     62        Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
    7463                // want to be able to generate assignment, ctor, and dtor generically,
    7564                // so fname is either ?=?, ?{}, or ^?{}
    76                 UntypedExpr * fExpr = new UntypedExpr( new NameExpr( fname ) );
     65                UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
    7766
    7867                if ( addCast ) {
     
    8978                        dstParam = new CastExpr( dstParam, new ReferenceType( Type::Qualifiers(), castType ) );
    9079                }
    91                 fExpr->args.push_back( dstParam );
     80                fExpr->get_args().push_back( dstParam );
    9281
    9382                Statement * listInit = srcParam.buildListInit( fExpr );
    9483
    95                 // fetch next set of arguments
    96                 ++srcParam;
    97 
    98                 // return if adding reference fails - will happen on default constructor and destructor
    99                 if ( isReferenceCtorDtor && ! srcParam.addReference() ) {
    100                         delete fExpr;
    101                         return listInit;
    102                 }
    103 
    104                 std::list< Expression * > args = *srcParam;
    105                 fExpr->args.splice( fExpr->args.end(), args );
     84                std::list< Expression * > args = *++srcParam;
     85                fExpr->get_args().splice( fExpr->get_args().end(), args );
    10686
    10787                *out++ = new ExprStmt( noLabels, fExpr );
     
    125105                        // generate: for ( int i = 0; i < N; ++i )
    126106                        begin = new ConstantExpr( Constant::from_int( 0 ) );
    127                         end = array->dimension->clone();
     107                        end = array->get_dimension()->clone();
    128108                        cmp = new NameExpr( "?<?" );
    129109                        update = new NameExpr( "++?" );
     
    131111                        // generate: for ( int i = N-1; i >= 0; --i )
    132112                        begin = new UntypedExpr( new NameExpr( "?-?" ) );
    133                         ((UntypedExpr*)begin)->args.push_back( array->dimension->clone() );
    134                         ((UntypedExpr*)begin)->args.push_back( new ConstantExpr( Constant::from_int( 1 ) ) );
     113                        ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() );
     114                        ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) );
    135115                        end = new ConstantExpr( Constant::from_int( 0 ) );
    136116                        cmp = new NameExpr( "?>=?" );
     
    141121
    142122                UntypedExpr *cond = new UntypedExpr( cmp );
    143                 cond->args.push_back( new VariableExpr( index ) );
    144                 cond->args.push_back( end );
     123                cond->get_args().push_back( new VariableExpr( index ) );
     124                cond->get_args().push_back( end );
    145125
    146126                UntypedExpr *inc = new UntypedExpr( update );
    147                 inc->args.push_back( new VariableExpr( index ) );
     127                inc->get_args().push_back( new VariableExpr( index ) );
    148128
    149129                UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
    150                 dstIndex->args.push_back( dstParam );
    151                 dstIndex->args.push_back( new VariableExpr( index ) );
     130                dstIndex->get_args().push_back( dstParam );
     131                dstIndex->get_args().push_back( new VariableExpr( index ) );
    152132                dstParam = dstIndex;
    153133
    154134                // srcParam must keep track of the array indices to build the
    155135                // source parameter and/or array list initializer
    156                 srcParam.addArrayIndex( new VariableExpr( index ), array->dimension->clone() );
     136                srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() );
    157137
    158138                // for stmt's body, eventually containing call
    159139                CompoundStmt * body = new CompoundStmt( noLabels );
    160                 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->kids ), array->base, addCast, forward );
     140                Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
    161141
    162142                // block containing for stmt and index variable
    163143                std::list<Statement *> initList;
    164144                CompoundStmt * block = new CompoundStmt( noLabels );
    165                 block->push_back( new DeclStmt( noLabels, index ) );
     145                block->get_kids().push_back( new DeclStmt( noLabels, index ) );
    166146                if ( listInit ) block->get_kids().push_back( listInit );
    167                 block->push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
     147                block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
    168148
    169149                *out++ = block;
     
    171151
    172152        template< typename OutputIterator >
    173         Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
     153        Statement * genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
    174154                if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    175155                        genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
     
    185165        /// ImplicitCtorDtorStmt node.
    186166        template< typename OutputIterator >
    187         void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
     167        void genImplicitCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
    188168                ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl );
    189169                assert( obj );
     
    193173                bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) );
    194174                std::list< Statement * > stmts;
    195                 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward );
     175                genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward );
    196176
    197177                // currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call
Note: See TracChangeset for help on using the changeset viewer.