From 46a2b58c950f59d255497cff1f9f65862a5b2cf4 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Mon, 18 Nov 2024 16:11:42 -0800 Subject: [PATCH 1/2] Revise topology code gen Use fully-qualified names for instance defs --- .../TopologyCppWriter/TopologyCppWriterUtils.scala | 7 +------ .../tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp | 6 +++--- .../tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp | 8 ++++---- .../tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp | 4 ++-- .../tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp | 4 ++-- .../tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp | 4 ++-- .../tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp | 4 ++-- .../test/top/NestedNamespacesTopologyAc.ref.cpp | 2 +- .../test/top/NestedNamespacesTopologyAc.ref.hpp | 2 +- .../tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp | 4 ++-- .../tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp | 4 ++-- 11 files changed, 22 insertions(+), 27 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala index 90aa800673..886a309add 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala @@ -52,13 +52,8 @@ abstract class TopologyCppWriterUtils( def getComponentNameAsQualIdent(ci: ComponentInstance): String = getNameAsQualIdent(getComponentName(ci)) - def getShortName(name: Name.Qualified): Name.Qualified = { - val ens = s.a.getEnclosingNames(symbol) - name.shortName(ens) - } - def getNameAsQualIdent(name: Name.Qualified): String = - CppWriter.writeQualifiedName(getShortName(name)) + CppWriter.writeQualifiedName(name) def getSpecifierForPhase (phase: Int) (ci: ComponentInstance): Option[InitSpecifier] = ci.initSpecifierMap.get(phase) diff --git a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp index c238b683a6..1bb15dd72a 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -12,7 +12,7 @@ namespace M { - Active active1(FW_OPTIONAL_NAME("active1")); + M::Active active1(FW_OPTIONAL_NAME("active1")); } @@ -23,13 +23,13 @@ namespace M { namespace M { - Active active3(FW_OPTIONAL_NAME("active3")); + M::Active active3(FW_OPTIONAL_NAME("active3")); } namespace M { - Passive passive1(FW_OPTIONAL_NAME("passive1")); + M::Passive passive1(FW_OPTIONAL_NAME("passive1")); } diff --git a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp index b98140a2f5..588f3c197b 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp @@ -18,28 +18,28 @@ namespace M { //! active1 - extern Active active1; + extern M::Active active1; } namespace M { //! active2 - extern Active active2; + extern M::Active active2; } namespace M { //! active3 - extern Active active3; + extern M::Active active3; } namespace M { //! passive1 - extern Passive passive1; + extern M::Passive passive1; } diff --git a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp index c7006a2e47..68b5781a69 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp @@ -12,13 +12,13 @@ namespace M { - C c1(FW_OPTIONAL_NAME("c1")); + M::C c1(FW_OPTIONAL_NAME("c1")); } namespace M { - C c2(FW_OPTIONAL_NAME("c2")); + M::C c2(FW_OPTIONAL_NAME("c2")); } diff --git a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp index 684f552740..9f0fc43788 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp @@ -17,14 +17,14 @@ namespace M { //! c1 - extern C c1; + extern M::C c1; } namespace M { //! c2 - extern C c2; + extern M::C c2; } diff --git a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp index 32f9ac79c7..e531570fe2 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp @@ -12,13 +12,13 @@ namespace M { - C c1(FW_OPTIONAL_NAME("c1")); + M::C c1(FW_OPTIONAL_NAME("c1")); } namespace M { - C c2(FW_OPTIONAL_NAME("c2")); + M::C c2(FW_OPTIONAL_NAME("c2")); } diff --git a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp index c3ab0dbc58..5e9cbbe8ac 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp @@ -18,14 +18,14 @@ namespace M { //! c1 - extern C c1; + extern M::C c1; } namespace M { //! c2 - extern C c2; + extern M::C c2; } diff --git a/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.cpp index f7953d5e9f..8b343dc63a 100644 --- a/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.cpp @@ -10,7 +10,7 @@ // Component instances // ---------------------------------------------------------------------- -N::O::C c(FW_OPTIONAL_NAME("c")); +M::N::O::C c(FW_OPTIONAL_NAME("c")); namespace M { diff --git a/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp index c4b43049ed..1ddb411b85 100644 --- a/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp @@ -15,7 +15,7 @@ // ---------------------------------------------------------------------- //! c -extern N::O::C c; +extern M::N::O::C c; namespace M { diff --git a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp index 54b862eed9..ef108a998e 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp @@ -12,13 +12,13 @@ namespace M { - C c1(FW_OPTIONAL_NAME("c1")); + M::C c1(FW_OPTIONAL_NAME("c1")); } namespace M { - C c2(FW_OPTIONAL_NAME("c2")); + M::C c2(FW_OPTIONAL_NAME("c2")); } diff --git a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp index 575c1ff280..8e0cd7b5d7 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp @@ -17,14 +17,14 @@ namespace M { //! c1 - extern C c1; + extern M::C c1; } namespace M { //! c2 - extern C c2; + extern M::C c2; } From 7c64ff05204fd70a33ea0fa51f2901f8031876e8 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Mon, 18 Nov 2024 16:29:20 -0800 Subject: [PATCH 2/2] Revise basic test Exercise name generation outside of topology namespace --- .../test/top/BasicTopologyAc.ref.cpp | 30 ++++++++----------- .../test/top/BasicTopologyAc.ref.hpp | 24 +++++++-------- compiler/tools/fpp-to-cpp/test/top/basic.fpp | 11 +++++-- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp index 1bb15dd72a..0fda8bc701 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -10,12 +10,6 @@ // Component instances // ---------------------------------------------------------------------- -namespace M { - - M::Active active1(FW_OPTIONAL_NAME("active1")); - -} - namespace M { Active active2; @@ -39,6 +33,8 @@ namespace M { } +M::Active active1(FW_OPTIONAL_NAME("active1")); + namespace M { @@ -60,11 +56,11 @@ namespace M { // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - M::active1.init(QueueSizes::M_active1, InstanceIds::M_active1); M::active2.initSpecial(); M::active3.init(QueueSizes::M_active3, InstanceIds::M_active3); M::passive1.init(InstanceIds::M_passive1); M::passive2.init(InstanceIds::M_passive2); + active1.init(QueueSizes::active1, InstanceIds::active1); } void configComponents(const TopologyState& state) { @@ -72,7 +68,7 @@ namespace M { } void setBaseIds() { - M::active1.setIdBase(BaseIds::M_active1); + active1.setIdBase(BaseIds::active1); M::active2.setIdBase(BaseIds::M_active2); M::active3.setIdBase(BaseIds::M_active3); M::passive1.setIdBase(BaseIds::M_passive1); @@ -84,7 +80,7 @@ namespace M { // C1 M::passive1.set_p_OutputPort( 0, - M::active1.get_p_InputPort(0) + active1.get_p_InputPort(0) ); // C2 @@ -107,12 +103,6 @@ namespace M { } void startTasks(const TopologyState& state) { - M::active1.start( - static_cast(Priorities::M_active1), - static_cast(StackSizes::M_active1), - static_cast(CPUs::M_active1), - static_cast(TaskIds::M_active1) - ); M::active2.startSpecial(); M::active3.start( Os::Task::TASK_DEFAULT, // Default priority @@ -120,18 +110,24 @@ namespace M { Os::Task::TASK_DEFAULT, // Default CPU static_cast(TaskIds::M_active3) ); + active1.start( + static_cast(Priorities::active1), + static_cast(StackSizes::active1), + static_cast(CPUs::active1), + static_cast(TaskIds::active1) + ); } void stopTasks(const TopologyState& state) { - M::active1.exit(); M::active2.stopSpecial(); M::active3.exit(); + active1.exit(); } void freeThreads(const TopologyState& state) { - (void) M::active1.ActiveComponentBase::join(); M::active2.freeSpecial(); (void) M::active3.ActiveComponentBase::join(); + (void) active1.ActiveComponentBase::join(); } void tearDownComponents(const TopologyState& state) { diff --git a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp index 588f3c197b..b7cfcddbd4 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp @@ -15,13 +15,6 @@ // Component instances // ---------------------------------------------------------------------- -namespace M { - - //! active1 - extern M::Active active1; - -} - namespace M { //! active2 @@ -50,6 +43,9 @@ namespace M { } +//! active1 +extern M::Active active1; + namespace M { // ---------------------------------------------------------------------- @@ -67,7 +63,7 @@ namespace M { namespace BaseIds { enum { - M_active1 = 0x100, + active1 = 0x100, M_active2 = 0x200, M_active3 = 0x300, M_passive1 = 0x300, @@ -77,45 +73,45 @@ namespace M { namespace CPUs { enum { - M_active1 = 0, + active1 = 0, }; } namespace InstanceIds { enum { - M_active1, M_active2, M_active3, M_passive1, M_passive2, + active1, }; } namespace Priorities { enum { - M_active1 = 1, + active1 = 1, }; } namespace QueueSizes { enum { - M_active1 = 10, M_active2 = 10, M_active3 = 10, + active1 = 10, }; } namespace StackSizes { enum { - M_active1 = 1024, + active1 = 1024, }; } namespace TaskIds { enum { - M_active1, M_active2, M_active3, + active1, }; } diff --git a/compiler/tools/fpp-to-cpp/test/top/basic.fpp b/compiler/tools/fpp-to-cpp/test/top/basic.fpp index f0daaa2a43..b2a907f449 100644 --- a/compiler/tools/fpp-to-cpp/test/top/basic.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/basic.fpp @@ -14,9 +14,14 @@ module M { } - instance active1: Active base id 0x100 \ - at "Active.hpp" \ - queue size 10 stack size 1024 priority 1 cpu 0 +} + +instance active1: M.Active base id 0x100 \ + at "Active.hpp" \ + queue size 10 stack size 1024 priority 1 cpu 0 + +module M { + instance active2: Active base id 0x200 \ queue size 10 \ {