Ignore:
Timestamp:
Jul 12, 2017, 4:57:23 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, 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:
c5e3208
Parents:
a61ad31
Message:

Update autogen to generate ctor/dtor/assign with references

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    ra61ad31 r49148d5  
    4343        template< typename OutputIterator >
    4444        Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
    45         // want to be able to generate assignment, ctor, and dtor generically,
    46         // so fname is either ?=?, ?{}, or ^?{}
    47         UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
     45                // want to be able to generate assignment, ctor, and dtor generically,
     46                // so fname is either ?=?, ?{}, or ^?{}
     47                UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
    4848
    49         // do something special for unnamed members
    50         dstParam = new AddressExpr( dstParam );
    51         if ( addCast ) {
    52                 // cast to T* with qualifiers removed, so that qualified objects can be constructed
    53                 // and destructed with the same functions as non-qualified objects.
    54                 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
    55                 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
    56                 // remove lvalue as a qualifier, this can change to
    57                 //   type->get_qualifiers() = Type::Qualifiers();
    58                 assert( type );
    59                 Type * castType = type->clone();
    60                 castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
    61                 castType->set_lvalue( true ); // xxx - might not need this
    62                 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
    63         }
    64         fExpr->get_args().push_back( dstParam );
     49                if ( addCast ) {
     50                        // cast to T& with qualifiers removed, so that qualified objects can be constructed
     51                        // and destructed with the same functions as non-qualified objects.
     52                        // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
     53                        // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
     54                        // remove lvalue as a qualifier, this can change to
     55                        //   type->get_qualifiers() = Type::Qualifiers();
     56                        assert( type );
     57                        Type * castType = type->clone();
     58                        castType->get_qualifiers() -= Type::Qualifiers( Type::Lvalue | Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
     59                        // castType->set_lvalue( true ); // xxx - might not need this
     60                        dstParam = new CastExpr( dstParam, new ReferenceType( Type::Qualifiers(), castType ) );
     61                }
     62                fExpr->get_args().push_back( dstParam );
    6563
    66         Statement * listInit = srcParam.buildListInit( fExpr );
     64                Statement * listInit = srcParam.buildListInit( fExpr );
    6765
    68         std::list< Expression * > args = *++srcParam;
    69         fExpr->get_args().splice( fExpr->get_args().end(), args );
     66                std::list< Expression * > args = *++srcParam;
     67                fExpr->get_args().splice( fExpr->get_args().end(), args );
    7068
    71         *out++ = new ExprStmt( noLabels, fExpr );
     69                *out++ = new ExprStmt( noLabels, fExpr );
    7270
    73         srcParam.clearArrayIndices();
     71                srcParam.clearArrayIndices();
    7472
    75         return listInit;
     73                return listInit;
    7674        }
    7775
     
    109107
    110108                UntypedExpr *inc = new UntypedExpr( update );
    111                 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
     109                inc->get_args().push_back( new VariableExpr( index ) );
    112110
    113111                UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
Note: See TracChangeset for help on using the changeset viewer.