diff --git a/grammars/vhdlParser.g4 b/grammars/vhdlParser.g4 index 59e06305..393b41d3 100644 --- a/grammars/vhdlParser.g4 +++ b/grammars/vhdlParser.g4 @@ -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 )? ( @@ -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 )? @@ -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 @@ -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 @@ -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 @@ -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 ; diff --git a/include/hdlConvertor/vhdlConvertor/archParser.h b/include/hdlConvertor/vhdlConvertor/archParser.h index e2b6074c..f0b157a2 100644 --- a/include/hdlConvertor/vhdlConvertor/archParser.h +++ b/include/hdlConvertor/vhdlConvertor/archParser.h @@ -3,17 +3,17 @@ #include #include #include +#include + 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 visitArchitecture_body( vhdlParser::Architecture_bodyContext *ctx); diff --git a/include/hdlConvertor/vhdlConvertor/baseVhdlParser.h b/include/hdlConvertor/vhdlConvertor/baseVhdlParser.h new file mode 100644 index 00000000..6572edd7 --- /dev/null +++ b/include/hdlConvertor/vhdlConvertor/baseVhdlParser.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include + +namespace hdlConvertor { +namespace vhdl { + +class BaseVhdlParser { +public: + VhdlCommentParser &commentParser; + bool hierarchyOnly; + + BaseVhdlParser(VhdlCommentParser &commentParser, bool _hierarchyOnly); + BaseVhdlParser(BaseVhdlParser & parent); +}; + +} +} diff --git a/include/hdlConvertor/vhdlConvertor/blockDeclarationParser.h b/include/hdlConvertor/vhdlConvertor/blockDeclarationParser.h index d8a47329..5eaa9eb6 100644 --- a/include/hdlConvertor/vhdlConvertor/blockDeclarationParser.h +++ b/include/hdlConvertor/vhdlConvertor/blockDeclarationParser.h @@ -7,18 +7,16 @@ #include #include #include +#include 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> &objs); diff --git a/include/hdlConvertor/vhdlConvertor/entityParser.h b/include/hdlConvertor/vhdlConvertor/entityParser.h index da966bde..f2f1aec5 100644 --- a/include/hdlConvertor/vhdlConvertor/entityParser.h +++ b/include/hdlConvertor/vhdlConvertor/entityParser.h @@ -5,17 +5,15 @@ #include #include #include +#include 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 visitEntity_declaration( vhdlParser::Entity_declarationContext *ctx); diff --git a/include/hdlConvertor/vhdlConvertor/generateStatementParser.h b/include/hdlConvertor/vhdlConvertor/generateStatementParser.h index 0f14d703..2f2bbefe 100644 --- a/include/hdlConvertor/vhdlConvertor/generateStatementParser.h +++ b/include/hdlConvertor/vhdlConvertor/generateStatementParser.h @@ -10,20 +10,16 @@ #include #include #include +#include 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 visitGenerate_statement( vhdlParser::Generate_statementContext *ctx); std::unique_ptr visitFor_generate_statement( diff --git a/include/hdlConvertor/vhdlConvertor/packageHeaderParser.h b/include/hdlConvertor/vhdlConvertor/packageHeaderParser.h index a699ad55..4367a202 100644 --- a/include/hdlConvertor/vhdlConvertor/packageHeaderParser.h +++ b/include/hdlConvertor/vhdlConvertor/packageHeaderParser.h @@ -12,23 +12,19 @@ #include #include #include +#include namespace hdlConvertor { namespace vhdl { -class VhdlPackageHeaderParser { +class VhdlPackageHeaderParser : public BaseVhdlParser { std::unique_ptr ph; - bool hierarchyOnly; public: + using BaseVhdlParser::BaseVhdlParser; using vhdlParser = vhdl_antlr::vhdlParser; - VhdlPackageHeaderParser(bool _hierarchyOnly); std::unique_ptr 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 visitComponent_declaration( diff --git a/include/hdlConvertor/vhdlConvertor/packageParser.h b/include/hdlConvertor/vhdlConvertor/packageParser.h index 3ff2adba..33d77142 100644 --- a/include/hdlConvertor/vhdlConvertor/packageParser.h +++ b/include/hdlConvertor/vhdlConvertor/packageParser.h @@ -15,22 +15,20 @@ #include #include #include +#include namespace hdlConvertor { namespace vhdl { -class VhdlPackageParser { +class VhdlPackageParser : public BaseVhdlParser { public: + using BaseVhdlParser::BaseVhdlParser; using vhdlParser = vhdl_antlr::vhdlParser; std::unique_ptr p; - bool hierarchyOnly; - VhdlPackageParser(bool _hierarchyOnly); std::unique_ptr visitPackage_body( vhdlParser::Package_bodyContext *ctx); - void visitPackage_body_declarative_item( - vhdlParser::Package_body_declarative_itemContext *ctx); }; diff --git a/include/hdlConvertor/vhdlConvertor/processParser.h b/include/hdlConvertor/vhdlConvertor/processParser.h index e5700a88..e224b93d 100644 --- a/include/hdlConvertor/vhdlConvertor/processParser.h +++ b/include/hdlConvertor/vhdlConvertor/processParser.h @@ -6,25 +6,29 @@ #include #include #include +#include namespace hdlConvertor { namespace vhdl { -class VhdlProcessParser { - +class VhdlProcessParser : public BaseVhdlParser { public: + using BaseVhdlParser::BaseVhdlParser; using vhdlParser = vhdl_antlr::vhdlParser; - static std::unique_ptr visitProcess_statement( + std::unique_ptr visitProcess_statement( vhdlParser::Process_statementContext *ctx); - static void visitProcess_sensitivity_list( + void visitProcess_sensitivity_list( vhdlParser::Process_sensitivity_listContext *ctx, std::vector> &sensitivity); - static void visitSensitivity_list(vhdlParser::Sensitivity_listContext *ctx, + void visitSensitivity_list(vhdlParser::Sensitivity_listContext *ctx, std::vector> &sensitivity); - static void visitProcess_declarative_item( + void visitProcess_declarative_item( vhdlParser::Process_declarative_itemContext *ctx, std::vector> &objs); + void visitProcess_or_package_declarative_item( + vhdlParser::Process_or_package_declarative_itemContext *ctx, + std::vector> &objs); }; } diff --git a/include/hdlConvertor/vhdlConvertor/statementParser.h b/include/hdlConvertor/vhdlConvertor/statementParser.h index 1c70da12..4d6c2565 100644 --- a/include/hdlConvertor/vhdlConvertor/statementParser.h +++ b/include/hdlConvertor/vhdlConvertor/statementParser.h @@ -8,80 +8,78 @@ #include #include #include -#include +#include namespace hdlConvertor { namespace vhdl { -// [TODO] make methods non static and parse code positions and comments -class VhdlStatementParser { - VhdlCommentParser & commentParser; +class VhdlStatementParser: public BaseVhdlParser { public: + using BaseVhdlParser::BaseVhdlParser; using vhdlParser = vhdl_antlr::vhdlParser; - bool hierarchyOnly; - VhdlStatementParser(VhdlCommentParser & _commentParser, bool _hierarchyOnly); - static std::unique_ptr visitSequential_statement( + std::unique_ptr visitSequential_statement( vhdlParser::Sequential_statementContext *ctx); - static std::unique_ptr visitSignal_assignment_statement( + std::unique_ptr visitSignal_assignment_statement( vhdlParser::Signal_assignment_statementContext *ctx); - static std::unique_ptr visitSimple_signal_assignment( + std::unique_ptr visitSimple_signal_assignment( vhdlParser::Simple_signal_assignmentContext *ctx); - static std::unique_ptr visitSimple_waveform_assignment( + std::unique_ptr visitSimple_waveform_assignment( vhdlParser::Simple_waveform_assignmentContext *ctx); - static std::unique_ptr visitSimple_force_assignment( + std::unique_ptr visitSimple_force_assignment( vhdlParser::Simple_force_assignmentContext *ctx); - static std::unique_ptr visitSimple_release_assignment( + std::unique_ptr visitSimple_release_assignment( vhdlParser::Simple_release_assignmentContext *ctx); - static std::unique_ptr visitConditional_signal_assignment( + std::unique_ptr visitConditional_signal_assignment( vhdlParser::Conditional_signal_assignmentContext *ctx); - static std::unique_ptr visitConditional_waveform_assignment( + std::unique_ptr visitConditional_waveform_assignment( vhdlParser::Conditional_waveform_assignmentContext *ctx); - static std::unique_ptr visitConditional_force_assignment( + std::unique_ptr visitConditional_force_assignment( vhdlParser::Conditional_force_assignmentContext *ctx); - static std::unique_ptr visitSelected_signal_assignment( + std::unique_ptr visitSelected_signal_assignment( vhdlParser::Selected_signal_assignmentContext *ctx); - static std::unique_ptr visitVariable_assignment_statement( + std::unique_ptr visitVariable_assignment_statement( vhdlParser::Variable_assignment_statementContext *ctx); - static std::unique_ptr visitIf_statement( + std::unique_ptr visitIf_statement( vhdlParser::If_statementContext *ctx); - static std::unique_ptr visitSimple_variable_assignment( + std::unique_ptr visitSimple_variable_assignment( vhdlParser::Simple_variable_assignmentContext *ctx); - static std::unique_ptr visitConditional_variable_assignment( + std::unique_ptr visitConditional_variable_assignment( vhdlParser::Conditional_variable_assignmentContext *ctx); - static std::unique_ptr visitSelected_variable_assignment( + std::unique_ptr visitSelected_variable_assignment( vhdlParser::Selected_variable_assignmentContext *ctx); - static std::unique_ptr visitReturn_statement( + std::unique_ptr visitReturn_statement( vhdlParser::Return_statementContext *ctx); - static std::unique_ptr visitLoop_statement( + std::unique_ptr visitLoop_statement( vhdlParser::Loop_statementContext *ctx); - static std::pair, std::unique_ptr> visitParameter_specification( + std::pair, + std::unique_ptr> visitParameter_specification( vhdlParser::Parameter_specificationContext *ctx); - static std::unique_ptr visitSelected_waveforms( + std::unique_ptr visitSelected_waveforms( vhdlParser::Selected_waveformsContext *ctx, - std::unique_ptr sel, std::unique_ptr dst, - bool is_blocking); - static std::unique_ptr visitConcurrent_selected_signal_assignment( + std::unique_ptr sel, + std::unique_ptr dst, bool is_blocking); + std::unique_ptr visitConcurrent_selected_signal_assignment( vhdlParser::Concurrent_selected_signal_assignmentContext *ctx); - static std::unique_ptr visitIteration_scheme( + std::unique_ptr visitIteration_scheme( vhdlParser::Iteration_schemeContext *ctx); - static std::unique_ptr visitNull_statement( + std::unique_ptr visitNull_statement( vhdlParser::Null_statementContext *ctx); - static std::unique_ptr visitAssertion( + std::unique_ptr visitAssertion( vhdlParser::AssertionContext *ctx); - static std::unique_ptr visitAssertion_statement( + std::unique_ptr visitAssertion_statement( vhdlParser::Assertion_statementContext *ctx); - static std::unique_ptr visitConcurrent_assertion_statement( + std::unique_ptr visitConcurrent_assertion_statement( vhdlParser::Concurrent_assertion_statementContext *ctx); - static std::unique_ptr visitReport_statement( + std::unique_ptr visitReport_statement( vhdlParser::Report_statementContext *ctx); - static std::unique_ptr visitWait_statement( + std::unique_ptr visitWait_statement( vhdlParser::Wait_statementContext *ctx); - static std::unique_ptr visitCase_statement( + std::unique_ptr visitCase_statement( vhdlParser::Case_statementContext *ctx); - static std::unique_ptr visitSequence_of_statements( + std::unique_ptr visitSequence_of_statements( vhdlParser::Sequence_of_statementsContext *ctx); - static std::unique_ptr visitConcurrent_signal_assignment_statement( + std::unique_ptr visitConcurrent_signal_assignment_statement( vhdlParser::Concurrent_signal_assignment_statementContext *ctx); void visitConcurrent_statement(vhdlParser::Concurrent_statementContext *ctx, std::vector> &stms); diff --git a/include/hdlConvertor/vhdlConvertor/subProgramDeclarationParser.h b/include/hdlConvertor/vhdlConvertor/subProgramDeclarationParser.h index fba29444..67fc9a59 100644 --- a/include/hdlConvertor/vhdlConvertor/subProgramDeclarationParser.h +++ b/include/hdlConvertor/vhdlConvertor/subProgramDeclarationParser.h @@ -25,9 +25,6 @@ class VhdlSubProgramDeclarationParser { static std::unique_ptr< std::vector>> visitFormal_parameter_list( vhdlParser::Formal_parameter_listContext *ctx); - static std::unique_ptr< - std::vector>> visitSubprogram_declarative_item( - vhdlParser::Subprogram_declarative_itemContext *ctx); }; } diff --git a/include/hdlConvertor/vhdlConvertor/subProgramParser.h b/include/hdlConvertor/vhdlConvertor/subProgramParser.h index 3a8eba1a..9e1d7919 100644 --- a/include/hdlConvertor/vhdlConvertor/subProgramParser.h +++ b/include/hdlConvertor/vhdlConvertor/subProgramParser.h @@ -7,25 +7,28 @@ #include #include #include +#include + namespace hdlConvertor { namespace vhdl { -class VhdlSubProgramParser { +class VhdlSubProgramParser : public BaseVhdlParser { public: + using BaseVhdlParser::BaseVhdlParser; using vhdlParser = vhdl_antlr::vhdlParser; - static std::unique_ptr visitSubprogram_body( + std::unique_ptr visitSubprogram_body( vhdlParser::Subprogram_bodyContext *ctx); - static std::unique_ptr visitSubprogram_specification( + std::unique_ptr visitSubprogram_specification( vhdlParser::Subprogram_specificationContext *ctx); - static std::unique_ptr visitProcedure_specification( + std::unique_ptr visitProcedure_specification( vhdlParser::Procedure_specificationContext *ctx); - static std::unique_ptr visitFunction_specification( + std::unique_ptr visitFunction_specification( vhdlParser::Function_specificationContext *ctx); - static std::unique_ptr>> visitFormal_parameter_list( + std::unique_ptr>> visitFormal_parameter_list( vhdlParser::Formal_parameter_listContext *ctx); - static void visitSubprogram_declaration( + void visitSubprogram_declaration( vhdlParser::Subprogram_declarationContext *ctx); }; diff --git a/src/vhdlConvertor/archParser.cpp b/src/vhdlConvertor/archParser.cpp index 4714523a..fe878002 100644 --- a/src/vhdlConvertor/archParser.cpp +++ b/src/vhdlConvertor/archParser.cpp @@ -11,10 +11,6 @@ namespace vhdl { using vhdlParser = vhdl_antlr::vhdlParser; using namespace hdlConvertor::hdlAst; -VhdlArchParser::VhdlArchParser(VhdlCommentParser &_commentParser, - bool _hierarchyOnly) : - commentParser(_commentParser), hierarchyOnly(_hierarchyOnly) { -} std::unique_ptr VhdlArchParser::visitArchitecture_body( vhdlParser::Architecture_bodyContext *ctx) { auto a = create_object(ctx); diff --git a/src/vhdlConvertor/baseVhdlParser.cpp b/src/vhdlConvertor/baseVhdlParser.cpp new file mode 100644 index 00000000..ed59878c --- /dev/null +++ b/src/vhdlConvertor/baseVhdlParser.cpp @@ -0,0 +1,15 @@ +#include + +namespace hdlConvertor { +namespace vhdl { + +BaseVhdlParser::BaseVhdlParser(VhdlCommentParser &_commentParser, + bool _hierarchyOnly) : + commentParser(_commentParser), hierarchyOnly(_hierarchyOnly) { +} +BaseVhdlParser::BaseVhdlParser(BaseVhdlParser &parent) : + commentParser(parent.commentParser), hierarchyOnly(parent.hierarchyOnly) { +} + +} +} diff --git a/src/vhdlConvertor/blockDeclarationParser.cpp b/src/vhdlConvertor/blockDeclarationParser.cpp index 5889fc4d..7ba2f143 100644 --- a/src/vhdlConvertor/blockDeclarationParser.cpp +++ b/src/vhdlConvertor/blockDeclarationParser.cpp @@ -16,10 +16,6 @@ namespace hdlConvertor { namespace vhdl { -VhdlBlockDeclarationParser::VhdlBlockDeclarationParser(VhdlCommentParser &_commentParser, bool hierarchyOnly) : - commentParser(_commentParser), hierarchyOnly(hierarchyOnly) { -} - /* * @note Some declarations can spot multiple objects * that is why this function just does not return hdlAst::iHdlObj* diff --git a/src/vhdlConvertor/designFileParser.cpp b/src/vhdlConvertor/designFileParser.cpp index cbbe6b29..8876c496 100644 --- a/src/vhdlConvertor/designFileParser.cpp +++ b/src/vhdlConvertor/designFileParser.cpp @@ -51,8 +51,14 @@ void VhdlDesignFileParser::visitLibrary_unit( // : secondary_unit | primary_unit // ; - VhdlDesignFileParser::visitSecondary_unit(ctx->secondary_unit()); - VhdlDesignFileParser::visitPrimary_unit(ctx->primary_unit()); + auto su = ctx->secondary_unit(); + if (su) { + visitSecondary_unit(su); + return; + } + auto pu = ctx->primary_unit(); + assert(pu); + visitPrimary_unit(pu); } void VhdlDesignFileParser::visitSecondary_unit( vhdlParser::Secondary_unitContext *ctx) { @@ -70,7 +76,7 @@ void VhdlDesignFileParser::visitSecondary_unit( } auto pack = ctx->package_body(); if (pack) { - VhdlPackageParser pparser(hierarchyOnly); + VhdlPackageParser pparser(commentParser, hierarchyOnly); auto p = pparser.visitPackage_body(pack); context.objs.push_back(move(p)); @@ -89,12 +95,12 @@ void VhdlDesignFileParser::visitContext_clause( } void VhdlDesignFileParser::visitPrimary_unit( vhdlParser::Primary_unitContext *ctx) { - if (!ctx) - return; - // primary_unit - // : entity_declaration - // | configuration_declaration - // | package_declaration + // primary_unit: + // entity_declaration + // | configuration_declaration + // | package_declaration + // | package_instantiation_declaration + // | context_declaration // ; auto ed = ctx->entity_declaration(); if (ed) { @@ -111,11 +117,25 @@ void VhdlDesignFileParser::visitPrimary_unit( } auto pd = ctx->package_declaration(); if (pd) { - VhdlPackageHeaderParser php(hierarchyOnly); + VhdlPackageHeaderParser php(commentParser, hierarchyOnly); auto ph = php.visitPackage_declaration(pd); context.objs.push_back(std::move(ph)); + return; + } + auto pid = ctx->package_instantiation_declaration(); + if (pid) { + NotImplementedLogger::print( + "DesignFileParser.visitPackage_instantiation_declaration", pid); + return; + } + auto cnd = ctx->context_declaration(); + if (cnd) { + NotImplementedLogger::print("DesignFileParser.visitContext_declaration", + cnd); + return; } + NotImplementedLogger::print("DesignFileParser.visitPrimary_unit", ctx); } void VhdlDesignFileParser::visitContext_item( vhdlParser::Context_itemContext *ctx) { diff --git a/src/vhdlConvertor/entityParser.cpp b/src/vhdlConvertor/entityParser.cpp index ce3b5f83..64efc636 100644 --- a/src/vhdlConvertor/entityParser.cpp +++ b/src/vhdlConvertor/entityParser.cpp @@ -3,16 +3,8 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include @@ -22,10 +14,6 @@ namespace vhdl { using vhdlParser = vhdl_antlr::vhdlParser; using namespace hdlAst; -VhdlEntityParser::VhdlEntityParser(VhdlCommentParser &_commentParser, - bool _hierarchyOnly) : - commentParser(_commentParser), hierarchyOnly(_hierarchyOnly) { -} std::unique_ptr VhdlEntityParser::visitEntity_declaration( vhdlParser::Entity_declarationContext *ctx) { // entity_declaration: @@ -59,87 +47,10 @@ std::unique_ptr VhdlEntityParser::visitEntity_declaration( void VhdlEntityParser::visitEntity_declarative_item( vhdlParser::Entity_declarative_itemContext *ctx, std::vector> & objs) { // 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 // ; - - auto sp = ctx->subprogram_declaration(); - if (sp) { - auto f = VhdlSubProgramDeclarationParser::visitSubprogram_declaration( - sp); - objs.push_back(std::move(f)); - return; - } - auto sb = ctx->subprogram_body(); - if (sb) { - auto f = VhdlSubProgramParser::visitSubprogram_body(sb); - objs.push_back(std::move(f)); - return; - } - auto sid = ctx->subprogram_instantiation_declaration(); - if (sid) { - NotImplementedLogger::print( - "VhdlEntityParser.visitSubprogram_instantiation_declaration", sid); - return; - } - auto pd = ctx->package_declaration(); - if (pd) { - VhdlPackageHeaderParser ph(hierarchyOnly); - auto pac_header = ph.visitPackage_declaration(pd); - objs.push_back(std::move(pac_header)); - return; - } - auto pb = ctx->package_body(); - if (pb) { - VhdlPackageParser pp(hierarchyOnly); - auto p = pp.visitPackage_body(pb); - objs.push_back(std::move(p)); - return; - } - auto pid = ctx->package_instantiation_declaration(); - if (pid) { - NotImplementedLogger::print( - "VhdlEntityParser.visitEntity_declarative_item - package_instantiation_declaration", - pid); - return; - } - auto td = ctx->type_declaration(); - if (td) { - auto t = VhdlTypeDeclarationParser::visitType_declaration(td); - objs.push_back(std::move(t)); - return; - } - auto st = ctx->subtype_declaration(); - if (st) { - auto _st = VhdlTypeDeclarationParser::visitSubtype_declaration(st); - objs.push_back(std::move(_st)); - return; - } - auto constd = ctx->constant_declaration(); - if (constd) { - auto constants = VhdlConstantParser::visitConstant_declaration(constd); - for (auto & c : *constants) { - objs.push_back(std::move(c)); - } - return; - } auto sd = ctx->signal_declaration(); if (sd) { auto signals = VhdlSignalParser::visitSignal_declaration(sd); @@ -148,60 +59,16 @@ void VhdlEntityParser::visitEntity_declarative_item( } return; } - auto vd = ctx->variable_declaration(); - if (vd) { - auto variables = VhdlVariableParser::visitVariable_declaration(vd); - for (auto & v : *variables) { - objs.push_back(std::move(v)); - } - return; - } - auto fd = ctx->file_declaration(); - if (fd) { - NotImplementedLogger::print("VhdlEntityParser.visitFile_declaration", fd); - return; - } - auto aliasd = ctx->alias_declaration(); - if (aliasd) { - NotImplementedLogger::print("VhdlEntityParser.visitAlias_declaration", - aliasd); - return; - } - auto atrd = ctx->attribute_declaration(); - if (atrd) { - NotImplementedLogger::print("VhdlEntityParser.visitAttribute_declaration", - atrd); - return; - } - auto as = ctx->attribute_specification(); - if (as) { - NotImplementedLogger::print("VhdlEntityParser.visitAttribute_specification", - as); + auto pdi = ctx->process_declarative_item(); + if (pdi) { + VhdlProcessParser pp(commentParser, hierarchyOnly); + pp.visitProcess_declarative_item(pdi, objs); return; } auto discs = ctx->disconnection_specification(); - if (discs) { + assert(discs); NotImplementedLogger::print( "VhdlEntityParser.visitDisconnection_specification", discs); - return; - } - auto uc = ctx->use_clause(); - if (uc) { - HdlContext c; - VhdlDesignFileParser dfp(commentParser.tokens, c, hierarchyOnly); - dfp.visitUse_clause(uc, objs); - assert(c.objs.size() == 0); - return; - } - auto gtd = ctx->group_template_declaration(); - if (gtd) { - NotImplementedLogger::print( - "VhdlEntityParser.visitGroup_template_declaration", gtd); - return; - } - auto gd = ctx->group_declaration(); - assert(gd); - NotImplementedLogger::print("VhdlEntityParser.visitGroup_declaration", gd); } void VhdlEntityParser::visitGeneric_clause( vhdlParser::Generic_clauseContext *ctx, diff --git a/src/vhdlConvertor/generateStatementParser.cpp b/src/vhdlConvertor/generateStatementParser.cpp index e96cab84..51240232 100644 --- a/src/vhdlConvertor/generateStatementParser.cpp +++ b/src/vhdlConvertor/generateStatementParser.cpp @@ -26,11 +26,6 @@ using namespace hdlConvertor::hdlAst; using vhdlParser = vhdl_antlr::vhdlParser; using namespace std; -VhdlGenerateStatementParser::VhdlGenerateStatementParser( - VhdlCommentParser &_commentParser, bool _hierarchyOnly) : - commentParser(_commentParser), hierarchyOnly(_hierarchyOnly) { -} - std::unique_ptr VhdlGenerateStatementParser::visitGenerate_statement( vhdlParser::Generate_statementContext *ctx) { //generate_statement @@ -63,8 +58,8 @@ std::unique_ptr VhdlGenerateStatementParser::visitFor_generate_st // END GENERATE ( label )? SEMI // ; - auto args = VhdlStatementParser::visitParameter_specification( - ctx->parameter_specification()); + VhdlStatementParser sp(commentParser, hierarchyOnly); + auto args = sp.visitParameter_specification(ctx->parameter_specification()); auto objs = visitGenerate_statement_body(ctx->generate_statement_body()); auto fstm = create_object(ctx, move(args.first), move(args.second), move(objs)); diff --git a/src/vhdlConvertor/packageHeaderParser.cpp b/src/vhdlConvertor/packageHeaderParser.cpp index bd81fe8e..3cd8cc7b 100644 --- a/src/vhdlConvertor/packageHeaderParser.cpp +++ b/src/vhdlConvertor/packageHeaderParser.cpp @@ -1,18 +1,10 @@ #include #include #include -#include -#include -#include -#include #include -#include +#include #include -#include -#include -#include -#include -#include +#include #include @@ -22,132 +14,52 @@ namespace vhdl { using vhdlParser = vhdl_antlr::vhdlParser; using namespace hdlConvertor::hdlAst; -VhdlPackageHeaderParser::VhdlPackageHeaderParser(bool _hierarchyOnly) { - hierarchyOnly = _hierarchyOnly; -} - std::unique_ptr VhdlPackageHeaderParser::visitPackage_declaration( vhdlParser::Package_declarationContext *ctx) { // package_declaration: - // PACKAGE identifier IS - // package_header - // package_declarative_part - // END ( PACKAGE )? ( identifier )? SEMI + // KW_PACKAGE identifier KW_IS + // ( + // generic_clause ( generic_map_aspect SEMI )? + // )? + // ( package_declarative_item )* + // KW_END ( KW_PACKAGE )? ( identifier )? SEMI // ; ph = create_object(ctx); ph->name = VhdlLiteralParser::getIdentifierStr(ctx->identifier(0)); ph->defs_only = true; if (!hierarchyOnly) { - auto ph_ctx = ctx->package_header(); - if (ph_ctx) - visitPackage_header(ph_ctx); - auto pdp = ctx->package_declarative_part(); - if (pdp) - visitPackage_declarative_part(pdp); + auto gc = ctx->generic_clause(); + if (gc) + //visitGeneric_clause(gc); + NotImplementedLogger::print("VhdlPackageHeaderParser.visitGeneric_clause", + gc); + auto gma = ctx->generic_map_aspect(); + if (gma) + //visitGeneric_map_aspect(gma); + NotImplementedLogger::print( + "VhdlPackageHeaderParser.visitGeneric_map_aspect", gma); + for (auto i : ctx->package_declarative_item()) { + visitPackage_declarative_item(i); + } } return std::move(ph); } - -void VhdlPackageHeaderParser::visitPackage_header( - vhdlParser::Package_headerContext *ctx) { - // package_header: - // ( generic_clause - // ( generic_map_aspect SEMI )? )? - // ; - auto gc = ctx->generic_clause(); - if (gc) - //visitGeneric_clause(gc); - NotImplementedLogger::print("PackageHeaderParser.visitGeneric_clause", - gc); - auto gma = ctx->generic_map_aspect(); - if (gma) - //visitGeneric_map_aspect(gma); - NotImplementedLogger::print( - "PackageHeaderParser.visitGeneric_map_aspect", gma); -} - -void VhdlPackageHeaderParser::visitPackage_declarative_part( - vhdlParser::Package_declarative_partContext *ctx) { - // package_declarative_part - // : ( package_declarative_item )* - // ; - for (auto i : ctx->package_declarative_item()) { - visitPackage_declarative_item(i); - } -} - void VhdlPackageHeaderParser::visitPackage_declarative_item( vhdlParser::Package_declarative_itemContext *ctx) { - // VHDL-93 syntax, maybe -- - // package_declarative_item - // : subprogram_declaration - // | type_declaration - // | subtype_declaration - // | constant_declaration - // | signal_declaration - // | variable_declaration - // | file_declaration - // | alias_declaration - // | component_declaration - // | attribute_declaration - // | attribute_specification - // | disconnection_specification - // | use_clause - // | group_template_declaration - // | group_declaration - // | nature_declaration - // | subnature_declaration - // | terminal_declaration + // package_declarative_item: + // process_or_package_declarative_item + // | signal_declaration + // | component_declaration + // | disconnection_specification // ; - auto sp = ctx->subprogram_declaration(); - if (sp) { - ph->objs.push_back( - VhdlSubProgramDeclarationParser::visitSubprogram_declaration( - sp)); - return; - } - auto sid = ctx->subprogram_instantiation_declaration(); - if (sid) { - NotImplementedLogger::print( - "PackageHeaderParser.visitPackage_declarative_item - subprogram_instantiation_declaration", - sid); - return; - } - auto pd = ctx->package_declaration(); - if (pd) { - VhdlPackageHeaderParser php(hierarchyOnly); - auto pac_header = php.visitPackage_declaration(pd); - ph->objs.push_back(std::move(pac_header)); - return; - } - auto pid = ctx->package_instantiation_declaration(); - if (pid) { - NotImplementedLogger::print( - "PackageHeaderParser.visitPackage_declarative_item - package_instantiation_declaration", - pid); - return; - } - auto td = ctx->type_declaration(); - if (td) { - auto t = VhdlTypeDeclarationParser::visitType_declaration(td); - ph->objs.push_back(std::move(t)); - return; - } - auto st = ctx->subtype_declaration(); - if (st) { - auto _st = VhdlTypeDeclarationParser::visitSubtype_declaration(st); - ph->objs.push_back(std::move(_st)); - return; - } - auto constd = ctx->constant_declaration(); - if (constd) { - auto constants = VhdlConstantParser::visitConstant_declaration(constd); - for (auto &c : *constants) { - ph->objs.push_back(move(c)); - } + auto ppdi = ctx->process_or_package_declarative_item(); + if (ppdi) { + VhdlProcessParser pp(commentParser, hierarchyOnly); + pp.visitProcess_or_package_declarative_item(ppdi, ph->objs); return; } + auto sd = ctx->signal_declaration(); if (sd) { auto signals = VhdlSignalParser::visitSignal_declaration(sd); @@ -156,68 +68,15 @@ void VhdlPackageHeaderParser::visitPackage_declarative_item( } return; } - auto vd = ctx->variable_declaration(); - if (vd) { - auto variables = VhdlVariableParser::visitVariable_declaration(vd); - for (auto &v : *variables) { - ph->objs.push_back(move(v)); - } - return; - } - auto fd = ctx->file_declaration(); - if (fd) { - NotImplementedLogger::print("PackageHeaderParser.visitFile_declaration", - fd); - return; - } - auto aliasd = ctx->alias_declaration(); - if (aliasd) { - NotImplementedLogger::print( - "PackageHeaderParser.visitAlias_declaration", aliasd); - return; - } auto compd = ctx->component_declaration(); if (compd) { ph->objs.push_back(visitComponent_declaration(compd)); return; } - auto atrd = ctx->attribute_declaration(); - if (atrd) { - NotImplementedLogger::print( - "PackageHeaderParser.visitAttribute_declaration", atrd); - return; - } - auto as = ctx->attribute_specification(); - if (as) { - NotImplementedLogger::print( - "PackageHeaderParser.visitAttribute_specification", as); - return; - } auto discs = ctx->disconnection_specification(); - if (discs) { - NotImplementedLogger::print( - "PackageHeaderParser.visitDisconnection_specification", discs); - return; - } - auto uc = ctx->use_clause(); - if (uc) { - NotImplementedLogger::print("PackageHeaderParser.visitUse_clause", uc); - return; - } - auto gtd = ctx->group_template_declaration(); - if (gtd) { - NotImplementedLogger::print( - "PackageHeaderParser.visitGroup_template_declaration", gtd); - return; - } - auto gd = ctx->group_declaration(); - if (gd) { - NotImplementedLogger::print( - "PackageHeaderParser.visitGroup_declaration", gd); - return; - } + assert(discs); NotImplementedLogger::print( - "VhdlPackageHeaderParser.visitPackage_declarative_item", ctx); + "VhdlPackageHeaderParser.visitDisconnection_specification", discs); } std::unique_ptr VhdlPackageHeaderParser::visitComponent_declaration( vhdlParser::Component_declarationContext *ctx) { diff --git a/src/vhdlConvertor/packageParser.cpp b/src/vhdlConvertor/packageParser.cpp index 8e940101..ba488058 100644 --- a/src/vhdlConvertor/packageParser.cpp +++ b/src/vhdlConvertor/packageParser.cpp @@ -1,19 +1,7 @@ #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include - +#include +#include #include namespace hdlConvertor { @@ -22,14 +10,11 @@ namespace vhdl { using vhdlParser = vhdl_antlr::vhdlParser; using namespace hdlConvertor::hdlAst; -VhdlPackageParser::VhdlPackageParser(bool _hierarchyOnly) { - hierarchyOnly = _hierarchyOnly; -} std::unique_ptr VhdlPackageParser::visitPackage_body( vhdlParser::Package_bodyContext* ctx) { // package_body: // PACKAGE BODY identifier IS - // ( package_body_declarative_item )* + // ( process_declarative_item )* // END ( PACKAGE BODY )? ( identifier )? SEMI // ; p = create_object(ctx); @@ -37,124 +22,15 @@ std::unique_ptr VhdlPackageParser::visitPackage_body( p->defs_only = false; if (!hierarchyOnly) { - auto pbdi = ctx->package_body_declarative_item(); - for (auto i : pbdi) { - visitPackage_body_declarative_item(i); + auto pdi = ctx->process_declarative_item(); + VhdlProcessParser pp(commentParser, hierarchyOnly); + for (auto i : pdi) { + pp.visitProcess_declarative_item(i, p->objs); } } return std::move(p); } -void VhdlPackageParser::visitPackage_body_declarative_item( - vhdlParser::Package_body_declarative_itemContext* ctx) { - // package_body_declarative_item - // : subprogram_declaration - // | subprogram_body - // | type_declaration - // | subtype_declaration - // | constant_declaration - // | variable_declaration - // | file_declaration - // | alias_declaration - // | use_clause - // | group_template_declaration - // | group_declaration - // ; - // - //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 - //; - - - auto sp = ctx->subprogram_declaration(); - if (sp) { - p->objs.push_back(VhdlSubProgramDeclarationParser::visitSubprogram_declaration(sp)); - return; - } - auto sb = ctx->subprogram_body(); - if (sb) { - auto f = VhdlSubProgramParser::visitSubprogram_body(sb); - p->objs.push_back(std::move(f)); - return; - } - auto td = ctx->type_declaration(); - if (td) { - auto t = VhdlTypeDeclarationParser::visitType_declaration(td); - p->objs.push_back(std::move(t)); - return; - return; - } - auto st = ctx->subtype_declaration(); - if (st) { - auto _st = VhdlTypeDeclarationParser::visitSubtype_declaration(st); - p->objs.push_back(std::move(_st)); - return; - } - auto constd = ctx->constant_declaration(); - if (constd) { - auto constants = VhdlConstantParser::visitConstant_declaration(constd); - for (auto & c : *constants) { - p->objs.push_back(std::move(c)); - } - return; - } - auto vd = ctx->variable_declaration(); - if (vd) { - auto variables = VhdlVariableParser::visitVariable_declaration(vd); - for (auto & v : *variables) { - p->objs.push_back(std::move(v)); - } - return; - } - auto fd = ctx->file_declaration(); - if (fd) { - NotImplementedLogger::print( - "PackageParser.visitFile_declaration", fd); - return; - } - - auto aliasd = ctx->alias_declaration(); - if (aliasd) { - NotImplementedLogger::print( - "PackageParser.visitAlias_declaration", aliasd); - return; - } - auto uc = ctx->use_clause(); - if (uc) { - NotImplementedLogger::print("PackageParser.visitUse_clause", uc); - return; - } - auto gtd = ctx->group_template_declaration(); - if (gtd) { - NotImplementedLogger::print( - "PackageParser.visitGroup_template_declaration", gtd); - return; - } - auto gd = ctx->group_declaration(); - if (gd) { - NotImplementedLogger::print( - "PackageParser.visitGroup_declaration", gd); - return; - } - NotImplementedLogger::print( - "VhdlPackageParser.visitPackage_body_declarative_item", ctx); -} } } diff --git a/src/vhdlConvertor/processParser.cpp b/src/vhdlConvertor/processParser.cpp index 3890a206..027e05f0 100644 --- a/src/vhdlConvertor/processParser.cpp +++ b/src/vhdlConvertor/processParser.cpp @@ -9,7 +9,9 @@ #include #include #include - +#include +#include +#include namespace hdlConvertor { namespace vhdl { @@ -37,8 +39,9 @@ std::unique_ptr VhdlProcessParser::visitProcess_statement for (auto pd : ctx->process_declarative_item()) { visitProcess_declarative_item(pd, stms); } + VhdlStatementParser sp(commentParser, hierarchyOnly); for (auto s : ctx->sequential_statement()) { - stms.push_back(VhdlStatementParser::visitSequential_statement(s)); + stms.push_back(sp.visitSequential_statement(s)); } return p; @@ -62,25 +65,53 @@ void VhdlProcessParser::visitSensitivity_list( sensitivity.push_back(VhdlReferenceParser::visitName(n)); } } - void VhdlProcessParser::visitProcess_declarative_item( vhdlParser::Process_declarative_itemContext *ctx, std::vector> &objs) { - //process_declarative_item - // : subprogram_declaration - // | subprogram_body - // | type_declaration - // | subtype_declaration - // | constant_declaration - // | variable_declaration - // | file_declaration - // | alias_declaration - // | attribute_declaration - // | attribute_specification - // | use_clause - // | group_template_declaration - // | group_declaration - // ; + // process_declarative_item: + // process_or_package_declarative_item + // | subprogram_body + // | package_body + // ; + auto ppdi = ctx->process_or_package_declarative_item(); + if (ppdi) { + visitProcess_or_package_declarative_item(ppdi, objs); + return; + } + auto sb = ctx->subprogram_body(); + if (sb) { + VhdlSubProgramParser spp(commentParser, hierarchyOnly); + auto f = spp.visitSubprogram_body(sb); + objs.push_back(std::move(f)); + return; + } + auto pb = ctx->package_body(); + assert(pb); + VhdlPackageParser pp(commentParser, hierarchyOnly); + auto p = pp.visitPackage_body(pb); + objs.push_back(std::move(p)); +} + +void VhdlProcessParser::visitProcess_or_package_declarative_item( + vhdlParser::Process_or_package_declarative_itemContext *ctx, + std::vector> &objs) { + // process_or_package_declarative_item: + // subprogram_declaration + // | subprogram_instantiation_declaration + // | package_declaration + // | 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 + // ; auto sp = ctx->subprogram_declaration(); if (sp) { objs.push_back( @@ -88,10 +119,26 @@ void VhdlProcessParser::visitProcess_declarative_item( sp)); return; } - auto sb = ctx->subprogram_body(); - if (sb) { - auto f = VhdlSubProgramParser::visitSubprogram_body(sb); - objs.push_back(std::move(f)); + auto sid = ctx->subprogram_instantiation_declaration(); + if (sid) { + NotImplementedLogger::print( + "VhdlProcessParser.visitSubprogram_instantiation_declaration", + sid); + return; + } + auto pd = ctx->package_declaration(); + if (pd) { + VhdlPackageHeaderParser ph(commentParser, hierarchyOnly); + auto pac_header = ph.visitPackage_declaration(pd); + objs.push_back(std::move(pac_header)); + return; + } + + auto pid = ctx->package_instantiation_declaration(); + if (pid) { + NotImplementedLogger::print( + "VhdlEntityParser.visitEntity_declarative_item - package_instantiation_declaration", + pid); return; } auto td = ctx->type_declaration(); @@ -124,45 +171,45 @@ void VhdlProcessParser::visitProcess_declarative_item( } auto fd = ctx->file_declaration(); if (fd) { - NotImplementedLogger::print("ProcessParser.visitFile_declaration", fd); + NotImplementedLogger::print("VhdlProcessParser.visitFile_declaration", + fd); return; } auto aliasd = ctx->alias_declaration(); if (aliasd) { - NotImplementedLogger::print("ProcessParser.visitAlias_declaration", + NotImplementedLogger::print("VhdlProcessParser.visitAlias_declaration", aliasd); return; } auto atrd = ctx->attribute_declaration(); if (atrd) { - NotImplementedLogger::print("ProcessParser.visitAttribute_declaration", - atrd); + NotImplementedLogger::print( + "VhdlProcessParser.visitAttribute_declaration", atrd); return; } auto as = ctx->attribute_specification(); if (as) { NotImplementedLogger::print( - "ProcessParser.visitAttribute_specification", as); + "VhdlProcessParser.visitAttribute_specification", as); return; } auto uc = ctx->use_clause(); if (uc) { - NotImplementedLogger::print("ProcessParser.visitUse_clause", uc); + HdlContext c; + VhdlDesignFileParser dfp(commentParser.tokens, c, hierarchyOnly); + dfp.visitUse_clause(uc, objs); + assert(c.objs.size() == 0); return; } auto gtd = ctx->group_template_declaration(); if (gtd) { NotImplementedLogger::print( - "ProcessParser.visitGroup_template_declaration", gtd); + "VhdlProcessParser.visitGroup_template_declaration", gtd); return; } auto gd = ctx->group_declaration(); - if (gd) { - NotImplementedLogger::print("ProcessParser.visitGroup_declaration", gd); - return; - } - NotImplementedLogger::print("ProcessParser.visitProcess_declarative_item", - ctx); + assert(gd); + NotImplementedLogger::print("VhdlProcessParser.visitGroup_declaration", gd); return; } diff --git a/src/vhdlConvertor/statementParser.cpp b/src/vhdlConvertor/statementParser.cpp index df040e9b..70d9a4ca 100644 --- a/src/vhdlConvertor/statementParser.cpp +++ b/src/vhdlConvertor/statementParser.cpp @@ -27,10 +27,6 @@ bool is_others(unique_ptr &e) { return (_e && _e->symb == HdlValueSymbol_t::symb_OTHERS); } -VhdlStatementParser::VhdlStatementParser(VhdlCommentParser & _commentParser, bool _hierarchyOnly) : - commentParser(_commentParser), hierarchyOnly(_hierarchyOnly) { -} - unique_ptr VhdlStatementParser::visitSequence_of_statements( vhdlParser::Sequence_of_statementsContext *ctx) { // sequence_of_statements @@ -199,7 +195,8 @@ unique_ptr VhdlStatementParser::visitWait_statement( if (sc) { // sensitivity_clause: ON sensitivity_list; // sensitivity_list: name ( COMMA name )*; - VhdlProcessParser::visitSensitivity_list(sc->sensitivity_list(), sens); + VhdlProcessParser pp(commentParser, hierarchyOnly); + pp.visitSensitivity_list(sc->sensitivity_list(), sens); } if (cc) { // condition_clause: UNTIL condition; @@ -721,7 +718,8 @@ unique_ptr VhdlStatementParser::visitConcurrent_statement_with_op auto p = ctx->process_statement(); if (p) { - return VhdlProcessParser::visitProcess_statement(p); + VhdlProcessParser pp(commentParser, hierarchyOnly); + return pp.visitProcess_statement(p); } auto cpc = ctx->concurrent_procedure_call_statement(); if (cpc) { diff --git a/src/vhdlConvertor/subProgramDeclarationParser.cpp b/src/vhdlConvertor/subProgramDeclarationParser.cpp index 479d5bff..644a8b58 100644 --- a/src/vhdlConvertor/subProgramDeclarationParser.cpp +++ b/src/vhdlConvertor/subProgramDeclarationParser.cpp @@ -100,105 +100,6 @@ std::unique_ptr static_unique_pointer_cast (std::unique_ptr&& old){ //conversion: unique_ptr->FROM*->TO*->unique_ptr } -std::unique_ptr>> VhdlSubProgramDeclarationParser::visitSubprogram_declarative_item( - vhdlParser::Subprogram_declarative_itemContext *ctx) { - // subprogram_declarative_item - // : subprogram_declaration - // | subprogram_body - // | type_declaration - // | subtype_declaration - // | constant_declaration - // | variable_declaration - // | file_declaration - // | alias_declaration - // | attribute_declaration - // | attribute_specification - // | use_clause - // | group_template_declaration - // | group_declaration - // ; - auto objs = std::make_unique>>(); - do { - auto sp = ctx->subprogram_declaration(); - if (sp) { - auto p = VhdlSubProgramDeclarationParser::visitSubprogram_declaration(sp); - auto _p = static_unique_pointer_cast(move(p)); - objs->push_back(std::move(_p)); - break; - } - auto sb = ctx->subprogram_body(); - if (sb) { - auto p = VhdlSubProgramParser::visitSubprogram_body(sb); - auto _p = static_unique_pointer_cast(move(p)); - objs->push_back(std::move(_p)); - break; - } - auto td = ctx->type_declaration(); - if (td) { - auto t = VhdlTypeDeclarationParser::visitType_declaration(td); - objs->push_back(std::move(t)); - break; - } - auto st = ctx->subtype_declaration(); - if (st) { - auto t = VhdlTypeDeclarationParser::visitSubtype_declaration(st); - objs->push_back(std::move(t)); - break; - } - auto constd = ctx->constant_declaration(); - if (constd) { - return VhdlConstantParser::visitConstant_declaration(constd); - } - auto vd = ctx->variable_declaration(); - if (vd) { - return VhdlVariableParser::visitVariable_declaration(vd); - } - auto fd = ctx->file_declaration(); - if (fd) { - NotImplementedLogger::print("PackageParser.visitFile_declaration", - fd); - break; - } - auto aliasd = ctx->alias_declaration(); - if (aliasd) { - NotImplementedLogger::print("PackageParser.visitAlias_declaration", - aliasd); - break; - } - auto atrd = ctx->attribute_declaration(); - if (atrd) { - NotImplementedLogger::print( - "PackageParser.visitAttribute_declaration", atrd); - break; - } - auto as = ctx->attribute_specification(); - if (as) { - NotImplementedLogger::print( - "PackageParser.visitAttribute_specification", as); - break; - } - auto uc = ctx->use_clause(); - if (uc) { - NotImplementedLogger::print("PackageParser.visitUse_clause", uc); - break; - } - auto gtd = ctx->group_template_declaration(); - if (gtd) { - NotImplementedLogger::print( - "PackageParser.visitGroup_template_declaration", gtd); - break; - } - auto gd = ctx->group_declaration(); - if (gd) { - NotImplementedLogger::print("PackageParser.visitGroup_declaration", - gd); - break; - } - - } while (0); - - return objs; -} } } diff --git a/src/vhdlConvertor/subProgramParser.cpp b/src/vhdlConvertor/subProgramParser.cpp index 162d1608..a793b7d2 100644 --- a/src/vhdlConvertor/subProgramParser.cpp +++ b/src/vhdlConvertor/subProgramParser.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -17,22 +18,20 @@ std::unique_ptr VhdlSubProgramParser::visitSubprogram_body( vhdlParser::Subprogram_bodyContext *ctx) { // subprogram_body: // subprogram_specification KW_IS - // ( subprogram_declarative_item )* + // ( process_declarative_item )* // KW_BEGIN // ( sequential_statement )* // KW_END ( subprogram_kind )? ( designator )? SEMI // ; auto f = visitSubprogram_specification(ctx->subprogram_specification()); - for (auto sd : ctx->subprogram_declarative_item()) { - auto spdis = - VhdlSubProgramDeclarationParser::visitSubprogram_declarative_item( - sd); - for (auto &spdi : *spdis) - f->body.push_back(std::move(spdi)); + VhdlProcessParser pp(commentParser, hierarchyOnly); + for (auto sd : ctx->process_declarative_item()) { + pp.visitProcess_declarative_item(sd, f->body); } + VhdlStatementParser sp(commentParser, hierarchyOnly); for (auto s : ctx->sequential_statement()) { - auto stm = VhdlStatementParser::visitSequential_statement(s); + auto stm = sp.visitSequential_statement(s); f->body.push_back(move(stm)); } f->is_declaration_only = false; @@ -68,7 +67,8 @@ std::unique_ptr VhdlSubProgramParser::visitProcedure_specificati if (fpl) paramList = visitFormal_parameter_list(fpl); - return create_object(ctx, name, isOperator, nullptr, std::move(paramList)); + return create_object(ctx, name, isOperator, nullptr, + std::move(paramList)); } std::unique_ptr VhdlSubProgramParser::visitFunction_specification( @@ -90,8 +90,8 @@ std::unique_ptr VhdlSubProgramParser::visitFunction_specificatio if (fpl) paramList = visitFormal_parameter_list(fpl); - return create_object(ctx, name, isOperator, std::move(returnT), - std::move(paramList)); + return create_object(ctx, name, isOperator, + std::move(returnT), std::move(paramList)); } std::unique_ptr>> VhdlSubProgramParser::visitFormal_parameter_list(