Ignore:
Timestamp:
Oct 19, 2017, 12:01:04 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
837ce06
Parents:
b96ec83 (diff), a15b72c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    rb96ec83 r6840e7c  
    1919#include <string>                 // for string
    2020
     21#include "CodeGen/OperatorTable.h"
    2122#include "Common/UniqueName.h"    // for UniqueName
    2223#include "InitTweak/InitTweak.h"  // for InitExpander
     
    5152
    5253        // generate the type of a copy constructor for paramType
    53         FunctionType * genDefaultType( Type * paramType );
     54        FunctionType * genCopyType( Type * paramType );
    5455
    5556        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
     
    6061        /// optionally returns a statement which must be inserted prior to the containing loop, if there is one
    6162        template< typename OutputIterator >
    62         Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
     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
    6374                // want to be able to generate assignment, ctor, and dtor generically,
    6475                // so fname is either ?=?, ?{}, or ^?{}
    65                 UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
     76                UntypedExpr * fExpr = new UntypedExpr( new NameExpr( fname ) );
    6677
    6778                if ( addCast ) {
     
    7889                        dstParam = new CastExpr( dstParam, new ReferenceType( Type::Qualifiers(), castType ) );
    7990                }
    80                 fExpr->get_args().push_back( dstParam );
     91                fExpr->args.push_back( dstParam );
    8192
    8293                Statement * listInit = srcParam.buildListInit( fExpr );
    8394
    84                 std::list< Expression * > args = *++srcParam;
    85                 fExpr->get_args().splice( fExpr->get_args().end(), args );
     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 );
    86106
    87107                *out++ = new ExprStmt( noLabels, fExpr );
     
    105125                        // generate: for ( int i = 0; i < N; ++i )
    106126                        begin = new ConstantExpr( Constant::from_int( 0 ) );
    107                         end = array->get_dimension()->clone();
     127                        end = array->dimension->clone();
    108128                        cmp = new NameExpr( "?<?" );
    109129                        update = new NameExpr( "++?" );
     
    111131                        // generate: for ( int i = N-1; i >= 0; --i )
    112132                        begin = new UntypedExpr( new NameExpr( "?-?" ) );
    113                         ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() );
    114                         ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) );
     133                        ((UntypedExpr*)begin)->args.push_back( array->dimension->clone() );
     134                        ((UntypedExpr*)begin)->args.push_back( new ConstantExpr( Constant::from_int( 1 ) ) );
    115135                        end = new ConstantExpr( Constant::from_int( 0 ) );
    116136                        cmp = new NameExpr( "?>=?" );
     
    121141
    122142                UntypedExpr *cond = new UntypedExpr( cmp );
    123                 cond->get_args().push_back( new VariableExpr( index ) );
    124                 cond->get_args().push_back( end );
     143                cond->args.push_back( new VariableExpr( index ) );
     144                cond->args.push_back( end );
    125145
    126146                UntypedExpr *inc = new UntypedExpr( update );
    127                 inc->get_args().push_back( new VariableExpr( index ) );
     147                inc->args.push_back( new VariableExpr( index ) );
    128148
    129149                UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
    130                 dstIndex->get_args().push_back( dstParam );
    131                 dstIndex->get_args().push_back( new VariableExpr( index ) );
     150                dstIndex->args.push_back( dstParam );
     151                dstIndex->args.push_back( new VariableExpr( index ) );
    132152                dstParam = dstIndex;
    133153
    134154                // srcParam must keep track of the array indices to build the
    135155                // source parameter and/or array list initializer
    136                 srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() );
     156                srcParam.addArrayIndex( new VariableExpr( index ), array->dimension->clone() );
    137157
    138158                // for stmt's body, eventually containing call
    139159                CompoundStmt * body = new CompoundStmt( noLabels );
    140                 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
     160                Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->kids ), array->base, addCast, forward );
    141161
    142162                // block containing for stmt and index variable
    143163                std::list<Statement *> initList;
    144164                CompoundStmt * block = new CompoundStmt( noLabels );
    145                 block->get_kids().push_back( new DeclStmt( noLabels, index ) );
     165                block->push_back( new DeclStmt( noLabels, index ) );
    146166                if ( listInit ) block->get_kids().push_back( listInit );
    147                 block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
     167                block->push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
    148168
    149169                *out++ = block;
     
    151171
    152172        template< typename OutputIterator >
    153         Statement * genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
     173        Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
    154174                if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    155175                        genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
     
    165185        /// ImplicitCtorDtorStmt node.
    166186        template< typename OutputIterator >
    167         void genImplicitCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
     187        void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
    168188                ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl );
    169189                assert( obj );
     
    173193                bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) );
    174194                std::list< Statement * > stmts;
    175                 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward );
     195                genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward );
    176196
    177197                // 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.