@@ -139,53 +139,8 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
139
139
return mod2;
140
140
}
141
141
142
- template <typename T>
143
- bool argument_types_match (const Vec<ASR::expr_t *> &args,
144
- const T &sub) {
145
- if (args.size () <= sub.n_args ) {
146
- size_t i;
147
- for (i = 0 ; i < args.size (); i++) {
148
- ASR::Variable_t *v = LFortran::ASRUtils::EXPR2VAR (sub.m_args [i]);
149
- ASR::ttype_t *arg1 = ASRUtils::expr_type (args[i]);
150
- ASR::ttype_t *arg2 = v->m_type ;
151
- if (!ASRUtils::check_equal_type (arg1, arg2)) {
152
- return false ;
153
- }
154
- }
155
- for ( ; i < sub.n_args ; i++ ) {
156
- ASR::Variable_t *v = LFortran::ASRUtils::EXPR2VAR (sub.m_args [i]);
157
- if ( v->m_presence != ASR::presenceType::Optional ) {
158
- return false ;
159
- }
160
- }
161
- return true ;
162
- } else {
163
- return false ;
164
- }
165
- }
166
-
167
- bool select_func_subrout (const ASR::symbol_t * proc, const Vec<ASR::expr_t *> &args,
168
- const Location& loc, const std::function<void (const std::string &, const Location &)> err) {
169
- bool result = false ;
170
- if (ASR::is_a<ASR::Subroutine_t>(*proc)) {
171
- ASR::Subroutine_t *sub
172
- = ASR::down_cast<ASR::Subroutine_t>(proc);
173
- if (argument_types_match (args, *sub)) {
174
- result = true ;
175
- }
176
- } else if (ASR::is_a<ASR::Function_t>(*proc)) {
177
- ASR::Function_t *fn
178
- = ASR::down_cast<ASR::Function_t>(proc);
179
- if (argument_types_match (args, *fn)) {
180
- result = true ;
181
- }
182
- } else {
183
- err (" Only Subroutine and Function supported in generic procedure" , loc);
184
- }
185
- return result;
186
- }
187
-
188
142
std::map<int , ASR::symbol_t *> ast_overload;
143
+
189
144
template <class Derived >
190
145
class CommonVisitor : public AST ::BaseVisitor<Derived> {
191
146
public:
@@ -2190,7 +2145,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
2190
2145
ASR::symbol_t *s = current_scope->resolve_symbol (call_name), *s_generic = nullptr ;
2191
2146
if (s!=nullptr && s->type == ASR::symbolType::GenericProcedure) {
2192
2147
ASR::GenericProcedure_t *p = ASR::down_cast<ASR::GenericProcedure_t>(s);
2193
- int idx = select_generic_procedure (args, *p, x.base .base .loc );
2148
+ int idx = ASRUtils::select_generic_procedure (args, *p, x.base .base .loc ,
2149
+ [&](const std::string &msg, const Location &loc) { throw SemanticError (msg, loc); });
2194
2150
// Create ExternalSymbol for procedures in different modules.
2195
2151
s_generic = s;
2196
2152
s = p->m_procs [idx];
@@ -2340,27 +2296,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
2340
2296
x.base .base .loc );
2341
2297
}
2342
2298
}
2343
- int select_generic_procedure (const Vec<ASR::expr_t *> &args,
2344
- const ASR::GenericProcedure_t &p, Location loc) {
2345
- for (size_t i=0 ; i < p.n_procs ; i++) {
2346
-
2347
- if ( ASR::is_a<ASR::ClassProcedure_t>(*p.m_procs [i]) ) {
2348
- ASR::ClassProcedure_t *clss_fn
2349
- = ASR::down_cast<ASR::ClassProcedure_t>(p.m_procs [i]);
2350
- const ASR::symbol_t *proc = ASRUtils::symbol_get_past_external (clss_fn->m_proc );
2351
- if ( select_func_subrout (proc, args, loc,
2352
- [&](const std::string &msg, const Location &loc) { throw SemanticError (msg, loc); })
2353
- ){
2354
- return i;
2355
- }
2356
- } else {
2357
- if ( select_func_subrout (p.m_procs [i], args, loc, [&](const std::string &msg, const Location &loc) { throw SemanticError (msg, loc); }) ) {
2358
- return i;
2359
- }
2360
- }
2361
- }
2362
- throw SemanticError (" Arguments do not match for any generic procedure" , loc);
2363
- }
2364
2299
2365
2300
void visit_ImportFrom (const AST::ImportFrom_t &/* x*/ ) {
2366
2301
// Handled by SymbolTableVisitor already
0 commit comments