From 2a76ee5f4222a19e72fac96b7c4e870a86729abe Mon Sep 17 00:00:00 2001 From: jwest115 Date: Tue, 25 Jun 2024 15:35:51 -0700 Subject: [PATCH 01/25] use qualified component instance names in json dictionary, updated tests --- .../DictionaryJsonEncoder.scala | 18 +-- .../top/BasicDpTopologyDictionary.ref.json | 44 +++---- .../top/FirstTopTopologyDictionary.ref.json | 74 ++++++------ ...alifiedCompInstTopologyDictionary.ref.json | 111 ++++++++++++++++++ .../top/SecondTopTopologyDictionary.ref.json | 74 ++++++------ ...alifiedCompInstTopologyDictionary.ref.json | 111 ++++++++++++++++++ compiler/tools/fpp-to-dict/test/top/run.sh | 9 ++ compiler/tools/fpp-to-dict/test/top/tests.sh | 1 + .../tools/fpp-to-dict/test/top/update-ref.sh | 7 ++ 9 files changed, 341 insertions(+), 108 deletions(-) create mode 100644 compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json create mode 100644 compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json diff --git a/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala b/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala index 04818cd63..f04e08c42 100644 --- a/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala +++ b/compiler/lib/src/main/scala/codegen/DictionaryJsonWriter/DictionaryJsonEncoder.scala @@ -314,8 +314,7 @@ case class DictionaryJsonEncoder( override def apply(entry: (BigInt, CommandEntry)): Json = { val opcode = entry._1 val command = entry._2.command - val componentInstUnqualName = entry._2.componentInstance.getUnqualifiedName - val name = s"${componentInstUnqualName}.${command.getName}" + val name = s"${entry._2.componentInstance.toString}.${command.getName}" command match { case Command.NonParam(aNode, kind) => { val (preA, node, postA) = aNode @@ -365,8 +364,7 @@ case class DictionaryJsonEncoder( override def apply(entry: (BigInt, ParamEntry)): Json = { val numIdentifier = entry._1 val param = entry._2.param - val componentInstUnqualName = entry._2.componentInstance.getUnqualifiedName - val name = s"${componentInstUnqualName}.${param.getName}" + val name = s"${entry._2.componentInstance.toString}.${param.getName}" val (preA, node, postA) = param.aNode val json = Json.obj( "name" -> name.asJson, @@ -386,8 +384,7 @@ case class DictionaryJsonEncoder( override def apply(entry: (BigInt, EventEntry)): Json = { val event = entry._2.event val numIdentifier = entry._1 - val componentInstUnqualName = entry._2.componentInstance.getUnqualifiedName - val name = s"${componentInstUnqualName}.${event.getName}" + val name = s"${entry._2.componentInstance.toString}.${event.getName}" val (preA, node, postA) = event.aNode val severityStr = node.data.severity match { case Ast.SpecEvent.ActivityHigh => "ACTIVITY_HI" @@ -423,8 +420,7 @@ case class DictionaryJsonEncoder( override def apply(entry: (BigInt, TlmChannelEntry)): Json = { val channel = entry._2.tlmChannel val numIdentifier = entry._1 - val componentInstUnqualName = entry._2.componentInstance.getUnqualifiedName - val name = s"${componentInstUnqualName}.${channel.getName}" + val name = s"${entry._2.componentInstance.toString}.${channel.getName}" val (preA, node, postA) = channel.aNode val json = Json.obj( "name" -> name.asJson, @@ -456,8 +452,7 @@ case class DictionaryJsonEncoder( override def apply(entry: (BigInt, RecordEntry)): Json = { val record = entry._2.record val numIdentifier = entry._1 - val componentInstUnqualName = entry._2.componentInstance.getUnqualifiedName - val name = s"${componentInstUnqualName}.${record.getName}" + val name = s"${entry._2.componentInstance.toString}.${record.getName}" val (preA, node, postA) = record.aNode val json = Json.obj( "name" -> name.asJson, @@ -477,8 +472,7 @@ case class DictionaryJsonEncoder( override def apply(entry: (BigInt, ContainerEntry)): Json = { val container = entry._2.container val numIdentifier = entry._1 - val componentInstUnqualName = entry._2.componentInstance.getUnqualifiedName - val name = s"${componentInstUnqualName}.${container.getName}" + val name = s"${entry._2.componentInstance.toString}.${container.getName}" val (preA, node, postA) = container.aNode val json = Json.obj( "name" -> name.asJson, diff --git a/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json index 48e190a3f..a07bec0c6 100644 --- a/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/BasicDpTopologyDictionary.ref.json @@ -70,7 +70,7 @@ ], "records" : [ { - "name" : "c2.DataArrayRecord", + "name" : "FppTest.c2.DataArrayRecord", "type" : { "name" : "FppTest.DpTestComponent.Data", "kind" : "qualifiedIdentifier" @@ -80,7 +80,7 @@ "annotation" : "Record 5" }, { - "name" : "c2.U32Record", + "name" : "FppTest.c2.U32Record", "type" : { "name" : "U32", "kind" : "integer", @@ -92,7 +92,7 @@ "annotation" : "Record 1" }, { - "name" : "c2.ComplexRecord", + "name" : "FppTest.c2.ComplexRecord", "type" : { "name" : "FppTest.DpTestComponent.Complex", "kind" : "qualifiedIdentifier" @@ -102,7 +102,7 @@ "annotation" : "Record 2" }, { - "name" : "c2.U32ArrayRecord", + "name" : "FppTest.c2.U32ArrayRecord", "type" : { "name" : "U32", "kind" : "integer", @@ -114,7 +114,7 @@ "annotation" : "Record 4" }, { - "name" : "c1.U32Record", + "name" : "FppTest.c1.U32Record", "type" : { "name" : "U32", "kind" : "integer", @@ -126,7 +126,7 @@ "annotation" : "Record 1" }, { - "name" : "c2.U8ArrayRecord", + "name" : "FppTest.c2.U8ArrayRecord", "type" : { "name" : "U8", "kind" : "integer", @@ -138,7 +138,7 @@ "annotation" : "Record 3" }, { - "name" : "c1.ComplexRecord2", + "name" : "FppTest.c1.ComplexRecord2", "type" : { "name" : "FppTest.DpTestComponent.Complex", "kind" : "qualifiedIdentifier" @@ -148,7 +148,7 @@ "annotation" : "Record 6" }, { - "name" : "c1.DataArrayRecord", + "name" : "FppTest.c1.DataArrayRecord", "type" : { "name" : "FppTest.DpTestComponent.Data", "kind" : "qualifiedIdentifier" @@ -158,7 +158,7 @@ "annotation" : "Record 5" }, { - "name" : "c2.ComplexRecord2", + "name" : "FppTest.c2.ComplexRecord2", "type" : { "name" : "FppTest.DpTestComponent.Complex", "kind" : "qualifiedIdentifier" @@ -168,7 +168,7 @@ "annotation" : "Record 6" }, { - "name" : "c1.U32ArrayRecord", + "name" : "FppTest.c1.U32ArrayRecord", "type" : { "name" : "U32", "kind" : "integer", @@ -180,7 +180,7 @@ "annotation" : "Record 4" }, { - "name" : "c1.U8ArrayRecord", + "name" : "FppTest.c1.U8ArrayRecord", "type" : { "name" : "U8", "kind" : "integer", @@ -192,7 +192,7 @@ "annotation" : "Record 3" }, { - "name" : "c1.ComplexRecord", + "name" : "FppTest.c1.ComplexRecord", "type" : { "name" : "FppTest.DpTestComponent.Complex", "kind" : "qualifiedIdentifier" @@ -204,61 +204,61 @@ ], "containers" : [ { - "name" : "c2.Container5", + "name" : "FppTest.c2.Container5", "id" : 6268, "defaultPriority" : 50, "annotation" : "Container 5" }, { - "name" : "c2.Container1", + "name" : "FppTest.c2.Container1", "id" : 5868, "defaultPriority" : 10, "annotation" : "Container 1" }, { - "name" : "c2.Container2", + "name" : "FppTest.c2.Container2", "id" : 5968, "defaultPriority" : 20, "annotation" : "Container 2" }, { - "name" : "c2.Container4", + "name" : "FppTest.c2.Container4", "id" : 6168, "defaultPriority" : 40, "annotation" : "Container 4" }, { - "name" : "c1.Container4", + "name" : "FppTest.c1.Container4", "id" : 5400, "defaultPriority" : 40, "annotation" : "Container 4" }, { - "name" : "c1.Container1", + "name" : "FppTest.c1.Container1", "id" : 5100, "defaultPriority" : 10, "annotation" : "Container 1" }, { - "name" : "c2.Container3", + "name" : "FppTest.c2.Container3", "id" : 6068, "defaultPriority" : 30, "annotation" : "Container 3" }, { - "name" : "c1.Container5", + "name" : "FppTest.c1.Container5", "id" : 5500, "defaultPriority" : 50, "annotation" : "Container 5" }, { - "name" : "c1.Container3", + "name" : "FppTest.c1.Container3", "id" : 5300, "defaultPriority" : 30, "annotation" : "Container 3" }, { - "name" : "c1.Container2", + "name" : "FppTest.c1.Container2", "id" : 5200, "defaultPriority" : 20, "annotation" : "Container 2" diff --git a/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json index 8f439e793..35e044681 100644 --- a/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/FirstTopTopologyDictionary.ref.json @@ -206,7 +206,7 @@ ], "commands" : [ { - "name" : "myFirstC2.Command1", + "name" : "Module1.myFirstC2.Command1", "commandKind" : "sync", "opcode" : 1024, "formalParams" : [ @@ -222,7 +222,7 @@ "annotation" : "Command with 1 arg (of type struct)" }, { - "name" : "myFirstC1.PARAM2_PARAM_SET", + "name" : "Module1.myFirstC1.PARAM2_PARAM_SET", "commandKind" : "set", "opcode" : 898, "formalParams" : [ @@ -238,7 +238,7 @@ "annotation" : "Parameter of type array (with 4 U32 values)" }, { - "name" : "myFirstC1.PARAM5_PARAM_SAVE", + "name" : "Module1.myFirstC1.PARAM5_PARAM_SAVE", "commandKind" : "save", "opcode" : 905, "formalParams" : [ @@ -246,7 +246,7 @@ "annotation" : "Parameter of type enum" }, { - "name" : "myFirstC1.PARAM3_PARAM_SAVE", + "name" : "Module1.myFirstC1.PARAM3_PARAM_SAVE", "commandKind" : "save", "opcode" : 901, "formalParams" : [ @@ -254,7 +254,7 @@ "annotation" : "Parameter of type string" }, { - "name" : "myFirstC1.PARAM1_PARAM_SAVE", + "name" : "Module1.myFirstC1.PARAM1_PARAM_SAVE", "commandKind" : "save", "opcode" : 773, "formalParams" : [ @@ -262,7 +262,7 @@ "annotation" : "Parameter (struct)" }, { - "name" : "myFirstC1.PARAM3_PARAM_SET", + "name" : "Module1.myFirstC1.PARAM3_PARAM_SET", "commandKind" : "set", "opcode" : 900, "formalParams" : [ @@ -279,7 +279,7 @@ "annotation" : "Parameter of type string" }, { - "name" : "myFirstC1.Command2", + "name" : "Module1.myFirstC1.Command2", "commandKind" : "sync", "opcode" : 769, "formalParams" : [ @@ -296,7 +296,7 @@ "annotation" : "Command with string arg" }, { - "name" : "myFirstC1.Command1", + "name" : "Module1.myFirstC1.Command1", "commandKind" : "async", "opcode" : 768, "formalParams" : [ @@ -317,7 +317,7 @@ "annotation" : "Command with I32 arg" }, { - "name" : "myFirstC2.Command2", + "name" : "Module1.myFirstC2.Command2", "commandKind" : "sync", "opcode" : 1025, "formalParams" : [ @@ -353,7 +353,7 @@ "annotation" : "Command with 3 args (of types string, I32, and bool)" }, { - "name" : "myFirstC1.PARAM2_PARAM_SAVE", + "name" : "Module1.myFirstC1.PARAM2_PARAM_SAVE", "commandKind" : "save", "opcode" : 899, "formalParams" : [ @@ -361,7 +361,7 @@ "annotation" : "Parameter of type array (with 4 U32 values)" }, { - "name" : "myFirstC1.PARAM4_PARAM_SET", + "name" : "Module1.myFirstC1.PARAM4_PARAM_SET", "commandKind" : "set", "opcode" : 902, "formalParams" : [ @@ -378,7 +378,7 @@ "annotation" : "Parameter of type F32" }, { - "name" : "myFirstC1.Command3", + "name" : "Module1.myFirstC1.Command3", "commandKind" : "sync", "opcode" : 770, "formalParams" : [ @@ -406,7 +406,7 @@ "annotation" : "Command with 2 args (array of strings and U32)" }, { - "name" : "myFirstC1.PARAM5_PARAM_SET", + "name" : "Module1.myFirstC1.PARAM5_PARAM_SET", "commandKind" : "set", "opcode" : 904, "formalParams" : [ @@ -422,7 +422,7 @@ "annotation" : "Parameter of type enum" }, { - "name" : "myFirstC1.PARAM1_PARAM_SET", + "name" : "Module1.myFirstC1.PARAM1_PARAM_SET", "commandKind" : "set", "opcode" : 772, "formalParams" : [ @@ -438,7 +438,7 @@ "annotation" : "Parameter (struct)" }, { - "name" : "myFirstC1.PARAM4_PARAM_SAVE", + "name" : "Module1.myFirstC1.PARAM4_PARAM_SAVE", "commandKind" : "save", "opcode" : 903, "formalParams" : [ @@ -446,7 +446,7 @@ "annotation" : "Parameter of type F32" }, { - "name" : "myFirstC1.Command4", + "name" : "Module1.myFirstC1.Command4", "commandKind" : "sync", "opcode" : 771, "formalParams" : [ @@ -456,7 +456,7 @@ ], "parameters" : [ { - "name" : "myFirstC1.Param2", + "name" : "Module1.myFirstC1.Param2", "type" : { "name" : "Module1.U32x4", "kind" : "qualifiedIdentifier" @@ -465,7 +465,7 @@ "annotation" : "Parameter of type array (with 4 U32 values)" }, { - "name" : "myFirstC1.Param5", + "name" : "Module1.myFirstC1.Param5", "type" : { "name" : "Module1.E1", "kind" : "qualifiedIdentifier" @@ -474,7 +474,7 @@ "annotation" : "Parameter of type enum" }, { - "name" : "myFirstC1.Param4", + "name" : "Module1.myFirstC1.Param4", "type" : { "name" : "F32", "kind" : "float", @@ -484,7 +484,7 @@ "annotation" : "Parameter of type F32" }, { - "name" : "myFirstC1.Param1", + "name" : "Module1.myFirstC1.Param1", "type" : { "name" : "Module1.S1", "kind" : "qualifiedIdentifier" @@ -497,7 +497,7 @@ "annotation" : "Parameter (struct)" }, { - "name" : "myFirstC1.Param3", + "name" : "Module1.myFirstC1.Param3", "type" : { "name" : "string", "kind" : "string", @@ -509,7 +509,7 @@ ], "events" : [ { - "name" : "myFirstC1.Event1", + "name" : "Module1.myFirstC1.Event1", "severity" : "ACTIVITY_HI", "formalParams" : [ { @@ -527,7 +527,7 @@ "annotation" : "Event with array arg (containing 4 F32 values)" }, { - "name" : "myFirstC1.Event2", + "name" : "Module1.myFirstC1.Event2", "severity" : "ACTIVITY_HI", "formalParams" : [ { @@ -545,7 +545,7 @@ "annotation" : "Event with enum arg" }, { - "name" : "myFirstC1.Event3", + "name" : "Module1.myFirstC1.Event3", "severity" : "ACTIVITY_HI", "formalParams" : [ { @@ -564,7 +564,7 @@ "annotation" : "Event with format specifier\nMultiple lines of annotation\nAnd not used on purpose" }, { - "name" : "myFirstC2.Event1", + "name" : "Module1.myFirstC2.Event1", "severity" : "WARNING_LO", "formalParams" : [ { @@ -586,7 +586,7 @@ ], "telemetryChannels" : [ { - "name" : "myFirstC2.TlmChannel1", + "name" : "Module1.myFirstC2.TlmChannel1", "type" : { "name" : "U32", "kind" : "integer", @@ -598,7 +598,7 @@ "annotation" : "Telemetry channel of type U32 with no high/low limits" }, { - "name" : "myFirstC1.MyTlmChannel3", + "name" : "Module1.myFirstC1.MyTlmChannel3", "type" : { "name" : "U64", "kind" : "integer", @@ -610,7 +610,7 @@ "annotation" : "Telemetry channel of type U64" }, { - "name" : "myFirstC2.TlmChannel3", + "name" : "Module1.myFirstC2.TlmChannel3", "type" : { "name" : "F64", "kind" : "float", @@ -628,7 +628,7 @@ } }, { - "name" : "myFirstC1.MyTlmChannel2", + "name" : "Module1.myFirstC1.MyTlmChannel2", "type" : { "name" : "F32", "kind" : "float", @@ -639,7 +639,7 @@ "annotation" : "Telemetry channel of type F32" }, { - "name" : "myFirstC1.TlmChannel1", + "name" : "Module1.myFirstC1.TlmChannel1", "type" : { "name" : "F64", "kind" : "float", @@ -662,7 +662,7 @@ } }, { - "name" : "myFirstC2.TlmChannel2", + "name" : "Module1.myFirstC2.TlmChannel2", "type" : { "name" : "F64", "kind" : "float", @@ -682,7 +682,7 @@ ], "records" : [ { - "name" : "myFirstC1.Record1", + "name" : "Module1.myFirstC1.Record1", "type" : { "name" : "U32", "kind" : "integer", @@ -694,7 +694,7 @@ "annotation" : "Record with single U32 value" }, { - "name" : "myFirstC1.Record2", + "name" : "Module1.myFirstC1.Record2", "type" : { "name" : "Module1.F64x4", "kind" : "qualifiedIdentifier" @@ -704,7 +704,7 @@ "annotation" : "Record with a single F64x4 value" }, { - "name" : "myFirstC1.Record3", + "name" : "Module1.myFirstC1.Record3", "type" : { "name" : "F32", "kind" : "float", @@ -717,17 +717,17 @@ ], "containers" : [ { - "name" : "myFirstC1.Container1", + "name" : "Module1.myFirstC1.Container1", "id" : 784, "annotation" : "Description of Container 1" }, { - "name" : "myFirstC1.Container2", + "name" : "Module1.myFirstC1.Container2", "id" : 785, "annotation" : "Description Container 2" }, { - "name" : "myFirstC1.Container3", + "name" : "Module1.myFirstC1.Container3", "id" : 786, "defaultPriority" : 10, "annotation" : "Description Container 3 with a default priority of 10" diff --git a/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json new file mode 100644 index 000000000..864d85175 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json @@ -0,0 +1,111 @@ +{ + "metadata" : { + "deploymentName" : "QualifiedCompInst", + "projectVersion" : "1.0.0", + "frameworkVersion" : "3.4.3", + "libraryVersions" : [ + "lib1-1.0.0", + "lib2-2.0.0" + ], + "dictionarySpecVersion" : "1.0.0" + }, + "typeDefinitions" : [ + { + "kind" : "enum", + "qualifiedName" : "M.E1", + "representationType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "enumeratedConstants" : [ + { + "name" : "X", + "value" : 0 + }, + { + "name" : "Y", + "value" : 1 + }, + { + "name" : "Z", + "value" : 2 + } + ], + "default" : "M.E1.X" + } + ], + "commands" : [ + { + "name" : "M.c1.P_PARAM_SET", + "commandKind" : "set", + "opcode" : 256, + "formalParams" : [ + { + "name" : "val", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "ref" : false + } + ] + }, + { + "name" : "M.c1.P_PARAM_SAVE", + "commandKind" : "save", + "opcode" : 257, + "formalParams" : [ + ] + }, + { + "name" : "M.c2.P_PARAM_SET", + "commandKind" : "set", + "opcode" : 512, + "formalParams" : [ + { + "name" : "val", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "ref" : false + } + ] + }, + { + "name" : "M.c2.P_PARAM_SAVE", + "commandKind" : "save", + "opcode" : 513, + "formalParams" : [ + ] + } + ], + "parameters" : [ + { + "name" : "M.c1.P", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "id" : 256 + }, + { + "name" : "M.c2.P", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "id" : 512 + } + ], + "events" : [ + ], + "telemetryChannels" : [ + ], + "records" : [ + ], + "containers" : [ + ] +} diff --git a/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json index 10c17d844..a5637c339 100644 --- a/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/SecondTopTopologyDictionary.ref.json @@ -206,7 +206,7 @@ ], "commands" : [ { - "name" : "mySecondC1.PARAM2_PARAM_SAVE", + "name" : "Module1.mySecondC1.PARAM2_PARAM_SAVE", "commandKind" : "save", "opcode" : 1411, "formalParams" : [ @@ -214,7 +214,7 @@ "annotation" : "Parameter of type array (with 4 U32 values)" }, { - "name" : "mySecondC1.Command2", + "name" : "Module1.mySecondC1.Command2", "commandKind" : "sync", "opcode" : 1281, "formalParams" : [ @@ -231,7 +231,7 @@ "annotation" : "Command with string arg" }, { - "name" : "mySecondC1.PARAM4_PARAM_SET", + "name" : "Module1.mySecondC1.PARAM4_PARAM_SET", "commandKind" : "set", "opcode" : 1414, "formalParams" : [ @@ -248,7 +248,7 @@ "annotation" : "Parameter of type F32" }, { - "name" : "mySecondC1.Command3", + "name" : "Module1.mySecondC1.Command3", "commandKind" : "sync", "opcode" : 1282, "formalParams" : [ @@ -276,7 +276,7 @@ "annotation" : "Command with 2 args (array of strings and U32)" }, { - "name" : "mySecondC1.PARAM3_PARAM_SAVE", + "name" : "Module1.mySecondC1.PARAM3_PARAM_SAVE", "commandKind" : "save", "opcode" : 1413, "formalParams" : [ @@ -284,7 +284,7 @@ "annotation" : "Parameter of type string" }, { - "name" : "mySecondC1.PARAM1_PARAM_SAVE", + "name" : "Module1.mySecondC1.PARAM1_PARAM_SAVE", "commandKind" : "save", "opcode" : 1285, "formalParams" : [ @@ -292,7 +292,7 @@ "annotation" : "Parameter (struct)" }, { - "name" : "mySecondC1.PARAM3_PARAM_SET", + "name" : "Module1.mySecondC1.PARAM3_PARAM_SET", "commandKind" : "set", "opcode" : 1412, "formalParams" : [ @@ -309,7 +309,7 @@ "annotation" : "Parameter of type string" }, { - "name" : "mySecondC1.Command1", + "name" : "Module1.mySecondC1.Command1", "commandKind" : "async", "opcode" : 1280, "formalParams" : [ @@ -330,7 +330,7 @@ "annotation" : "Command with I32 arg" }, { - "name" : "mySecondC1.PARAM2_PARAM_SET", + "name" : "Module1.mySecondC1.PARAM2_PARAM_SET", "commandKind" : "set", "opcode" : 1410, "formalParams" : [ @@ -346,7 +346,7 @@ "annotation" : "Parameter of type array (with 4 U32 values)" }, { - "name" : "mySecondC2.Command2", + "name" : "Module1.mySecondC2.Command2", "commandKind" : "sync", "opcode" : 1537, "formalParams" : [ @@ -382,7 +382,7 @@ "annotation" : "Command with 3 args (of types string, I32, and bool)" }, { - "name" : "mySecondC1.PARAM4_PARAM_SAVE", + "name" : "Module1.mySecondC1.PARAM4_PARAM_SAVE", "commandKind" : "save", "opcode" : 1415, "formalParams" : [ @@ -390,7 +390,7 @@ "annotation" : "Parameter of type F32" }, { - "name" : "mySecondC1.Command4", + "name" : "Module1.mySecondC1.Command4", "commandKind" : "sync", "opcode" : 1283, "formalParams" : [ @@ -398,7 +398,7 @@ "annotation" : "Command with no args" }, { - "name" : "mySecondC2.Command1", + "name" : "Module1.mySecondC2.Command1", "commandKind" : "sync", "opcode" : 1536, "formalParams" : [ @@ -414,7 +414,7 @@ "annotation" : "Command with 1 arg (of type struct)" }, { - "name" : "mySecondC1.PARAM1_PARAM_SET", + "name" : "Module1.mySecondC1.PARAM1_PARAM_SET", "commandKind" : "set", "opcode" : 1284, "formalParams" : [ @@ -430,7 +430,7 @@ "annotation" : "Parameter (struct)" }, { - "name" : "mySecondC1.PARAM5_PARAM_SET", + "name" : "Module1.mySecondC1.PARAM5_PARAM_SET", "commandKind" : "set", "opcode" : 1416, "formalParams" : [ @@ -446,7 +446,7 @@ "annotation" : "Parameter of type enum" }, { - "name" : "mySecondC1.PARAM5_PARAM_SAVE", + "name" : "Module1.mySecondC1.PARAM5_PARAM_SAVE", "commandKind" : "save", "opcode" : 1417, "formalParams" : [ @@ -456,7 +456,7 @@ ], "parameters" : [ { - "name" : "mySecondC1.Param3", + "name" : "Module1.mySecondC1.Param3", "type" : { "name" : "string", "kind" : "string", @@ -466,7 +466,7 @@ "annotation" : "Parameter of type string" }, { - "name" : "mySecondC1.Param1", + "name" : "Module1.mySecondC1.Param1", "type" : { "name" : "Module1.S1", "kind" : "qualifiedIdentifier" @@ -479,7 +479,7 @@ "annotation" : "Parameter (struct)" }, { - "name" : "mySecondC1.Param2", + "name" : "Module1.mySecondC1.Param2", "type" : { "name" : "Module1.U32x4", "kind" : "qualifiedIdentifier" @@ -488,7 +488,7 @@ "annotation" : "Parameter of type array (with 4 U32 values)" }, { - "name" : "mySecondC1.Param5", + "name" : "Module1.mySecondC1.Param5", "type" : { "name" : "Module1.E1", "kind" : "qualifiedIdentifier" @@ -497,7 +497,7 @@ "annotation" : "Parameter of type enum" }, { - "name" : "mySecondC1.Param4", + "name" : "Module1.mySecondC1.Param4", "type" : { "name" : "F32", "kind" : "float", @@ -509,7 +509,7 @@ ], "events" : [ { - "name" : "mySecondC1.Event1", + "name" : "Module1.mySecondC1.Event1", "severity" : "ACTIVITY_HI", "formalParams" : [ { @@ -527,7 +527,7 @@ "annotation" : "Event with array arg (containing 4 F32 values)" }, { - "name" : "mySecondC1.Event2", + "name" : "Module1.mySecondC1.Event2", "severity" : "ACTIVITY_HI", "formalParams" : [ { @@ -545,7 +545,7 @@ "annotation" : "Event with enum arg" }, { - "name" : "mySecondC1.Event3", + "name" : "Module1.mySecondC1.Event3", "severity" : "ACTIVITY_HI", "formalParams" : [ { @@ -564,7 +564,7 @@ "annotation" : "Event with format specifier\nMultiple lines of annotation\nAnd not used on purpose" }, { - "name" : "mySecondC2.Event1", + "name" : "Module1.mySecondC2.Event1", "severity" : "WARNING_LO", "formalParams" : [ { @@ -586,7 +586,7 @@ ], "telemetryChannels" : [ { - "name" : "mySecondC1.MyTlmChannel2", + "name" : "Module1.mySecondC1.MyTlmChannel2", "type" : { "name" : "F32", "kind" : "float", @@ -597,7 +597,7 @@ "annotation" : "Telemetry channel of type F32" }, { - "name" : "mySecondC1.MyTlmChannel3", + "name" : "Module1.mySecondC1.MyTlmChannel3", "type" : { "name" : "U64", "kind" : "integer", @@ -609,7 +609,7 @@ "annotation" : "Telemetry channel of type U64" }, { - "name" : "mySecondC2.TlmChannel3", + "name" : "Module1.mySecondC2.TlmChannel3", "type" : { "name" : "F64", "kind" : "float", @@ -627,7 +627,7 @@ } }, { - "name" : "mySecondC2.TlmChannel1", + "name" : "Module1.mySecondC2.TlmChannel1", "type" : { "name" : "U32", "kind" : "integer", @@ -639,7 +639,7 @@ "annotation" : "Telemetry channel of type U32 with no high/low limits" }, { - "name" : "mySecondC1.TlmChannel1", + "name" : "Module1.mySecondC1.TlmChannel1", "type" : { "name" : "F64", "kind" : "float", @@ -662,7 +662,7 @@ } }, { - "name" : "mySecondC2.TlmChannel2", + "name" : "Module1.mySecondC2.TlmChannel2", "type" : { "name" : "F64", "kind" : "float", @@ -682,7 +682,7 @@ ], "records" : [ { - "name" : "mySecondC1.Record1", + "name" : "Module1.mySecondC1.Record1", "type" : { "name" : "U32", "kind" : "integer", @@ -694,7 +694,7 @@ "annotation" : "Record with single U32 value" }, { - "name" : "mySecondC1.Record2", + "name" : "Module1.mySecondC1.Record2", "type" : { "name" : "Module1.F64x4", "kind" : "qualifiedIdentifier" @@ -704,7 +704,7 @@ "annotation" : "Record with a single F64x4 value" }, { - "name" : "mySecondC1.Record3", + "name" : "Module1.mySecondC1.Record3", "type" : { "name" : "F32", "kind" : "float", @@ -717,17 +717,17 @@ ], "containers" : [ { - "name" : "mySecondC1.Container1", + "name" : "Module1.mySecondC1.Container1", "id" : 1296, "annotation" : "Description of Container 1" }, { - "name" : "mySecondC1.Container2", + "name" : "Module1.mySecondC1.Container2", "id" : 1297, "annotation" : "Description Container 2" }, { - "name" : "mySecondC1.Container3", + "name" : "Module1.mySecondC1.Container3", "id" : 1298, "defaultPriority" : 10, "annotation" : "Description Container 3 with a default priority of 10" diff --git a/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json new file mode 100644 index 000000000..13824f733 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json @@ -0,0 +1,111 @@ +{ + "metadata" : { + "deploymentName" : "UnqualifiedCompInst", + "projectVersion" : "1.0.0", + "frameworkVersion" : "3.4.3", + "libraryVersions" : [ + "lib1-1.0.0", + "lib2-2.0.0" + ], + "dictionarySpecVersion" : "1.0.0" + }, + "typeDefinitions" : [ + { + "kind" : "enum", + "qualifiedName" : "M.E1", + "representationType" : { + "name" : "U32", + "kind" : "integer", + "size" : 32, + "signed" : false + }, + "enumeratedConstants" : [ + { + "name" : "X", + "value" : 0 + }, + { + "name" : "Y", + "value" : 1 + }, + { + "name" : "Z", + "value" : 2 + } + ], + "default" : "M.E1.X" + } + ], + "commands" : [ + { + "name" : "c3.P_PARAM_SET", + "commandKind" : "set", + "opcode" : 768, + "formalParams" : [ + { + "name" : "val", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "ref" : false + } + ] + }, + { + "name" : "c3.P_PARAM_SAVE", + "commandKind" : "save", + "opcode" : 769, + "formalParams" : [ + ] + }, + { + "name" : "c4.P_PARAM_SET", + "commandKind" : "set", + "opcode" : 1024, + "formalParams" : [ + { + "name" : "val", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "ref" : false + } + ] + }, + { + "name" : "c4.P_PARAM_SAVE", + "commandKind" : "save", + "opcode" : 1025, + "formalParams" : [ + ] + } + ], + "parameters" : [ + { + "name" : "c3.P", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "id" : 768 + }, + { + "name" : "c4.P", + "type" : { + "name" : "M.E1", + "kind" : "qualifiedIdentifier" + }, + "id" : 1024 + } + ], + "events" : [ + ], + "telemetryChannels" : [ + ], + "records" : [ + ], + "containers" : [ + ] +} diff --git a/compiler/tools/fpp-to-dict/test/top/run.sh b/compiler/tools/fpp-to-dict/test/top/run.sh index b6dd742cb..a795558e1 100644 --- a/compiler/tools/fpp-to-dict/test/top/run.sh +++ b/compiler/tools/fpp-to-dict/test/top/run.sh @@ -18,4 +18,13 @@ duplicate() { run_test '' duplicate && \ compare duplicate +} + +unqualifiedComponentInstances() +{ + run_test "-i builtin.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" unqualifiedComponentInstances && \ + validate_json_schema QualifiedCompInst && \ + validate_json_schema UnqualifiedCompInst && \ + diff_json QualifiedCompInst && \ + diff_json UnqualifiedCompInst } \ No newline at end of file diff --git a/compiler/tools/fpp-to-dict/test/top/tests.sh b/compiler/tools/fpp-to-dict/test/top/tests.sh index 14929e6ef..347daf0d0 100644 --- a/compiler/tools/fpp-to-dict/test/top/tests.sh +++ b/compiler/tools/fpp-to-dict/test/top/tests.sh @@ -2,4 +2,5 @@ tests=" multipleTops dataProducts duplicate +unqualifiedComponentInstances " diff --git a/compiler/tools/fpp-to-dict/test/top/update-ref.sh b/compiler/tools/fpp-to-dict/test/top/update-ref.sh index 8265476ac..49acd6831 100644 --- a/compiler/tools/fpp-to-dict/test/top/update-ref.sh +++ b/compiler/tools/fpp-to-dict/test/top/update-ref.sh @@ -9,4 +9,11 @@ dataProducts() { update "-i builtin.fpp -p 1.0.0 -f 3.4.3" dataProducts move_json BasicDp +} + +unqualifiedComponentInstances() +{ + update "-i builtin.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" unqualifiedComponentInstances + move_json QualifiedCompInst + move_json UnqualifiedCompInst } \ No newline at end of file From b5cdd681e766d098725df2987edab66182b1f59d Mon Sep 17 00:00:00 2001 From: jwest115 Date: Wed, 26 Jun 2024 18:39:53 -0700 Subject: [PATCH 02/25] use fully qualified names for component instance names, updated tests --- .../TopologyCppWriterUtils.scala | 2 +- .../test/top/BasicTopologyAc.ref.cpp | 72 +++++++++---------- .../test/top/BasicTopologyAc.ref.hpp | 60 ++++++++-------- .../test/top/CommandsTopologyAc.ref.cpp | 16 ++--- .../test/top/CommandsTopologyAc.ref.hpp | 16 ++--- .../test/top/HealthTopologyAc.ref.cpp | 48 ++++++------- .../test/top/HealthTopologyAc.ref.hpp | 26 +++---- .../test/top/ParamsTopologyAc.ref.cpp | 22 +++--- .../test/top/ParamsTopologyAc.ref.hpp | 16 ++--- compiler/tools/fpp-to-cpp/test/top/basic.fpp | 14 ++-- .../tools/fpp-to-cpp/test/top/commands.fpp | 2 +- compiler/tools/fpp-to-cpp/test/top/params.fpp | 4 +- 12 files changed, 149 insertions(+), 149 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 0f48a25e4..618776bae 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala @@ -58,7 +58,7 @@ abstract class TopologyCppWriterUtils( } def getNameAsIdent(name: Name.Qualified): String = - CppWriter.identFromQualifiedName(getShortName(name)) + CppWriter.identFromQualifiedName(name) def getNameAsQualIdent(name: Name.Qualified): String = CppWriter.writeQualifiedName(getShortName(name)) 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 604fd119f..c8c10853b 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -15,7 +15,7 @@ namespace M { namespace ConfigObjects { - namespace active2 { + namespace M_active2 { U32 x = 0; } @@ -26,52 +26,52 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - Active active1(FW_OPTIONAL_NAME("active1")); + Active M_active1(FW_OPTIONAL_NAME("M_active1")); - Active active2; + Active M_active2; - Active active3(FW_OPTIONAL_NAME("active3")); + Active M_active3(FW_OPTIONAL_NAME("M_active3")); - Passive passive1(FW_OPTIONAL_NAME("passive1")); + Passive M_passive1(FW_OPTIONAL_NAME("M_passive1")); - ConcretePassive passive2(FW_OPTIONAL_NAME("passive2")); + ConcretePassive M_passive2(FW_OPTIONAL_NAME("M_passive2")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - active1.init(QueueSizes::active1, InstanceIds::active1); - active2.initSpecial(); - active3.init(QueueSizes::active3, InstanceIds::active3); - passive1.init(InstanceIds::passive1); - passive2.init(InstanceIds::passive2); + 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); } void configComponents(const TopologyState& state) { - active2.config(); + M_active2.config(); } void setBaseIds() { - active1.setIdBase(BaseIds::active1); - active2.setIdBase(BaseIds::active2); - active3.setIdBase(BaseIds::active3); - passive1.setIdBase(BaseIds::passive1); - passive2.setIdBase(BaseIds::passive2); + M_active1.setIdBase(BaseIds::M_active1); + M_active2.setIdBase(BaseIds::M_active2); + M_active3.setIdBase(BaseIds::M_active3); + M_passive1.setIdBase(BaseIds::M_passive1); + M_passive2.setIdBase(BaseIds::M_passive2); } void connectComponents() { // C1 - passive1.set_p_OutputPort( + M_passive1.set_p_OutputPort( 0, - active1.get_p_InputPort(0) + M_active1.get_p_InputPort(0) ); // C2 - passive2.set_p_OutputPort( + M_passive2.set_p_OutputPort( 0, - active2.get_p_InputPort(0) + M_active2.get_p_InputPort(0) ); } @@ -88,35 +88,35 @@ namespace M { } void startTasks(const TopologyState& state) { - active1.start( - static_cast(Priorities::active1), - static_cast(StackSizes::active1), - static_cast(CPUs::active1), - static_cast(TaskIds::active1) + M_active1.start( + static_cast(Priorities::M_active1), + static_cast(StackSizes::M_active1), + static_cast(CPUs::M_active1), + static_cast(TaskIds::M_active1) ); - active2.startSpecial(); - active3.start( + M_active2.startSpecial(); + M_active3.start( Os::Task::TASK_DEFAULT, // Default priority Os::Task::TASK_DEFAULT, // Default stack size Os::Task::TASK_DEFAULT, // Default CPU - static_cast(TaskIds::active3) + static_cast(TaskIds::M_active3) ); } void stopTasks(const TopologyState& state) { - active1.exit(); - active2.stopSpecial(); - active3.exit(); + M_active1.exit(); + M_active2.stopSpecial(); + M_active3.exit(); } void freeThreads(const TopologyState& state) { - (void) active1.ActiveComponentBase::join(); - active2.freeSpecial(); - (void) active3.ActiveComponentBase::join(); + (void) M_active1.ActiveComponentBase::join(); + M_active2.freeSpecial(); + (void) M_active3.ActiveComponentBase::join(); } void tearDownComponents(const TopologyState& state) { - active2.tearDown(); + M_active2.tearDown(); } // ---------------------------------------------------------------------- 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 28dac8ff9..4154a388a 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp @@ -18,7 +18,7 @@ namespace M { // ---------------------------------------------------------------------- namespace ConfigConstants { - namespace active2 { + namespace M_active2 { enum { X = 0, Y = 1 @@ -28,55 +28,55 @@ namespace M { namespace BaseIds { enum { - active1 = 0x100, - active2 = 0x200, - active3 = 0x300, - passive1 = 0x300, - passive2 = 0x400, + M_active1 = 0x100, + M_active2 = 0x200, + M_active3 = 0x300, + M_passive1 = 0x300, + M_passive2 = 0x400, }; } namespace CPUs { enum { - active1 = 0, + M_active1 = 0, }; } namespace InstanceIds { enum { - active1, - active2, - active3, - passive1, - passive2, + M_active1, + M_active2, + M_active3, + M_passive1, + M_passive2, }; } namespace Priorities { enum { - active1 = 1, + M_active1 = 1, }; } namespace QueueSizes { enum { - active1 = 10, - active2 = 10, - active3 = 10, + M_active1 = 10, + M_active2 = 10, + M_active3 = 10, }; } namespace StackSizes { enum { - active1 = 1024, + M_active1 = 1024, }; } namespace TaskIds { enum { - active1, - active2, - active3, + M_active1, + M_active2, + M_active3, }; } @@ -84,20 +84,20 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - //! active1 - extern Active active1; + //! M_active1 + extern Active M_active1; - //! active2 - extern Active active2; + //! M_active2 + extern Active M_active2; - //! active3 - extern Active active3; + //! M_active3 + extern Active M_active3; - //! passive1 - extern Passive passive1; + //! M_passive1 + extern Passive M_passive1; - //! passive2 - extern ConcretePassive passive2; + //! M_passive2 + extern ConcretePassive M_passive2; // ---------------------------------------------------------------------- // Helper functions 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 fd6a365fc..2ae0d0618 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp @@ -13,17 +13,17 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - C c1(FW_OPTIONAL_NAME("c1")); + C M_c1(FW_OPTIONAL_NAME("M_c1")); - C c2(FW_OPTIONAL_NAME("c2")); + C M_c2(FW_OPTIONAL_NAME("M_c2")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - c1.init(InstanceIds::c1); - c2.init(InstanceIds::c2); + M_c1.init(InstanceIds::M_c1); + M_c2.init(InstanceIds::M_c2); } void configComponents(const TopologyState& state) { @@ -31,8 +31,8 @@ namespace M { } void setBaseIds() { - c1.setIdBase(BaseIds::c1); - c2.setIdBase(BaseIds::c2); + M_c1.setIdBase(BaseIds::M_c1); + M_c2.setIdBase(BaseIds::M_c2); } void connectComponents() { @@ -40,8 +40,8 @@ namespace M { } void regCommands() { - c1.regCommandsSpecial(); - c2.regCommands(); + M_c1.regCommandsSpecial(); + M_c2.regCommands(); } void readParameters() { 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 a7fc3c984..62b07b902 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp @@ -18,15 +18,15 @@ namespace M { namespace BaseIds { enum { - c1 = 0x100, - c2 = 0x200, + M_c1 = 0x100, + M_c2 = 0x200, }; } namespace InstanceIds { enum { - c1, - c2, + M_c1, + M_c2, }; } @@ -34,11 +34,11 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - //! c1 - extern C c1; + //! M_c1 + extern C M_c1; - //! c2 - extern C c2; + //! M_c2 + extern C M_c2; // ---------------------------------------------------------------------- // Helper functions 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 2ace23686..6885ee890 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp @@ -15,17 +15,17 @@ namespace M { namespace ConfigObjects { - namespace health { + namespace M_health { Svc::Health::PingEntry pingEntries[NUM_PING_ENTRIES] = { { - PingEntries::c1::WARN, - PingEntries::c1::FATAL, - "c1" + PingEntries::M_c1::WARN, + PingEntries::M_c1::FATAL, + "M_c1" }, { - PingEntries::c2::WARN, - PingEntries::c2::FATAL, - "c2" + PingEntries::M_c2::WARN, + PingEntries::M_c2::FATAL, + "M_c2" }, }; } @@ -37,20 +37,20 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - C c1(FW_OPTIONAL_NAME("c1")); + C M_c1(FW_OPTIONAL_NAME("M_c1")); - C c2(FW_OPTIONAL_NAME("c2")); + C M_c2(FW_OPTIONAL_NAME("M_c2")); - Svc::Health health(FW_OPTIONAL_NAME("health")); + Svc::Health M_health(FW_OPTIONAL_NAME("M_health")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - c1.init(InstanceIds::c1); - c2.init(InstanceIds::c2); - health.init(InstanceIds::health); + M_c1.init(InstanceIds::M_c1); + M_c2.init(InstanceIds::M_c2); + M_health.init(InstanceIds::M_health); } void configComponents(const TopologyState& state) { @@ -58,29 +58,29 @@ namespace M { } void setBaseIds() { - health.setIdBase(BaseIds::health); - c1.setIdBase(BaseIds::c1); - c2.setIdBase(BaseIds::c2); + M_health.setIdBase(BaseIds::M_health); + M_c1.setIdBase(BaseIds::M_c1); + M_c2.setIdBase(BaseIds::M_c2); } void connectComponents() { // Health - c1.set_pingOut_OutputPort( + M_c1.set_pingOut_OutputPort( 0, - health.get_pingIn_InputPort(0) + M_health.get_pingIn_InputPort(0) ); - c2.set_pingOut_OutputPort( + M_c2.set_pingOut_OutputPort( 0, - health.get_pingIn_InputPort(1) + M_health.get_pingIn_InputPort(1) ); - health.set_pingOut_OutputPort( + M_health.set_pingOut_OutputPort( 0, - c1.get_pingIn_InputPort(0) + M_c1.get_pingIn_InputPort(0) ); - health.set_pingOut_OutputPort( + M_health.set_pingOut_OutputPort( 1, - c2.get_pingIn_InputPort(0) + M_c2.get_pingIn_InputPort(0) ); } 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 b6df48883..ec29fafc2 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp @@ -19,17 +19,17 @@ namespace M { namespace BaseIds { enum { - health = 0x100, - c1 = 0x200, - c2 = 0x300, + M_health = 0x100, + M_c1 = 0x200, + M_c2 = 0x300, }; } namespace InstanceIds { enum { - c1, - c2, - health, + M_c1, + M_c2, + M_health, }; } @@ -39,7 +39,7 @@ namespace M { namespace ConfigObjects { - namespace health { + namespace M_health { //!< Number of entries in the pingEntryies array constexpr FwSizeType NUM_PING_ENTRIES = 2; //!< Ping entry configuration for Svc::Health @@ -52,14 +52,14 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - //! c1 - extern C c1; + //! M_c1 + extern C M_c1; - //! c2 - extern C c2; + //! M_c2 + extern C M_c2; - //! health - extern Svc::Health health; + //! M_health + extern Svc::Health M_health; // ---------------------------------------------------------------------- // Helper functions 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 0cd036571..0bda95b21 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp @@ -13,17 +13,17 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - C c1(FW_OPTIONAL_NAME("c1")); + C M_c1(FW_OPTIONAL_NAME("M_c1")); - C c2(FW_OPTIONAL_NAME("c2")); + C M_c2(FW_OPTIONAL_NAME("M_c2")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - c1.init(InstanceIds::c1); - c2.init(InstanceIds::c2); + M_c1.init(InstanceIds::M_c1); + M_c2.init(InstanceIds::M_c2); } void configComponents(const TopologyState& state) { @@ -31,8 +31,8 @@ namespace M { } void setBaseIds() { - c1.setIdBase(BaseIds::c1); - c2.setIdBase(BaseIds::c2); + M_c1.setIdBase(BaseIds::M_c1); + M_c2.setIdBase(BaseIds::M_c2); } void connectComponents() { @@ -40,17 +40,17 @@ namespace M { } void regCommands() { - c1.regCommands(); - c2.regCommands(); + M_c1.regCommands(); + M_c2.regCommands(); } void readParameters() { - c1.readParamFile(); + M_c1.readParamFile(); } void loadParameters() { - c1.loadParamsSpecial(); - c2.loadParameters(); + M_c1.loadParamsSpecial(); + M_c2.loadParameters(); } void startTasks(const TopologyState& state) { 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 43a0fde78..77efd4cc8 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp @@ -18,15 +18,15 @@ namespace M { namespace BaseIds { enum { - c1 = 0x100, - c2 = 0x200, + M_c1 = 0x100, + M_c2 = 0x200, }; } namespace InstanceIds { enum { - c1, - c2, + M_c1, + M_c2, }; } @@ -34,11 +34,11 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - //! c1 - extern C c1; + //! M_c1 + extern C M_c1; - //! c2 - extern C c2; + //! M_c2 + extern C M_c2; // ---------------------------------------------------------------------- // Helper functions diff --git a/compiler/tools/fpp-to-cpp/test/top/basic.fpp b/compiler/tools/fpp-to-cpp/test/top/basic.fpp index 64a08f6c2..066c67e5f 100644 --- a/compiler/tools/fpp-to-cpp/test/top/basic.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/basic.fpp @@ -33,31 +33,31 @@ module M { """ phase Phases.instances """ - Active active2; + Active M_active2; """ phase Phases.initComponents """ - active2.initSpecial(); + M_active2.initSpecial(); """ phase Phases.configComponents """ - active2.config(); + M_active2.config(); """ phase Phases.startTasks """ - active2.startSpecial(); + M_active2.startSpecial(); """ phase Phases.stopTasks """ - active2.stopSpecial(); + M_active2.stopSpecial(); """ phase Phases.freeThreads """ - active2.freeSpecial(); + M_active2.freeSpecial(); """ phase Phases.tearDownComponents """ - active2.tearDown(); + M_active2.tearDown(); """ } diff --git a/compiler/tools/fpp-to-cpp/test/top/commands.fpp b/compiler/tools/fpp-to-cpp/test/top/commands.fpp index 9a5e87b85..af22b8191 100644 --- a/compiler/tools/fpp-to-cpp/test/top/commands.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/commands.fpp @@ -15,7 +15,7 @@ module M { instance c1: C base id 0x100 { phase Phases.regCommands """ - c1.regCommandsSpecial(); + M_c1.regCommandsSpecial(); """ } diff --git a/compiler/tools/fpp-to-cpp/test/top/params.fpp b/compiler/tools/fpp-to-cpp/test/top/params.fpp index 64d4c5177..7d62e1ede 100644 --- a/compiler/tools/fpp-to-cpp/test/top/params.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/params.fpp @@ -19,11 +19,11 @@ module M { instance c1: C base id 0x100 { phase Phases.readParameters """ - c1.readParamFile(); + M_c1.readParamFile(); """ phase Phases.loadParameters """ - c1.loadParamsSpecial(); + M_c1.loadParamsSpecial(); """ } From 1f8bbf2429a778cec5a1872dea5b9f5d68babf6f Mon Sep 17 00:00:00 2001 From: jwest115 Date: Tue, 9 Jul 2024 16:44:32 -0700 Subject: [PATCH 03/25] put component instances in indiv namespcaes --- .../TopComponentInstances.scala | 16 +++++++++------- .../TopologyCppWriter/TopologyCppWriter.scala | 8 +++++--- .../TopologyCppWriterUtils.scala | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 7256e12f5..ddd11a63c 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -12,10 +12,7 @@ case class TopComponentInstances( private val bannerComment = "Component instances" - def getHppLines: List[Line] = addBannerComment( - bannerComment, - getDeclLines - ) + def getHppLines: List[(List[String], List[Line])] = getDeclLines def getCppLines: List[Line] = addBannerComment( bannerComment, @@ -23,16 +20,21 @@ case class TopComponentInstances( ) private def getDeclLines = { - def getCode(ci: ComponentInstance): List[Line] = { + def getCode(ci: ComponentInstance): (List[String], List[Line]) = { val implType = getImplType(ci) val instanceName = getNameAsIdent(ci.qualifiedName) - Line.addPrefixLine (line(s"//! $instanceName")) ( + val instLines = Line.addPrefixLine (line(s"//! $instanceName")) ( lines( s"extern $implType $instanceName;" ) ) + val qualIdentList = instanceName contains "::" match { + case true => instanceName.substring(0, instanceName.lastIndexOf("::")).split("::").toList + case false => List() + } + (qualIdentList, addBannerComment(bannerComment, instLines)) } - flattenWithBlankPrefix(instances.map(getCode)) + instances.map(getCode) } private def getDefLines = { diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index 806fe8975..670722749 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -36,9 +36,8 @@ case class TopologyCppWriter( } val hppLines = linesMember( TopConstants(s, aNode).getLines ++ - TopConfigObjects(s, aNode).getHppLines ++ - TopComponentInstances(s, aNode).getHppLines - ) + TopConfigObjects(s, aNode).getHppLines + ) val cppIncludes = { val fileName = s"${ComputeCppFiles.FileNames.getTopology(name)}.hpp" linesMember( @@ -63,8 +62,11 @@ case class TopologyCppWriter( val setupTeardownFns = TopSetupTeardownFns(s, aNode, helperFnNames). getMembers val defs = hppLines :: cppLines :: (helperFns ++ setupTeardownFns) + val wrappedHppCompInst = TopComponentInstances(s, aNode).getHppLines.flatMap((compInstNamespaceIdentList, hppCompInstLines) => + wrapInNamespaces(compInstNamespaceIdentList, List(linesMember(hppCompInstLines)))) List( List(hppIncludes, cppIncludes), + wrappedHppCompInst, wrapInNamespaces(namespaceIdentList, defs) ).flatten } 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 618776bae..b6c5a6b37 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala @@ -58,7 +58,7 @@ abstract class TopologyCppWriterUtils( } def getNameAsIdent(name: Name.Qualified): String = - CppWriter.identFromQualifiedName(name) + CppWriter.writeQualifiedName(name) def getNameAsQualIdent(name: Name.Qualified): String = CppWriter.writeQualifiedName(getShortName(name)) From 17b4fa3e79551a7bb313e93d02410818d4553831 Mon Sep 17 00:00:00 2001 From: jwest115 Date: Sun, 14 Jul 2024 14:37:53 -0700 Subject: [PATCH 04/25] use c++ qualification for comp instance names, move constants to global namespace --- .../TopComponentInstances.scala | 9 +- .../TopologyCppWriter/TopHelperFns.scala | 31 ++-- .../TopologyCppWriter/TopologyCppWriter.scala | 12 +- .../TopologyCppWriterUtils.scala | 3 + .../test/top/BasicTopologyAc.ref.cpp | 60 +++---- .../test/top/BasicTopologyAc.ref.hpp | 163 +++++++++++------- .../test/top/CommandsTopologyAc.ref.cpp | 16 +- .../test/top/CommandsTopologyAc.ref.hpp | 44 +++-- .../test/top/HealthTopologyAc.ref.cpp | 34 ++-- .../test/top/HealthTopologyAc.ref.hpp | 73 +++++--- .../top/NestedNamespacesTopologyAc.ref.hpp | 43 +++-- .../test/top/ParamsTopologyAc.ref.cpp | 22 +-- .../test/top/ParamsTopologyAc.ref.hpp | 44 +++-- compiler/tools/fpp-to-cpp/test/top/basic.fpp | 14 +- .../tools/fpp-to-cpp/test/top/commands.fpp | 2 +- compiler/tools/fpp-to-cpp/test/top/params.fpp | 4 +- 16 files changed, 324 insertions(+), 250 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index ddd11a63c..5d6395e2b 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -22,14 +22,15 @@ case class TopComponentInstances( private def getDeclLines = { def getCode(ci: ComponentInstance): (List[String], List[Line]) = { val implType = getImplType(ci) - val instanceName = getNameAsIdent(ci.qualifiedName) + val instanceName = ci.getUnqualifiedName + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) val instLines = Line.addPrefixLine (line(s"//! $instanceName")) ( lines( s"extern $implType $instanceName;" ) ) - val qualIdentList = instanceName contains "::" match { - case true => instanceName.substring(0, instanceName.lastIndexOf("::")).split("::").toList + val qualIdentList = cppQualifiedName contains "::" match { + case true => cppQualifiedName.substring(0, cppQualifiedName.lastIndexOf("::")).split("::").toList case false => List() } (qualIdentList, addBannerComment(bannerComment, instLines)) @@ -40,7 +41,7 @@ case class TopComponentInstances( private def getDefLines = { def getCode(ci: ComponentInstance): List[Line] = { val implType = getImplType(ci) - val instanceName = getNameAsIdent(ci.qualifiedName) + val instanceName = getNameAsCppQualified(ci.qualifiedName) getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( lines( s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala index 18c581728..a4561d467 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala @@ -51,13 +51,14 @@ case class TopHelperFns( private def getInitComponentsFn = { def getCode(ci: ComponentInstance): List[Line] = { + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) val name = getNameAsIdent(ci.qualifiedName) getCodeLinesForPhase (CppWriter.Phases.initComponents) (ci).getOrElse( ci.component.aNode._2.data.kind match { case Ast.ComponentKind.Passive => - lines(s"$name.init(InstanceIds::$name);") + lines(s"$cppQualifiedName.init(InstanceIds::$name);") case _ => - lines(s"$name.init(QueueSizes::$name, InstanceIds::$name);") + lines(s"$cppQualifiedName.init(QueueSizes::$name, InstanceIds::$name);") } ) } @@ -89,8 +90,9 @@ case class TopHelperFns( private def getSetBaseIdsFn = { val name = "setBaseIds" val body = instancesByBaseId.map(ci => { + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) val name = getNameAsIdent(ci.qualifiedName) - line(s"$name.setIdBase(BaseIds::$name);") + line(s"$cppQualifiedName.setIdBase(BaseIds::$name);") }) val memberOpt = getFnMemberOpt( "Set component base Ids", @@ -103,10 +105,10 @@ case class TopHelperFns( private def getConnectComponentsFn = { def getPortInfo(pii: PortInstanceIdentifier, c: Connection) = { - val instanceName = getNameAsIdent(pii.componentInstance.qualifiedName) + val cppQualifiedName = getNameAsCppQualified(pii.componentInstance.qualifiedName) val portName = pii.portInstance.getUnqualifiedName val portNumber = t.getPortNumber(pii.portInstance, c).get - (instanceName, portName, portNumber) + (cppQualifiedName, portName, portNumber) } def writeConnection(c: Connection) = { val out = getPortInfo(c.from.port, c) @@ -140,8 +142,8 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = { getCodeLinesForPhase (CppWriter.Phases.regCommands) (ci).getOrElse( if (hasCommands(ci)) { - val name = getNameAsIdent(ci.qualifiedName) - lines(s"$name.regCommands();") + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + lines(s"$cppQualifiedName.regCommands();") } else Nil ) @@ -173,8 +175,8 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = { getCodeLinesForPhase (CppWriter.Phases.loadParameters) (ci).getOrElse( if (hasParams(ci)) { - val name = getNameAsIdent(ci.qualifiedName) - lines(s"$name.loadParameters();") + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + lines(s"$cppQualifiedName.loadParameters();") } else Nil ) @@ -193,6 +195,7 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = getCodeLinesForPhase (CppWriter.Phases.startTasks) (ci).getOrElse { if (isActive(ci)) { + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) val name = getNameAsIdent(ci.qualifiedName) val priority = ci.priority match { case Some(_) => s"static_cast(Priorities::$name)," @@ -207,7 +210,7 @@ case class TopHelperFns( case None => "Os::Task::TASK_DEFAULT, // Default CPU" } wrapInScope( - s"$name.start(", + s"$cppQualifiedName.start(", ( List( priority, @@ -235,8 +238,8 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = getCodeLinesForPhase (CppWriter.Phases.stopTasks) (ci).getOrElse { if (isActive(ci)) { - val name = getNameAsIdent(ci.qualifiedName) - lines(s"$name.exit();") + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + lines(s"$cppQualifiedName.exit();") } else Nil } @@ -254,8 +257,8 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = getCodeLinesForPhase (CppWriter.Phases.freeThreads) (ci).getOrElse { if (isActive(ci)) { - val name = getNameAsIdent(ci.qualifiedName) - lines(s"(void) $name.ActiveComponentBase::join();") + val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + lines(s"(void) $cppQualifiedName.ActiveComponentBase::join();") } else Nil } diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index 670722749..f58aef791 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -34,10 +34,9 @@ case class TopologyCppWriter( ).sorted linesMember(Line.blank :: strings.map(line)) } - val hppLines = linesMember( - TopConstants(s, aNode).getLines ++ - TopConfigObjects(s, aNode).getHppLines - ) + val hppLines = linesMember(TopConfigObjects(s, aNode).getHppLines) + val hppConstantLines = linesMember(TopConstants(s, aNode).getLines) + val hppComponentInstanceLines = TopComponentInstances(s, aNode).getHppLines val cppIncludes = { val fileName = s"${ComputeCppFiles.FileNames.getTopology(name)}.hpp" linesMember( @@ -62,11 +61,12 @@ case class TopologyCppWriter( val setupTeardownFns = TopSetupTeardownFns(s, aNode, helperFnNames). getMembers val defs = hppLines :: cppLines :: (helperFns ++ setupTeardownFns) - val wrappedHppCompInst = TopComponentInstances(s, aNode).getHppLines.flatMap((compInstNamespaceIdentList, hppCompInstLines) => + val wrappedHppComponentInstances = hppComponentInstanceLines.flatMap((compInstNamespaceIdentList, hppCompInstLines) => wrapInNamespaces(compInstNamespaceIdentList, List(linesMember(hppCompInstLines)))) List( List(hppIncludes, cppIncludes), - wrappedHppCompInst, + wrappedHppComponentInstances, + List(hppConstantLines), wrapInNamespaces(namespaceIdentList, defs) ).flatten } 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 b6c5a6b37..ecd14b9d5 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala @@ -58,6 +58,9 @@ abstract class TopologyCppWriterUtils( } def getNameAsIdent(name: Name.Qualified): String = + CppWriter.identFromQualifiedName(name) + + def getNameAsCppQualified(name: Name.Qualified): String = CppWriter.writeQualifiedName(name) def getNameAsQualIdent(name: Name.Qualified): String = 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 c8c10853b..65969e92c 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -26,52 +26,52 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - Active M_active1(FW_OPTIONAL_NAME("M_active1")); + Active M::active1(FW_OPTIONAL_NAME("M::active1")); - Active M_active2; + Active M::active2; - Active M_active3(FW_OPTIONAL_NAME("M_active3")); + Active M::active3(FW_OPTIONAL_NAME("M::active3")); - Passive M_passive1(FW_OPTIONAL_NAME("M_passive1")); + Passive M::passive1(FW_OPTIONAL_NAME("M::passive1")); - ConcretePassive M_passive2(FW_OPTIONAL_NAME("M_passive2")); + ConcretePassive M::passive2(FW_OPTIONAL_NAME("M::passive2")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- 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); + 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); } void configComponents(const TopologyState& state) { - M_active2.config(); + M::active2.config(); } void setBaseIds() { - M_active1.setIdBase(BaseIds::M_active1); - M_active2.setIdBase(BaseIds::M_active2); - M_active3.setIdBase(BaseIds::M_active3); - M_passive1.setIdBase(BaseIds::M_passive1); - M_passive2.setIdBase(BaseIds::M_passive2); + M::active1.setIdBase(BaseIds::M_active1); + M::active2.setIdBase(BaseIds::M_active2); + M::active3.setIdBase(BaseIds::M_active3); + M::passive1.setIdBase(BaseIds::M_passive1); + M::passive2.setIdBase(BaseIds::M_passive2); } void connectComponents() { // C1 - M_passive1.set_p_OutputPort( + M::passive1.set_p_OutputPort( 0, - M_active1.get_p_InputPort(0) + M::active1.get_p_InputPort(0) ); // C2 - M_passive2.set_p_OutputPort( + M::passive2.set_p_OutputPort( 0, - M_active2.get_p_InputPort(0) + M::active2.get_p_InputPort(0) ); } @@ -88,14 +88,14 @@ namespace M { } void startTasks(const TopologyState& state) { - M_active1.start( + 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( + M::active2.startSpecial(); + M::active3.start( Os::Task::TASK_DEFAULT, // Default priority Os::Task::TASK_DEFAULT, // Default stack size Os::Task::TASK_DEFAULT, // Default CPU @@ -104,19 +104,19 @@ namespace M { } void stopTasks(const TopologyState& state) { - M_active1.exit(); - M_active2.stopSpecial(); - M_active3.exit(); + M::active1.exit(); + M::active2.stopSpecial(); + M::active3.exit(); } void freeThreads(const TopologyState& state) { - (void) M_active1.ActiveComponentBase::join(); - M_active2.freeSpecial(); - (void) M_active3.ActiveComponentBase::join(); + (void) M::active1.ActiveComponentBase::join(); + M::active2.freeSpecial(); + (void) M::active3.ActiveComponentBase::join(); } void tearDownComponents(const TopologyState& state) { - M_active2.tearDown(); + M::active2.tearDown(); } // ---------------------------------------------------------------------- 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 4154a388a..87fb0f285 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp @@ -14,90 +14,121 @@ namespace M { // ---------------------------------------------------------------------- - // Constants + // Component instances // ---------------------------------------------------------------------- + //! active1 + extern Active active1; - namespace ConfigConstants { - namespace M_active2 { - enum { - X = 0, - Y = 1 - }; - } - } +} - namespace BaseIds { - enum { - M_active1 = 0x100, - M_active2 = 0x200, - M_active3 = 0x300, - M_passive1 = 0x300, - M_passive2 = 0x400, - }; - } +namespace M { - namespace CPUs { - enum { - M_active1 = 0, - }; - } + // ---------------------------------------------------------------------- + // Component instances + // ---------------------------------------------------------------------- + //! active2 + extern Active active2; - namespace InstanceIds { - enum { - M_active1, - M_active2, - M_active3, - M_passive1, - M_passive2, - }; - } +} - namespace Priorities { - enum { - M_active1 = 1, - }; - } +namespace M { - namespace QueueSizes { - enum { - M_active1 = 10, - M_active2 = 10, - M_active3 = 10, - }; - } + // ---------------------------------------------------------------------- + // Component instances + // ---------------------------------------------------------------------- + //! active3 + extern Active active3; - namespace StackSizes { - enum { - M_active1 = 1024, - }; - } +} - namespace TaskIds { - enum { - M_active1, - M_active2, - M_active3, - }; - } +namespace M { // ---------------------------------------------------------------------- // Component instances // ---------------------------------------------------------------------- + //! passive1 + extern Passive passive1; + +} + +namespace M { - //! M_active1 - extern Active M_active1; + // ---------------------------------------------------------------------- + // Component instances + // ---------------------------------------------------------------------- + //! passive2 + extern ConcretePassive passive2; - //! M_active2 - extern Active M_active2; +} - //! M_active3 - extern Active M_active3; +// ---------------------------------------------------------------------- +// Constants +// ---------------------------------------------------------------------- - //! M_passive1 - extern Passive M_passive1; +namespace ConfigConstants { + namespace M_active2 { + enum { + X = 0, + Y = 1 + }; + } +} - //! M_passive2 - extern ConcretePassive M_passive2; +namespace BaseIds { + enum { + M_active1 = 0x100, + M_active2 = 0x200, + M_active3 = 0x300, + M_passive1 = 0x300, + M_passive2 = 0x400, + }; +} + +namespace CPUs { + enum { + M_active1 = 0, + }; +} + +namespace InstanceIds { + enum { + M_active1, + M_active2, + M_active3, + M_passive1, + M_passive2, + }; +} + +namespace Priorities { + enum { + M_active1 = 1, + }; +} + +namespace QueueSizes { + enum { + M_active1 = 10, + M_active2 = 10, + M_active3 = 10, + }; +} + +namespace StackSizes { + enum { + M_active1 = 1024, + }; +} + +namespace TaskIds { + enum { + M_active1, + M_active2, + M_active3, + }; +} + +namespace M { // ---------------------------------------------------------------------- // Helper functions 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 2ae0d0618..71e3f7f23 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp @@ -13,17 +13,17 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - C M_c1(FW_OPTIONAL_NAME("M_c1")); + C M::c1(FW_OPTIONAL_NAME("M::c1")); - C M_c2(FW_OPTIONAL_NAME("M_c2")); + C M::c2(FW_OPTIONAL_NAME("M::c2")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - M_c1.init(InstanceIds::M_c1); - M_c2.init(InstanceIds::M_c2); + M::c1.init(InstanceIds::M_c1); + M::c2.init(InstanceIds::M_c2); } void configComponents(const TopologyState& state) { @@ -31,8 +31,8 @@ namespace M { } void setBaseIds() { - M_c1.setIdBase(BaseIds::M_c1); - M_c2.setIdBase(BaseIds::M_c2); + M::c1.setIdBase(BaseIds::M_c1); + M::c2.setIdBase(BaseIds::M_c2); } void connectComponents() { @@ -40,8 +40,8 @@ namespace M { } void regCommands() { - M_c1.regCommandsSpecial(); - M_c2.regCommands(); + M::c1.regCommandsSpecial(); + M::c2.regCommands(); } void readParameters() { 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 62b07b902..0b579dc0c 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp @@ -13,32 +13,42 @@ namespace M { // ---------------------------------------------------------------------- - // Constants + // Component instances // ---------------------------------------------------------------------- + //! c1 + extern C c1; - namespace BaseIds { - enum { - M_c1 = 0x100, - M_c2 = 0x200, - }; - } +} - namespace InstanceIds { - enum { - M_c1, - M_c2, - }; - } +namespace M { // ---------------------------------------------------------------------- // Component instances // ---------------------------------------------------------------------- + //! c2 + extern C c2; + +} - //! M_c1 - extern C M_c1; +// ---------------------------------------------------------------------- +// Constants +// ---------------------------------------------------------------------- - //! M_c2 - extern C M_c2; +namespace BaseIds { + enum { + M_c1 = 0x100, + M_c2 = 0x200, + }; +} + +namespace InstanceIds { + enum { + M_c1, + M_c2, + }; +} + +namespace M { // ---------------------------------------------------------------------- // Helper functions 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 6885ee890..fad922316 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp @@ -37,20 +37,20 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - C M_c1(FW_OPTIONAL_NAME("M_c1")); + C M::c1(FW_OPTIONAL_NAME("M::c1")); - C M_c2(FW_OPTIONAL_NAME("M_c2")); + C M::c2(FW_OPTIONAL_NAME("M::c2")); - Svc::Health M_health(FW_OPTIONAL_NAME("M_health")); + Svc::Health M::health(FW_OPTIONAL_NAME("M::health")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - M_c1.init(InstanceIds::M_c1); - M_c2.init(InstanceIds::M_c2); - M_health.init(InstanceIds::M_health); + M::c1.init(InstanceIds::M_c1); + M::c2.init(InstanceIds::M_c2); + M::health.init(InstanceIds::M_health); } void configComponents(const TopologyState& state) { @@ -58,29 +58,29 @@ namespace M { } void setBaseIds() { - M_health.setIdBase(BaseIds::M_health); - M_c1.setIdBase(BaseIds::M_c1); - M_c2.setIdBase(BaseIds::M_c2); + M::health.setIdBase(BaseIds::M_health); + M::c1.setIdBase(BaseIds::M_c1); + M::c2.setIdBase(BaseIds::M_c2); } void connectComponents() { // Health - M_c1.set_pingOut_OutputPort( + M::c1.set_pingOut_OutputPort( 0, - M_health.get_pingIn_InputPort(0) + M::health.get_pingIn_InputPort(0) ); - M_c2.set_pingOut_OutputPort( + M::c2.set_pingOut_OutputPort( 0, - M_health.get_pingIn_InputPort(1) + M::health.get_pingIn_InputPort(1) ); - M_health.set_pingOut_OutputPort( + M::health.set_pingOut_OutputPort( 0, - M_c1.get_pingIn_InputPort(0) + M::c1.get_pingIn_InputPort(0) ); - M_health.set_pingOut_OutputPort( + M::health.set_pingOut_OutputPort( 1, - M_c2.get_pingIn_InputPort(0) + M::c2.get_pingIn_InputPort(0) ); } 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 ec29fafc2..3b8e7ef21 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp @@ -14,24 +14,54 @@ namespace M { // ---------------------------------------------------------------------- - // Constants + // Component instances // ---------------------------------------------------------------------- + //! c1 + extern C c1; - namespace BaseIds { - enum { - M_health = 0x100, - M_c1 = 0x200, - M_c2 = 0x300, - }; - } +} - namespace InstanceIds { - enum { - M_c1, - M_c2, - M_health, - }; - } +namespace M { + + // ---------------------------------------------------------------------- + // Component instances + // ---------------------------------------------------------------------- + //! c2 + extern C c2; + +} + +namespace M { + + // ---------------------------------------------------------------------- + // Component instances + // ---------------------------------------------------------------------- + //! health + extern Svc::Health health; + +} + +// ---------------------------------------------------------------------- +// Constants +// ---------------------------------------------------------------------- + +namespace BaseIds { + enum { + M_health = 0x100, + M_c1 = 0x200, + M_c2 = 0x300, + }; +} + +namespace InstanceIds { + enum { + M_c1, + M_c2, + M_health, + }; +} + +namespace M { // ---------------------------------------------------------------------- // Component configuration objects @@ -48,19 +78,6 @@ namespace M { } - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- - - //! M_c1 - extern C M_c1; - - //! M_c2 - extern C M_c2; - - //! M_health - extern Svc::Health M_health; - // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- 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 6b35604ef..6e07d55b6 100644 --- a/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp @@ -10,30 +10,29 @@ #include "C.hpp" #include "NestedNamespacesTopologyDefs.hpp" -namespace M { - - // ---------------------------------------------------------------------- - // Constants - // ---------------------------------------------------------------------- - - namespace BaseIds { - enum { - c = 0x100, - }; - } - - namespace InstanceIds { - enum { - c, - }; - } +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- +//! c +extern N::O::C c; + +// ---------------------------------------------------------------------- +// Constants +// ---------------------------------------------------------------------- + +namespace BaseIds { + enum { + c = 0x100, + }; +} - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- +namespace InstanceIds { + enum { + c, + }; +} - //! c - extern N::O::C c; +namespace M { // ---------------------------------------------------------------------- // Helper functions 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 0bda95b21..60a172f58 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp @@ -13,17 +13,17 @@ namespace M { // Component instances // ---------------------------------------------------------------------- - C M_c1(FW_OPTIONAL_NAME("M_c1")); + C M::c1(FW_OPTIONAL_NAME("M::c1")); - C M_c2(FW_OPTIONAL_NAME("M_c2")); + C M::c2(FW_OPTIONAL_NAME("M::c2")); // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- void initComponents(const TopologyState& state) { - M_c1.init(InstanceIds::M_c1); - M_c2.init(InstanceIds::M_c2); + M::c1.init(InstanceIds::M_c1); + M::c2.init(InstanceIds::M_c2); } void configComponents(const TopologyState& state) { @@ -31,8 +31,8 @@ namespace M { } void setBaseIds() { - M_c1.setIdBase(BaseIds::M_c1); - M_c2.setIdBase(BaseIds::M_c2); + M::c1.setIdBase(BaseIds::M_c1); + M::c2.setIdBase(BaseIds::M_c2); } void connectComponents() { @@ -40,17 +40,17 @@ namespace M { } void regCommands() { - M_c1.regCommands(); - M_c2.regCommands(); + M::c1.regCommands(); + M::c2.regCommands(); } void readParameters() { - M_c1.readParamFile(); + M::c1.readParamFile(); } void loadParameters() { - M_c1.loadParamsSpecial(); - M_c2.loadParameters(); + M::c1.loadParamsSpecial(); + M::c2.loadParameters(); } void startTasks(const TopologyState& state) { 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 77efd4cc8..ce95b45e5 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp @@ -13,32 +13,42 @@ namespace M { // ---------------------------------------------------------------------- - // Constants + // Component instances // ---------------------------------------------------------------------- + //! c1 + extern C c1; - namespace BaseIds { - enum { - M_c1 = 0x100, - M_c2 = 0x200, - }; - } +} - namespace InstanceIds { - enum { - M_c1, - M_c2, - }; - } +namespace M { // ---------------------------------------------------------------------- // Component instances // ---------------------------------------------------------------------- + //! c2 + extern C c2; + +} - //! M_c1 - extern C M_c1; +// ---------------------------------------------------------------------- +// Constants +// ---------------------------------------------------------------------- - //! M_c2 - extern C M_c2; +namespace BaseIds { + enum { + M_c1 = 0x100, + M_c2 = 0x200, + }; +} + +namespace InstanceIds { + enum { + M_c1, + M_c2, + }; +} + +namespace M { // ---------------------------------------------------------------------- // Helper functions diff --git a/compiler/tools/fpp-to-cpp/test/top/basic.fpp b/compiler/tools/fpp-to-cpp/test/top/basic.fpp index 066c67e5f..21ca30b8c 100644 --- a/compiler/tools/fpp-to-cpp/test/top/basic.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/basic.fpp @@ -33,31 +33,31 @@ module M { """ phase Phases.instances """ - Active M_active2; + Active M::active2; """ phase Phases.initComponents """ - M_active2.initSpecial(); + M::active2.initSpecial(); """ phase Phases.configComponents """ - M_active2.config(); + M::active2.config(); """ phase Phases.startTasks """ - M_active2.startSpecial(); + M::active2.startSpecial(); """ phase Phases.stopTasks """ - M_active2.stopSpecial(); + M::active2.stopSpecial(); """ phase Phases.freeThreads """ - M_active2.freeSpecial(); + M::active2.freeSpecial(); """ phase Phases.tearDownComponents """ - M_active2.tearDown(); + M::active2.tearDown(); """ } diff --git a/compiler/tools/fpp-to-cpp/test/top/commands.fpp b/compiler/tools/fpp-to-cpp/test/top/commands.fpp index af22b8191..73d50516b 100644 --- a/compiler/tools/fpp-to-cpp/test/top/commands.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/commands.fpp @@ -15,7 +15,7 @@ module M { instance c1: C base id 0x100 { phase Phases.regCommands """ - M_c1.regCommandsSpecial(); + M::c1.regCommandsSpecial(); """ } diff --git a/compiler/tools/fpp-to-cpp/test/top/params.fpp b/compiler/tools/fpp-to-cpp/test/top/params.fpp index 7d62e1ede..23053a8a4 100644 --- a/compiler/tools/fpp-to-cpp/test/top/params.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/params.fpp @@ -19,11 +19,11 @@ module M { instance c1: C base id 0x100 { phase Phases.readParameters """ - M_c1.readParamFile(); + M::c1.readParamFile(); """ phase Phases.loadParameters """ - M_c1.loadParamsSpecial(); + M::c1.loadParamsSpecial(); """ } From a49bc6487d424d3689a6aed014875bd9ae05cf2d Mon Sep 17 00:00:00 2001 From: jwest115 Date: Mon, 15 Jul 2024 17:44:09 -0700 Subject: [PATCH 05/25] move constants back to topology, refactor topology comp instance codegen --- .../TopComponentInstances.scala | 20 ++- .../TopologyCppWriter/TopConfigObjects.scala | 6 +- .../TopologyCppWriter/TopConstants.scala | 16 +-- .../TopologyCppWriter/TopHelperFns.scala | 26 ++-- .../TopologyCppWriter/TopologyCppWriter.scala | 12 +- .../TopologyCppWriterUtils.scala | 6 - .../test/top/BasicTopologyAc.ref.hpp | 135 ++++++++---------- .../test/top/CommandsTopologyAc.ref.hpp | 44 +++--- .../test/top/HealthTopologyAc.ref.hpp | 49 +++---- .../top/NestedNamespacesTopologyAc.ref.hpp | 31 ++-- .../test/top/ParamsTopologyAc.ref.hpp | 44 +++--- 11 files changed, 185 insertions(+), 204 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 5d6395e2b..d784cf3ad 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -12,18 +12,23 @@ case class TopComponentInstances( private val bannerComment = "Component instances" - def getHppLines: List[(List[String], List[Line])] = getDeclLines + def getHppMembers: List[CppDoc.Member] = { + getDeclMembers match { + case Nil => List() + case l => linesMember(CppDocWriter.writeBannerComment(bannerComment)) :: l + } + } def getCppLines: List[Line] = addBannerComment( bannerComment, getDefLines ) - private def getDeclLines = { - def getCode(ci: ComponentInstance): (List[String], List[Line]) = { + private def getDeclMembers = { + def getCode(ci: ComponentInstance): List[CppDoc.Member] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) val instLines = Line.addPrefixLine (line(s"//! $instanceName")) ( lines( s"extern $implType $instanceName;" @@ -33,15 +38,16 @@ case class TopComponentInstances( case true => cppQualifiedName.substring(0, cppQualifiedName.lastIndexOf("::")).split("::").toList case false => List() } - (qualIdentList, addBannerComment(bannerComment, instLines)) + + wrapInNamespaces(qualIdentList, List(linesMember(Line.blank :: instLines))) } - instances.map(getCode) + instances.flatMap(getCode) } private def getDefLines = { def getCode(ci: ComponentInstance): List[Line] = { val implType = getImplType(ci) - val instanceName = getNameAsCppQualified(ci.qualifiedName) + val instanceName = CppWriter.writeQualifiedName(ci.qualifiedName) getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( lines( s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConfigObjects.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConfigObjects.scala index 3ec15dcae..2e6676810 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConfigObjects.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConfigObjects.scala @@ -44,7 +44,7 @@ case class TopConfigObjects( flattenWithBlankPrefix( pairs.map { case (ci, code) => wrapInNamespace( - getNameAsIdent(ci.qualifiedName), + CppWriter.identFromQualifiedName(ci.qualifiedName), code ) } @@ -77,7 +77,7 @@ case class TopConfigObjects( flattenWithBlankPrefix( pairs.map { case (ci, code) => wrapInNamespace( - getNameAsIdent(ci.qualifiedName), + CppWriter.identFromQualifiedName(ci.qualifiedName), code ) } @@ -99,7 +99,7 @@ case class TopConfigObjects( // Entry for connected port case Some(ci) => val name = ci.qualifiedName - val ident = getNameAsIdent(name) + val ident = CppWriter.identFromQualifiedName(name) List( s"PingEntries::$ident::WARN,", s"PingEntries::$ident::FATAL,", diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConstants.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConstants.scala index df23fe47f..4be494cfe 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConstants.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopConstants.scala @@ -37,7 +37,7 @@ case class TopConstants( "ConfigConstants", pairs.flatMap { case (ci, code) => wrapInNamespace( - getNameAsIdent(ci.qualifiedName), + CppWriter.identFromQualifiedName(ci.qualifiedName), lines(code) ) } @@ -62,7 +62,7 @@ case class TopConstants( generateEnum( "BaseIds", ci => { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) val value = CppWriter.writeId(ci.baseId) Some(s"$name = $value") }, @@ -74,7 +74,7 @@ case class TopConstants( "CPUs", ci => ci.cpu.map( cpu => { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) s"$name = $cpu" } ) @@ -84,7 +84,7 @@ case class TopConstants( generateEnum( "InstanceIds", ci => { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) Some(s"$name") } ) @@ -94,7 +94,7 @@ case class TopConstants( "Priorities", ci => ci.priority.map( priority => { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) s"$name = $priority" } ) @@ -105,7 +105,7 @@ case class TopConstants( "QueueSizes", ci => ci.queueSize.map( queueSize => { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) s"$name = $queueSize" } ) @@ -116,7 +116,7 @@ case class TopConstants( "StackSizes", ci => ci.stackSize.map( stackSize => { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) s"$name = $stackSize" } ) @@ -130,7 +130,7 @@ case class TopConstants( val kind = c.aNode._2.data.kind kind match { case Ast.ComponentKind.Active => - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) Some(name.toString) case _ => None } diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala index a4561d467..57c0d4525 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopHelperFns.scala @@ -51,8 +51,8 @@ case class TopHelperFns( private def getInitComponentsFn = { def getCode(ci: ComponentInstance): List[Line] = { - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) - val name = getNameAsIdent(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) getCodeLinesForPhase (CppWriter.Phases.initComponents) (ci).getOrElse( ci.component.aNode._2.data.kind match { case Ast.ComponentKind.Passive => @@ -74,7 +74,7 @@ case class TopHelperFns( private def getConfigComponentsFn = { def getCode(ci: ComponentInstance): List[Line] = { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) getCodeLinesForPhase (CppWriter.Phases.configComponents) (ci).getOrElse(Nil) } val name = "configComponents" @@ -90,8 +90,8 @@ case class TopHelperFns( private def getSetBaseIdsFn = { val name = "setBaseIds" val body = instancesByBaseId.map(ci => { - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) - val name = getNameAsIdent(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) line(s"$cppQualifiedName.setIdBase(BaseIds::$name);") }) val memberOpt = getFnMemberOpt( @@ -105,7 +105,7 @@ case class TopHelperFns( private def getConnectComponentsFn = { def getPortInfo(pii: PortInstanceIdentifier, c: Connection) = { - val cppQualifiedName = getNameAsCppQualified(pii.componentInstance.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(pii.componentInstance.qualifiedName) val portName = pii.portInstance.getUnqualifiedName val portNumber = t.getPortNumber(pii.portInstance, c).get (cppQualifiedName, portName, portNumber) @@ -142,7 +142,7 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = { getCodeLinesForPhase (CppWriter.Phases.regCommands) (ci).getOrElse( if (hasCommands(ci)) { - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) lines(s"$cppQualifiedName.regCommands();") } else Nil @@ -175,7 +175,7 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = { getCodeLinesForPhase (CppWriter.Phases.loadParameters) (ci).getOrElse( if (hasParams(ci)) { - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) lines(s"$cppQualifiedName.loadParameters();") } else Nil @@ -195,8 +195,8 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = getCodeLinesForPhase (CppWriter.Phases.startTasks) (ci).getOrElse { if (isActive(ci)) { - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) - val name = getNameAsIdent(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) val priority = ci.priority match { case Some(_) => s"static_cast(Priorities::$name)," case None => "Os::Task::TASK_DEFAULT, // Default priority" @@ -238,7 +238,7 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = getCodeLinesForPhase (CppWriter.Phases.stopTasks) (ci).getOrElse { if (isActive(ci)) { - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) lines(s"$cppQualifiedName.exit();") } else Nil @@ -257,7 +257,7 @@ case class TopHelperFns( def getCode(ci: ComponentInstance): List[Line] = getCodeLinesForPhase (CppWriter.Phases.freeThreads) (ci).getOrElse { if (isActive(ci)) { - val cppQualifiedName = getNameAsCppQualified(ci.qualifiedName) + val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) lines(s"(void) $cppQualifiedName.ActiveComponentBase::join();") } else Nil @@ -274,7 +274,7 @@ case class TopHelperFns( private def getTearDownComponentsFn = { def getCode(ci: ComponentInstance): List[Line] = { - val name = getNameAsIdent(ci.qualifiedName) + val name = CppWriter.identFromQualifiedName(ci.qualifiedName) getCodeLinesForPhase (CppWriter.Phases.tearDownComponents) (ci).getOrElse(Nil) } val name = "tearDownComponents" diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index f58aef791..4cedaeb65 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -34,9 +34,12 @@ case class TopologyCppWriter( ).sorted linesMember(Line.blank :: strings.map(line)) } - val hppLines = linesMember(TopConfigObjects(s, aNode).getHppLines) + val hppLines = linesMember( + TopConstants(s, aNode).getLines ++ + TopConfigObjects(s, aNode).getHppLines + ) val hppConstantLines = linesMember(TopConstants(s, aNode).getLines) - val hppComponentInstanceLines = TopComponentInstances(s, aNode).getHppLines + val hppComponentInstanceMembers = TopComponentInstances(s, aNode).getHppMembers val cppIncludes = { val fileName = s"${ComputeCppFiles.FileNames.getTopology(name)}.hpp" linesMember( @@ -61,12 +64,9 @@ case class TopologyCppWriter( val setupTeardownFns = TopSetupTeardownFns(s, aNode, helperFnNames). getMembers val defs = hppLines :: cppLines :: (helperFns ++ setupTeardownFns) - val wrappedHppComponentInstances = hppComponentInstanceLines.flatMap((compInstNamespaceIdentList, hppCompInstLines) => - wrapInNamespaces(compInstNamespaceIdentList, List(linesMember(hppCompInstLines)))) List( List(hppIncludes, cppIncludes), - wrappedHppComponentInstances, - List(hppConstantLines), + hppComponentInstanceMembers, wrapInNamespaces(namespaceIdentList, defs) ).flatten } 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 ecd14b9d5..90aa80067 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriterUtils.scala @@ -57,12 +57,6 @@ abstract class TopologyCppWriterUtils( name.shortName(ens) } - def getNameAsIdent(name: Name.Qualified): String = - CppWriter.identFromQualifiedName(name) - - def getNameAsCppQualified(name: Name.Qualified): String = - CppWriter.writeQualifiedName(name) - def getNameAsQualIdent(name: Name.Qualified): String = CppWriter.writeQualifiedName(getShortName(name)) 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 87fb0f285..b98140a2f 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp @@ -11,11 +11,12 @@ #include "BasicTopologyDefs.hpp" #include "Passive.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! active1 extern Active active1; @@ -23,9 +24,6 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! active2 extern Active active2; @@ -33,9 +31,6 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! active3 extern Active active3; @@ -43,9 +38,6 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! passive1 extern Passive passive1; @@ -53,82 +45,79 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! passive2 extern ConcretePassive passive2; } -// ---------------------------------------------------------------------- -// Constants -// ---------------------------------------------------------------------- +namespace M { + + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- -namespace ConfigConstants { - namespace M_active2 { + namespace ConfigConstants { + namespace M_active2 { + enum { + X = 0, + Y = 1 + }; + } + } + + namespace BaseIds { enum { - X = 0, - Y = 1 + M_active1 = 0x100, + M_active2 = 0x200, + M_active3 = 0x300, + M_passive1 = 0x300, + M_passive2 = 0x400, }; } -} - -namespace BaseIds { - enum { - M_active1 = 0x100, - M_active2 = 0x200, - M_active3 = 0x300, - M_passive1 = 0x300, - M_passive2 = 0x400, - }; -} - -namespace CPUs { - enum { - M_active1 = 0, - }; -} -namespace InstanceIds { - enum { - M_active1, - M_active2, - M_active3, - M_passive1, - M_passive2, - }; -} + namespace CPUs { + enum { + M_active1 = 0, + }; + } -namespace Priorities { - enum { - M_active1 = 1, - }; -} + namespace InstanceIds { + enum { + M_active1, + M_active2, + M_active3, + M_passive1, + M_passive2, + }; + } -namespace QueueSizes { - enum { - M_active1 = 10, - M_active2 = 10, - M_active3 = 10, - }; -} + namespace Priorities { + enum { + M_active1 = 1, + }; + } -namespace StackSizes { - enum { - M_active1 = 1024, - }; -} + namespace QueueSizes { + enum { + M_active1 = 10, + M_active2 = 10, + M_active3 = 10, + }; + } -namespace TaskIds { - enum { - M_active1, - M_active2, - M_active3, - }; -} + namespace StackSizes { + enum { + M_active1 = 1024, + }; + } -namespace M { + namespace TaskIds { + enum { + M_active1, + M_active2, + M_active3, + }; + } // ---------------------------------------------------------------------- // Helper functions 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 0b579dc0c..684f55274 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp @@ -10,11 +10,12 @@ #include "C.hpp" #include "CommandsTopologyDefs.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! c1 extern C c1; @@ -22,33 +23,30 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! c2 extern C c2; } -// ---------------------------------------------------------------------- -// Constants -// ---------------------------------------------------------------------- - -namespace BaseIds { - enum { - M_c1 = 0x100, - M_c2 = 0x200, - }; -} +namespace M { -namespace InstanceIds { - enum { - M_c1, - M_c2, - }; -} + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- -namespace M { + namespace BaseIds { + enum { + M_c1 = 0x100, + M_c2 = 0x200, + }; + } + + namespace InstanceIds { + enum { + M_c1, + M_c2, + }; + } // ---------------------------------------------------------------------- // Helper functions 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 3b8e7ef21..c3ab0dbc5 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp @@ -11,11 +11,12 @@ #include "Health.hpp" #include "HealthTopologyDefs.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! c1 extern C c1; @@ -23,9 +24,6 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! c2 extern C c2; @@ -33,35 +31,32 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! health extern Svc::Health health; } -// ---------------------------------------------------------------------- -// Constants -// ---------------------------------------------------------------------- +namespace M { -namespace BaseIds { - enum { - M_health = 0x100, - M_c1 = 0x200, - M_c2 = 0x300, - }; -} + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- -namespace InstanceIds { - enum { - M_c1, - M_c2, - M_health, - }; -} + namespace BaseIds { + enum { + M_health = 0x100, + M_c1 = 0x200, + M_c2 = 0x300, + }; + } -namespace M { + namespace InstanceIds { + enum { + M_c1, + M_c2, + M_health, + }; + } // ---------------------------------------------------------------------- // Component configuration objects 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 6e07d55b6..c4b43049e 100644 --- a/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.hpp @@ -13,26 +13,27 @@ // ---------------------------------------------------------------------- // Component instances // ---------------------------------------------------------------------- + //! c extern N::O::C c; -// ---------------------------------------------------------------------- -// Constants -// ---------------------------------------------------------------------- - -namespace BaseIds { - enum { - c = 0x100, - }; -} +namespace M { -namespace InstanceIds { - enum { - c, - }; -} + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- -namespace M { + namespace BaseIds { + enum { + c = 0x100, + }; + } + + namespace InstanceIds { + enum { + c, + }; + } // ---------------------------------------------------------------------- // Helper functions 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 ce95b45e5..575c1ff28 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp @@ -10,11 +10,12 @@ #include "C.hpp" #include "ParamsTopologyDefs.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! c1 extern C c1; @@ -22,33 +23,30 @@ namespace M { namespace M { - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- //! c2 extern C c2; } -// ---------------------------------------------------------------------- -// Constants -// ---------------------------------------------------------------------- - -namespace BaseIds { - enum { - M_c1 = 0x100, - M_c2 = 0x200, - }; -} +namespace M { -namespace InstanceIds { - enum { - M_c1, - M_c2, - }; -} + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- -namespace M { + namespace BaseIds { + enum { + M_c1 = 0x100, + M_c2 = 0x200, + }; + } + + namespace InstanceIds { + enum { + M_c1, + M_c2, + }; + } // ---------------------------------------------------------------------- // Helper functions From 6ae868c6a79d058d551314e6961176a61085dd78 Mon Sep 17 00:00:00 2001 From: jwest115 Date: Tue, 16 Jul 2024 10:11:22 -0700 Subject: [PATCH 06/25] update fpp-to-cpp `HealthTopologyDefs` --- .../test/top/check-cpp-dir/Health/HealthTopologyDefs.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/tools/fpp-to-cpp/test/top/check-cpp-dir/Health/HealthTopologyDefs.hpp b/compiler/tools/fpp-to-cpp/test/top/check-cpp-dir/Health/HealthTopologyDefs.hpp index 0b6e0187e..c9d16bebf 100644 --- a/compiler/tools/fpp-to-cpp/test/top/check-cpp-dir/Health/HealthTopologyDefs.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/check-cpp-dir/Health/HealthTopologyDefs.hpp @@ -3,13 +3,13 @@ namespace M { typedef int TopologyState; namespace PingEntries { - namespace c1 { + namespace M_c1 { enum { WARN = 1, FATAL = 2 }; } - namespace c2 { + namespace M_c2 { enum { WARN = 1, FATAL = 2 From 9a6d482d9944b8259f9e320eb7776adcce1c4ab6 Mon Sep 17 00:00:00 2001 From: jwest115 Date: Wed, 17 Jul 2024 16:17:29 -0700 Subject: [PATCH 07/25] add fpp-to-dict test case --- ...alifiedCompInstTopologyDictionary.ref.json | 36 ++--------------- ...alifiedCompInstTopologyDictionary.ref.json | 36 ++--------------- .../top/unqualifiedComponentInstances.fpp | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 66 deletions(-) create mode 100644 compiler/tools/fpp-to-dict/test/top/unqualifiedComponentInstances.fpp diff --git a/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json index 864d85175..8e64ae12d 100644 --- a/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/QualifiedCompInstTopologyDictionary.ref.json @@ -38,7 +38,7 @@ ], "commands" : [ { - "name" : "M.c1.P_PARAM_SET", + "name" : "M.I1.P_PARAM_SET", "commandKind" : "set", "opcode" : 256, "formalParams" : [ @@ -53,51 +53,21 @@ ] }, { - "name" : "M.c1.P_PARAM_SAVE", + "name" : "M.I1.P_PARAM_SAVE", "commandKind" : "save", "opcode" : 257, "formalParams" : [ ] - }, - { - "name" : "M.c2.P_PARAM_SET", - "commandKind" : "set", - "opcode" : 512, - "formalParams" : [ - { - "name" : "val", - "type" : { - "name" : "M.E1", - "kind" : "qualifiedIdentifier" - }, - "ref" : false - } - ] - }, - { - "name" : "M.c2.P_PARAM_SAVE", - "commandKind" : "save", - "opcode" : 513, - "formalParams" : [ - ] } ], "parameters" : [ { - "name" : "M.c1.P", + "name" : "M.I1.P", "type" : { "name" : "M.E1", "kind" : "qualifiedIdentifier" }, "id" : 256 - }, - { - "name" : "M.c2.P", - "type" : { - "name" : "M.E1", - "kind" : "qualifiedIdentifier" - }, - "id" : 512 } ], "events" : [ diff --git a/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json b/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json index 13824f733..4cfebfd39 100644 --- a/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json +++ b/compiler/tools/fpp-to-dict/test/top/UnqualifiedCompInstTopologyDictionary.ref.json @@ -38,7 +38,7 @@ ], "commands" : [ { - "name" : "c3.P_PARAM_SET", + "name" : "I2.P_PARAM_SET", "commandKind" : "set", "opcode" : 768, "formalParams" : [ @@ -53,51 +53,21 @@ ] }, { - "name" : "c3.P_PARAM_SAVE", + "name" : "I2.P_PARAM_SAVE", "commandKind" : "save", "opcode" : 769, "formalParams" : [ ] - }, - { - "name" : "c4.P_PARAM_SET", - "commandKind" : "set", - "opcode" : 1024, - "formalParams" : [ - { - "name" : "val", - "type" : { - "name" : "M.E1", - "kind" : "qualifiedIdentifier" - }, - "ref" : false - } - ] - }, - { - "name" : "c4.P_PARAM_SAVE", - "commandKind" : "save", - "opcode" : 1025, - "formalParams" : [ - ] } ], "parameters" : [ { - "name" : "c3.P", + "name" : "I2.P", "type" : { "name" : "M.E1", "kind" : "qualifiedIdentifier" }, "id" : 768 - }, - { - "name" : "c4.P", - "type" : { - "name" : "M.E1", - "kind" : "qualifiedIdentifier" - }, - "id" : 1024 } ], "events" : [ diff --git a/compiler/tools/fpp-to-dict/test/top/unqualifiedComponentInstances.fpp b/compiler/tools/fpp-to-dict/test/top/unqualifiedComponentInstances.fpp new file mode 100644 index 000000000..f8c6d0a96 --- /dev/null +++ b/compiler/tools/fpp-to-dict/test/top/unqualifiedComponentInstances.fpp @@ -0,0 +1,40 @@ +module M { + + # enums + enum E1: U32 { + X = 0 + Y = 1 + Z = 2 + } default X + + passive component C { + + command recv port cmdOut + + command reg port cmdRegOut + + command resp port cmdResponseIn + + param P: M.E1 + + param get port prmGetOut + + param set port prmSetOut + } + + instance I1: C base id 0x100 +} + +topology QualifiedCompInst { + + instance M.I1 + +} + +instance I2: M.C base id 0x300 + +topology UnqualifiedCompInst { + + instance I2 + +} From 70fbd40e6d26f1fb45d19d7c76bf8522c8ec90ec Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Thu, 18 Jul 2024 12:03:29 -0700 Subject: [PATCH 08/25] Refactor TopComponentInstances --- .../TopComponentInstances.scala | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index d784cf3ad..ef8b48aea 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -13,10 +13,11 @@ case class TopComponentInstances( private val bannerComment = "Component instances" def getHppMembers: List[CppDoc.Member] = { - getDeclMembers match { - case Nil => List() - case l => linesMember(CppDocWriter.writeBannerComment(bannerComment)) :: l - } + val declMembers = getDeclMembers + lazy val commentMember = + linesMember(CppDocWriter.writeBannerComment(bannerComment)) + lazy val members = commentMember :: declMembers + guardedList (!declMembers.isEmpty) (members) } def getCppLines: List[Line] = addBannerComment( @@ -28,18 +29,12 @@ case class TopComponentInstances( def getCode(ci: ComponentInstance): List[CppDoc.Member] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName - val cppQualifiedName = CppWriter.writeQualifiedName(ci.qualifiedName) - val instLines = Line.addPrefixLine (line(s"//! $instanceName")) ( - lines( - s"extern $implType $instanceName;" - ) + val instLines = lines( + s"""| + |//! $instanceName + |extern $implType $instanceName;""" ) - val qualIdentList = cppQualifiedName contains "::" match { - case true => cppQualifiedName.substring(0, cppQualifiedName.lastIndexOf("::")).split("::").toList - case false => List() - } - - wrapInNamespaces(qualIdentList, List(linesMember(Line.blank :: instLines))) + wrapInNamespaces(ci.qualifiedName.qualifier, List(linesMember(instLines))) } instances.flatMap(getCode) } From 97aaa7b10c0fc3073e300357ad86eca5053f3021 Mon Sep 17 00:00:00 2001 From: jwest115 Date: Mon, 29 Jul 2024 11:06:38 -0700 Subject: [PATCH 09/25] fix comp inst defs in topology cpp --- .../codegen/CppWriter/CppDocHppWriter.scala | 17 ++++--- .../TopComponentInstances.scala | 25 ++++++---- .../TopologyCppWriter/TopologyCppWriter.scala | 9 ++-- .../test/top/BasicTopologyAc.ref.cpp | 47 +++++++++++++------ .../test/top/CommandsTopologyAc.ref.cpp | 18 +++++-- .../test/top/HealthTopologyAc.ref.cpp | 32 +++++++++---- .../top/NestedNamespacesTopologyAc.ref.cpp | 10 ++-- .../test/top/ParamsTopologyAc.ref.cpp | 18 +++++-- 8 files changed, 115 insertions(+), 61 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala index 29903b1ef..d29c0f4cb 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala @@ -171,11 +171,14 @@ object CppDocHppWriter extends CppDocWriter { } override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = { - val name = namespace.name - val startLines = List(Line.blank, line(s"namespace $name {")) - val outputLines = namespace.members.map(visitNamespaceMember(in, _)).flatten - val endLines = List(Line.blank, line("}")) - startLines ++ outputLines.map(indentIn(_)) ++ endLines + namespace.members.flatMap(visitNamespaceMember(in, _)) match { + case Nil => Nil + case outputLines => { + val name = namespace.name + val startLines = List(Line.blank, line(s"namespace $name {")) + val endLines = List(Line.blank, line("}")) + startLines ++ outputLines.map(indentIn(_)) ++ endLines + } + } } - -} +} \ No newline at end of file diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index ef8b48aea..6fc0e314c 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -20,10 +20,13 @@ case class TopComponentInstances( guardedList (!declMembers.isEmpty) (members) } - def getCppLines: List[Line] = addBannerComment( - bannerComment, - getDefLines - ) + def getCppMembers: List[CppDoc.Member] = { + val defMembers = getDefMembers + lazy val commentMember = + linesMember(CppDocWriter.writeBannerComment(bannerComment), CppDoc.Lines.Cpp) + lazy val members = commentMember :: defMembers + guardedList(!defMembers.isEmpty) (members) + } private def getDeclMembers = { def getCode(ci: ComponentInstance): List[CppDoc.Member] = { @@ -39,17 +42,19 @@ case class TopComponentInstances( instances.flatMap(getCode) } - private def getDefLines = { - def getCode(ci: ComponentInstance): List[Line] = { + private def getDefMembers = { + def getCode(ci: ComponentInstance): List[CppDoc.Member] = { val implType = getImplType(ci) - val instanceName = CppWriter.writeQualifiedName(ci.qualifiedName) - getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( + val instanceName = ci.getUnqualifiedName + val instLines = getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( lines( - s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" + s"""| + |$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));""" ) ) + wrapInNamespaces(ci.qualifiedName.qualifier, List(linesMember(instLines, CppDoc.Lines.Cpp))) } - flattenWithBlankPrefix(instances.map(getCode)) + instances.flatMap(getCode) } private def getImplType(ci: ComponentInstance) = { diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index 4cedaeb65..77ef8699d 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -50,13 +50,11 @@ case class TopologyCppWriter( CppDoc.Lines.Cpp ) } + val cppComponentInstanceMembers = TopComponentInstances(s, aNode).getCppMembers val cppLines = linesMember( Line.blank :: - List.concat( - addBlankPostfix( - TopConfigObjects(s, aNode).getCppLines, - ), - TopComponentInstances(s, aNode).getCppLines + addBlankPostfix( + TopConfigObjects(s, aNode).getCppLines, ), CppDoc.Lines.Cpp ) @@ -67,6 +65,7 @@ case class TopologyCppWriter( List( List(hppIncludes, cppIncludes), hppComponentInstanceMembers, + cppComponentInstanceMembers, wrapInNamespaces(namespaceIdentList, defs) ).flatten } 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 65969e92c..9148f6454 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -6,6 +6,39 @@ #include "BasicTopologyAc.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + +namespace M { + + Active active1(FW_OPTIONAL_NAME("active1")); + +} + +namespace M { + Active M::active2; + +} + +namespace M { + + Active active3(FW_OPTIONAL_NAME("active3")); + +} + +namespace M { + + Passive passive1(FW_OPTIONAL_NAME("passive1")); + +} + +namespace M { + + ConcretePassive passive2(FW_OPTIONAL_NAME("passive2")); + +} + namespace M { @@ -22,20 +55,6 @@ namespace M { } - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- - - Active M::active1(FW_OPTIONAL_NAME("M::active1")); - - Active M::active2; - - Active M::active3(FW_OPTIONAL_NAME("M::active3")); - - Passive M::passive1(FW_OPTIONAL_NAME("M::passive1")); - - ConcretePassive M::passive2(FW_OPTIONAL_NAME("M::passive2")); - // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- 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 71e3f7f23..c7006a2e4 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp @@ -6,16 +6,24 @@ #include "CommandsTopologyAc.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + namespace M { + C c1(FW_OPTIONAL_NAME("c1")); - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- +} + +namespace M { + + C c2(FW_OPTIONAL_NAME("c2")); - C M::c1(FW_OPTIONAL_NAME("M::c1")); +} + +namespace M { - C M::c2(FW_OPTIONAL_NAME("M::c2")); // ---------------------------------------------------------------------- // Helper functions 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 fad922316..32f9ac79c 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp @@ -6,6 +6,28 @@ #include "HealthTopologyAc.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + +namespace M { + + C c1(FW_OPTIONAL_NAME("c1")); + +} + +namespace M { + + C c2(FW_OPTIONAL_NAME("c2")); + +} + +namespace M { + + Svc::Health health(FW_OPTIONAL_NAME("health")); + +} + namespace M { @@ -33,16 +55,6 @@ namespace M { } - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- - - C M::c1(FW_OPTIONAL_NAME("M::c1")); - - C M::c2(FW_OPTIONAL_NAME("M::c2")); - - Svc::Health M::health(FW_OPTIONAL_NAME("M::health")); - // ---------------------------------------------------------------------- // Helper functions // ---------------------------------------------------------------------- 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 0e63afa0a..f7953d5e9 100644 --- a/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/NestedNamespacesTopologyAc.ref.cpp @@ -6,14 +6,14 @@ #include "NestedNamespacesTopologyAc.hpp" -namespace M { +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- +N::O::C c(FW_OPTIONAL_NAME("c")); - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- +namespace M { - N::O::C c(FW_OPTIONAL_NAME("c")); // ---------------------------------------------------------------------- // Helper functions 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 60a172f58..54b862eed 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp @@ -6,16 +6,24 @@ #include "ParamsTopologyAc.hpp" +// ---------------------------------------------------------------------- +// Component instances +// ---------------------------------------------------------------------- + namespace M { + C c1(FW_OPTIONAL_NAME("c1")); - // ---------------------------------------------------------------------- - // Component instances - // ---------------------------------------------------------------------- +} + +namespace M { + + C c2(FW_OPTIONAL_NAME("c2")); - C M::c1(FW_OPTIONAL_NAME("M::c1")); +} + +namespace M { - C M::c2(FW_OPTIONAL_NAME("M::c2")); // ---------------------------------------------------------------------- // Helper functions From 1792dbce813d5fbecafba7aef497dfe0c32da8e8 Mon Sep 17 00:00:00 2001 From: jwest115 Date: Mon, 29 Jul 2024 11:31:02 -0700 Subject: [PATCH 10/25] fix phase instance in basic.fpp unit test --- compiler/tools/fpp-to-cpp/test/top/basic.fpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/tools/fpp-to-cpp/test/top/basic.fpp b/compiler/tools/fpp-to-cpp/test/top/basic.fpp index 21ca30b8c..f0daaa2a4 100644 --- a/compiler/tools/fpp-to-cpp/test/top/basic.fpp +++ b/compiler/tools/fpp-to-cpp/test/top/basic.fpp @@ -33,7 +33,7 @@ module M { """ phase Phases.instances """ - Active M::active2; + Active active2; """ phase Phases.initComponents """ From 3721deae64b28a991b21ff1f0d8bd4dae0b9b4e8 Mon Sep 17 00:00:00 2001 From: jwest115 Date: Mon, 29 Jul 2024 11:32:03 -0700 Subject: [PATCH 11/25] add updated ref file --- compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9148f6454..c238b683a 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -17,7 +17,7 @@ namespace M { } namespace M { - Active M::active2; + Active active2; } From 652c1408e28423a84873909ea4209aaca70d5569 Mon Sep 17 00:00:00 2001 From: jwest115 Date: Mon, 29 Jul 2024 17:29:50 -0700 Subject: [PATCH 12/25] refactor wrap cpp/hpp lines in namespaces --- .../codegen/CppWriter/CppDocCppWriter.scala | 15 +++--- .../codegen/CppWriter/CppDocHppWriter.scala | 15 +++--- .../codegen/CppWriter/CppWriterUtils.scala | 9 ++++ .../TopComponentInstances.scala | 48 ++++++++----------- .../TopologyCppWriter/TopologyCppWriter.scala | 8 ++-- .../test/top/BasicTopologyAc.ref.cpp | 9 ---- .../test/top/BasicTopologyAc.ref.hpp | 10 ---- .../test/top/CommandsTopologyAc.ref.cpp | 4 -- .../test/top/CommandsTopologyAc.ref.hpp | 4 -- .../test/top/HealthTopologyAc.ref.cpp | 6 --- .../test/top/HealthTopologyAc.ref.hpp | 6 --- .../test/top/ParamsTopologyAc.ref.cpp | 4 -- .../test/top/ParamsTopologyAc.ref.hpp | 4 -- 13 files changed, 45 insertions(+), 97 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala index 78329f243..19b6b668d 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala @@ -159,14 +159,11 @@ object CppDocCppWriter extends CppDocWriter { case _ => writeSelectedLines(in, lines.cppFileNameBaseOpt, lines.content) } - override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = - namespace.members.flatMap(visitNamespaceMember(in, _)) match { - case Nil => Nil - case outputLines => - val name = namespace.name - List(Line.blank, line(s"namespace $name {")) ++ - outputLines.map(indentIn(_)) ++ - List(Line.blank, line("}")) - } + override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = { + val name = namespace.name + List(Line.blank, line(s"namespace $name {")) ++ + namespace.members.flatMap(visitNamespaceMember(in, _)).map(indentIn(_)) ++ + List(Line.blank, line("}")) + } } diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala index d29c0f4cb..093d8a487 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala @@ -171,14 +171,11 @@ object CppDocHppWriter extends CppDocWriter { } override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = { - namespace.members.flatMap(visitNamespaceMember(in, _)) match { - case Nil => Nil - case outputLines => { - val name = namespace.name - val startLines = List(Line.blank, line(s"namespace $name {")) - val endLines = List(Line.blank, line("}")) - startLines ++ outputLines.map(indentIn(_)) ++ endLines - } - } + val name = namespace.name + val startLines = List(Line.blank, line(s"namespace $name {")) + val outputLines = namespace.members.flatMap(visitNamespaceMember(in, _)) + val endLines = List(Line.blank, line("}")) + startLines ++ outputLines.map(indentIn(_)) ++ endLines } + } \ No newline at end of file diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala index f840e0aa8..1e55cc3de 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala @@ -413,6 +413,15 @@ trait CppWriterUtils extends LineUtils { List(namespaceMember(head, wrapInNamespaces(tail, members))) } + def wrapInNamespaceLines( + namespaceNames: List[String], + ll: List[Line] + ): List[Line] = namespaceNames match { + case Nil => ll + case head :: tail => + wrapInScope(s"namespace $head {", wrapInNamespaceLines(tail, ll), "}") + } + } object CppWriterUtils { diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 6fc0e314c..6329b0826 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -12,49 +12,41 @@ case class TopComponentInstances( private val bannerComment = "Component instances" - def getHppMembers: List[CppDoc.Member] = { - val declMembers = getDeclMembers - lazy val commentMember = - linesMember(CppDocWriter.writeBannerComment(bannerComment)) - lazy val members = commentMember :: declMembers - guardedList (!declMembers.isEmpty) (members) - } - - def getCppMembers: List[CppDoc.Member] = { - val defMembers = getDefMembers - lazy val commentMember = - linesMember(CppDocWriter.writeBannerComment(bannerComment), CppDoc.Lines.Cpp) - lazy val members = commentMember :: defMembers - guardedList(!defMembers.isEmpty) (members) - } - - private def getDeclMembers = { - def getCode(ci: ComponentInstance): List[CppDoc.Member] = { + def getHppLines: List[Line] = addBannerComment( + bannerComment, + getDeclLines + ) + + def getCppLines: List[Line] = addBannerComment( + bannerComment, + getDefLines + ) + + private def getDeclLines = { + def getCode(ci: ComponentInstance): List[Line] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName val instLines = lines( - s"""| - |//! $instanceName + s"""|//! $instanceName |extern $implType $instanceName;""" ) - wrapInNamespaces(ci.qualifiedName.qualifier, List(linesMember(instLines))) + wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) } - instances.flatMap(getCode) + flattenWithBlankPrefix(instances.map(getCode)) } - private def getDefMembers = { - def getCode(ci: ComponentInstance): List[CppDoc.Member] = { + private def getDefLines = { + def getCode(ci: ComponentInstance): List[Line] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName val instLines = getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( lines( - s"""| - |$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));""" + s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" ) ) - wrapInNamespaces(ci.qualifiedName.qualifier, List(linesMember(instLines, CppDoc.Lines.Cpp))) + wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) } - instances.flatMap(getCode) + flattenWithBlankPrefix(instances.map(getCode)) } private def getImplType(ci: ComponentInstance) = { diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index 77ef8699d..126722629 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -39,7 +39,6 @@ case class TopologyCppWriter( TopConfigObjects(s, aNode).getHppLines ) val hppConstantLines = linesMember(TopConstants(s, aNode).getLines) - val hppComponentInstanceMembers = TopComponentInstances(s, aNode).getHppMembers val cppIncludes = { val fileName = s"${ComputeCppFiles.FileNames.getTopology(name)}.hpp" linesMember( @@ -50,7 +49,6 @@ case class TopologyCppWriter( CppDoc.Lines.Cpp ) } - val cppComponentInstanceMembers = TopComponentInstances(s, aNode).getCppMembers val cppLines = linesMember( Line.blank :: addBlankPostfix( @@ -64,8 +62,10 @@ case class TopologyCppWriter( val defs = hppLines :: cppLines :: (helperFns ++ setupTeardownFns) List( List(hppIncludes, cppIncludes), - hppComponentInstanceMembers, - cppComponentInstanceMembers, + List( + linesMember(TopComponentInstances(s, aNode).getHppLines), + linesMember(TopComponentInstances(s, aNode).getCppLines, CppDoc.Lines.Cpp) + ), wrapInNamespaces(namespaceIdentList, defs) ).flatten } 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 c238b683a..809172044 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -11,32 +11,23 @@ // ---------------------------------------------------------------------- namespace M { - Active active1(FW_OPTIONAL_NAME("active1")); - } namespace M { Active active2; - } namespace M { - Active active3(FW_OPTIONAL_NAME("active3")); - } namespace M { - Passive passive1(FW_OPTIONAL_NAME("passive1")); - } namespace M { - ConcretePassive passive2(FW_OPTIONAL_NAME("passive2")); - } namespace M { 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 b98140a2f..828d813f9 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp @@ -16,38 +16,28 @@ // ---------------------------------------------------------------------- namespace M { - //! active1 extern Active active1; - } namespace M { - //! active2 extern Active active2; - } namespace M { - //! active3 extern Active active3; - } namespace M { - //! passive1 extern Passive passive1; - } namespace M { - //! passive2 extern ConcretePassive passive2; - } namespace M { 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 c7006a2e4..3ef6950e6 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp @@ -11,15 +11,11 @@ // ---------------------------------------------------------------------- namespace M { - C c1(FW_OPTIONAL_NAME("c1")); - } namespace M { - C c2(FW_OPTIONAL_NAME("c2")); - } namespace M { 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 684f55274..4c22791bf 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp @@ -15,17 +15,13 @@ // ---------------------------------------------------------------------- namespace M { - //! c1 extern C c1; - } namespace M { - //! c2 extern C c2; - } namespace M { 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 32f9ac79c..407bedb0f 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp @@ -11,21 +11,15 @@ // ---------------------------------------------------------------------- namespace M { - C c1(FW_OPTIONAL_NAME("c1")); - } namespace M { - C c2(FW_OPTIONAL_NAME("c2")); - } namespace M { - Svc::Health health(FW_OPTIONAL_NAME("health")); - } namespace M { 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 c3ab0dbc5..4b5a9065f 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp @@ -16,24 +16,18 @@ // ---------------------------------------------------------------------- namespace M { - //! c1 extern C c1; - } namespace M { - //! c2 extern C c2; - } namespace M { - //! health extern Svc::Health health; - } 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 54b862eed..eae9c76d2 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp @@ -11,15 +11,11 @@ // ---------------------------------------------------------------------- namespace M { - C c1(FW_OPTIONAL_NAME("c1")); - } namespace M { - C c2(FW_OPTIONAL_NAME("c2")); - } namespace M { 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 575c1ff28..228d5b078 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp @@ -15,17 +15,13 @@ // ---------------------------------------------------------------------- namespace M { - //! c1 extern C c1; - } namespace M { - //! c2 extern C c2; - } namespace M { From e2a9505f576a89844a4bdc08752785a5a2b76916 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Tue, 30 Jul 2024 17:50:57 -0700 Subject: [PATCH 13/25] Refactor C++ code gen --- .../codegen/CppWriter/CppDocHppWriter.scala | 6 +++--- .../codegen/CppWriter/CppWriterUtils.scala | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala index 093d8a487..bdfefeaf4 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala @@ -62,7 +62,7 @@ object CppDocHppWriter extends CppDocWriter { val commentLines = CppDocWriter.writeDoxygenCommentOpt(c.comment) val openLines = c.superclassDecls match { case Some(d) => List( - line(s"class $name :"), + line(s"class $name :"), indentIn(line(d)), line("{") ) @@ -175,7 +175,7 @@ object CppDocHppWriter extends CppDocWriter { val startLines = List(Line.blank, line(s"namespace $name {")) val outputLines = namespace.members.flatMap(visitNamespaceMember(in, _)) val endLines = List(Line.blank, line("}")) - startLines ++ outputLines.map(indentIn(_)) ++ endLines + startLines ++ outputLines.map(indentIn(_)) ++ endLines } -} \ No newline at end of file +} diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala index 1e55cc3de..ec5b252e6 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppWriterUtils.scala @@ -63,6 +63,15 @@ trait CppWriterUtils extends LineUtils { def wrapInNamespace(namespace: String, ll: List[Line]): List[Line] = wrapInScope(s"namespace $namespace {", ll, "}") + def wrapInNamespaceLines( + namespaceNames: List[String], + ll: List[Line] + ): List[Line] = namespaceNames match { + case Nil => ll + case head :: tail => + wrapInNamespace(head, wrapInNamespaceLines(tail, ll)) + } + def wrapInNamedEnum(name: String, ll: List[Line]): List[Line] = wrapInScope(s"enum $name {", ll, "};") @@ -413,15 +422,6 @@ trait CppWriterUtils extends LineUtils { List(namespaceMember(head, wrapInNamespaces(tail, members))) } - def wrapInNamespaceLines( - namespaceNames: List[String], - ll: List[Line] - ): List[Line] = namespaceNames match { - case Nil => ll - case head :: tail => - wrapInScope(s"namespace $head {", wrapInNamespaceLines(tail, ll), "}") - } - } object CppWriterUtils { From ace6166970c7152170dde3837f08ba6f28694e80 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Tue, 30 Jul 2024 17:59:35 -0700 Subject: [PATCH 14/25] Refactor CppDocWriter --- .../main/scala/codegen/CppWriter/CppDocCppWriter.scala | 7 ------- .../main/scala/codegen/CppWriter/CppDocHppWriter.scala | 8 -------- .../src/main/scala/codegen/CppWriter/CppDocWriter.scala | 8 ++++++++ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala index 19b6b668d..697cee2b2 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala @@ -159,11 +159,4 @@ object CppDocCppWriter extends CppDocWriter { case _ => writeSelectedLines(in, lines.cppFileNameBaseOpt, lines.content) } - override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = { - val name = namespace.name - List(Line.blank, line(s"namespace $name {")) ++ - namespace.members.flatMap(visitNamespaceMember(in, _)).map(indentIn(_)) ++ - List(Line.blank, line("}")) - } - } diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala index bdfefeaf4..6e1359983 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocHppWriter.scala @@ -170,12 +170,4 @@ object CppDocHppWriter extends CppDocWriter { } } - override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = { - val name = namespace.name - val startLines = List(Line.blank, line(s"namespace $name {")) - val outputLines = namespace.members.flatMap(visitNamespaceMember(in, _)) - val endLines = List(Line.blank, line("}")) - startLines ++ outputLines.map(indentIn(_)) ++ endLines - } - } diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocWriter.scala index d7faaf0ac..ec8d75ee0 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocWriter.scala @@ -34,6 +34,14 @@ trait CppDocWriter extends CppDocVisitor with LineUtils { type Output = List[Line] + override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = { + val name = namespace.name + val startLines = List(Line.blank, line(s"namespace $name {")) + val outputLines = namespace.members.flatMap(visitNamespaceMember(in, _)) + val endLines = List(Line.blank, line("}")) + startLines ++ outputLines.map(indentIn(_)) ++ endLines + } + } object CppDocWriter extends LineUtils { From 89abf629a4bddbe9d3be3212601f9e29f7215e17 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Tue, 30 Jul 2024 23:41:20 -0700 Subject: [PATCH 15/25] Remove unused line --- .../codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index 126722629..5e5b23383 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -38,7 +38,6 @@ case class TopologyCppWriter( TopConstants(s, aNode).getLines ++ TopConfigObjects(s, aNode).getHppLines ) - val hppConstantLines = linesMember(TopConstants(s, aNode).getLines) val cppIncludes = { val fileName = s"${ComputeCppFiles.FileNames.getTopology(name)}.hpp" linesMember( From 1e4af2b39185209be15c1e55310bd951e2107ada Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 00:00:35 -0700 Subject: [PATCH 16/25] Refactor Topology Cpp Writer --- .../TopologyCppWriter/TopologyCppWriter.scala | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index 5e5b23383..e8257ba6b 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -24,8 +24,15 @@ case class TopologyCppWriter( ) } - private def getMembers: List[CppDoc.Member] = { - val hppIncludes = { + private def getMembers: List[CppDoc.Member] = + List.concat( + getIncludeMembers, + getComponentInstanceMembers, + getTopologyMembers + ) + + private def getIncludeMembers: List[CppDoc.Member] = { + val hpp = { val strings = ( TopComponentIncludes(s, aNode).getHeaderStrings :+ CppWriter.headerString( @@ -34,11 +41,7 @@ case class TopologyCppWriter( ).sorted linesMember(Line.blank :: strings.map(line)) } - val hppLines = linesMember( - TopConstants(s, aNode).getLines ++ - TopConfigObjects(s, aNode).getHppLines - ) - val cppIncludes = { + val cpp = { val fileName = s"${ComputeCppFiles.FileNames.getTopology(name)}.hpp" linesMember( List( @@ -48,25 +51,32 @@ case class TopologyCppWriter( CppDoc.Lines.Cpp ) } + List(hpp, cpp) + } + + private def getComponentInstanceMembers: List[CppDoc.Member] = { + val hpp = linesMember(TopComponentInstances(s, aNode).getHppLines) + val cpp = linesMember( + TopComponentInstances(s, aNode).getCppLines, + CppDoc.Lines.Cpp + ) + List(hpp, cpp) + } + + private def getTopologyMembers: List[CppDoc.Member] = { + val hppLines = linesMember( + TopConstants(s, aNode).getLines ++ + TopConfigObjects(s, aNode).getHppLines + ) val cppLines = linesMember( - Line.blank :: - addBlankPostfix( - TopConfigObjects(s, aNode).getCppLines, - ), + Line.blank :: addBlankPostfix(TopConfigObjects(s, aNode).getCppLines), CppDoc.Lines.Cpp ) val (helperFnNames, helperFns) = TopHelperFns(s, aNode).getMembers - val setupTeardownFns = TopSetupTeardownFns(s, aNode, helperFnNames). - getMembers + val setupTeardownFns = + TopSetupTeardownFns(s, aNode, helperFnNames).getMembers val defs = hppLines :: cppLines :: (helperFns ++ setupTeardownFns) - List( - List(hppIncludes, cppIncludes), - List( - linesMember(TopComponentInstances(s, aNode).getHppLines), - linesMember(TopComponentInstances(s, aNode).getCppLines, CppDoc.Lines.Cpp) - ), - wrapInNamespaces(namespaceIdentList, defs) - ).flatten + wrapInNamespaces(namespaceIdentList, defs) } } From 8f631a69e3217100e058f21b86b5d258f75bb9f1 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 08:23:12 -0700 Subject: [PATCH 17/25] Refactor topology code gen --- .../TopComponentInstances.scala | 26 +++++++++++-------- .../TopologyCppWriter/TopologyCppWriter.scala | 12 +++------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 6329b0826..7f2e50167 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -12,17 +12,21 @@ case class TopComponentInstances( private val bannerComment = "Component instances" - def getHppLines: List[Line] = addBannerComment( - bannerComment, - getDeclLines - ) - - def getCppLines: List[Line] = addBannerComment( - bannerComment, - getDefLines - ) + def getMembers: List[CppDoc.Member] = { + val hppLines = getHppLines + lazy val cppLines = getCppLines + lazy val comment = CppDocWriter.writeBannerComment(bannerComment) + hppLines match { + case Nil => Nil + case _ => List( + linesMember(comment, CppDoc.Lines.Both), + linesMember(hppLines, CppDoc.Lines.Hpp), + linesMember(cppLines, CppDoc.Lines.Cpp) + ) + } + } - private def getDeclLines = { + private def getHppLines = { def getCode(ci: ComponentInstance): List[Line] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName @@ -35,7 +39,7 @@ case class TopComponentInstances( flattenWithBlankPrefix(instances.map(getCode)) } - private def getDefLines = { + private def getCppLines = { def getCode(ci: ComponentInstance): List[Line] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala index e8257ba6b..84f847948 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopologyCppWriter.scala @@ -31,6 +31,9 @@ case class TopologyCppWriter( getTopologyMembers ) + private def getComponentInstanceMembers = + TopComponentInstances(s, aNode).getMembers + private def getIncludeMembers: List[CppDoc.Member] = { val hpp = { val strings = ( @@ -54,15 +57,6 @@ case class TopologyCppWriter( List(hpp, cpp) } - private def getComponentInstanceMembers: List[CppDoc.Member] = { - val hpp = linesMember(TopComponentInstances(s, aNode).getHppLines) - val cpp = linesMember( - TopComponentInstances(s, aNode).getCppLines, - CppDoc.Lines.Cpp - ) - List(hpp, cpp) - } - private def getTopologyMembers: List[CppDoc.Member] = { val hppLines = linesMember( TopConstants(s, aNode).getLines ++ From 5e1fe5ff25eb4fabb503cdd3387aadea3800cec4 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 08:45:03 -0700 Subject: [PATCH 18/25] Refactor top component instances --- .../TopologyCppWriter/TopComponentInstances.scala | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 7f2e50167..b65edafa9 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -16,14 +16,13 @@ case class TopComponentInstances( val hppLines = getHppLines lazy val cppLines = getCppLines lazy val comment = CppDocWriter.writeBannerComment(bannerComment) - hppLines match { - case Nil => Nil - case _ => List( + guardedList (!hppLines.isEmpty) ( + List( linesMember(comment, CppDoc.Lines.Both), linesMember(hppLines, CppDoc.Lines.Hpp), linesMember(cppLines, CppDoc.Lines.Cpp) ) - } + ) } private def getHppLines = { @@ -34,9 +33,9 @@ case class TopComponentInstances( s"""|//! $instanceName |extern $implType $instanceName;""" ) - wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) + Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) } - flattenWithBlankPrefix(instances.map(getCode)) + instances.flatMap(getCode) } private def getCppLines = { @@ -48,9 +47,9 @@ case class TopComponentInstances( s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" ) ) - wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) + Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) } - flattenWithBlankPrefix(instances.map(getCode)) + instances.flatMap(getCode) } private def getImplType(ci: ComponentInstance) = { From cf2783438522485ed16f71f19da028cd3809a0d5 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 08:59:58 -0700 Subject: [PATCH 19/25] Refactor top component instances --- .../TopComponentInstances.scala | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index b65edafa9..e5ee1702f 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -13,19 +13,22 @@ case class TopComponentInstances( private val bannerComment = "Component instances" def getMembers: List[CppDoc.Member] = { - val hppLines = getHppLines - lazy val cppLines = getCppLines - lazy val comment = CppDocWriter.writeBannerComment(bannerComment) - guardedList (!hppLines.isEmpty) ( - List( - linesMember(comment, CppDoc.Lines.Both), - linesMember(hppLines, CppDoc.Lines.Hpp), - linesMember(cppLines, CppDoc.Lines.Cpp) + val hppLinesMembers = getHppLinesMembers + val cppLinesMembers = List(linesMember(getCppLines, CppDoc.Lines.Cpp)) + lazy val commentMembers = List( + linesMember( + CppDocWriter.writeBannerComment(bannerComment), + CppDoc.Lines.Both ) ) + List.concat( + guardedList (!hppLinesMembers.isEmpty) (commentMembers), + hppLinesMembers, + cppLinesMembers + ) } - private def getHppLines = { + private def getHppLinesMembers = { def getCode(ci: ComponentInstance): List[Line] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName @@ -35,7 +38,8 @@ case class TopComponentInstances( ) Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) } - instances.flatMap(getCode) + val hppLines = instances.flatMap(getCode) + guardedList (!hppLines.isEmpty) (List(linesMember(hppLines, CppDoc.Lines.Hpp))) } private def getCppLines = { From 1370cda0c58ecebb7ba45931dc50144f2dbfa609 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 09:10:57 -0700 Subject: [PATCH 20/25] Refactor topology code gen --- .../TopComponentInstances.scala | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index e5ee1702f..500be4cc4 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -13,8 +13,7 @@ case class TopComponentInstances( private val bannerComment = "Component instances" def getMembers: List[CppDoc.Member] = { - val hppLinesMembers = getHppLinesMembers - val cppLinesMembers = List(linesMember(getCppLines, CppDoc.Lines.Cpp)) + val instanceMembers = getInstanceMembers lazy val commentMembers = List( linesMember( CppDocWriter.writeBannerComment(bannerComment), @@ -22,24 +21,39 @@ case class TopComponentInstances( ) ) List.concat( - guardedList (!hppLinesMembers.isEmpty) (commentMembers), - hppLinesMembers, - cppLinesMembers + guardedList (!instanceMembers.isEmpty) (commentMembers), + instanceMembers ) } - private def getHppLinesMembers = { - def getCode(ci: ComponentInstance): List[Line] = { + private def getInstanceMembers = { + def getMembers(ci: ComponentInstance): List[CppDoc.Member] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName - val instLines = lines( - s"""|//! $instanceName - |extern $implType $instanceName;""" - ) - Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) + val hpp = { + val instLines = lines( + s"""|//! $instanceName + |extern $implType $instanceName;""" + ) + linesMember( + Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines), + CppDoc.Lines.Hpp + ) + } + val cpp = { + val instLines = getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( + lines( + s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" + ) + ) + linesMember( + Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines), + CppDoc.Lines.Cpp + ) + } + List(hpp, cpp) } - val hppLines = instances.flatMap(getCode) - guardedList (!hppLines.isEmpty) (List(linesMember(hppLines, CppDoc.Lines.Hpp))) + instances.flatMap(getMembers) } private def getCppLines = { From b4fb04848ebec0b78344687805b5f4bf032f4dd5 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 09:36:26 -0700 Subject: [PATCH 21/25] Refactor topology code gen --- .../TopComponentInstances.scala | 40 +++++-------------- .../test/top/BasicTopologyAc.ref.cpp | 9 +++++ .../test/top/BasicTopologyAc.ref.hpp | 10 +++++ .../test/top/CommandsTopologyAc.ref.cpp | 4 ++ .../test/top/CommandsTopologyAc.ref.hpp | 4 ++ .../test/top/HealthTopologyAc.ref.cpp | 6 +++ .../test/top/HealthTopologyAc.ref.hpp | 6 +++ .../test/top/ParamsTopologyAc.ref.cpp | 4 ++ .../test/top/ParamsTopologyAc.ref.hpp | 4 ++ 9 files changed, 58 insertions(+), 29 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 500be4cc4..41664e562 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -30,46 +30,28 @@ case class TopComponentInstances( def getMembers(ci: ComponentInstance): List[CppDoc.Member] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName - val hpp = { - val instLines = lines( - s"""|//! $instanceName + val hpp = linesMember( + lines( + s"""| + |//! $instanceName |extern $implType $instanceName;""" - ) - linesMember( - Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines), - CppDoc.Lines.Hpp - ) - } + ), + CppDoc.Lines.Hpp + ) val cpp = { val instLines = getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( lines( - s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" + s"""| + |$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));""" ) ) - linesMember( - Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines), - CppDoc.Lines.Cpp - ) + linesMember(instLines, CppDoc.Lines.Cpp) } - List(hpp, cpp) + wrapInNamespaces(ci.qualifiedName.qualifier, List(hpp, cpp)) } instances.flatMap(getMembers) } - private def getCppLines = { - def getCode(ci: ComponentInstance): List[Line] = { - val implType = getImplType(ci) - val instanceName = ci.getUnqualifiedName - val instLines = getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( - lines( - s"$implType $instanceName(FW_OPTIONAL_NAME($q$instanceName$q));" - ) - ) - Line.blank :: wrapInNamespaceLines(ci.qualifiedName.qualifier, instLines) - } - instances.flatMap(getCode) - } - private def getImplType(ci: ComponentInstance) = { val implType = ci.aNode._2.data.implType.map(_.data) implType.getOrElse(getComponentNameAsQualIdent(ci)) 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 809172044..c238b683a 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.cpp @@ -11,23 +11,32 @@ // ---------------------------------------------------------------------- namespace M { + Active active1(FW_OPTIONAL_NAME("active1")); + } namespace M { Active active2; + } namespace M { + Active active3(FW_OPTIONAL_NAME("active3")); + } namespace M { + Passive passive1(FW_OPTIONAL_NAME("passive1")); + } namespace M { + ConcretePassive passive2(FW_OPTIONAL_NAME("passive2")); + } namespace M { 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 828d813f9..b98140a2f 100644 --- a/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/BasicTopologyAc.ref.hpp @@ -16,28 +16,38 @@ // ---------------------------------------------------------------------- namespace M { + //! active1 extern Active active1; + } namespace M { + //! active2 extern Active active2; + } namespace M { + //! active3 extern Active active3; + } namespace M { + //! passive1 extern Passive passive1; + } namespace M { + //! passive2 extern ConcretePassive passive2; + } namespace M { 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 3ef6950e6..c7006a2e4 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.cpp @@ -11,11 +11,15 @@ // ---------------------------------------------------------------------- namespace M { + C c1(FW_OPTIONAL_NAME("c1")); + } namespace M { + C c2(FW_OPTIONAL_NAME("c2")); + } namespace M { 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 4c22791bf..684f55274 100644 --- a/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/CommandsTopologyAc.ref.hpp @@ -15,13 +15,17 @@ // ---------------------------------------------------------------------- namespace M { + //! c1 extern C c1; + } namespace M { + //! c2 extern C c2; + } namespace M { 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 407bedb0f..32f9ac79c 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.cpp @@ -11,15 +11,21 @@ // ---------------------------------------------------------------------- namespace M { + C c1(FW_OPTIONAL_NAME("c1")); + } namespace M { + C c2(FW_OPTIONAL_NAME("c2")); + } namespace M { + Svc::Health health(FW_OPTIONAL_NAME("health")); + } namespace M { 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 4b5a9065f..c3ab0dbc5 100644 --- a/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/HealthTopologyAc.ref.hpp @@ -16,18 +16,24 @@ // ---------------------------------------------------------------------- namespace M { + //! c1 extern C c1; + } namespace M { + //! c2 extern C c2; + } namespace M { + //! health extern Svc::Health health; + } 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 eae9c76d2..54b862eed 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.cpp @@ -11,11 +11,15 @@ // ---------------------------------------------------------------------- namespace M { + C c1(FW_OPTIONAL_NAME("c1")); + } namespace M { + C c2(FW_OPTIONAL_NAME("c2")); + } namespace M { 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 228d5b078..575c1ff28 100644 --- a/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/top/ParamsTopologyAc.ref.hpp @@ -15,13 +15,17 @@ // ---------------------------------------------------------------------- namespace M { + //! c1 extern C c1; + } namespace M { + //! c2 extern C c2; + } namespace M { From be905669d92bc872da70c93495c7cb691087bc16 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 09:42:21 -0700 Subject: [PATCH 22/25] Refactor topology code gen --- .../TopComponentInstances.scala | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 41664e562..2eb25a028 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -10,22 +10,21 @@ case class TopComponentInstances( aNode: Ast.Annotated[AstNode[Ast.DefTopology]] ) extends TopologyCppWriterUtils(s, aNode) { - private val bannerComment = "Component instances" - def getMembers: List[CppDoc.Member] = { val instanceMembers = getInstanceMembers - lazy val commentMembers = List( - linesMember( - CppDocWriter.writeBannerComment(bannerComment), - CppDoc.Lines.Both - ) - ) List.concat( - guardedList (!instanceMembers.isEmpty) (commentMembers), + guardedList (!instanceMembers.isEmpty) (List(getCommentMember)), instanceMembers ) } + private val bannerComment = "Component instances" + + private def getCommentMember = linesMember( + CppDocWriter.writeBannerComment(bannerComment), + CppDoc.Lines.Both + ) + private def getInstanceMembers = { def getMembers(ci: ComponentInstance): List[CppDoc.Member] = { val implType = getImplType(ci) From d368418805f4e542e32ddec073385dbbe56f7b21 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 10:11:49 -0700 Subject: [PATCH 23/25] Refactor topology code gen --- .../CppWriter/TopologyCppWriter/TopComponentInstances.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala index 2eb25a028..930720f7d 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/TopologyCppWriter/TopComponentInstances.scala @@ -29,7 +29,7 @@ case class TopComponentInstances( def getMembers(ci: ComponentInstance): List[CppDoc.Member] = { val implType = getImplType(ci) val instanceName = ci.getUnqualifiedName - val hpp = linesMember( + val hppMember = linesMember( lines( s"""| |//! $instanceName @@ -37,7 +37,7 @@ case class TopComponentInstances( ), CppDoc.Lines.Hpp ) - val cpp = { + val cppMember = { val instLines = getCodeLinesForPhase (CppWriter.Phases.instances) (ci).getOrElse( lines( s"""| @@ -46,7 +46,7 @@ case class TopComponentInstances( ) linesMember(instLines, CppDoc.Lines.Cpp) } - wrapInNamespaces(ci.qualifiedName.qualifier, List(hpp, cpp)) + wrapInNamespaces(ci.qualifiedName.qualifier, List(hppMember, cppMember)) } instances.flatMap(getMembers) } From 0a8cd3dead108427452e8af4129733904f85af7f Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 31 Jul 2024 13:36:08 -0700 Subject: [PATCH 24/25] Revise cpp doc writer --- .../scala/codegen/CppWriter/CppDocCppWriter.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala index 697cee2b2..f9724561c 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/CppDocCppWriter.scala @@ -159,4 +159,17 @@ object CppDocCppWriter extends CppDocWriter { case _ => writeSelectedLines(in, lines.cppFileNameBaseOpt, lines.content) } + override def visitNamespace(in: Input, namespace: CppDoc.Namespace) = + namespace.members.flatMap(visitNamespaceMember(in, _)) match { + // If the namespace has no members, then don't write it out. + // This can happen where a namespace member has members + // that write code to some cpp files and not others. + case Nil => Nil + case outputLines => + val name = namespace.name + List(Line.blank, line(s"namespace $name {")) ++ + outputLines.map(indentIn(_)) ++ + List(Line.blank, line("}")) + } + } From e6d9f24904a514d70c44a7bb4dca8af7fc5d57ad Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 14 Aug 2024 13:30:23 -0700 Subject: [PATCH 25/25] Add newlines at end of files --- compiler/tools/fpp-to-dict/test/top/run.sh | 2 +- compiler/tools/fpp-to-dict/test/top/update-ref.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/tools/fpp-to-dict/test/top/run.sh b/compiler/tools/fpp-to-dict/test/top/run.sh index a795558e1..e2e604e00 100644 --- a/compiler/tools/fpp-to-dict/test/top/run.sh +++ b/compiler/tools/fpp-to-dict/test/top/run.sh @@ -27,4 +27,4 @@ unqualifiedComponentInstances() validate_json_schema UnqualifiedCompInst && \ diff_json QualifiedCompInst && \ diff_json UnqualifiedCompInst -} \ No newline at end of file +} diff --git a/compiler/tools/fpp-to-dict/test/top/update-ref.sh b/compiler/tools/fpp-to-dict/test/top/update-ref.sh index 49acd6831..2b091d650 100644 --- a/compiler/tools/fpp-to-dict/test/top/update-ref.sh +++ b/compiler/tools/fpp-to-dict/test/top/update-ref.sh @@ -16,4 +16,4 @@ unqualifiedComponentInstances() update "-i builtin.fpp -p 1.0.0 -f 3.4.3 -l lib1-1.0.0,lib2-2.0.0" unqualifiedComponentInstances move_json QualifiedCompInst move_json UnqualifiedCompInst -} \ No newline at end of file +}