Changeset 1a5ad8c


Ignore:
Timestamp:
Oct 19, 2017, 11:15:36 AM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
f30b261
Parents:
12536d3
git-author:
Rob Schluntz <rschlunt@…> (10/18/17 11:45:01)
git-committer:
Rob Schluntz <rschlunt@…> (10/19/17 11:15:36)
Message:

Update autogen to generate reference rebind for reference member copy constructors

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    r12536d3 r1a5ad8c  
    168168                deleteAll( indices );
    169169                indices.clear();
     170        }
     171
     172        bool InitExpander::addReference() {
     173                bool added = false;
     174                for ( Expression *& expr : cur ) {
     175                        expr = new AddressExpr( expr );
     176                        added = true;
     177                }
     178                return added;
    170179        }
    171180
  • src/InitTweak/InitTweak.h

    r12536d3 r1a5ad8c  
    105105                void addArrayIndex( Expression * index, Expression * dimension );
    106106                void clearArrayIndices();
     107                bool addReference();
    107108
    108109                class ExpanderImpl;
  • src/SymTab/Autogen.cc

    r12536d3 r1a5ad8c  
    379379                                // don't make a function whose parameter is an unnamed bitfield
    380380                                continue;
    381                         } else if ( ! InitTweak::isConstructable( field->get_type() ) ) {
    382                                 continue;
    383381                        }
    384382                        memCtorType->parameters.push_back( new ObjectDecl( field->name, Type::StorageClasses(), LinkageSpec::Cforall, 0, field->get_type()->clone(), 0 ) );
     
    412410                                        // don't assign const members, but do construct/destruct
    413411                                        continue;
    414                                 } else if ( CodeGen::isCtorDtor( func->name ) && ! InitTweak::isConstructable( type ) ) {
    415                                         // don't construct non-constructable types
    416                                         continue;
    417412                                }
    418413
     
    423418                                        srcParam = dynamic_cast<ObjectDecl*>( func->get_functionType()->get_parameters().back() );
    424419                                }
     420
    425421                                // srcParam may be NULL, in which case we have default ctor/dtor
    426422                                assert( dstParam );
     
    446442                                if ( isUnnamedBitfield( dynamic_cast< ObjectDecl * > ( field ) ) ) {
    447443                                        // don't make a function whose parameter is an unnamed bitfield
    448                                         continue;
    449                                 } else if ( ! InitTweak::isConstructable( field->get_type() ) ) {
    450                                         // don't construct non-constructable types
    451444                                        continue;
    452445                                } else if ( parameter != params.end() ) {
  • src/SymTab/Autogen.h

    r12536d3 r1a5ad8c  
    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
     
    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.