Skip to content

Commit

Permalink
refactor: rename symbol StructType to Struct and ttype Struct t…
Browse files Browse the repository at this point in the history
…o `StructType` (lfortran#4254)
  • Loading branch information
kmr-srbh authored Jun 14, 2024
1 parent ae863f1 commit b64761d
Show file tree
Hide file tree
Showing 197 changed files with 1,653 additions and 1,653 deletions.
10 changes: 5 additions & 5 deletions src/lfortran/semantics/ast_body_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
AST::Name_t* name_t = AST::down_cast<AST::Name_t>(x.m_args[i].m_start);
ASR::symbol_t *v = current_scope->resolve_symbol(name_t->m_id);
if (v) {
ASR::ttype_t* struct_t = ASRUtils::TYPE(ASR::make_Struct_t(al, x.base.base.loc, v));
ASR::ttype_t* struct_t = ASRUtils::TYPE(ASR::make_StructType_t(al, x.base.base.loc, v));
new_arg.m_type = struct_t;
} else {
throw SemanticError("`The type-spec: " + std::string(name_t->m_id)
Expand Down Expand Up @@ -1326,8 +1326,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
if( assoc_variable ) {
ASR::ttype_t* selector_type = nullptr;
ASR::symbol_t* sym_underlying = ASRUtils::symbol_get_past_external(sym);
if( ASR::is_a<ASR::StructType_t>(*sym_underlying) ) {
selector_type = ASRUtils::TYPE(ASR::make_Struct_t(al, sym->base.loc, sym));
if( ASR::is_a<ASR::Struct_t>(*sym_underlying) ) {
selector_type = ASRUtils::TYPE(ASR::make_StructType_t(al, sym->base.loc, sym));
} else if( ASR::is_a<ASR::ClassType_t>(*sym_underlying) ) {
selector_type = ASRUtils::TYPE(ASR::make_Class_t(al, sym->base.loc, sym));
} else {
Expand Down Expand Up @@ -1372,8 +1372,8 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
if( assoc_variable ) {
ASR::ttype_t* selector_type = nullptr;
ASR::symbol_t* sym_underlying = ASRUtils::symbol_get_past_external(sym);
if( ASR::is_a<ASR::StructType_t>(*sym_underlying) ) {
selector_type = ASRUtils::TYPE(ASR::make_Struct_t(al, sym->base.loc, sym));
if( ASR::is_a<ASR::Struct_t>(*sym_underlying) ) {
selector_type = ASRUtils::TYPE(ASR::make_StructType_t(al, sym->base.loc, sym));
} else if( ASR::is_a<ASR::ClassType_t>(*sym_underlying) ) {
selector_type = ASRUtils::TYPE(ASR::make_Class_t(al, sym->base.loc, sym));
} else {
Expand Down
94 changes: 47 additions & 47 deletions src/lfortran/semantics/ast_common_visitor.h

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions src/lfortran/semantics/ast_symboltable_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,19 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
for( auto& itr: symtab->get_scope() ) {
ASR::symbol_t* sym = itr.second;
if( !ASR::is_a<ASR::Variable_t>(*sym) &&
!ASR::is_a<ASR::StructType_t>(*sym) ) {
!ASR::is_a<ASR::Struct_t>(*sym) ) {
continue ;
}

if( ASR::is_a<ASR::StructType_t>(*sym) ) {
fix_struct_type(ASR::down_cast<ASR::StructType_t>(sym)->m_symtab);
if( ASR::is_a<ASR::Struct_t>(*sym) ) {
fix_struct_type(ASR::down_cast<ASR::Struct_t>(sym)->m_symtab);
continue ;
}

ASR::ttype_t* sym_type = ASRUtils::type_get_past_pointer(
ASRUtils::symbol_type(sym));
if( ASR::is_a<ASR::Struct_t>(*sym_type) ) {
ASR::Struct_t* struct_t = ASR::down_cast<ASR::Struct_t>(sym_type);
if( ASR::is_a<ASR::StructType_t>(*sym_type) ) {
ASR::StructType_t* struct_t = ASR::down_cast<ASR::StructType_t>(sym_type);
ASR::symbol_t* der_sym = struct_t->m_derived_type;
if( ASR::is_a<ASR::ExternalSymbol_t>(*der_sym) &&
ASR::down_cast<ASR::ExternalSymbol_t>(der_sym)->m_external == nullptr &&
Expand Down Expand Up @@ -1390,7 +1390,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
+ derived_type_name + "' not declared", x.base.base.loc);

}
type = ASRUtils::TYPE(ASR::make_Struct_t(al, x.base.base.loc, v));
type = ASRUtils::TYPE(ASR::make_StructType_t(al, x.base.base.loc, v));
break;
}
default :
Expand Down Expand Up @@ -1669,16 +1669,16 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
for( auto& item: current_scope->get_scope() ) {
// ExternalSymbol means that current module/program
// already depends on the module of ExternalSymbol
// present inside StructType's scope. So the order
// present inside Struct's scope. So the order
// is already established and hence no need to store
// this ExternalSymbol as a dependency.
if( ASR::is_a<ASR::ExternalSymbol_t>(*item.second) ) {
continue;
}
ASR::ttype_t* var_type = ASRUtils::type_get_past_pointer(ASRUtils::symbol_type(item.second));
char* aggregate_type_name = nullptr;
if( ASR::is_a<ASR::Struct_t>(*var_type) ) {
ASR::symbol_t* sym = ASR::down_cast<ASR::Struct_t>(var_type)->m_derived_type;
if( ASR::is_a<ASR::StructType_t>(*var_type) ) {
ASR::symbol_t* sym = ASR::down_cast<ASR::StructType_t>(var_type)->m_derived_type;
aggregate_type_name = ASRUtils::symbol_name(sym);
} else if( ASR::is_a<ASR::Class_t>(*var_type) ) {
ASR::symbol_t* sym = ASR::down_cast<ASR::Class_t>(var_type)->m_class_type;
Expand All @@ -1688,7 +1688,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
struct_dependencies.push_back(al, aggregate_type_name);
}
}
tmp = ASR::make_StructType_t(al, x.base.base.loc, current_scope,
tmp = ASR::make_Struct_t(al, x.base.base.loc, current_scope,
s2c(al, to_lower(x.m_name)), struct_dependencies.p, struct_dependencies.size(),
data_member_names.p, data_member_names.size(),
ASR::abiType::Source, dflt_access, false, is_abstract, nullptr, 0, nullptr, parent_sym);
Expand Down Expand Up @@ -1924,7 +1924,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
std::string sym_name_str = proc.first;
if( current_scope->get_symbol(proc.first) != nullptr ) {
ASR::symbol_t* der_type_name = current_scope->get_symbol(proc.first);
if( der_type_name->type == ASR::symbolType::StructType ||
if( der_type_name->type == ASR::symbolType::Struct ||
der_type_name->type == ASR::symbolType::Function ) {
sym_name_str = "~" + proc.first;
}
Expand Down Expand Up @@ -1978,7 +1978,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
Location loc;
loc.first = 1;
loc.last = 1;
ASR::StructType_t *clss = ASR::down_cast<ASR::StructType_t>(
ASR::Struct_t *clss = ASR::down_cast<ASR::Struct_t>(
current_scope->get_symbol(proc.first));
for (auto &pname : proc.second) {
Vec<ASR::symbol_t*> cand_procs;
Expand Down Expand Up @@ -2033,7 +2033,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
if (var_type_clss_sym == clss_sym) {
return true;
}
var_type_clss_sym = ASR::down_cast<ASR::StructType_t>(var_type_clss_sym)->m_parent;
var_type_clss_sym = ASR::down_cast<ASR::Struct_t>(var_type_clss_sym)->m_parent;
}
}
return false;
Expand Down Expand Up @@ -2065,7 +2065,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
}
}

bool check_is_deferred(const std::string& pname, ASR::StructType_t* clss) {
bool check_is_deferred(const std::string& pname, ASR::Struct_t* clss) {
auto& cdf = class_deferred_procedures;
while( true ) {
std::string proc = clss->m_name;
Expand All @@ -2076,8 +2076,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
if( !clss_sym ) {
break;
}
LCOMPILERS_ASSERT(ASR::is_a<ASR::StructType_t>(*clss_sym));
clss = ASR::down_cast<ASR::StructType_t>(clss_sym);
LCOMPILERS_ASSERT(ASR::is_a<ASR::Struct_t>(*clss_sym));
clss = ASR::down_cast<ASR::Struct_t>(clss_sym);
}
return false;
}
Expand All @@ -2086,7 +2086,7 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
for (auto &proc : class_procedures) {
ASR::symbol_t* clss_sym = ASRUtils::symbol_get_past_external(
current_scope->resolve_symbol(proc.first));
ASR::StructType_t *clss = ASR::down_cast<ASR::StructType_t>(clss_sym);
ASR::Struct_t *clss = ASR::down_cast<ASR::Struct_t>(clss_sym);
SymbolTable* proc_scope = ASRUtils::symbol_parent_symtab(clss_sym);
for (auto &pname : proc.second) {
auto &loc = pname.second["procedure"].loc;
Expand Down Expand Up @@ -2220,8 +2220,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
dflt_access
);
current_scope->add_or_overwrite_symbol(sym, ASR::down_cast<ASR::symbol_t>(es));
} else if( ASR::is_a<ASR::StructType_t>(*item.second) ) {
ASR::StructType_t *mv = ASR::down_cast<ASR::StructType_t>(item.second);
} else if( ASR::is_a<ASR::Struct_t>(*item.second) ) {
ASR::Struct_t *mv = ASR::down_cast<ASR::Struct_t>(item.second);
// `mv` is the Variable in a module. Now we construct
// an ExternalSymbol that points to it.
Str name;
Expand Down Expand Up @@ -2500,9 +2500,9 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
dflt_access
);
current_scope->add_symbol(local_sym, ASR::down_cast<ASR::symbol_t>(v));
} else if( ASR::is_a<ASR::StructType_t>(*t) ) {
} else if( ASR::is_a<ASR::Struct_t>(*t) ) {
ASR::symbol_t* imported_struct_type = current_scope->get_symbol(local_sym);
ASR::StructType_t *mv = ASR::down_cast<ASR::StructType_t>(t);
ASR::Struct_t *mv = ASR::down_cast<ASR::Struct_t>(t);
if (imported_struct_type != nullptr) {
imported_struct_type = ASRUtils::symbol_get_past_external(imported_struct_type);
if( imported_struct_type == t ) {
Expand Down Expand Up @@ -3027,8 +3027,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
ASR::symbol_t *arg_sym0 = current_scope->resolve_symbol(arg);
ASR::symbol_t *arg_sym = ASRUtils::symbol_get_past_external(arg_sym0);
ASR::ttype_t *arg_type = nullptr;
if (ASR::is_a<ASR::StructType_t>(*arg_sym)) {
arg_type = ASRUtils::TYPE(ASR::make_Struct_t(al, x.m_args[i]->base.loc, arg_sym0));
if (ASR::is_a<ASR::Struct_t>(*arg_sym)) {
arg_type = ASRUtils::TYPE(ASR::make_StructType_t(al, x.m_args[i]->base.loc, arg_sym0));
} else {
arg_type = ASRUtils::symbol_type(arg_sym);
}
Expand Down
6 changes: 3 additions & 3 deletions src/libasr/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ symbol
| GenericProcedure(symbol_table parent_symtab, identifier name, symbol* procs, access access)
| CustomOperator(symbol_table parent_symtab, identifier name, symbol* procs, access access)
| ExternalSymbol(symbol_table parent_symtab, identifier name, symbol external, identifier module_name, identifier* scope_names, identifier original_name, access access)
| StructType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, bool is_packed, bool is_abstract, call_arg* initializers, expr? alignment, symbol? parent)
| Struct(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, bool is_packed, bool is_abstract, call_arg* initializers, expr? alignment, symbol? parent)
| EnumType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, enumtype enum_value_type, ttype type, symbol? parent)
| UnionType(symbol_table symtab, identifier name, identifier* dependencies, identifier* members, abi abi, access access, call_arg* initializers, symbol? parent)
| Variable(symbol_table parent_symtab, identifier name, identifier* dependencies, intent intent, expr? symbolic_value, expr? value, storage_type storage, ttype type, symbol? type_declaration, abi abi, access access, presence presence, bool value_attr)
Expand Down Expand Up @@ -84,7 +84,7 @@ expr
| IntrinsicArrayFunction(int arr_intrinsic_id, expr* args, int overload_id, ttype? type, expr? value)
| IntrinsicImpureFunction(int impure_intrinsic_id, expr* args, int overload_id, ttype? type, expr? value)
| TypeInquiry(int inquiry_id, ttype arg_type, expr? arg, ttype type, expr value)
| StructTypeConstructor(symbol dt_sym, call_arg* args, ttype type, expr? value)
| StructConstructor(symbol dt_sym, call_arg* args, ttype type, expr? value)
| EnumTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
| UnionTypeConstructor(symbol dt_sym, expr* args, ttype type, expr? value)
| ImpliedDoLoop(expr* values, expr var, expr start, expr end, expr? increment, ttype type, expr? value)
Expand Down Expand Up @@ -192,7 +192,7 @@ ttype
| Set(ttype type)
| List(ttype type)
| Tuple(ttype* type)
| Struct(symbol derived_type)
| StructType(symbol derived_type)
| Enum(symbol enum_type)
| Union(symbol union_type)
| Class(symbol class_type)
Expand Down
Loading

0 comments on commit b64761d

Please sign in to comment.