- Timestamp:
- Sep 14, 2023, 11:44:35 AM (15 months ago)
- Branches:
- master
- Children:
- 697c957
- Parents:
- a738c68
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/GenPoly.cc
ra738c68 r3df4cd9 48 48 } 49 49 50 bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env) { 51 for (auto ¶m : params) { 52 auto paramType = param.strict_as<ast::TypeExpr>(); 53 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 ¶m : 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; 54 55 } 55 56 return false; … … 62 63 assertf(paramType, "Aggregate parameters should be type expressions"); 63 64 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; 64 74 } 65 75 return false; … … 185 195 } 186 196 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 202 197 const ast::Type * isPolyType( const ast::Type * type, 203 198 const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) { … … 207 202 if ( typeVars.contains( *inst ) ) return type; 208 203 } else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) { 209 return isPolyType( array->base, subst );204 return isPolyType( array->base, typeVars, subst ); 210 205 } else if ( auto sue = dynamic_cast< const ast::StructInstType * >( type ) ) { 211 if ( hasPolyParams( sue->params, subst ) ) return type;206 if ( hasPolyParams( sue->params, typeVars, subst ) ) return type; 212 207 } else if ( auto sue = dynamic_cast< const ast::UnionInstType * >( type ) ) { 213 if ( hasPolyParams( sue->params, subst ) ) return type;208 if ( hasPolyParams( sue->params, typeVars, subst ) ) return type; 214 209 } 215 210 return nullptr;
Note: See TracChangeset
for help on using the changeset viewer.