@@ -421,15 +421,17 @@ ASR::Module_t* load_module(Allocator &al, SymbolTable *symtab,
421
421
}
422
422
423
423
ASR::symbol_t * import_from_module (Allocator &al, ASR::Module_t *m, SymbolTable *current_scope,
424
- std::string mname, std::string cur_sym_name, std::string new_sym_name,
424
+ std::string mname, std::string cur_sym_name, std::string& new_sym_name,
425
425
const Location &loc, bool skip_current_scope_check=false ) {
426
- // std::cout<<"module_name: "<<m->m_name<<std::endl;
426
+ // std::cout<<"module_name: "<<m->m_name<<" "<<cur_sym_name<<" "<<new_sym_name<<std::endl;
427
+ new_sym_name = ASRUtils::get_mangled_name (m, new_sym_name);
427
428
// for( auto& itr: m->m_symtab->get_scope() ) {
428
429
// std::cout<<"itr.first: "<<itr.first<<std::endl;
429
430
// }
430
431
ASR::symbol_t *t = m->m_symtab ->resolve_symbol (cur_sym_name);
432
+ // std::cout<<"t: "<<t<<std::endl;
431
433
if (!t) {
432
- throw SemanticError (" The symbol '" + cur_sym_name + " ' not found in the module '" + mname + " '" ,
434
+ throw SemanticError (" The symbol '" + cur_sym_name + " ' not found in the module '" + std::string (m-> m_name ) + " '" ,
433
435
loc);
434
436
}
435
437
if (!skip_current_scope_check &&
@@ -487,6 +489,8 @@ ASR::symbol_t* import_from_module(Allocator &al, ASR::Module_t *m, SymbolTable *
487
489
SymbolTable *symtab = current_scope;
488
490
// while (symtab->parent != nullptr) symtab = symtab->parent;
489
491
ASR::symbol_t *sym = symtab->resolve_symbol (es->m_module_name );
492
+ // std::cout<<"sym: "<<sym<<std::endl;
493
+ // std::cout<<"sym.type: "<<ASRUtils::symbol_get_past_external(sym)->type<<" "<<es->m_module_name<<" "<<es->m_name<<std::endl;
490
494
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(sym);
491
495
return import_from_module (al, m, symtab, es->m_module_name ,
492
496
cur_sym_name, new_sym_name, loc);
@@ -1020,6 +1024,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
1020
1024
std::string mod_name = ASR::down_cast<ASR::ExternalSymbol_t>(stemp)->m_module_name ;
1021
1025
ASR::symbol_t *mt = symtab->resolve_symbol (mod_name);
1022
1026
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(mt);
1027
+ local_sym = ASRUtils::get_mangled_name (m, local_sym);
1023
1028
stemp = import_from_module (al, m, symtab, mod_name,
1024
1029
remote_sym, local_sym, loc);
1025
1030
LFORTRAN_ASSERT (ASR::is_a<ASR::ExternalSymbol_t>(*stemp));
@@ -3547,7 +3552,18 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
3547
3552
throw SemanticError (" The module '" + msym + " ' cannot be loaded" ,
3548
3553
x.base .base .loc );
3549
3554
}
3550
- current_module_dependencies.push_back (al, s2c (al, msym));
3555
+ if ( msym == " __init__" ) {
3556
+ for ( auto item: ASRUtils::symbol_symtab (t)->get_scope () ) {
3557
+ if ( ASR::is_a<ASR::ExternalSymbol_t>(*item.second ) &&
3558
+ !present (current_module_dependencies,
3559
+ ASR::down_cast<ASR::ExternalSymbol_t>(item.second )->m_module_name ) ) {
3560
+ current_module_dependencies.push_back (al,
3561
+ ASR::down_cast<ASR::ExternalSymbol_t>(item.second )->m_module_name );
3562
+ }
3563
+ }
3564
+ } else {
3565
+ current_module_dependencies.push_back (al, s2c (al, msym));
3566
+ }
3551
3567
}
3552
3568
3553
3569
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t);
@@ -3557,7 +3573,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
3557
3573
}
3558
3574
std::string new_sym_name = ASRUtils::get_mangled_name (m, remote_sym);
3559
3575
ASR::symbol_t *t = import_from_module (al, m, current_scope, msym,
3560
- remote_sym, new_sym_name, x.base .base .loc , false );
3576
+ remote_sym, new_sym_name, x.base .base .loc , true );
3561
3577
current_scope->add_symbol (new_sym_name, t);
3562
3578
}
3563
3579
@@ -4636,7 +4652,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
4636
4652
ASR::symbol_t *sym = current_scope->resolve_symbol (sym_name);
4637
4653
if (!sym) {
4638
4654
sym = import_from_module (al, m, current_scope, value,
4639
- x.m_attr , sym_name, x.base .base .loc , true );
4655
+ x.m_attr , sym_name, x.base .base .loc , false );
4640
4656
LFORTRAN_ASSERT (ASR::is_a<ASR::ExternalSymbol_t>(*sym));
4641
4657
current_scope->add_symbol (sym_name, sym);
4642
4658
}
0 commit comments