Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGeneric.cpp

    r30bf6bf ra21aaff  
    4242
    4343using type_vector = ast::vector< ast::TypeExpr >;
    44 
    45 template<typename C, typename V>
    46 bool contains( C const & container, V const & value ) {
    47         return std::any_of( container.begin(), container.end(),
    48                         [value]( auto& element ){ return element == value; } );
    49 }
    5044
    5145/// Abstracts type equality for a list of parameter types.
     
    429423}
    430424
    431 class GenericInstantiator final :
     425struct GenericInstantiator final :
    432426                public ast::WithCodeLocation,
    433427                public ast::WithConstTypeSubstitution,
     
    450444        /// member from an instantiation.
    451445        int memberIndex = -1;
    452         /// The polymorphic types we are currently instantiating.
    453         ast::vector<ast::Decl> instantiating;
    454 public:
    455446
    456447        GenericInstantiator() :
     
    606597                        );
    607598
    608                         // Insert the declaration so it doesn't create it again,
     599                        // Forward declare before recursion. (TODO: Only when needed, #199.)
    609600                        insert( inst, typeSubs, newDecl );
    610                         // ... but mark this declaration as one we are working on.
    611                         auto guard = makeFuncGuard(
    612                                 [this, newDecl](){ instantiating.push_back( newDecl ); },
    613                                 [this](){ instantiating.pop_back(); } );
     601                        if ( AggrDecl const * forwardDecl = ast::asForward( newDecl ) ) {
     602                                declsToAddBefore.push_back( forwardDecl );
     603                        }
    614604                        // Recursively instantiate members:
    615605                        concDecl = strict_dynamic_cast<AggrDecl const *>(
    616606                                newDecl->accept( *visitor ) );
    617 
    618                         // Produce the declaration after its members are instantiated.
     607                        // Must occur before declaration is added so
     608                        // that member instantiation appear first.
    619609                        declsToAddBefore.push_back( concDecl );
    620                 } else if ( contains( instantiating, concDecl ) ) {
    621                         if ( AggrDecl const * forwardDecl = ast::asForward( concDecl ) ) {
    622                                 declsToAddBefore.push_back( forwardDecl );
    623                         }
    624610                }
    625611                return new ast::SueInstType<AggrDecl>( concDecl, inst->qualifiers );
Note: See TracChangeset for help on using the changeset viewer.