Skip to content

Commit

Permalink
Added support pure module subroutine under interface
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Oct 30, 2021
1 parent 56b355e commit 9f37cb9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion grammar/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ symbol
| Module(symbol_table symtab, identifier name, identifier* dependencies,
bool loaded_from_mod)
| Subroutine(symbol_table symtab, identifier name, expr* args, stmt* body,
abi abi, access access, deftype deftype, string? bindc_name)
abi abi, access access, deftype deftype, string? bindc_name, bool pure,
bool module)
| Function(symbol_table symtab, identifier name, expr* args, stmt* body,
expr return_var, abi abi, access access, deftype deftype,
string? bindc_name)
Expand Down
2 changes: 1 addition & 1 deletion src/lfortran/mod_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ ASR::TranslationUnit_t* parse_gfortran_mod_file(Allocator &al, const std::string
ASR::asr_t *asr = ASR::make_Subroutine_t(al, loc,
proc_symtab, name, nullptr, 0,
nullptr, 0, ASR::abiType::GFortranModule, ASR::Public,
ASR::Interface, nullptr);
ASR::Interface, nullptr, false, false);
s.p.proc = down_cast<ASR::symbol_t>(asr);
std::string sym_name = s.name;
if (parent_scope->scope.find(sym_name) != parent_scope->scope.end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/lfortran/pass/array_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ArrayOpVisitor : public ASR::BaseWalkVisitor<ArrayOpVisitor>
a_args.push_back(al, s->m_return_var);
ASR::asr_t* s_sub_asr = ASR::make_Subroutine_t(al, s->base.base.loc, s->m_symtab,
s->m_name, a_args.p, a_args.size(), s->m_body, s->n_body,
s->m_abi, s->m_access, s->m_deftype, nullptr);
s->m_abi, s->m_access, s->m_deftype, nullptr, false, false);
ASR::symbol_t* s_sub = ASR::down_cast<ASR::symbol_t>(s_sub_asr);
replace_vec.push_back(std::make_pair(item.first, s_sub));
}
Expand Down
3 changes: 2 additions & 1 deletion src/lfortran/pass/global_stmts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ void pass_wrap_global_stmts_into_function(Allocator &al,
/* a_body */ body.p,
/* n_body */ body.size(),
ASR::abiType::Source,
ASR::Public, ASR::Implementation, nullptr);
ASR::Public, ASR::Implementation, nullptr,
false, false);
std::string sym_name = fn_name;
if (unit.m_global_scope->scope.find(sym_name) != unit.m_global_scope->scope.end()) {
throw LFortranException("Function already defined");
Expand Down
38 changes: 37 additions & 1 deletion src/lfortran/semantics/ast_symboltable_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
if (is_interface){
deftype = ASR::deftypeType::Interface;
}
bool is_pure = false, is_module = false;
for( size_t i = 0; i < x.n_attributes; i++ ) {
switch( x.m_attributes[i]->type ) {
case AST::decl_attributeType::SimpleAttribute: {
AST::SimpleAttribute_t* simple_attr = AST::down_cast<AST::SimpleAttribute_t>(x.m_attributes[i]);
if( simple_attr->m_attr == AST::simple_attributeType::AttrPure ) {
is_pure = true;
} else if( simple_attr->m_attr == AST::simple_attributeType::AttrModule ) {
is_module = true;
}
break;
}
default: {
// Continue with the original behaviour
// of not processing unrequired attributes
break;
}
}
}
tmp = ASR::make_Subroutine_t(
al, x.base.base.loc,
/* a_symtab */ current_scope,
Expand All @@ -250,7 +269,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
/* a_body */ nullptr,
/* n_body */ 0,
current_procedure_abi_type,
s_access, deftype, bindc_name);
s_access, deftype, bindc_name,
is_pure, is_module);
if (parent_scope->scope.find(sym_name) != parent_scope->scope.end()) {
ASR::symbol_t *f1 = parent_scope->scope[sym_name];
ASR::Subroutine_t *f2 = ASR::down_cast<ASR::Subroutine_t>(f1);
Expand Down Expand Up @@ -971,6 +991,22 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
char *proc_name = proc->m_names[i];
proc_names.push_back(std::string(proc_name));
}
} else if(AST::is_a<AST::InterfaceProc_t>(*item)) {
visit_interface_item(*item);
AST::InterfaceProc_t *proc
= AST::down_cast<AST::InterfaceProc_t>(item);
switch(proc->m_proc->type) {
case AST::program_unitType::Subroutine: {
AST::Subroutine_t* subrout = AST::down_cast<AST::Subroutine_t>(proc->m_proc);
char* proc_name = subrout->m_name;
proc_names.push_back(std::string(proc_name));
break;
}
default: {
LFORTRAN_ASSERT(false);
break;
}
}
} else {
throw SemanticError("Interface procedure type not imlemented yet", item->base.loc);
}
Expand Down

0 comments on commit 9f37cb9

Please sign in to comment.