@@ -139,7 +139,6 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
139
139
return mod2;
140
140
}
141
141
142
- std::map<int , ASR::symbol_t *> ast_overload;
143
142
144
143
template <class Derived >
145
144
class CommonVisitor : public AST ::BaseVisitor<Derived> {
@@ -158,10 +157,13 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
158
157
// The main module is stored directly in TranslationUnit, other modules are Modules
159
158
bool main_module;
160
159
PythonIntrinsicProcedures intrinsic_procedures;
160
+ std::map<int , ASR::symbol_t *> &ast_overload;
161
161
162
162
CommonVisitor (Allocator &al, SymbolTable *symbol_table,
163
- diag::Diagnostics &diagnostics, bool main_module)
164
- : diag{diagnostics}, al{al}, current_scope{symbol_table}, main_module{main_module} {
163
+ diag::Diagnostics &diagnostics, bool main_module,
164
+ std::map<int , ASR::symbol_t *> &ast_overload)
165
+ : diag{diagnostics}, al{al}, current_scope{symbol_table}, main_module{main_module},
166
+ ast_overload{ast_overload} {
165
167
current_module_dependencies.reserve (al, 4 );
166
168
}
167
169
@@ -475,8 +477,9 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
475
477
476
478
477
479
SymbolTableVisitor (Allocator &al, SymbolTable *symbol_table,
478
- diag::Diagnostics &diagnostics, bool main_module)
479
- : CommonVisitor(al, symbol_table, diagnostics, main_module), is_derived_type{false } {}
480
+ diag::Diagnostics &diagnostics, bool main_module,
481
+ std::map<int , ASR::symbol_t *> &ast_overload)
482
+ : CommonVisitor(al, symbol_table, diagnostics, main_module, ast_overload), is_derived_type{false } {}
480
483
481
484
482
485
ASR::symbol_t * resolve_symbol (const Location &loc, const std::string &sub_name) {
@@ -767,10 +770,10 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
767
770
};
768
771
769
772
Result<ASR::asr_t *> symbol_table_visitor (Allocator &al, const AST::Module_t &ast,
770
- diag::Diagnostics &diagnostics, bool main_module)
773
+ diag::Diagnostics &diagnostics, bool main_module,
774
+ std::map<int , ASR::symbol_t *> &ast_overload)
771
775
{
772
- ast_overload.clear ();
773
- SymbolTableVisitor v (al, nullptr , diagnostics, main_module);
776
+ SymbolTableVisitor v (al, nullptr , diagnostics, main_module, ast_overload);
774
777
try {
775
778
v.visit_Module (ast);
776
779
} catch (const SemanticError &e) {
@@ -792,8 +795,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
792
795
ASR::asr_t *asr;
793
796
Vec<ASR::stmt_t *> *current_body;
794
797
795
- BodyVisitor (Allocator &al, ASR::asr_t *unit, diag::Diagnostics &diagnostics, bool main_module)
796
- : CommonVisitor(al, nullptr , diagnostics, main_module), asr{unit} {}
798
+ BodyVisitor (Allocator &al, ASR::asr_t *unit, diag::Diagnostics &diagnostics,
799
+ bool main_module, std::map<int , ASR::symbol_t *> &ast_overload)
800
+ : CommonVisitor(al, nullptr , diagnostics, main_module, ast_overload), asr{unit} {}
797
801
798
802
// Transforms statements to a list of ASR statements
799
803
// In addition, it also inserts the following nodes if needed:
@@ -2326,9 +2330,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
2326
2330
Result<ASR::TranslationUnit_t*> body_visitor (Allocator &al,
2327
2331
const AST::Module_t &ast,
2328
2332
diag::Diagnostics &diagnostics,
2329
- ASR::asr_t *unit, bool main_module)
2333
+ ASR::asr_t *unit, bool main_module,
2334
+ std::map<int , ASR::symbol_t *> &ast_overload)
2330
2335
{
2331
- BodyVisitor b (al, unit, diagnostics, main_module);
2336
+ BodyVisitor b (al, unit, diagnostics, main_module, ast_overload );
2332
2337
try {
2333
2338
b.visit_Module (ast);
2334
2339
} catch (const SemanticError &e) {
@@ -2362,10 +2367,13 @@ std::string pickle_python(AST::ast_t &ast, bool colors, bool indent) {
2362
2367
Result<ASR::TranslationUnit_t*> python_ast_to_asr (Allocator &al,
2363
2368
AST::ast_t &ast, diag::Diagnostics &diagnostics, bool main_module)
2364
2369
{
2370
+ std::map<int , ASR::symbol_t *> ast_overload;
2371
+
2365
2372
AST::Module_t *ast_m = AST::down_cast2<AST::Module_t>(&ast);
2366
2373
2367
2374
ASR::asr_t *unit;
2368
- auto res = symbol_table_visitor (al, *ast_m, diagnostics, main_module);
2375
+ auto res = symbol_table_visitor (al, *ast_m, diagnostics, main_module,
2376
+ ast_overload);
2369
2377
if (res.ok ) {
2370
2378
unit = res.result ;
2371
2379
} else {
@@ -2374,7 +2382,8 @@ Result<ASR::TranslationUnit_t*> python_ast_to_asr(Allocator &al,
2374
2382
ASR::TranslationUnit_t *tu = ASR::down_cast2<ASR::TranslationUnit_t>(unit);
2375
2383
LFORTRAN_ASSERT (asr_verify (*tu));
2376
2384
2377
- auto res2 = body_visitor (al, *ast_m, diagnostics, unit, main_module);
2385
+ auto res2 = body_visitor (al, *ast_m, diagnostics, unit, main_module,
2386
+ ast_overload);
2378
2387
if (res2.ok ) {
2379
2388
tu = res2.result ;
2380
2389
} else {
0 commit comments