@@ -583,6 +583,8 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
583
583
std::string unit_src = " " ;
584
584
indentation_level = 0 ;
585
585
indentation_spaces = 4 ;
586
+ SymbolTable* current_scope_copy = current_scope;
587
+ current_scope = global_scope;
586
588
c_ds_api->set_indentation (indentation_level, indentation_spaces);
587
589
c_ds_api->set_global_scope (global_scope);
588
590
c_utils_functions->set_indentation (indentation_level, indentation_spaces);
760
762
out_file.close ();
761
763
}
762
764
}
765
+ current_scope = current_scope_copy;
763
766
}
764
767
765
768
void visit_Module (const ASR::Module_t &x) {
768
771
} else {
769
772
intrinsic_module = false ;
770
773
}
771
-
774
+ SymbolTable *current_scope_copy = current_scope;
775
+ current_scope = x.m_symtab ;
772
776
std::string unit_src = " " ;
773
777
for (auto &item : x.m_symtab ->get_scope ()) {
774
778
if (ASR::is_a<ASR::Variable_t>(*item.second )) {
@@ -813,13 +817,15 @@ R"(
813
817
}
814
818
src = unit_src;
815
819
intrinsic_module = false ;
820
+ current_scope = current_scope_copy;
816
821
}
817
822
818
823
void visit_Program (const ASR::Program_t &x) {
819
824
// Topologically sort all program functions
820
825
// and then define them in the right order
821
826
std::vector<std::string> func_order = ASRUtils::determine_function_definition_order (x.m_symtab );
822
-
827
+ SymbolTable *current_scope_copy = current_scope;
828
+ current_scope = x.m_symtab ;
823
829
// Generate code for nested subroutines and functions first:
824
830
std::string contains;
825
831
for (auto &item : func_order) {
@@ -898,6 +904,7 @@ R"( // Initialise Numpy
898
904
+ decl + body
899
905
+ indent1 + " return 0;\n }\n " ;
900
906
indentation_level -= 2 ;
907
+ current_scope = current_scope_copy;
901
908
}
902
909
903
910
template <typename T>
0 commit comments