Changeset 4d2434a for src/SymTab


Ignore:
Timestamp:
Aug 2, 2016, 6:37:08 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8a443f4
Parents:
39f84a4
Message:

major reorganization of constructor generation from initializer list so that it now works with multi-dimensional arrays

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    r39f84a4 r4d2434a  
    3737        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
    3838        template< typename OutputIterator >
    39         void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward = true );
     39        void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
    4040
    4141        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types.
    4242        template< typename OutputIterator >
    43         void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out ) {
     43        void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
    4444                // want to be able to generate assignment, ctor, and dtor generically,
    4545                // so fname is either ?=?, ?{}, or ^?{}
     
    4747
    4848                // do something special for unnamed members
    49                 fExpr->get_args().push_back( new AddressExpr( dstParam ) );
     49                dstParam = new AddressExpr( dstParam );
     50                if ( addCast ) {
     51                        // cast to T* with qualifiers removed, so that qualified objects can be constructed
     52                        // and destructed with the same functions as non-qualified objects.
     53                        // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
     54                        // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
     55                        // remove lvalue as a qualifier, this can change to
     56                        //   type->get_qualifiers() = Type::Qualifiers();
     57                        assert( type );
     58                        Type * castType = type->clone();
     59                        castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
     60                        castType->set_isLvalue( true ); // xxx - might not need this
     61                        dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
     62                }
     63                fExpr->get_args().push_back( dstParam );
    5064
    5165    Statement * listInit = srcParam.buildListInit( fExpr );
     
    5670    std::list< Expression * > args = *++srcParam;
    5771    fExpr->get_args().splice( fExpr->get_args().end(), args );
    58 /*              if ( srcParam ) {
    59                         // xxx -
    60                         // make srcParam more complicated
    61                         // if srcParam contains
    62                         fExpr->get_args().push_back( srcParam );
    63                 }
    64 */
     72
    6573                *out++ = new ExprStmt( noLabels, fExpr );
     74
     75    srcParam.clearArrayIndices();
    6676        }
    6777
     
    6979        /// If forward is true, loop goes from 0 to N-1, else N-1 to 0
    7080        template< typename OutputIterator >
    71         void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool forward = true ) {
     81        void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) {
    7282                static UniqueName indexName( "_index" );
    7383
     
    124134                // for stmt's body, eventually containing call
    125135                CompoundStmt * body = new CompoundStmt( noLabels );
    126                 genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), forward );
     136                genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
    127137
    128138                // block containing for stmt and index variable
     
    136146
    137147        template< typename OutputIterator >
    138         void genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward ) {
     148        void genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
    139149                if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    140                         genArrayCall( srcParam, dstParam, fname, out, at, forward );
     150                        genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
    141151                } else {
    142                         genScalarCall( srcParam, dstParam, fname, out );
     152                        genScalarCall( srcParam, dstParam, fname, out, type, addCast );
    143153                }
    144154        }
     
    155165                if ( isUnnamedBitfield( obj ) ) return;
    156166
     167                bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) );
    157168                std::list< Statement * > stmts;
    158                 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), forward );
     169                genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward );
    159170
    160171                // 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
     
    162173    if ( stmts.size() == 1 ) {
    163174                Statement * callStmt = stmts.front();
    164                 if ( (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ) ) {
     175                if ( addCast ) {
    165176                        // implicitly generated ctor/dtor calls should be wrapped
    166177                        // so that later passes are aware they were generated.
Note: See TracChangeset for help on using the changeset viewer.