Skip to content

Commit

Permalink
Merge pull request #2322 from Shaikh-Ubaid/rename_and_fix_typo
Browse files Browse the repository at this point in the history
Rename `m_global_scope` and fix typo
  • Loading branch information
Shaikh-Ubaid authored Sep 13, 2023
2 parents df414fb + cc1def0 commit 8b60246
Show file tree
Hide file tree
Showing 33 changed files with 146 additions and 146 deletions.
2 changes: 1 addition & 1 deletion src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ int get_symbols (const std::string &infile,
}
std::vector<LCompilers::document_symbols> symbol_lists;
LCompilers::document_symbols loc;
for (auto &a : x.result->m_global_scope->get_scope()) {
for (auto &a : x.result->m_symtab->get_scope()) {
std::string symbol_name = a.first;
uint32_t first_line;
uint32_t last_line;
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
module ASR {

unit
= TranslationUnit(symbol_table global_scope, node* items)
= TranslationUnit(symbol_table symtab, node* items)

-- # Documentation for the symbol type

Expand Down
4 changes: 2 additions & 2 deletions src/libasr/asr_scopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ struct SymbolTable {
public:
SymbolTable *parent;
// The ASR node (either symbol_t or TranslationUnit_t) that contains this
// SymbolTable as m_symtab / m_global_scope member. One of:
// SymbolTable as m_symtab member. One of:
// * symbol_symtab(down_cast<symbol_t>(this->asr_owner)) == this
// * down_cast2<TranslationUnit_t>(this->asr_owner)->m_global_scope == this
// * down_cast2<TranslationUnit_t>(this->asr_owner)->m_symtab == this
ASR::asr_t *asr_owner = nullptr;
unsigned int counter;

Expand Down
10 changes: 5 additions & 5 deletions src/libasr/asr_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::vector<std::string> determine_module_dependencies(
const ASR::TranslationUnit_t &unit)
{
std::map<std::string, std::vector<std::string>> deps;
for (auto &item : unit.m_global_scope->get_scope()) {
for (auto &item : unit.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Module_t>(*item.second)) {
std::string name = item.first;
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(item.second);
Expand Down Expand Up @@ -116,7 +116,7 @@ void extract_module_python(const ASR::TranslationUnit_t &m,
std::vector<std::pair<std::string, ASR::Module_t*>>& children_modules,
std::string module_name) {
bool module_found = false;
for (auto &a : m.m_global_scope->get_scope()) {
for (auto &a : m.m_symtab->get_scope()) {
if( ASR::is_a<ASR::Module_t>(*a.second) ) {
if( a.first == "__main__" ) {
module_found = true;
Expand Down Expand Up @@ -219,8 +219,8 @@ void update_call_args(Allocator &al, SymbolTable *current_scope, bool implicit_i
}

ASR::Module_t* extract_module(const ASR::TranslationUnit_t &m) {
LCOMPILERS_ASSERT(m.m_global_scope->get_scope().size()== 1);
for (auto &a : m.m_global_scope->get_scope()) {
LCOMPILERS_ASSERT(m.m_symtab->get_scope().size()== 1);
for (auto &a : m.m_symtab->get_scope()) {
LCOMPILERS_ASSERT(ASR::is_a<ASR::Module_t>(*a.second));
return ASR::down_cast<ASR::Module_t>(a.second);
}
Expand Down Expand Up @@ -370,7 +370,7 @@ void set_intrinsic(ASR::symbol_t* sym) {
}

void set_intrinsic(ASR::TranslationUnit_t* trans_unit) {
for( auto& itr: trans_unit->m_global_scope->get_scope() ) {
for( auto& itr: trans_unit->m_symtab->get_scope() ) {
set_intrinsic(itr.second);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ static inline bool is_arg_dummy(int intent) {

static inline bool main_program_present(const ASR::TranslationUnit_t &unit)
{
for (auto &a : unit.m_global_scope->get_scope()) {
for (auto &a : unit.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Program_t>(*a.second)) return true;
}
return false;
Expand Down
24 changes: 12 additions & 12 deletions src/libasr/asr_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
}

void visit_TranslationUnit(const TranslationUnit_t &x) {
current_symtab = x.m_global_scope;
require(x.m_global_scope != nullptr,
"The TranslationUnit::m_global_scope cannot be nullptr");
require(x.m_global_scope->parent == nullptr,
"The TranslationUnit::m_global_scope->parent must be nullptr");
require(id_symtab_map.find(x.m_global_scope->counter) == id_symtab_map.end(),
"TranslationUnit::m_global_scope->counter must be unique");
require(x.m_global_scope->asr_owner == (ASR::asr_t*)&x,
"The TranslationUnit::m_global_scope::asr_owner must point to itself");
require(down_cast2<TranslationUnit_t>(current_symtab->asr_owner)->m_global_scope == current_symtab,
current_symtab = x.m_symtab;
require(x.m_symtab != nullptr,
"The TranslationUnit::m_symtab cannot be nullptr");
require(x.m_symtab->parent == nullptr,
"The TranslationUnit::m_symtab->parent must be nullptr");
require(id_symtab_map.find(x.m_symtab->counter) == id_symtab_map.end(),
"TranslationUnit::m_symtab->counter must be unique");
require(x.m_symtab->asr_owner == (ASR::asr_t*)&x,
"The TranslationUnit::m_symtab::asr_owner must point to itself");
require(down_cast2<TranslationUnit_t>(current_symtab->asr_owner)->m_symtab == current_symtab,
"The asr_owner invariant failed");
id_symtab_map[x.m_global_scope->counter] = x.m_global_scope;
for (auto &a : x.m_global_scope->get_scope()) {
id_symtab_map[x.m_symtab->counter] = x.m_symtab;
for (auto &a : x.m_symtab->get_scope()) {
this->visit_symbol(*a.second);
}
for (size_t i=0; i<x.n_items; i++) {
Expand Down
26 changes: 13 additions & 13 deletions src/libasr/codegen/asr_to_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class ASRToCVisitor : public BaseCCPPVisitor<ASRToCVisitor>

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

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


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

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

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

unit_src += "\n";
unit_src += "// Implementations\n";
Expand All @@ -651,10 +651,10 @@ R"(
std::vector<std::string> build_order
= ASRUtils::determine_module_dependencies(x);
for (auto &item : build_order) {
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
!= x.m_global_scope->get_scope().end());
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
!= x.m_symtab->get_scope().end());
if (startswith(item, "lfortran_intrinsic")) {
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
if( ASRUtils::get_body_size(mod) != 0 ) {
visit_symbol(*mod);
unit_src += src;
Expand All @@ -666,7 +666,7 @@ R"(
// Process global functions
size_t i;
for (i = 0; i < global_func_order.size(); i++) {
ASR::symbol_t* sym = x.m_global_scope->get_symbol(global_func_order[i]);
ASR::symbol_t* sym = x.m_symtab->get_symbol(global_func_order[i]);
// Ignore external symbols because they are already defined by the loop above.
if( !sym || ASR::is_a<ASR::ExternalSymbol_t>(*sym) ) {
continue ;
Expand All @@ -679,17 +679,17 @@ R"(
std::vector<std::string> build_order
= ASRUtils::determine_module_dependencies(x);
for (auto &item : build_order) {
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
!= x.m_global_scope->get_scope().end());
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
!= x.m_symtab->get_scope().end());
if (!startswith(item, "lfortran_intrinsic")) {
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
visit_symbol(*mod);
unit_src += src;
}
}

// Then the main program:
for (auto &item : x.m_global_scope->get_scope()) {
for (auto &item : x.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Program_t>(*item.second)) {
visit_symbol(*item.second);
unit_src += src;
Expand Down
18 changes: 9 additions & 9 deletions src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class BaseCCPPVisitor : public ASR::BaseVisitor<Struct>
ds_funcs_defined + util_funcs_defined;
}
void visit_TranslationUnit(const ASR::TranslationUnit_t &x) {
global_scope = x.m_global_scope;
global_scope = x.m_symtab;
// All loose statements must be converted to a function, so the items
// must be empty:
LCOMPILERS_ASSERT(x.n_items == 0);
Expand All @@ -236,18 +236,18 @@ R"(#include <stdio.h>
std::vector<std::string> build_order
= ASRUtils::determine_module_dependencies(x);
for (auto &item : build_order) {
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
!= x.m_global_scope->get_scope().end());
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
!= x.m_symtab->get_scope().end());
if (startswith(item, "lfortran_intrinsic")) {
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
self().visit_symbol(*mod);
unit_src += src;
}
}
}

// Process procedures first:
for (auto &item : x.m_global_scope->get_scope()) {
for (auto &item : x.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Function_t>(*item.second)) {
self().visit_symbol(*item.second);
unit_src += src;
Expand All @@ -258,17 +258,17 @@ R"(#include <stdio.h>
std::vector<std::string> build_order
= ASRUtils::determine_module_dependencies(x);
for (auto &item : build_order) {
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
!= x.m_global_scope->get_scope().end());
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
!= x.m_symtab->get_scope().end());
if (!startswith(item, "lfortran_intrinsic")) {
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
self().visit_symbol(*mod);
unit_src += src;
}
}

// Then the main program:
for (auto &item : x.m_global_scope->get_scope()) {
for (auto &item : x.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Program_t>(*item.second)) {
self().visit_symbol(*item.second);
unit_src += src;
Expand Down
22 changes: 11 additions & 11 deletions src/libasr/codegen/asr_to_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class ASRToCPPVisitor : public BaseCCPPVisitor<ASRToCPPVisitor>


void visit_TranslationUnit(const ASR::TranslationUnit_t &x) {
global_scope = x.m_global_scope;
global_scope = x.m_symtab;
// All loose statements must be converted to a function, so the items
// must be empty:
LCOMPILERS_ASSERT(x.n_items == 0);
Expand Down Expand Up @@ -366,9 +366,9 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
// Pre-declare all functions first, then generate code
// Otherwise some function might not be found.
std::string unit_src = "// Forward declarations\n";
unit_src += declare_all_functions(*x.m_global_scope);
unit_src += declare_all_functions(*x.m_symtab);
// Now pre-declare all functions from modules and programs
for (auto &item : x.m_global_scope->get_scope()) {
for (auto &item : x.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Module_t>(*item.second)) {
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(item.second);
unit_src += declare_all_functions(*m->m_symtab);
Expand All @@ -387,18 +387,18 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
std::vector<std::string> build_order
= ASRUtils::determine_module_dependencies(x);
for (auto &item : build_order) {
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
!= x.m_global_scope->get_scope().end());
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
!= x.m_symtab->get_scope().end());
if (startswith(item, "lfortran_intrinsic")) {
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
visit_symbol(*mod);
unit_src += src;
}
}
}

// Process procedures first:
for (auto &item : x.m_global_scope->get_scope()) {
for (auto &item : x.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Function_t>(*item.second)) {
visit_symbol(*item.second);
unit_src += src;
Expand All @@ -409,17 +409,17 @@ Kokkos::View<T*> from_std_vector(const std::vector<T> &v)
std::vector<std::string> build_order
= ASRUtils::determine_module_dependencies(x);
for (auto &item : build_order) {
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
!= x.m_global_scope->get_scope().end());
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
!= x.m_symtab->get_scope().end());
if (!startswith(item, "lfortran_intrinsic")) {
ASR::symbol_t *mod = x.m_global_scope->get_symbol(item);
ASR::symbol_t *mod = x.m_symtab->get_symbol(item);
visit_symbol(*mod);
unit_src += src;
}
}

// Then the main program:
for (auto &item : x.m_global_scope->get_scope()) {
for (auto &item : x.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Program_t>(*item.second)) {
visit_symbol(*item.second);
unit_src += src;
Expand Down
18 changes: 9 additions & 9 deletions src/libasr/codegen/asr_to_julia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>

void visit_TranslationUnit(const ASR::TranslationUnit_t& x)
{
global_scope = x.m_global_scope;
global_scope = x.m_symtab;

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

// Process procedures first:
for (auto& item : x.m_global_scope->get_scope()) {
for (auto& item : x.m_symtab->get_scope()) {
if (ASR::is_a<ASR::Function_t>(*item.second)) {
visit_symbol(*item.second);
unit_src += src;
Expand All @@ -540,17 +540,17 @@ class ASRToJuliaVisitor : public ASR::BaseVisitor<ASRToJuliaVisitor>
// Then do all the modules in the right order
std::vector<std::string> build_order = ASRUtils::determine_module_dependencies(x);
for (auto& item : build_order) {
LCOMPILERS_ASSERT(x.m_global_scope->get_scope().find(item)
!= x.m_global_scope->get_scope().end());
LCOMPILERS_ASSERT(x.m_symtab->get_scope().find(item)
!= x.m_symtab->get_scope().end());
if (!startswith(item, "lfortran_intrinsic")) {
ASR::symbol_t* mod = x.m_global_scope->get_symbol(item);
ASR::symbol_t* mod = x.m_symtab->get_symbol(item);
visit_symbol(*mod);
unit_src += src;
}
}

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

0 comments on commit 8b60246

Please sign in to comment.