From ecb8b6acbf274dece06fc5534588b5e608fb723c Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Thu, 29 Aug 2024 18:14:28 -0700 Subject: [PATCH] Code cleanup --- .../ComponentImplWriter.scala | 9 +- .../ComponentStateMachines.scala | 128 +++++++++--------- 2 files changed, 63 insertions(+), 74 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentImplWriter.scala b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentImplWriter.scala index 1382f7b95..905f07653 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentImplWriter.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentImplWriter.scala @@ -221,19 +221,14 @@ case class ComponentImplWriter( "PRIVATE", "Overflow hook implementations for state machines", stateMachineInstances.filter(_.queueFull == Ast.QueueFull.Hook).map( - smi => { - val smName = s.writeSymbol(smi.symbol) - val enumName = s.getName(smi.symbol) - - functionClassMember( + smi => functionClassMember( Some(s"Overflow hook implementation for ${smi.getName}"), inputOverflowHookName(smi.getName, MessageType.StateMachine), - ComponentStateMachines.signalParams(smName, enumName), + ComponentStateMachines.signalParams(s, smi.symbol), CppDoc.Type("void"), lines("// TODO"), CppDoc.Function.Override ) - } ) ) ) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala index 3a56fa847..6f9a58124 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala @@ -138,83 +138,75 @@ case class ComponentStateMachines( |""", stateMachineInstances.filter(_.queueFull == Ast.QueueFull.Hook).map( smi => { - val smName = s.writeSymbol(smi.symbol) - val enumName = s.getName(smi.symbol) - - getVirtualOverflowHook( - smi.getName, - MessageType.StateMachine, - ComponentStateMachines.signalParams(smName, enumName) - ) + smi.getName, + MessageType.StateMachine, + ComponentStateMachines.signalParams(s, smi.symbol) + ) } ), CppDoc.Lines.Hpp ) private def getSignalSendMember: List[CppDoc.Class.Member] = { - lazy val members = stateMachineInstances.map { smi => - val smName = s.writeSymbol(smi.symbol) - val enumName = s.getName(smi.symbol) + lazy val members = stateMachineInstances.map { smi => + val serializeCode = + lines( + s"""|ComponentIpcSerializableBuffer msg; + |Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; + | + |// Serialize the message ID + |_status = msg.serialize(static_cast($stateMachineCppConstantName)); + |FW_ASSERT ( + | _status == Fw::FW_SERIALIZE_OK, + | static_cast(_status) + |); + | + |// Fake port number to make message dequeue work + |_status = msg.serialize(static_cast(0)); + |FW_ASSERT ( + | _status == Fw::FW_SERIALIZE_OK, + | static_cast(_status) + |); + | + |_status = msg.serialize(static_cast(STATE_MACHINE_${smi.getName.toUpperCase})); + |FW_ASSERT( + | _status == Fw::FW_SERIALIZE_OK, + | static_cast(_status) + |); + | + |_status = msg.serialize(static_cast(signal)); + |FW_ASSERT( + | _status == Fw::FW_SERIALIZE_OK, + | static_cast(_status) + |); + | + |_status = msg.serialize(data); + |FW_ASSERT( + | _status == Fw::FW_SERIALIZE_OK, + | static_cast(_status) + |);""" + ) - val serializeCode = - lines( - s"""|ComponentIpcSerializableBuffer msg; - |Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK; - | - |// Serialize the message ID - |_status = msg.serialize(static_cast($stateMachineCppConstantName)); - |FW_ASSERT ( - | _status == Fw::FW_SERIALIZE_OK, - | static_cast(_status) - |); - | - |// Fake port number to make message dequeue work - |_status = msg.serialize(static_cast(0)); - |FW_ASSERT ( - | _status == Fw::FW_SERIALIZE_OK, - | static_cast(_status) - |); - | - |_status = msg.serialize(static_cast(STATE_MACHINE_${smi.getName.toUpperCase})); - |FW_ASSERT( - | _status == Fw::FW_SERIALIZE_OK, - | static_cast(_status) - |); - | - |_status = msg.serialize(static_cast(signal)); - |FW_ASSERT( - | _status == Fw::FW_SERIALIZE_OK, - | static_cast(_status) - |); - | - |_status = msg.serialize(data); - |FW_ASSERT( - | _status == Fw::FW_SERIALIZE_OK, - | static_cast(_status) - |);""" - ) - - val sendLogicCode = List.concat( - writeSendMessageLogic( - "msg", smi.queueFull, smi.priority, - MessageType.StateMachine, smi.getName, - ComponentStateMachines.signalParams(smName, enumName) + val sendLogicCode = List.concat( + writeSendMessageLogic( + "msg", smi.queueFull, smi.priority, + MessageType.StateMachine, smi.getName, + ComponentStateMachines.signalParams(s, smi.symbol) + ) ) - ) - - lazy val member = functionClassMember( - Some(s"State machine base-class function for sendSignals"), - s"${smi.getName}_stateMachineInvoke", - ComponentStateMachines.signalParams(smName, enumName), - CppDoc.Type("void"), - Line.blank :: intersperseBlankLines( - List(serializeCode, sendLogicCode) + functionClassMember( + Some(s"State machine base-class function for sendSignals"), + s"${smi.getName}_stateMachineInvoke", + ComponentStateMachines.signalParams(s, smi.symbol), + CppDoc.Type("void"), + Line.blank :: intersperseBlankLines( + List(serializeCode, sendLogicCode) + ) ) - ) - member + } addAccessTagAndComment( @@ -228,10 +220,12 @@ case class ComponentStateMachines( object ComponentStateMachines { - def signalParams(stateMachineName: String, enumName: String) = { + def signalParams(s: CppWriterState, sym: Symbol.StateMachine) = { + val smName = s.writeSymbol(sym) + val enumName = s.getName(sym) List( CppDoc.Function.Param( - CppDoc.Type(s"const ${stateMachineName}_Interface::${enumName}_Signals"), + CppDoc.Type(s"const ${smName}_Interface::${enumName}_Signals"), "signal", Some("The state machine signal") ),