Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGeneric.cc

    r87c3bef r5a3ac84  
    1616#include <cassert>
    1717#include <list>
     18#include <unordered_map>
    1819#include <utility>
    1920#include <vector>
    20 #include <unordered_map>
    2121
    2222#include "InstantiateGeneric.h"
     
    2525#include "GenPoly.h"
    2626#include "ScopedSet.h"
     27#include "ScrubTyVars.h"
    2728#include "PolyMutator.h"
    2829
     
    7778                        if ( params.size() != that.params.size() ) return false;
    7879
    79                         SymTab::Indexer dummy;
    8080                        for ( std::list< Type* >::const_iterator it = params.begin(), jt = that.params.begin(); it != params.end(); ++it, ++jt ) {
    81                                 if ( ! ResolvExpr::typesCompatible( *it, *jt, dummy ) ) return false;
     81                                if ( ! typesPolyCompatible( *it, *jt ) ) return false;
    8282                        }
    8383                        return true;
     
    227227                        if ( (*baseParam)->isComplete() ) {
    228228                                // substitute parameter for complete (otype or sized dtype) type
    229                                 int pointerLevels = 0;
    230                                 if ( hasPolyBase( paramType->get_type(), &pointerLevels ) && pointerLevels > 0 ) {
    231                                         // Make a void* with equivalent nesting
    232                                         Type* voidPtr = new VoidType( Type::Qualifiers() );
    233                                         while ( pointerLevels > 0 ) {
    234                                                 // Just about data layout, so qualifiers *shouldn't* matter
    235                                                 voidPtr = new PointerType( Type::Qualifiers(), voidPtr );
    236                                                 --pointerLevels;
    237                                         }
    238                                         out.push_back( new TypeExpr( voidPtr ) );
     229                                if ( isPolyType( paramType->get_type() ) ) {
     230                                        // substitute polymorphic parameter type in to generic type
     231                                        out.push_back( paramType->clone() );
     232                                        gt = genericType::dynamic;
    239233                                } else {
    240                                         // Just clone parameter type
    241                                         out.push_back( paramType->clone() );
     234                                        // normalize possibly dtype-static parameter type
     235                                        out.push_back( new TypeExpr{
     236                                                ScrubTyVars::scrubAll( paramType->get_type()->clone() ) } );
     237                                        gt |= genericType::concrete;
    242238                                }
    243                                 // make the struct concrete or dynamic depending on the parameter
    244                                 gt |= isPolyType( paramType->get_type() ) ? genericType::dynamic : genericType::concrete;
    245239                        } else switch ( (*baseParam)->get_kind() ) {
    246240                                case TypeDecl::Dtype:
     
    372366                                concDecl = new StructDecl( typeNamer.newName( inst->get_name() ) );
    373367                                concDecl->set_body( inst->get_baseStruct()->has_body() );
    374                                 substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs,        concDecl->get_members() );
     368                                substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
    375369                                DeclMutator::addDeclaration( concDecl );
    376370                                insert( inst, typeSubs, concDecl );
Note: See TracChangeset for help on using the changeset viewer.