diff --git a/src/libasr/pass/unique_symbols.cpp b/src/libasr/pass/unique_symbols.cpp index b96ec9db25..f00e9fc2dc 100644 --- a/src/libasr/pass/unique_symbols.cpp +++ b/src/libasr/pass/unique_symbols.cpp @@ -295,8 +295,9 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor { } } - void visit_StructType(const ASR::StructType_t &x) { - ASR::StructType_t& xx = const_cast(x); + template + void update_symbols_2(const T &x) { + T& xx = const_cast(x); ASR::symbol_t *sym = ASR::down_cast((ASR::asr_t*)&x); if (sym_to_new_name.find(sym) != sym_to_new_name.end()) { xx.m_name = s2c(al, sym_to_new_name[sym]); @@ -331,76 +332,16 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor { current_scope = current_scope_copy; } + void visit_StructType(const ASR::StructType_t &x) { + update_symbols_2(x); + } + void visit_EnumType(const ASR::EnumType_t &x) { - ASR::EnumType_t& xx = const_cast(x); - ASR::symbol_t *sym = ASR::down_cast((ASR::asr_t*)&x); - if (sym_to_new_name.find(sym) != sym_to_new_name.end()) { - xx.m_name = s2c(al, sym_to_new_name[sym]); - } - std::map current_scope_copy = current_scope; - for (size_t i=0; iget_scope(); - for (size_t i=0; iget_scope()) { - visit_symbol(*a.second); - } - for (auto &a: current_scope) { - if (sym_to_new_name.find(a.second) != sym_to_new_name.end()) { - xx.m_symtab->erase_symbol(a.first); - xx.m_symtab->add_symbol(sym_to_new_name[a.second], a.second); - } - } - current_scope = current_scope_copy; + update_symbols_2(x); } void visit_UnionType(const ASR::UnionType_t &x) { - ASR::UnionType_t& xx = const_cast(x); - ASR::symbol_t *sym = ASR::down_cast((ASR::asr_t*)&x); - if (sym_to_new_name.find(sym) != sym_to_new_name.end()) { - xx.m_name = s2c(al, sym_to_new_name[sym]); - } - std::map current_scope_copy = current_scope; - for (size_t i=0; iget_scope(); - for (size_t i=0; iget_scope()) { - visit_symbol(*a.second); - } - for (auto &a: current_scope) { - if (sym_to_new_name.find(a.second) != sym_to_new_name.end()) { - xx.m_symtab->erase_symbol(a.first); - xx.m_symtab->add_symbol(sym_to_new_name[a.second], a.second); - } - } - current_scope = current_scope_copy; + update_symbols_2(x); } void visit_Variable(const ASR::Variable_t &x) {