Skip to content

Commit

Permalink
vhdl: rm code duplication in *_declarative_item
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic30 committed Aug 28, 2020
1 parent 36b636a commit d4a3333
Show file tree
Hide file tree
Showing 24 changed files with 304 additions and 816 deletions.
124 changes: 17 additions & 107 deletions grammars/vhdlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,9 @@ entity_declaration:
KW_END ( KW_ENTITY )? ( identifier )? SEMI
;
entity_declarative_item:
subprogram_declaration
| subprogram_body
| subprogram_instantiation_declaration
| package_declaration
| package_body
| package_instantiation_declaration
| type_declaration
| subtype_declaration
| constant_declaration
| signal_declaration
| variable_declaration
| file_declaration
| alias_declaration
| attribute_declaration
| attribute_specification
signal_declaration
| process_declarative_item
| disconnection_specification
| use_clause
| group_template_declaration
| group_declaration
;
entity_statement:
( label COLON )? (
Expand Down Expand Up @@ -263,30 +247,11 @@ operator_symbol: STRING_LITERAL;
formal_parameter_list: interface_list;
subprogram_body:
subprogram_specification KW_IS
( subprogram_declarative_item )*
( process_declarative_item )*
KW_BEGIN
( sequential_statement )*
KW_END ( subprogram_kind )? ( designator )? SEMI
;
subprogram_declarative_item:
subprogram_declaration
| subprogram_body
| subprogram_instantiation_declaration
| package_declaration
| package_body
| package_instantiation_declaration
| type_declaration
| subtype_declaration
| constant_declaration
| variable_declaration
| file_declaration
| alias_declaration
| attribute_declaration
| attribute_specification
| use_clause
| group_template_declaration
| group_declaration
;
subprogram_kind: KW_PROCEDURE | KW_FUNCTION;
subprogram_instantiation_declaration:
subprogram_kind designator KW_IS KW_NEW name ( signature )?
Expand All @@ -297,61 +262,23 @@ signature: LSQUARE_BR ( type_mark ( COMMA type_mark )* )? ( KW_RETURN type_mark
;
package_declaration:
KW_PACKAGE identifier KW_IS
package_header
package_declarative_part
(
generic_clause ( generic_map_aspect SEMI )?
)?
( package_declarative_item )*
KW_END ( KW_PACKAGE )? ( identifier )? SEMI
;
package_header:
( generic_clause
( generic_map_aspect SEMI )? )?
;
package_declarative_part:
( package_declarative_item )*
;
package_declarative_item:
subprogram_declaration
| subprogram_instantiation_declaration
| package_declaration
| package_instantiation_declaration
| type_declaration
| subtype_declaration
| constant_declaration
process_or_package_declarative_item
| signal_declaration
| variable_declaration
| file_declaration
| alias_declaration
| component_declaration
| attribute_declaration
| attribute_specification
| disconnection_specification
| use_clause
| group_template_declaration
| group_declaration
;
;
package_body:
KW_PACKAGE KW_BODY identifier KW_IS
( package_body_declarative_item )*
( process_declarative_item )*
KW_END ( KW_PACKAGE KW_BODY )? ( identifier )? SEMI
;
package_body_declarative_item:
subprogram_declaration
| subprogram_body
| subprogram_instantiation_declaration
| package_declaration
| package_body
| package_instantiation_declaration
| type_declaration
| subtype_declaration
| constant_declaration
| variable_declaration
| file_declaration
| alias_declaration
| attribute_declaration
| attribute_specification
| use_clause
| group_template_declaration
| group_declaration
;
package_instantiation_declaration:
KW_PACKAGE identifier KW_IS KW_NEW name
( generic_map_aspect )? SEMI
Expand Down Expand Up @@ -439,28 +366,9 @@ protected_type_declarative_item:
;
protected_type_body:
KW_PROTECTED KW_BODY
( protected_type_body_declarative_item )*
( process_declarative_item )*
KW_END KW_PROTECTED KW_BODY ( identifier )?
;
protected_type_body_declarative_item:
subprogram_declaration
| subprogram_body
| subprogram_instantiation_declaration
| package_declaration
| package_body
| package_instantiation_declaration
| type_declaration
| subtype_declaration
| constant_declaration
| variable_declaration
| file_declaration
| alias_declaration
| attribute_declaration
| attribute_specification
| use_clause
| group_template_declaration
| group_declaration
;
type_declaration:
full_type_declaration
| incomplete_type_declaration
Expand Down Expand Up @@ -999,12 +907,10 @@ process_statement:
KW_END ( KW_POSTPONED )? KW_PROCESS ( label )? SEMI
;
process_sensitivity_list: KW_ALL | sensitivity_list;
process_declarative_item:
process_or_package_declarative_item:
subprogram_declaration
| subprogram_body
| subprogram_instantiation_declaration
| package_declaration
| package_body
| package_instantiation_declaration
| type_declaration
| subtype_declaration
Expand All @@ -1018,7 +924,11 @@ process_declarative_item:
| group_template_declaration
| group_declaration
;

process_declarative_item:
process_or_package_declarative_item
| subprogram_body
| package_body
;
concurrent_procedure_call_statement:
( KW_POSTPONED )? procedure_call SEMI
;
Expand Down
8 changes: 4 additions & 4 deletions include/hdlConvertor/vhdlConvertor/archParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
#include <hdlConvertor/vhdlConvertor/vhdlParser/vhdlParser.h>
#include <hdlConvertor/hdlAst/hdlModuleDef.h>
#include <hdlConvertor/vhdlConvertor/commentParser.h>
#include <hdlConvertor/vhdlConvertor/baseVhdlParser.h>


namespace hdlConvertor {
namespace vhdl {

class VhdlArchParser {
VhdlCommentParser &commentParser;
class VhdlArchParser : public BaseVhdlParser {
public:
using BaseVhdlParser::BaseVhdlParser;
using vhdlParser = vhdl_antlr::vhdlParser;

bool hierarchyOnly;
VhdlArchParser(VhdlCommentParser & _commentParser, bool _hierarchyOnly);
std::unique_ptr<hdlAst::HdlModuleDef> visitArchitecture_body(
vhdlParser::Architecture_bodyContext *ctx);

Expand Down
20 changes: 20 additions & 0 deletions include/hdlConvertor/vhdlConvertor/baseVhdlParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <vector>

#include <hdlConvertor/vhdlConvertor/commentParser.h>

namespace hdlConvertor {
namespace vhdl {

class BaseVhdlParser {
public:
VhdlCommentParser &commentParser;
bool hierarchyOnly;

BaseVhdlParser(VhdlCommentParser &commentParser, bool _hierarchyOnly);
BaseVhdlParser(BaseVhdlParser & parent);
};

}
}
8 changes: 3 additions & 5 deletions include/hdlConvertor/vhdlConvertor/blockDeclarationParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
#include <hdlConvertor/hdlAst/iHdlObj.h>
#include <hdlConvertor/hdlAst/hdlModuleDec.h>
#include <hdlConvertor/vhdlConvertor/commentParser.h>
#include <hdlConvertor/vhdlConvertor/baseVhdlParser.h>

namespace hdlConvertor {
namespace vhdl {

class VhdlBlockDeclarationParser {
VhdlCommentParser &commentParser;
class VhdlBlockDeclarationParser : public BaseVhdlParser{
public:
using BaseVhdlParser::BaseVhdlParser;
using vhdlParser = vhdl_antlr::vhdlParser;

bool hierarchyOnly;
VhdlBlockDeclarationParser(VhdlCommentParser &_commentParser, bool hierarchyOnly);

void visitBlock_declarative_item(
vhdlParser::Block_declarative_itemContext *ctx,
std::vector<std::unique_ptr<hdlAst::iHdlObj>> &objs);
Expand Down
8 changes: 3 additions & 5 deletions include/hdlConvertor/vhdlConvertor/entityParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
#include <hdlConvertor/vhdlConvertor/vhdlParser/vhdlParser.h>
#include <hdlConvertor/hdlAst/hdlModuleDec.h>
#include <hdlConvertor/vhdlConvertor/commentParser.h>
#include <hdlConvertor/vhdlConvertor/baseVhdlParser.h>

namespace hdlConvertor {
namespace vhdl {

class VhdlEntityParser {
VhdlCommentParser &commentParser;
class VhdlEntityParser : public BaseVhdlParser {
public:
using BaseVhdlParser::BaseVhdlParser;
using vhdlParser = vhdl_antlr::vhdlParser;
bool hierarchyOnly;

VhdlEntityParser(VhdlCommentParser &commentParser, bool _hierarchyOnly);

std::unique_ptr<hdlAst::HdlModuleDec> visitEntity_declaration(
vhdlParser::Entity_declarationContext *ctx);
Expand Down
10 changes: 3 additions & 7 deletions include/hdlConvertor/vhdlConvertor/generateStatementParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
#include <hdlConvertor/hdlAst/hdlStmCase.h>
#include <hdlConvertor/hdlAst/hdlModuleDec.h>
#include <hdlConvertor/vhdlConvertor/commentParser.h>
#include <hdlConvertor/vhdlConvertor/baseVhdlParser.h>

namespace hdlConvertor {
namespace vhdl {

class VhdlGenerateStatementParser {
VhdlCommentParser &commentParser;
class VhdlGenerateStatementParser : public BaseVhdlParser {
public:
using BaseVhdlParser::BaseVhdlParser;
using vhdlParser = vhdl_antlr::vhdlParser;

bool hierarchyOnly;

VhdlGenerateStatementParser(VhdlCommentParser &_commentParser,
bool _hierarchyOnly);

std::unique_ptr<hdlAst::iHdlStatement> visitGenerate_statement(
vhdlParser::Generate_statementContext *ctx);
std::unique_ptr<hdlAst::iHdlStatement> visitFor_generate_statement(
Expand Down
10 changes: 3 additions & 7 deletions include/hdlConvertor/vhdlConvertor/packageHeaderParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,19 @@
#include <hdlConvertor/hdlAst/hdlModuleDec.h>
#include <hdlConvertor/hdlAst/hdlIdDef.h>
#include <hdlConvertor/hdlAst/hdlFunctionDef.h>
#include <hdlConvertor/vhdlConvertor/baseVhdlParser.h>

namespace hdlConvertor {
namespace vhdl {

class VhdlPackageHeaderParser {
class VhdlPackageHeaderParser : public BaseVhdlParser {
std::unique_ptr<hdlAst::HdlValueIdspace> ph;
bool hierarchyOnly;
public:
using BaseVhdlParser::BaseVhdlParser;
using vhdlParser = vhdl_antlr::vhdlParser;

VhdlPackageHeaderParser(bool _hierarchyOnly);
std::unique_ptr<hdlAst::HdlValueIdspace> visitPackage_declaration(
vhdlParser::Package_declarationContext *ctx);
void visitPackage_header(
vhdlParser::Package_headerContext *ctx);
void visitPackage_declarative_part(
vhdlParser::Package_declarative_partContext *ctx);
void visitPackage_declarative_item(
vhdlParser::Package_declarative_itemContext *ctx);
std::unique_ptr<hdlAst::HdlModuleDec> visitComponent_declaration(
Expand Down
8 changes: 3 additions & 5 deletions include/hdlConvertor/vhdlConvertor/packageParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
#include <hdlConvertor/hdlAst/hdlValue.h>
#include <hdlConvertor/hdlAst/hdlIdDef.h>
#include <hdlConvertor/hdlAst/hdlFunctionDef.h>
#include <hdlConvertor/vhdlConvertor/baseVhdlParser.h>

namespace hdlConvertor {
namespace vhdl {

class VhdlPackageParser {
class VhdlPackageParser : public BaseVhdlParser {
public:
using BaseVhdlParser::BaseVhdlParser;
using vhdlParser = vhdl_antlr::vhdlParser;

std::unique_ptr<hdlAst::HdlValueIdspace> p;
bool hierarchyOnly;

VhdlPackageParser(bool _hierarchyOnly);
std::unique_ptr<hdlAst::HdlValueIdspace> visitPackage_body(
vhdlParser::Package_bodyContext *ctx);
void visitPackage_body_declarative_item(
vhdlParser::Package_body_declarative_itemContext *ctx);

};

Expand Down
16 changes: 10 additions & 6 deletions include/hdlConvertor/vhdlConvertor/processParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@
#include <hdlConvertor/hdlAst/iHdlExpr.h>
#include <hdlConvertor/hdlAst/hdlStmProcess.h>
#include <hdlConvertor/hdlAst/iHdlStatement.h>
#include <hdlConvertor/vhdlConvertor/baseVhdlParser.h>

namespace hdlConvertor {
namespace vhdl {

class VhdlProcessParser {

class VhdlProcessParser : public BaseVhdlParser {
public:
using BaseVhdlParser::BaseVhdlParser;
using vhdlParser = vhdl_antlr::vhdlParser;

static std::unique_ptr<hdlAst::HdlStmProcess> visitProcess_statement(
std::unique_ptr<hdlAst::HdlStmProcess> visitProcess_statement(
vhdlParser::Process_statementContext *ctx);
static void visitProcess_sensitivity_list(
void visitProcess_sensitivity_list(
vhdlParser::Process_sensitivity_listContext *ctx,
std::vector<std::unique_ptr<hdlAst::iHdlExprItem>> &sensitivity);
static void visitSensitivity_list(vhdlParser::Sensitivity_listContext *ctx,
void visitSensitivity_list(vhdlParser::Sensitivity_listContext *ctx,
std::vector<std::unique_ptr<hdlAst::iHdlExprItem>> &sensitivity);
static void visitProcess_declarative_item(
void visitProcess_declarative_item(
vhdlParser::Process_declarative_itemContext *ctx,
std::vector<std::unique_ptr<hdlAst::iHdlObj>> &objs);
void visitProcess_or_package_declarative_item(
vhdlParser::Process_or_package_declarative_itemContext *ctx,
std::vector<std::unique_ptr<hdlAst::iHdlObj>> &objs);
};

}
Expand Down
Loading

0 comments on commit d4a3333

Please sign in to comment.