@@ -142,6 +142,10 @@ static inline std::string type_to_str(const ASR::ttype_t *t)
142
142
return type_to_str (ASRUtils::type_get_past_pointer (
143
143
const_cast <ASR::ttype_t *>(t))) + " pointer" ;
144
144
}
145
+ case ASR::ttypeType::TypeParameter: {
146
+ ASR::TypeParameter_t* tp = ASR::down_cast<ASR::TypeParameter_t>(t);
147
+ return tp->m_param ;
148
+ }
145
149
default : throw LCompilersException (" Not implemented " + std::to_string (t->type ) + " ." );
146
150
}
147
151
}
@@ -983,16 +987,12 @@ static inline bool is_logical(ASR::ttype_t &x) {
983
987
}
984
988
985
989
static inline bool is_generic (ASR::ttype_t &x) {
986
- return ASR::is_a<ASR::TypeParameter_t>(*type_get_past_pointer (&x));
987
- }
988
-
989
- static inline std::string get_parameter_name (const ASR::ttype_t * t) {
990
- switch (t->type ) {
991
- case ASR::ttypeType::TypeParameter: {
992
- ASR::TypeParameter_t* tp = ASR::down_cast<ASR::TypeParameter_t>(t);
993
- return tp->m_param ;
990
+ switch (x.type ) {
991
+ case ASR::ttypeType::List: {
992
+ ASR::List_t *list_type = ASR::down_cast<ASR::List_t>(type_get_past_pointer (&x));
993
+ return is_generic (*list_type->m_type );
994
994
}
995
- default : throw LCompilersException ( " Cannot obtain type parameter from this type " );
995
+ default : return ASR::is_a<ASR::TypeParameter_t>(* type_get_past_pointer (&x) );
996
996
}
997
997
}
998
998
@@ -1156,7 +1156,7 @@ static inline ASR::ttype_t* duplicate_type(Allocator& al, const ASR::ttype_t* t,
1156
1156
ASR::dimension_t * dimsp = dims ? dims->p : tp->m_dims ;
1157
1157
size_t dimsn = dims ? dims->n : tp->n_dims ;
1158
1158
return ASRUtils::TYPE (ASR::make_TypeParameter_t (al, t->base .loc ,
1159
- tp->m_param , dimsp, dimsn));
1159
+ tp->m_param , dimsp, dimsn, tp-> m_rt , tp-> n_rt ));
1160
1160
}
1161
1161
default : throw LCompilersException (" Not implemented " + std::to_string (t->type ));
1162
1162
}
@@ -1183,7 +1183,7 @@ static inline ASR::ttype_t* duplicate_type_without_dims(Allocator& al, const ASR
1183
1183
case ASR::ttypeType::TypeParameter: {
1184
1184
ASR::TypeParameter_t* tp = ASR::down_cast<ASR::TypeParameter_t>(t);
1185
1185
return ASRUtils::TYPE (ASR::make_TypeParameter_t (al, t->base .loc ,
1186
- tp->m_param , nullptr , 0 ));
1186
+ tp->m_param , nullptr , 0 , tp-> m_rt , tp-> n_rt ));
1187
1187
}
1188
1188
default : throw LCompilersException (" Not implemented " + std::to_string (t->type ));
1189
1189
}
@@ -1416,6 +1416,17 @@ static inline ASR::ttype_t* get_type_parameter(ASR::ttype_t* t) {
1416
1416
}
1417
1417
}
1418
1418
1419
+ static inline bool has_trait (ASR::TypeParameter_t *tp, ASR::traitType rt) {
1420
+ for (size_t i=0 ; i<tp->n_rt ; i++) {
1421
+ ASR::Restriction_t *restriction = ASR::down_cast<ASR::Restriction_t>(tp->m_rt [i]);
1422
+ if (restriction->m_rt == rt) {
1423
+ return true ;
1424
+ }
1425
+ }
1426
+ return false ;
1427
+ }
1428
+
1429
+
1419
1430
class ReplaceArgVisitor : public ASR ::BaseExprReplacer<ReplaceArgVisitor> {
1420
1431
1421
1432
private:
0 commit comments