Skip to content

Commit

Permalink
Include the interface name in AST
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Mar 5, 2021
1 parent a1fe312 commit f28f0f2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
9 changes: 8 additions & 1 deletion grammar/AST.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ unit_decl2
| ParameterStatement(parameter_item* items)
| Private(identifier* vars)
| Public(identifier* vars)
| Interface(identifier? name, interface_item* items)
| Interface(interface_header header, interface_item* items)

interface_header
= InterfaceHeader1()
| InterfaceHeader2(identifier name)
| InterfaceHeader3()
| InterfaceHeader4()
| InterfaceHeader5()

interface_item
= InterfaceProc(program_unit proc)
Expand Down
2 changes: 1 addition & 1 deletion src/lfortran/ast_to_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class ASTToCPPVisitor : public BaseVisitor<ASTToCPPVisitor>
s.append(color(style::reset));
}
s.append(" ");
s.append(x.m_name);
s.append(AST::down_cast<AST::InterfaceHeader2_t>(x.m_header)->m_name);
s.append(" ");
s.append("Unimplementedidentifier");
s.append(")");
Expand Down
2 changes: 1 addition & 1 deletion src/lfortran/ast_to_cpp_hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class ASTToCPPHIPVisitor : public BaseVisitor<ASTToCPPHIPVisitor>
s.append(color(style::reset));
}
s.append(" ");
s.append(x.m_name);
s.append(AST::down_cast<AST::InterfaceHeader2_t>(x.m_header)->m_name);
s.append(" ");
s.append("Unimplementedidentifier");
s.append(")");
Expand Down
2 changes: 1 addition & 1 deletion src/lfortran/ast_to_openmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class ASTToOPENMPVisitor : public BaseVisitor<ASTToOPENMPVisitor>
s.append(color(style::reset));
}
s.append(" ");
s.append(x.m_name);
s.append(AST::down_cast<AST::InterfaceHeader2_t>(x.m_header)->m_name);
s.append(" ");
s.append("Unimplementedidentifier");
s.append(")");
Expand Down
14 changes: 8 additions & 6 deletions src/lfortran/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg)
%type <ast> decl
%type <vec_ast> decl_star
%type <ast> interface_decl
%type <ast> interface_stmt
%type <ast> derived_type_decl
%type <ast> enum_decl
%type <ast> program
Expand Down Expand Up @@ -415,15 +416,16 @@ submodule

interface_decl
: interface_stmt sep interface_body endinterface sep {
$$ = INTERFACE($3, @$); }
$$ = INTERFACE($1, $3, @$); }
;

interface_stmt
: KW_INTERFACE
| KW_INTERFACE id
| KW_INTERFACE KW_ASSIGNMENT "(" "=" ")"
| KW_INTERFACE KW_OPERATOR "(" operator_type ")"
| KW_ABSTRACT KW_INTERFACE
: KW_INTERFACE { $$ = INTERFACE_HEADER1(@$); }
| KW_INTERFACE id { $$ = INTERFACE_HEADER2($2, @$); }
| KW_INTERFACE KW_ASSIGNMENT "(" "=" ")" { $$ = INTERFACE_HEADER3(@$); }
| KW_INTERFACE KW_OPERATOR "(" operator_type ")" {
$$ = INTERFACE_HEADER4(@$); }
| KW_ABSTRACT KW_INTERFACE { $$ = INTERFACE_HEADER5(@$); }
;

endinterface
Expand Down
14 changes: 11 additions & 3 deletions src/lfortran/parser/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,15 @@ ast_t* FUNCCALLORARRAY0(Allocator &al, const ast_t *id,
#define PUBLIC(syms, l) make_Public_t(p.m_a, l, \
nullptr, 0)

#define INTERFACE(contains, l) LFortran::AST::make_Interface_t(p.m_a, l, \
nullptr, INTERFACE_ITEMS(contains), contains.size())
#define INTERFACE_HEADER1(l) LFortran::AST::make_InterfaceHeader1_t(p.m_a, l)
#define INTERFACE_HEADER2(id, l) LFortran::AST::make_InterfaceHeader2_t(p.m_a, l, \
name2char(id))
#define INTERFACE_HEADER3(l) LFortran::AST::make_InterfaceHeader3_t(p.m_a, l)
#define INTERFACE_HEADER4(l) LFortran::AST::make_InterfaceHeader4_t(p.m_a, l)
#define INTERFACE_HEADER5(l) LFortran::AST::make_InterfaceHeader5_t(p.m_a, l)

#define INTERFACE(header, contains, l) LFortran::AST::make_Interface_t(p.m_a, l, \
down_cast<LFortran::AST::interface_header_t>(header), INTERFACE_ITEMS(contains), contains.size())
#define INTERFACE_MODULE_PROC(names, l) \
LFortran::AST::make_InterfaceModuleProcedure_t(p.m_a, l, \
REDUCE_ARGS(p.m_a, names), names.size())
Expand All @@ -843,6 +850,7 @@ ast_t* FUNCCALLORARRAY0(Allocator &al, const ast_t *id,

// TODO: Add DerivedType AST node
#define DERIVED_TYPE(name, l) make_Interface_t(p.m_a, l, \
name2char(name), nullptr, 0)
down_cast<LFortran::AST::interface_header_t>(INTERFACE_HEADER2(name, l)), \
nullptr, 0)

#endif

0 comments on commit f28f0f2

Please sign in to comment.