@@ -232,15 +232,15 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
232
232
233
233
public:
234
234
std::unordered_map<ASR::symbol_t *, std::string>& sym_to_new_name;
235
- std::unordered_map <std::string, ASR::symbol_t *> current_scope;
235
+ std::map <std::string, ASR::symbol_t *> current_scope;
236
236
237
237
UniqueSymbolVisitor (Allocator& al_,
238
238
std::unordered_map<ASR::symbol_t *, std::string> &sn) : al(al_), sym_to_new_name(sn){}
239
239
240
240
241
241
void visit_TranslationUnit (const ASR::TranslationUnit_t &x) {
242
242
ASR::TranslationUnit_t& xx = const_cast <ASR::TranslationUnit_t&>(x);
243
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
243
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
244
244
current_scope = x.m_global_scope ->get_scope ();
245
245
for (auto &a : xx.m_global_scope ->get_scope ()) {
246
246
visit_symbol (*a.second );
@@ -256,7 +256,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
256
256
257
257
void visit_Program (const ASR::Program_t &x) {
258
258
ASR::Program_t& xx = const_cast <ASR::Program_t&>(x);
259
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
259
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
260
260
ASR::symbol_t *sym = ASR::down_cast<ASR::symbol_t >((ASR::asr_t *)&x);
261
261
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
262
262
xx.m_name = s2c (al, sym_to_new_name[sym]);
@@ -284,7 +284,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
284
284
285
285
void visit_Module (const ASR::Module_t &x) {
286
286
ASR::Module_t& xx = const_cast <ASR::Module_t&>(x);
287
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
287
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
288
288
ASR::symbol_t *sym = ASR::down_cast<ASR::symbol_t >((ASR::asr_t *)&x);
289
289
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
290
290
xx.m_name = s2c (al, sym_to_new_name[sym]);
@@ -312,7 +312,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
312
312
313
313
void visit_Function (const ASR::Function_t &x) {
314
314
ASR::Function_t& xx = const_cast <ASR::Function_t&>(x);
315
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
315
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
316
316
ASR::symbol_t *sym = ASR::down_cast<ASR::symbol_t >((ASR::asr_t *)&x);
317
317
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
318
318
xx.m_name = s2c (al, sym_to_new_name[sym]);
@@ -376,7 +376,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
376
376
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
377
377
xx.m_name = s2c (al, sym_to_new_name[sym]);
378
378
}
379
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
379
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
380
380
for (size_t i=0 ; i<xx.n_dependencies ; i++) {
381
381
if (current_scope.find (xx.m_dependencies [i]) != current_scope.end ()) {
382
382
sym = current_scope[xx.m_dependencies [i]];
@@ -412,7 +412,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
412
412
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
413
413
xx.m_name = s2c (al, sym_to_new_name[sym]);
414
414
}
415
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
415
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
416
416
for (size_t i=0 ; i<xx.n_dependencies ; i++) {
417
417
if (current_scope.find (xx.m_dependencies [i]) != current_scope.end ()) {
418
418
sym = current_scope[xx.m_dependencies [i]];
@@ -448,7 +448,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
448
448
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
449
449
xx.m_name = s2c (al, sym_to_new_name[sym]);
450
450
}
451
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
451
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
452
452
for (size_t i=0 ; i<xx.n_dependencies ; i++) {
453
453
if (current_scope.find (xx.m_dependencies [i]) != current_scope.end ()) {
454
454
sym = current_scope[xx.m_dependencies [i]];
@@ -500,7 +500,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
500
500
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
501
501
xx.m_name = s2c (al, sym_to_new_name[sym]);
502
502
}
503
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
503
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
504
504
current_scope = x.m_symtab ->get_scope ();
505
505
for (auto &a : x.m_symtab ->get_scope ()) {
506
506
visit_symbol (*a.second );
@@ -528,7 +528,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
528
528
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
529
529
xx.m_name = s2c (al, sym_to_new_name[sym]);
530
530
}
531
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
531
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
532
532
current_scope = x.m_symtab ->get_scope ();
533
533
for (auto &a : x.m_symtab ->get_scope ()) {
534
534
visit_symbol (*a.second );
@@ -548,7 +548,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
548
548
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
549
549
xx.m_name = s2c (al, sym_to_new_name[sym]);
550
550
}
551
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
551
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
552
552
current_scope = x.m_symtab ->get_scope ();
553
553
for (auto &a : x.m_symtab ->get_scope ()) {
554
554
visit_symbol (*a.second );
@@ -568,7 +568,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
568
568
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
569
569
xx.m_name = s2c (al, sym_to_new_name[sym]);
570
570
}
571
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
571
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
572
572
current_scope = x.m_symtab ->get_scope ();
573
573
for (auto &a : x.m_symtab ->get_scope ()) {
574
574
visit_symbol (*a.second );
@@ -588,7 +588,7 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
588
588
if (sym_to_new_name.find (sym) != sym_to_new_name.end ()) {
589
589
xx.m_name = s2c (al, sym_to_new_name[sym]);
590
590
}
591
- std::unordered_map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
591
+ std::map <std::string, ASR::symbol_t *> current_scope_copy = current_scope;
592
592
current_scope = x.m_symtab ->get_scope ();
593
593
for (auto &a : x.m_symtab ->get_scope ()) {
594
594
visit_symbol (*a.second );
@@ -606,8 +606,16 @@ class UniqueSymbolVisitor: public ASR::BaseWalkVisitor<UniqueSymbolVisitor> {
606
606
607
607
608
608
void pass_unique_symbols (Allocator &al, ASR::TranslationUnit_t &unit,
609
- const LCompilers::PassOptions& /* pass_options*/ ) {
610
- SymbolRenameVisitor v (true , true , true , true );
609
+ const LCompilers::PassOptions& pass_options) {
610
+ bool any_present = (pass_options.module_name_mangling || pass_options.global_symbols_mangling ||
611
+ pass_options.intrinsic_symbols_mangling || pass_options.all_symbols_mangling );
612
+ if (!any_present || lcompilers_unique_ID.empty ()) {
613
+ return ;
614
+ }
615
+ SymbolRenameVisitor v (pass_options.module_name_mangling ,
616
+ pass_options.global_symbols_mangling ,
617
+ pass_options.intrinsic_symbols_mangling ,
618
+ pass_options.all_symbols_mangling );
611
619
v.visit_TranslationUnit (unit);
612
620
UniqueSymbolVisitor u (al, v.sym_to_renamed );
613
621
u.visit_TranslationUnit (unit);
0 commit comments