@@ -175,6 +175,26 @@ namespace CastingUtil {
175
175
int save_pyc_files (const LFortran::ASR::TranslationUnit_t &u,
176
176
std::string infile) {
177
177
LFORTRAN_ASSERT (LFortran::asr_verify (u));
178
+ Allocator al (4 *1024 );
179
+ LFortran::SymbolTable *symtab =
180
+ al.make_new <LFortran::SymbolTable>(nullptr );
181
+ std::vector<std::pair<ASR::Module_t*, SymbolTable*>> module_parent;
182
+ for (auto &item : u.m_global_scope ->get_scope ()) {
183
+ if (LFortran::ASR::is_a<LFortran::ASR::Module_t>(*item.second )) {
184
+ LFortran::ASR::Module_t *m = LFortran::ASR::down_cast<LFortran::ASR::Module_t>(item.second );
185
+
186
+ symtab->add_symbol (std::string (m->m_name ), item.second );
187
+ module_parent.push_back (std::make_pair (m, m->m_symtab ->parent ));
188
+ m->m_symtab ->parent = symtab;
189
+ }
190
+ }
191
+
192
+ LFortran::Location loc;
193
+ LFortran::ASR::asr_t *asr = LFortran::ASR::make_TranslationUnit_t (al, loc,
194
+ symtab, nullptr , 0 );
195
+ LFortran::ASR::TranslationUnit_t *tu =
196
+ LFortran::ASR::down_cast2<LFortran::ASR::TranslationUnit_t>(asr);
197
+ LFORTRAN_ASSERT (LFortran::asr_verify (*tu));
178
198
179
199
std::string modfile_binary = LFortran::save_pycfile (u);
180
200
@@ -187,6 +207,10 @@ int save_pyc_files(const LFortran::ASR::TranslationUnit_t &u,
187
207
out.open (modfile, std::ofstream::out | std::ofstream::binary);
188
208
out << modfile_binary;
189
209
}
210
+
211
+ for ( auto & mod_par: module_parent ) {
212
+ mod_par.first ->m_symtab ->parent = mod_par.second ;
213
+ }
190
214
return 0 ;
191
215
}
192
216
@@ -265,11 +289,8 @@ ASR::TranslationUnit_t* compile_module_till_asr(Allocator& al,
265
289
// Convert the module from AST to ASR
266
290
LFortran::LocationManager lm;
267
291
lm.in_filename = infile;
268
- unsigned int symtab_global_counter = SymbolTable::get_global_counter ();
269
- SymbolTable::reset_global_counter ();
270
292
Result<ASR::TranslationUnit_t*> r2 = python_ast_to_asr (al, *ast,
271
293
diagnostics, false , true , false , infile, " " );
272
- SymbolTable::set_global_counter (symtab_global_counter);
273
294
save_pyc_files (*r2.result , infile + " c" );
274
295
std::string input;
275
296
read_file (infile, input);
0 commit comments