Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/InstantiateGeneric.cc

    r5a3ac84 r87c3bef  
    1616#include <cassert>
    1717#include <list>
    18 #include <unordered_map>
    1918#include <utility>
    2019#include <vector>
     20#include <unordered_map>
    2121
    2222#include "InstantiateGeneric.h"
     
    2525#include "GenPoly.h"
    2626#include "ScopedSet.h"
    27 #include "ScrubTyVars.h"
    2827#include "PolyMutator.h"
    2928
     
    7877                        if ( params.size() != that.params.size() ) return false;
    7978
     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 ( ! typesPolyCompatible( *it, *jt ) ) return false;
     81                                if ( ! ResolvExpr::typesCompatible( *it, *jt, dummy ) ) return false;
    8282                        }
    8383                        return true;
     
    227227                        if ( (*baseParam)->isComplete() ) {
    228228                                // substitute parameter for complete (otype or sized dtype) type
    229                                 if ( isPolyType( paramType->get_type() ) ) {
    230                                         // substitute polymorphic parameter type in to generic 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 ) );
     239                                } else {
     240                                        // Just clone parameter type
    231241                                        out.push_back( paramType->clone() );
    232                                         gt = genericType::dynamic;
    233                                 } else {
    234                                         // normalize possibly dtype-static parameter type
    235                                         out.push_back( new TypeExpr{
    236                                                 ScrubTyVars::scrubAll( paramType->get_type()->clone() ) } );
    237                                         gt |= genericType::concrete;
    238242                                }
     243                                // make the struct concrete or dynamic depending on the parameter
     244                                gt |= isPolyType( paramType->get_type() ) ? genericType::dynamic : genericType::concrete;
    239245                        } else switch ( (*baseParam)->get_kind() ) {
    240246                                case TypeDecl::Dtype:
     
    366372                                concDecl = new StructDecl( typeNamer.newName( inst->get_name() ) );
    367373                                concDecl->set_body( inst->get_baseStruct()->has_body() );
    368                                 substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
     374                                substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs,        concDecl->get_members() );
    369375                                DeclMutator::addDeclaration( concDecl );
    370376                                insert( inst, typeSubs, concDecl );
Note: See TracChangeset for help on using the changeset viewer.