Skip to content

Fixed issues on template instantiation #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022
Merged
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
9 changes: 4 additions & 5 deletions src/libasr/pass/instantiate_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace LFortran {
class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstantiator>
{
public:
SymbolTable *func_scope;
SymbolTable *current_scope;
std::map<std::string, ASR::ttype_t*> subs;
std::map<std::string, ASR::symbol_t*> rt_subs;
Expand All @@ -18,18 +19,17 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
std::set<std::string> dependencies;

FunctionInstantiator(Allocator &al, std::map<std::string, ASR::ttype_t*> subs,
std::map<std::string, ASR::symbol_t*> rt_subs, SymbolTable *current_scope,
std::map<std::string, ASR::symbol_t*> rt_subs, SymbolTable *func_scope,
std::string new_func_name):
BaseExprStmtDuplicator(al),
current_scope{current_scope},
func_scope{func_scope},
subs{subs},
rt_subs{rt_subs},
new_func_name{new_func_name}
{}

ASR::asr_t* instantiate_Function(ASR::Function_t *x) {
dependencies.clear();
SymbolTable *parent_scope = current_scope;
current_scope = al.make_new<SymbolTable>(x->m_symtab->parent);

Vec<ASR::expr_t*> args;
Expand Down Expand Up @@ -135,7 +135,6 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti

ASR::symbol_t *t = ASR::down_cast<ASR::symbol_t>(result);
x->m_symtab->parent->add_symbol(new_func_name, t);
current_scope = parent_scope;

return result;
}
Expand Down Expand Up @@ -223,7 +222,7 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti

ASR::asr_t* duplicate_FunctionCall(ASR::FunctionCall_t *x) {
std::string sym_name = ASRUtils::symbol_name(x->m_name);
ASR::symbol_t *name = current_scope->get_symbol(sym_name);
ASR::symbol_t *name = func_scope->get_symbol(sym_name);
Vec<ASR::call_arg_t> args;
args.reserve(al, x->n_args);
for (size_t i=0; i<x->n_args; i++) {
Expand Down