@@ -1688,42 +1688,17 @@ static inline bool is_logical(ASR::ttype_t &x) {
1688
1688
type_get_past_pointer (&x))));
1689
1689
}
1690
1690
1691
- static inline bool is_generic (ASR::ttype_t &x) {
1692
- switch (x.type ) {
1693
- case ASR::ttypeType::List: {
1694
- ASR::List_t *list_type = ASR::down_cast<ASR::List_t>(type_get_past_pointer (&x));
1695
- return is_generic (*list_type->m_type );
1696
- }
1697
- case ASR::ttypeType::Array: {
1698
- ASR::Array_t* array_t = ASR::down_cast<ASR::Array_t>(type_get_past_pointer (&x));
1699
- return is_generic (*array_t ->m_type );
1700
- }
1701
- default : return ASR::is_a<ASR::TypeParameter_t>(*type_get_past_pointer (&x));
1702
- }
1703
- }
1704
-
1705
1691
static inline bool is_type_parameter (ASR::ttype_t &x) {
1706
1692
switch (x.type ) {
1707
1693
case ASR::ttypeType::List: {
1708
1694
ASR::List_t *list_type = ASR::down_cast<ASR::List_t>(type_get_past_pointer (&x));
1709
1695
return is_type_parameter (*list_type->m_type );
1710
1696
}
1711
- default : return ASR::is_a<ASR::TypeParameter_t>(*type_get_past_pointer (&x));
1712
- }
1713
- }
1714
-
1715
- static inline bool is_template_function (ASR::symbol_t *x) {
1716
- ASR::symbol_t * x2 = symbol_get_past_external (x);
1717
- switch (x2->type ) {
1718
- case ASR::symbolType::Function: {
1719
- const SymbolTable* parent_symtab = symbol_parent_symtab (x2);
1720
- if (ASR::is_a<ASR::symbol_t >(*parent_symtab->asr_owner )) {
1721
- ASR::symbol_t * parent_sym = ASR::down_cast<ASR::symbol_t >(parent_symtab->asr_owner );
1722
- return ASR::is_a<ASR::Template_t>(*parent_sym);
1723
- }
1724
- return false ;
1697
+ case ASR::ttypeType::Array: {
1698
+ ASR::Array_t *arr_type = ASR::down_cast<ASR::Array_t>(type_get_past_pointer (&x));
1699
+ return is_type_parameter (*arr_type->m_type );
1725
1700
}
1726
- default : return false ;
1701
+ default : return ASR::is_a<ASR::TypeParameter_t>(* type_get_past_pointer (&x)) ;
1727
1702
}
1728
1703
}
1729
1704
@@ -1742,20 +1717,19 @@ static inline bool is_generic_function(ASR::symbol_t *x) {
1742
1717
ASR::symbol_t * x2 = symbol_get_past_external (x);
1743
1718
switch (x2->type ) {
1744
1719
case ASR::symbolType::Function: {
1745
- ASR::Function_t *func_sym = ASR::down_cast<ASR::Function_t>(x2);
1746
- return (ASRUtils::get_FunctionType (func_sym)->n_type_params > 0 &&
1747
- !ASRUtils::get_FunctionType (func_sym)->m_is_restriction );
1748
- }
1749
- default : return false ;
1750
- }
1751
- }
1752
-
1753
- static inline bool is_restriction_function (ASR::symbol_t *x) {
1754
- ASR::symbol_t * x2 = symbol_get_past_external (x);
1755
- switch (x2->type ) {
1756
- case ASR::symbolType::Function: {
1757
- ASR::Function_t *func_sym = ASR::down_cast<ASR::Function_t>(x2);
1758
- return ASRUtils::get_FunctionType (func_sym)->m_is_restriction ;
1720
+ if (is_requirement_function (x2)) {
1721
+ return false ;
1722
+ }
1723
+ ASR::Function_t *func = ASR::down_cast<ASR::Function_t>(x2);
1724
+ ASR::FunctionType_t *func_type
1725
+ = ASR::down_cast<ASR::FunctionType_t>(func->m_function_signature );
1726
+ for (size_t i=0 ; i<func_type->n_arg_types ; i++) {
1727
+ if (is_type_parameter (*func_type->m_arg_types [i])) {
1728
+ return true ;
1729
+ }
1730
+ }
1731
+ return func_type->m_return_var_type
1732
+ && is_type_parameter (*func_type->m_return_var_type );
1759
1733
}
1760
1734
default : return false ;
1761
1735
}
@@ -2110,7 +2084,7 @@ static inline ASR::ttype_t* duplicate_type(Allocator& al, const ASR::ttype_t* t,
2110
2084
return ASRUtils::TYPE (ASR::make_FunctionType_t (al, ft->base .base .loc ,
2111
2085
arg_types.p , arg_types.size (), ft->m_return_var_type , ft->m_abi ,
2112
2086
ft->m_deftype , ft->m_bindc_name , ft->m_elemental , ft->m_pure , ft->m_module , ft->m_inline ,
2113
- ft->m_static , ft->m_type_params , ft-> n_type_params , ft-> m_restrictions , ft->n_restrictions ,
2087
+ ft->m_static , ft->m_restrictions , ft->n_restrictions ,
2114
2088
ft->m_is_restriction ));
2115
2089
}
2116
2090
default : throw LCompilersException (" Not implemented " + std::to_string (t->type ));
@@ -3119,7 +3093,7 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
3119
3093
const Location &a_loc, ASR::expr_t ** a_args, size_t n_args,
3120
3094
ASR::expr_t * a_return_var, ASR::abiType a_abi, ASR::deftypeType a_deftype,
3121
3095
char * a_bindc_name, bool a_elemental, bool a_pure, bool a_module, bool a_inline,
3122
- bool a_static, ASR:: ttype_t ** a_type_params, size_t n_type_params,
3096
+ bool a_static,
3123
3097
ASR::symbol_t ** a_restrictions, size_t n_restrictions, bool a_is_restriction) {
3124
3098
Vec<ASR::ttype_t *> arg_types;
3125
3099
arg_types.reserve (al, n_args);
@@ -3141,7 +3115,7 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
3141
3115
return ASR::make_FunctionType_t (
3142
3116
al, a_loc, arg_types.p , arg_types.size (), return_var_type, a_abi, a_deftype,
3143
3117
a_bindc_name, a_elemental, a_pure, a_module, a_inline,
3144
- a_static, a_type_params, n_type_params, a_restrictions, n_restrictions,
3118
+ a_static, a_restrictions, n_restrictions,
3145
3119
a_is_restriction);
3146
3120
}
3147
3121
@@ -3150,7 +3124,7 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al, const Location &a_loc
3150
3124
return ASRUtils::make_FunctionType_t_util (al, a_loc, a_args, n_args, a_return_var,
3151
3125
ft->m_abi , ft->m_deftype , ft->m_bindc_name , ft->m_elemental ,
3152
3126
ft->m_pure , ft->m_module , ft->m_inline , ft->m_static ,
3153
- ft->m_type_params , ft-> n_type_params , ft-> m_restrictions ,
3127
+ ft->m_restrictions ,
3154
3128
ft->n_restrictions , ft->m_is_restriction );
3155
3129
}
3156
3130
@@ -3159,12 +3133,12 @@ inline ASR::asr_t* make_Function_t_util(Allocator& al, const Location& loc,
3159
3133
ASR::expr_t ** a_args, size_t n_args, ASR::stmt_t ** m_body, size_t n_body,
3160
3134
ASR::expr_t * m_return_var, ASR::abiType m_abi, ASR::accessType m_access,
3161
3135
ASR::deftypeType m_deftype, char * m_bindc_name, bool m_elemental, bool m_pure,
3162
- bool m_module, bool m_inline, bool m_static, ASR:: ttype_t ** m_type_params, size_t n_type_params,
3136
+ bool m_module, bool m_inline, bool m_static,
3163
3137
ASR::symbol_t ** m_restrictions, size_t n_restrictions, bool m_is_restriction,
3164
3138
bool m_deterministic, bool m_side_effect_free, char *m_c_header=nullptr ) {
3165
3139
ASR::ttype_t * func_type = ASRUtils::TYPE (ASRUtils::make_FunctionType_t_util (
3166
3140
al, loc, a_args, n_args, m_return_var, m_abi, m_deftype, m_bindc_name,
3167
- m_elemental, m_pure, m_module, m_inline, m_static, m_type_params, n_type_params,
3141
+ m_elemental, m_pure, m_module, m_inline, m_static,
3168
3142
m_restrictions, n_restrictions, m_is_restriction));
3169
3143
return ASR::make_Function_t (
3170
3144
al, loc, m_symtab, m_name, func_type, m_dependencies, n_dependencies,
@@ -3353,7 +3327,6 @@ class SymbolDuplicator {
3353
3327
function_type->m_abi , function->m_access , function_type->m_deftype ,
3354
3328
function_type->m_bindc_name , function_type->m_elemental , function_type->m_pure ,
3355
3329
function_type->m_module , function_type->m_inline , function_type->m_static ,
3356
- function_type->m_type_params , function_type->n_type_params ,
3357
3330
function_type->m_restrictions , function_type->n_restrictions ,
3358
3331
function_type->m_is_restriction , function->m_deterministic ,
3359
3332
function->m_side_effect_free ));
0 commit comments