Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4959,28 +4959,30 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
}
paths.push_back(rl_path);
paths.push_back(parent_dir);
std::vector<std::string> mods;

for (size_t i=0; i<x.n_names; i++) {
mods.push_back(x.m_names[i].m_name);
}
for (auto &mod_sym : mods) {
bool lpython, enum_py, copy, sympy;
std::string mod_sym = x.m_names[i].m_name;
char* alias = x.m_names[i].m_asname;

// Initialize bools
bool lpython = false, enum_py = false, copy = false, sympy = false;

set_module_symbol(mod_sym, paths);

t = (ASR::symbol_t*)(load_module(al, global_scope,
mod_sym, x.base.base.loc, diag, lm, false, paths, lpython, enum_py, copy, sympy,
[&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); },
allow_implicit_casting));

if (lpython || enum_py || copy || sympy) {
// TODO: For now we skip lpython import completely. Later on we should note what symbols
// got imported from it, and give an error message if an annotation is used without
// importing it.
tmp = nullptr;
continue;
}
if (!t) {
throw SemanticError("The module '" + mod_sym + "' cannot be loaded",
throw SemanticError("The module " + mod_sym + " cannot be loaded",
x.base.base.loc);
}

if( mod_sym == "__init__" ) {
for( auto item: ASRUtils::symbol_symtab(t)->get_scope() ) {
if( ASR::is_a<ASR::ExternalSymbol_t>(*item.second) ) {
Expand All @@ -4991,6 +4993,19 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
} else {
current_module_dependencies.push_back(al, s2c(al, mod_sym));
}

// ALIAS LOGIC
if (alias) {
std::string alias_str = std::string(alias);
if (current_scope->get_symbol(alias_str) == nullptr) {
ASR::asr_t *ext_sym = ASR::make_ExternalSymbol_t(
al, x.base.base.loc, current_scope,
s2c(al, alias_str), t, s2c(al, mod_sym),
nullptr, 0, s2c(al, mod_sym), ASR::accessType::Public
);
current_scope->add_symbol(alias_str, ASR::down_cast<ASR::symbol_t>(ext_sym));
}
}
}
}

Expand Down
Loading