Skip to content

Commit 2c008fc

Browse files
committed
Rename m_global_scope to m_symtab
1 parent 4fd0124 commit 2c008fc

29 files changed

+139
-139
lines changed

src/bin/lpython.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ int get_symbols (const std::string &infile,
509509
}
510510
std::vector<LCompilers::document_symbols> symbol_lists;
511511
LCompilers::document_symbols loc;
512-
for (auto &a : x.result->m_global_scope->get_scope()) {
512+
for (auto &a : x.result->m_symtab->get_scope()) {
513513
std::string symbol_name = a.first;
514514
uint32_t first_line;
515515
uint32_t last_line;

src/libasr/ASR.asdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
module ASR {
3030

3131
unit
32-
= TranslationUnit(symbol_table global_scope, node* items)
32+
= TranslationUnit(symbol_table symtab, node* items)
3333

3434
-- # Documentation for the symbol type
3535

src/libasr/asr_scopes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ struct SymbolTable {
2121
public:
2222
SymbolTable *parent;
2323
// The ASR node (either symbol_t or TranslationUnit_t) that contains this
24-
// SymbolTable as m_symtab / m_global_scope member. One of:
24+
// SymbolTable as m_symtab member. One of:
2525
// * symbol_symtab(down_cast<symbol_t>(this->asr_owner)) == this
26-
// * down_cast2<TranslationUnit_t>(this->asr_owner)->m_global_scope == this
26+
// * down_cast2<TranslationUnit_t>(this->asr_owner)->m_symtab == this
2727
ASR::asr_t *asr_owner = nullptr;
2828
unsigned int counter;
2929

src/libasr/asr_utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ std::vector<std::string> determine_module_dependencies(
5252
const ASR::TranslationUnit_t &unit)
5353
{
5454
std::map<std::string, std::vector<std::string>> deps;
55-
for (auto &item : unit.m_global_scope->get_scope()) {
55+
for (auto &item : unit.m_symtab->get_scope()) {
5656
if (ASR::is_a<ASR::Module_t>(*item.second)) {
5757
std::string name = item.first;
5858
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(item.second);
@@ -116,7 +116,7 @@ void extract_module_python(const ASR::TranslationUnit_t &m,
116116
std::vector<std::pair<std::string, ASR::Module_t*>>& children_modules,
117117
std::string module_name) {
118118
bool module_found = false;
119-
for (auto &a : m.m_global_scope->get_scope()) {
119+
for (auto &a : m.m_symtab->get_scope()) {
120120
if( ASR::is_a<ASR::Module_t>(*a.second) ) {
121121
if( a.first == "__main__" ) {
122122
module_found = true;
@@ -219,8 +219,8 @@ void update_call_args(Allocator &al, SymbolTable *current_scope, bool implicit_i
219219
}
220220

221221
ASR::Module_t* extract_module(const ASR::TranslationUnit_t &m) {
222-
LCOMPILERS_ASSERT(m.m_global_scope->get_scope().size()== 1);
223-
for (auto &a : m.m_global_scope->get_scope()) {
222+
LCOMPILERS_ASSERT(m.m_symtab->get_scope().size()== 1);
223+
for (auto &a : m.m_symtab->get_scope()) {
224224
LCOMPILERS_ASSERT(ASR::is_a<ASR::Module_t>(*a.second));
225225
return ASR::down_cast<ASR::Module_t>(a.second);
226226
}
@@ -370,7 +370,7 @@ void set_intrinsic(ASR::symbol_t* sym) {
370370
}
371371

372372
void set_intrinsic(ASR::TranslationUnit_t* trans_unit) {
373-
for( auto& itr: trans_unit->m_global_scope->get_scope() ) {
373+
for( auto& itr: trans_unit->m_symtab->get_scope() ) {
374374
set_intrinsic(itr.second);
375375
}
376376
}

src/libasr/asr_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ static inline bool is_arg_dummy(int intent) {
16401640

16411641
static inline bool main_program_present(const ASR::TranslationUnit_t &unit)
16421642
{
1643-
for (auto &a : unit.m_global_scope->get_scope()) {
1643+
for (auto &a : unit.m_symtab->get_scope()) {
16441644
if (ASR::is_a<ASR::Program_t>(*a.second)) return true;
16451645
}
16461646
return false;

src/libasr/asr_verify.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
9494
}
9595

9696
void visit_TranslationUnit(const TranslationUnit_t &x) {
97-
current_symtab = x.m_global_scope;
98-
require(x.m_global_scope != nullptr,
99-
"The TranslationUnit::m_global_scope cannot be nullptr");
100-
require(x.m_global_scope->parent == nullptr,
101-
"The TranslationUnit::m_global_scope->parent must be nullptr");
102-
require(id_symtab_map.find(x.m_global_scope->counter) == id_symtab_map.end(),
103-
"TranslationUnit::m_global_scope->counter must be unique");
104-
require(x.m_global_scope->asr_owner == (ASR::asr_t*)&x,
105-
"The TranslationUnit::m_global_scope::asr_owner must point to itself");
106-
require(down_cast2<TranslationUnit_t>(current_symtab->asr_owner)->m_global_scope == current_symtab,
97+
current_symtab = x.m_symtab;
98+
require(x.m_symtab != nullptr,
99+
"The TranslationUnit::m_symtab cannot be nullptr");
100+
require(x.m_symtab->parent == nullptr,
101+
"The TranslationUnit::m_symtab->parent must be nullptr");
102+
require(id_symtab_map.find(x.m_symtab->counter) == id_symtab_map.end(),
103+
"TranslationUnit::m_symtab->counter must be unique");
104+
require(x.m_symtab->asr_owner == (ASR::asr_t*)&x,
105+
"The TranslationUnit::m_symtab::asr_owner must point to itself");
106+
require(down_cast2<TranslationUnit_t>(current_symtab->asr_owner)->m_symtab == current_symtab,
107107
"The asr_owner invariant failed");
108-
id_symtab_map[x.m_global_scope->counter] = x.m_global_scope;
109-
for (auto &a : x.m_global_scope->get_scope()) {
108+
id_symtab_map[x.m_symtab->counter] = x.m_symtab;
109+
for (auto &a : x.m_symtab->get_scope()) {
110110
this->visit_symbol(*a.second);
111111
}
112112
for (size_t i=0; i<x.n_items; i++) {

src/libasr/codegen/asr_to_c.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>
577577

578578
void visit_TranslationUnit(const ASR::TranslationUnit_t &x) {
579579
is_string_concat_present = false;
580-
global_scope = x.m_global_scope;
580+
global_scope = x.m_symtab;
581581
// All loose statements must be converted to a function, so the items
582582
// must be empty:
583583
LCOMPILERS_ASSERT(x.n_items == 0);
@@ -605,7 +605,7 @@ R"(
605605
std::string tab(indentation_spaces, ' ');
606606

607607
std::string unit_src_tmp;
608-
for (auto &item : x.m_global_scope->get_scope()) {
608+
for (auto &item : x.m_symtab->get_scope()) {
609609
if (ASR::is_a<ASR::Variable_t>(*item.second)) {
610610
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(item.second);
611611
unit_src_tmp = convert_variable_decl(*v);
@@ -618,7 +618,7 @@ R"(
618618

619619

620620
std::map<std::string, std::vector<std::string>> struct_dep_graph;
621-
for (auto &item : x.m_global_scope->get_scope()) {
621+
for (auto &item : x.m_symtab->get_scope()) {
622622
if (ASR::is_a<ASR::StructType_t>(*item.second) ||
623623
ASR::is_a<ASR::EnumType_t>(*item.second) ||
624624
ASR::is_a<ASR::UnionType_t>(*item.second)) {
@@ -634,14 +634,14 @@ R"(
634634
std::vector<std::string> struct_deps = ASRUtils::order_deps(struct_dep_graph);
635635

636636
for (auto &item : struct_deps) {
637-
ASR::symbol_t* struct_sym = x.m_global_scope->get_symbol(item);
637+
ASR::symbol_t* struct_sym = x.m_symtab->get_symbol(item);
638638
visit_symbol(*struct_sym);
639639
array_types_decls += src;
640640
}
641641

642642
// Topologically sort all global functions
643643
// and then define them in the right order
644-
std::vector<std::string> global_func_order = ASRUtils::determine_function_definition_order(x.m_global_scope);
644+
std::vector<std::string> global_func_order = ASRUtils::determine_function_definition_order(x.m_symtab);
645645

646646
unit_src += "\n";
647647
unit_src += "// Implementations\n";
@@ -651,10 +651,10 @@ R"(
651651
std::vector<std::string> build_order
652652
= ASRUtils::determine_module_dependencies(x);
653653
for (auto &item : build_order) {
654-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
655-
!= x.m_global_scope->get_scope().end());
654+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
655+
!= x.m_symtab->get_scope().end());
656656
if (startswith(item, "lfortran_intrinsic")) {
657-
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
657+
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
658658
if( ASRUtils::get_body_size(mod) != 0 ) {
659659
visit_symbol(*mod);
660660
unit_src += src;
@@ -666,7 +666,7 @@ R"(
666666
// Process global functions
667667
size_t i;
668668
for (i = 0; i < global_func_order.size(); i++) {
669-
ASR::symbol_t* sym = x.m_global_scope->get_symbol(global_func_order[i]);
669+
ASR::symbol_t* sym = x.m_symtab->get_symbol(global_func_order[i]);
670670
// Ignore external symbols because they are already defined by the loop above.
671671
if( !sym || ASR::is_a<ASR::ExternalSymbol_t>(*sym) ) {
672672
continue ;
@@ -679,17 +679,17 @@ R"(
679679
std::vector<std::string> build_order
680680
= ASRUtils::determine_module_dependencies(x);
681681
for (auto &item : build_order) {
682-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
683-
!= x.m_global_scope->get_scope().end());
682+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
683+
!= x.m_symtab->get_scope().end());
684684
if (!startswith(item, "lfortran_intrinsic")) {
685-
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
685+
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
686686
visit_symbol(*mod);
687687
unit_src += src;
688688
}
689689
}
690690

691691
// Then the main program:
692-
for (auto &item : x.m_global_scope->get_scope()) {
692+
for (auto &item : x.m_symtab->get_scope()) {
693693
if (ASR::is_a<ASR::Program_t>(*item.second)) {
694694
visit_symbol(*item.second);
695695
unit_src += src;

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class BaseCCPPVisitor : public ASR::BaseVisitor<Struct>
213213
ds_funcs_defined + util_funcs_defined;
214214
}
215215
void visit_TranslationUnit(const ASR::TranslationUnit_t &x) {
216-
global_scope = x.m_global_scope;
216+
global_scope = x.m_symtab;
217217
// All loose statements must be converted to a function, so the items
218218
// must be empty:
219219
LCOMPILERS_ASSERT(x.n_items == 0);
@@ -236,18 +236,18 @@ R"(#include <stdio.h>
236236
std::vector<std::string> build_order
237237
= ASRUtils::determine_module_dependencies(x);
238238
for (auto &item : build_order) {
239-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
240-
!= x.m_global_scope->get_scope().end());
239+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
240+
!= x.m_symtab->get_scope().end());
241241
if (startswith(item, "lfortran_intrinsic")) {
242-
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
242+
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
243243
self().visit_symbol(*mod);
244244
unit_src += src;
245245
}
246246
}
247247
}
248248

249249
// Process procedures first:
250-
for (auto &item : x.m_global_scope->get_scope()) {
250+
for (auto &item : x.m_symtab->get_scope()) {
251251
if (ASR::is_a<ASR::Function_t>(*item.second)) {
252252
self().visit_symbol(*item.second);
253253
unit_src += src;
@@ -258,17 +258,17 @@ R"(#include <stdio.h>
258258
std::vector<std::string> build_order
259259
= ASRUtils::determine_module_dependencies(x);
260260
for (auto &item : build_order) {
261-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
262-
!= x.m_global_scope->get_scope().end());
261+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
262+
!= x.m_symtab->get_scope().end());
263263
if (!startswith(item, "lfortran_intrinsic")) {
264-
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
264+
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
265265
self().visit_symbol(*mod);
266266
unit_src += src;
267267
}
268268
}
269269

270270
// Then the main program:
271-
for (auto &item : x.m_global_scope->get_scope()) {
271+
for (auto &item : x.m_symtab->get_scope()) {
272272
if (ASR::is_a<ASR::Program_t>(*item.second)) {
273273
self().visit_symbol(*item.second);
274274
unit_src += src;

src/libasr/codegen/asr_to_cpp.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class ASRToCPPVisitor : public BaseCCPPVisitor<ASRToCPPVisitor>
325325

326326

327327
void visit_TranslationUnit(const ASR::TranslationUnit_t &x) {
328-
global_scope = x.m_global_scope;
328+
global_scope = x.m_symtab;
329329
// All loose statements must be converted to a function, so the items
330330
// must be empty:
331331
LCOMPILERS_ASSERT(x.n_items == 0);
@@ -366,9 +366,9 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
366366
// Pre-declare all functions first, then generate code
367367
// Otherwise some function might not be found.
368368
std::string unit_src = "// Forward declarations\n";
369-
unit_src += declare_all_functions(*x.m_global_scope);
369+
unit_src += declare_all_functions(*x.m_symtab);
370370
// Now pre-declare all functions from modules and programs
371-
for (auto &item : x.m_global_scope->get_scope()) {
371+
for (auto &item : x.m_symtab->get_scope()) {
372372
if (ASR::is_a<ASR::Module_t>(*item.second)) {
373373
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(item.second);
374374
unit_src += declare_all_functions(*m->m_symtab);
@@ -387,18 +387,18 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
387387
std::vector<std::string> build_order
388388
= ASRUtils::determine_module_dependencies(x);
389389
for (auto &item : build_order) {
390-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
391-
!= x.m_global_scope->get_scope().end());
390+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
391+
!= x.m_symtab->get_scope().end());
392392
if (startswith(item, "lfortran_intrinsic")) {
393-
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
393+
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
394394
visit_symbol(*mod);
395395
unit_src += src;
396396
}
397397
}
398398
}
399399

400400
// Process procedures first:
401-
for (auto &item : x.m_global_scope->get_scope()) {
401+
for (auto &item : x.m_symtab->get_scope()) {
402402
if (ASR::is_a<ASR::Function_t>(*item.second)) {
403403
visit_symbol(*item.second);
404404
unit_src += src;
@@ -409,17 +409,17 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
409409
std::vector<std::string> build_order
410410
= ASRUtils::determine_module_dependencies(x);
411411
for (auto &item : build_order) {
412-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
413-
!= x.m_global_scope->get_scope().end());
412+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
413+
!= x.m_symtab->get_scope().end());
414414
if (!startswith(item, "lfortran_intrinsic")) {
415-
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
415+
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
416416
visit_symbol(*mod);
417417
unit_src += src;
418418
}
419419
}
420420

421421
// Then the main program:
422-
for (auto &item : x.m_global_scope->get_scope()) {
422+
for (auto &item : x.m_symtab->get_scope()) {
423423
if (ASR::is_a<ASR::Program_t>(*item.second)) {
424424
visit_symbol(*item.second);
425425
unit_src += src;

src/libasr/codegen/asr_to_julia.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>
502502

503503
void visit_TranslationUnit(const ASR::TranslationUnit_t& x)
504504
{
505-
global_scope = x.m_global_scope;
505+
global_scope = x.m_symtab;
506506

507507
// All loose statements must be converted to a function, so the items
508508
// must be empty:
@@ -519,18 +519,18 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>
519519
std::vector<std::string> build_order
520520
= ASRUtils::determine_module_dependencies(x);
521521
for (auto& item : build_order) {
522-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
523-
!= x.m_global_scope->get_scope().end());
522+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
523+
!= x.m_symtab->get_scope().end());
524524
if (startswith(item, "lfortran_intrinsic")) {
525-
ASR::symbol_t* mod = x.m_global_scope->get_symbol(item);
525+
ASR::symbol_t* mod = x.m_symtab->get_symbol(item);
526526
visit_symbol(*mod);
527527
unit_src += src;
528528
}
529529
}
530530
}
531531

532532
// Process procedures first:
533-
for (auto& item : x.m_global_scope->get_scope()) {
533+
for (auto& item : x.m_symtab->get_scope()) {
534534
if (ASR::is_a<ASR::Function_t>(*item.second)) {
535535
visit_symbol(*item.second);
536536
unit_src += src;
@@ -540,17 +540,17 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>
540540
// Then do all the modules in the right order
541541
std::vector<std::string> build_order = ASRUtils::determine_module_dependencies(x);
542542
for (auto& item : build_order) {
543-
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
544-
!= x.m_global_scope->get_scope().end());
543+
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
544+
!= x.m_symtab->get_scope().end());
545545
if (!startswith(item, "lfortran_intrinsic")) {
546-
ASR::symbol_t* mod = x.m_global_scope->get_symbol(item);
546+
ASR::symbol_t* mod = x.m_symtab->get_symbol(item);
547547
visit_symbol(*mod);
548548
unit_src += src;
549549
}
550550
}
551551

552552
// Then the main program:
553-
for (auto& item : x.m_global_scope->get_scope()) {
553+
for (auto& item : x.m_symtab->get_scope()) {
554554
if (ASR::is_a<ASR::Program_t>(*item.second)) {
555555
visit_symbol(*item.second);
556556
unit_src += src;

0 commit comments

Comments
 (0)