Changeset 696bf6e


Ignore:
Timestamp:
Sep 25, 2017, 3:56:14 PM (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:
b4bfa0a
Parents:
3aeaecd
Message:

Convert FixCtorExprs? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r3aeaecd r696bf6e  
    242242                };
    243243
    244                 class FixCtorExprs final : public GenPoly::DeclMutator {
    245                   public:
     244                struct FixCtorExprs final : public WithDeclsToAdd, public WithIndexer {
    246245                        /// expands ConstructorExpr nodes into comma expressions, using a temporary for the first argument
    247246                        static void fix( std::list< Declaration * > & translationUnit );
    248247
    249                         using GenPoly::DeclMutator::mutate;
    250                         virtual Expression * mutate( ConstructorExpr * ctorExpr ) override;
     248                        Expression * postmutate( ConstructorExpr * ctorExpr );
    251249                };
    252250        } // namespace
     
    325323
    326324                void FixCtorExprs::fix( std::list< Declaration * > & translationUnit ) {
    327                         FixCtorExprs fixer;
    328                         fixer.mutateDeclarationList( translationUnit );
     325                        PassVisitor<FixCtorExprs> fixer;
     326                        mutateAll( translationUnit, fixer );
    329327                }
    330328
     
    11461144                }
    11471145
    1148                 Expression * FixCtorExprs::mutate( ConstructorExpr * ctorExpr ) {
     1146                Expression * FixCtorExprs::postmutate( ConstructorExpr * ctorExpr ) {
    11491147                        static UniqueName tempNamer( "_tmp_ctor_expr" );
    11501148                        // xxx - is the size check necessary?
     
    11531151                        // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
    11541152                        ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr );
    1155                         addDeclaration( tmp );
     1153                        declsToAddBefore.push_back( tmp );
    11561154
    11571155                        // xxx - this can be TupleAssignExpr now. Need to properly handle this case.
     
    11621160                        delete ctorExpr;
    11631161
     1162                        // build assignment and replace constructor's first argument with new temporary
    11641163                        Expression *& firstArg = callExpr->get_args().front();
    1165 
    1166                         // xxx - hack in 'fake' assignment operator until resolver can easily be called in this pass. Once the resolver can be used in PassVisitor, this hack goes away.
    1167 
    1168                         // generate the type of assignment operator using the type of tmp minus any reference types
    1169                         Type * type = tmp->get_type()->stripReferences();
    1170                         FunctionType * ftype = SymTab::genAssignType( type );
    1171 
    1172                         // generate fake assignment decl and call it using &tmp and &firstArg
    1173                         // since tmp is guaranteed to be a reference and we want to assign pointers
    1174                         FunctionDecl * assignDecl = new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Intrinsic, ftype, nullptr );
    1175                         ApplicationExpr * assign = new ApplicationExpr( VariableExpr::functionPointer( assignDecl ) );
    1176                         assign->get_args().push_back( new AddressExpr( new VariableExpr( tmp ) ) );
    1177                         Expression * addrArg = new AddressExpr( firstArg );
    1178                         // if firstArg has type T&&, then &firstArg has type T*&.
    1179                         // Cast away the reference to a value type so that the argument
    1180                         // matches the assignment's parameter types
    1181                         if ( dynamic_cast<ReferenceType *>( addrArg->get_result() ) ) {
    1182                                 addrArg = new CastExpr( addrArg, addrArg->get_result()->stripReferences()->clone() );
    1183                         }
    1184                         assign->get_args().push_back( addrArg );
     1164                        Expression * assign = new UntypedExpr( new NameExpr( "?=?" ), { new AddressExpr( new VariableExpr( tmp ) ), new AddressExpr( firstArg ) } );
    11851165                        firstArg = new VariableExpr( tmp );
     1166
     1167                        // resolve assignment and dispose of new env
     1168                        Expression * resolvedAssign = ResolvExpr::findVoidExpression( assign, indexer );
     1169                        delete resolvedAssign->env;
     1170                        resolvedAssign->env = nullptr;
     1171                        delete assign;
    11861172
    11871173                        // for constructor expr:
     
    11921178                        //   T & tmp;
    11931179                        //   &tmp = &x, ?{}(tmp), tmp
    1194                         CommaExpr * commaExpr = new CommaExpr( assign, new CommaExpr( callExpr, new VariableExpr( tmp ) ) );
     1180                        CommaExpr * commaExpr = new CommaExpr( resolvedAssign, new CommaExpr( callExpr, new VariableExpr( tmp ) ) );
    11951181                        commaExpr->set_env( env );
    11961182                        return commaExpr;
Note: See TracChangeset for help on using the changeset viewer.