Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    rc92c09c r62423350  
    6666                };
    6767
    68                 struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithTypeSubstitution {
    69                         Type * postmutate( TupleType * tupleType );
    70 
    71                         void premutate( CompoundStmt * ) {
    72                                 GuardScope( typeMap );
     68                class TupleTypeReplacer : public GenPoly::DeclMutator {
     69                  public:
     70                        typedef GenPoly::DeclMutator Parent;
     71                        using Parent::mutate;
     72
     73                        virtual Type * mutate( TupleType * tupleType ) override;
     74
     75                        virtual CompoundStmt * mutate( CompoundStmt * stmt ) override {
     76                                typeMap.beginScope();
     77                                stmt = Parent::mutate( stmt );
     78                                typeMap.endScope();
     79                                return stmt;
    7380                        }
    7481                  private:
     
    104111                mutateAll( translationUnit, assnExpander );
    105112
    106                 PassVisitor<TupleTypeReplacer> replacer;
    107                 mutateAll( translationUnit, replacer );
     113                TupleTypeReplacer replacer;
     114                replacer.mutateDeclarationList( translationUnit );
    108115
    109116                PassVisitor<TupleIndexExpander> idxExpander;
     
    211218        }
    212219
    213         Type * TupleTypeReplacer::postmutate( TupleType * tupleType ) {
     220        Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
     221                tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
    214222                unsigned tupleSize = tupleType->size();
    215223                if ( ! typeMap.count( tupleSize ) ) {
     
    218226                        decl->set_body( true );
    219227                        for ( size_t i = 0; i < tupleSize; ++i ) {
    220                                 TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", tupleSize, "_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any );
     228                                TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any );
    221229                                decl->get_members().push_back( new ObjectDecl( toString("field_", i ), Type::StorageClasses(), LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) );
    222230                                decl->get_parameters().push_back( tyParam );
     
    227235                        }
    228236                        typeMap[tupleSize] = decl;
    229                         declsToAddBefore.push_back( decl );
     237                        addDeclaration( decl );
    230238                }
    231239                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
     
    233241                StructDecl * decl = typeMap[tupleSize];
    234242                StructInstType * newType = new StructInstType( qualifiers, decl );
    235                 for ( auto p : group_iterate( tupleType->get_types(), decl->get_parameters() ) ) {
    236                         Type * t = std::get<0>(p);
    237                         TypeDecl * td = std::get<1>(p);
     243                for ( Type * t : *tupleType ) {
    238244                        newType->get_parameters().push_back( new TypeExpr( t->clone() ) );
    239                         if ( env ) {
    240                                 // add bindings to the type environment.
    241                                 // xxx - This may not be sufficient, it may be necessary to rename type variables on StructInstType?
    242                                 env->add( td->get_name(), t->clone() );
    243                         }
    244245                }
    245246                delete tupleType;
Note: See TracChangeset for help on using the changeset viewer.