Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/GenPoly.cc

    r3df4cd9 rc97b448  
    4848                }
    4949
    50                 bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env ) {
    51                         for ( auto &param : params ) {
    52                                 auto paramType = param.as<ast::TypeExpr>();
    53                                 assertf( paramType, "Aggregate parameters should be type expressions" );
    54                                 if ( isPolyType( paramType->type, env ) ) return true;
     50                bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env) {
     51                        for (auto &param : params) {
     52                                auto paramType = param.strict_as<ast::TypeExpr>();
     53                                if (isPolyType(paramType->type, env)) return true;
    5554                        }
    5655                        return false;
     
    6362                                assertf(paramType, "Aggregate parameters should be type expressions");
    6463                                if ( isPolyType( paramType->get_type(), tyVars, env ) ) return true;
    65                         }
    66                         return false;
    67                 }
    68 
    69                 bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const TypeVarMap & typeVars, const ast::TypeSubstitution * env ) {
    70                         for ( auto & param : params ) {
    71                                 auto paramType = param.as<ast::TypeExpr>();
    72                                 assertf( paramType, "Aggregate parameters should be type expressions" );
    73                                 if ( isPolyType( paramType->type, typeVars, env ) ) return true;
    7464                        }
    7565                        return false;
     
    195185        }
    196186
     187        const ast::Type * isPolyType(const ast::Type * type, const TyVarMap & tyVars, const ast::TypeSubstitution * env) {
     188                type = replaceTypeInst( type, env );
     189
     190                if ( auto typeInst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
     191                        if ( tyVars.contains( typeInst->typeString() ) ) return type;
     192                } else if ( auto arrayType = dynamic_cast< const ast::ArrayType * >( type ) ) {
     193                        return isPolyType( arrayType->base, env );
     194                } else if ( auto structType = dynamic_cast< const ast::StructInstType* >( type ) ) {
     195                        if ( hasPolyParams( structType->params, env ) ) return type;
     196                } else if ( auto unionType = dynamic_cast< const ast::UnionInstType* >( type ) ) {
     197                        if ( hasPolyParams( unionType->params, env ) ) return type;
     198                }
     199                return nullptr;
     200        }
     201
    197202const ast::Type * isPolyType( const ast::Type * type,
    198203                const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) {
     
    202207                if ( typeVars.contains( *inst ) ) return type;
    203208        } else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) {
    204                 return isPolyType( array->base, typeVars, subst );
     209                return isPolyType( array->base, subst );
    205210        } else if ( auto sue = dynamic_cast< const ast::StructInstType * >( type ) ) {
    206                 if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
     211                if ( hasPolyParams( sue->params, subst ) ) return type;
    207212        } else if ( auto sue = dynamic_cast< const ast::UnionInstType * >( type ) ) {
    208                 if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
     213                if ( hasPolyParams( sue->params, subst ) ) return type;
    209214        }
    210215        return nullptr;
Note: See TracChangeset for help on using the changeset viewer.