Skip to content

Commit

Permalink
Merge pull request #396 from fprime-community/issue-391-native-types
Browse files Browse the repository at this point in the history
Remove native types from generated C++ code
  • Loading branch information
bocchino authored Apr 3, 2024
2 parents 5a9d922 + 31733f7 commit ffa08b7
Show file tree
Hide file tree
Showing 364 changed files with 19,345 additions and 19,359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ case class ComponentCommands (
|Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK;
|
|// Serialize for IPC
|_status = msg.serialize(static_cast<NATIVE_INT_TYPE>(${commandCppConstantName(cmd)}));
|_status = msg.serialize(static_cast<FwEnumStoreType>(${commandCppConstantName(cmd)}));
|FW_ASSERT (
| _status == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(_status)
|);
|
|// Fake port number to make message dequeue work
|NATIVE_INT_TYPE port = 0;
|FwIndexType port = 0;
|"""
),
intersperseBlankLines(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ case class ComponentCppWriter (
| // Max. message size = size of data + message id + port
| SERIALIZATION_SIZE =${if (buffUnion.nonEmpty) """
| sizeof(BuffUnion) +""" else "" }
| sizeof(NATIVE_INT_TYPE) +
| sizeof(NATIVE_INT_TYPE)
| sizeof(FwEnumStoreType) +
| sizeof(FwIndexType)
| };
|
| NATIVE_UINT_TYPE getBuffCapacity() const {
| Fw::Serializable::SizeType getBuffCapacity() const {
| return sizeof(m_buff);
| }
|
Expand Down Expand Up @@ -410,12 +410,11 @@ case class ComponentCppWriter (
case _ => List.concat(
if hasSerialAsyncInputPorts then lines(
"""|// Passed-in size added to port number and message type enumeration sizes.
|// NATIVE_INT_TYPE cast because of compiler warning.
|this->m_msgSize = FW_MAX(
| msgSize +
| static_cast<NATIVE_INT_TYPE>(sizeof(NATIVE_INT_TYPE)) +
| static_cast<NATIVE_INT_TYPE>(sizeof(I32)),
| static_cast<NATIVE_INT_TYPE>(ComponentIpcSerializableBuffer::SERIALIZATION_SIZE)
| static_cast<FwSizeType>(sizeof(FwIndexType)) +
| static_cast<FwSizeType>(sizeof(FwEnumStoreType)),
| static_cast<FwSizeType>(ComponentIpcSerializableBuffer::SERIALIZATION_SIZE)
|);
|
|Os::Queue::QueueStatus qStat = this->createQueue(queueDepth, this->m_msgSize);
Expand Down Expand Up @@ -760,7 +759,7 @@ case class ComponentCppWriter (
)
else lines("ComponentIpcSerializableBuffer msg;"),
lines(
s"""|NATIVE_INT_TYPE priority = 0;
s"""|FwQueuePriorityType priority = 0;
|
|Os::Queue::QueueStatus msgStatus = this->m_queue.receive(
| msg,
Expand All @@ -780,7 +779,7 @@ case class ComponentCppWriter (
|// Reset to beginning of buffer
|msg.resetDeser();
|
|NATIVE_INT_TYPE desMsg = 0;
|FwEnumStoreType desMsg = 0;
|Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
|FW_ASSERT(
| deserStatus == Fw::FW_SERIALIZE_OK,
Expand All @@ -796,7 +795,7 @@ case class ComponentCppWriter (
),
lines(
"""|
|NATIVE_INT_TYPE portNum = 0;
|FwIndexType portNum = 0;
|deserStatus = msg.deserialize(portNum);
|FW_ASSERT(
| deserStatus == Fw::FW_SERIALIZE_OK,
Expand Down Expand Up @@ -875,7 +874,7 @@ case class ComponentCppWriter (
lines(
"""|
|//! Stores max message size
|NATIVE_INT_TYPE m_msgSize;
|FwSizeType m_msgSize;
|"""
)
).flatten
Expand Down Expand Up @@ -947,8 +946,8 @@ object ComponentCppWriter extends CppWriterUtils {

val body = line(s"// Connect ${d.toString} port ${port.getUnqualifiedName}") ::
wrapInForLoopStaggered(
"PlatformIntType port = 0",
s"port < static_cast<PlatformIntType>(this->${numGetterName(port)}())",
"FwIndexType port = 0",
s"port < static_cast<FwIndexType>(this->${numGetterName(port)}())",
"port++",
List(
lines(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class ComponentCppWriterUtils(

/** Port number param as a CppDoc Function Param */
val portNumParam: CppDoc.Function.Param = CppDoc.Function.Param(
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwIndexType"),
"portNum",
Some("The port number")
)
Expand Down Expand Up @@ -276,23 +276,23 @@ abstract class ComponentCppWriterUtils(
val initParams: List[CppDoc.Function.Param] = List.concat(
if data.kind != Ast.ComponentKind.Passive then List(
CppDoc.Function.Param(
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwQueueSizeType"),
"queueDepth",
Some("The queue depth")
)
)
else Nil,
if hasSerialAsyncInputPorts then List(
CppDoc.Function.Param(
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwSizeType"),
"msgSize",
Some("The message size")
)
)
else Nil,
List(
CppDoc.Function.Param(
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwEnumStoreType"),
"instance",
Some("The instance number"),
Some("0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ case class ComponentDataProducts (
s"${portName}_handler",
List(
CppDoc.Function.Param(
CppDoc.Type("const NATIVE_INT_TYPE"),
CppDoc.Type("const FwIndexType"),
"portNum",
Some("The port number")
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ case class ComponentEvents (
linesClassMember(
Line.blank :: lines(
s"""|//! Throttle for ${event.getName}
|NATIVE_UINT_TYPE ${eventThrottleCounterName(event.getName)};
|FwIndexType ${eventThrottleCounterName(event.getName)};
|"""
)
)
Expand Down Expand Up @@ -337,4 +337,4 @@ case class ComponentEvents (
private def eventThrottleResetName(event: Event) =
s"${eventLogName(event)}_ThrottleClear"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ case class ComponentInputPorts(
lines(
s"""|// Serialize message ID
|_status = $bufferName.serialize(
| static_cast<NATIVE_INT_TYPE>(${portCppConstantName(p)})
| static_cast<FwEnumStoreType>(${portCppConstantName(p)})
|);
|FW_ASSERT(
| _status == Fw::FW_SERIALIZE_OK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ case class ComponentInternalPort (
|Fw::SerializeStatus _status = Fw::FW_SERIALIZE_OK;
|
|// Serialize the message ID
|_status = msg.serialize(static_cast<NATIVE_INT_TYPE>(${internalPortCppConstantName(p)}));
|_status = msg.serialize(static_cast<FwEnumStoreType>(${internalPortCppConstantName(p)}));
|FW_ASSERT (
| _status == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(_status)
|);
|
|// Fake port number to make message dequeue work
|_status = msg.serialize(static_cast<NATIVE_INT_TYPE>(0));
|_status = msg.serialize(static_cast<FwIndexType>(0));
|FW_ASSERT (
| _status == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(_status)
Expand Down Expand Up @@ -94,4 +94,4 @@ case class ComponentInternalPort (
private def internalInterfaceHandlerBaseName(name: String) =
s"${name}_internalInterfaceInvoke"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ case class ComponentPorts(
),
numGetterName(p),
Nil,
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwIndexType"),
lines(
s"return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->${variableName(p)}));"
s"return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->${variableName(p)}));"
),
CppDoc.Function.NonSV,
CppDoc.Function.Const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ case class ComponentTestImplWriter(
List.concat(
Line.blank :: lines(
s"""|// Maximum size of histories storing events, telemetry, and port outputs
|static const NATIVE_INT_TYPE $historySizeConstantName = 10;
|static const FwSizeType $historySizeConstantName = 10;
|
|// Instance ID supplied to the component instance under test
|static const NATIVE_INT_TYPE $idConstantName = 0;
|static const FwEnumStoreType $idConstantName = 0;
|"""
),
guardedList (data.kind != Ast.ComponentKind.Passive) (
lines(
s"""|
|// Queue depth supplied to the component instance under test
|static const NATIVE_INT_TYPE $queueDepthConstantName = 10;
|static const FwQueueSizeType $queueDepthConstantName = 10;
|"""
)
)
Expand Down Expand Up @@ -194,7 +194,7 @@ case class ComponentTestImplWriter(
p => p.getArraySize match {
case 1 => writeConnection(p, "0")
case size => wrapInForLoop(
"NATIVE_UINT_TYPE i = 0",
"FwIndexType i = 0",
s"i < $size",
"i++",
writeConnection(p, "i")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ case class ComponentTesterBaseWriter(
"init",
List(
CppDoc.Function.Param(
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwEnumStoreType"),
"instance",
Some("The instance number"),
Some("0")
Expand Down Expand Up @@ -607,7 +607,7 @@ case class ComponentTesterBaseWriter(
List.concat(
List(
CppDoc.Function.Param(
CppDoc.Type("const NATIVE_INT_TYPE"),
CppDoc.Type("const FwEnumStoreType"),
"instance",
Some("The instance number")
),
Expand Down Expand Up @@ -1097,7 +1097,7 @@ case class ComponentTesterBaseWriter(
paramSendName(prm.getName),
List(
CppDoc.Function.Param(
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwEnumStoreType"),
"instance",
Some("The component instance")
),
Expand Down Expand Up @@ -1137,7 +1137,7 @@ case class ComponentTesterBaseWriter(
paramSaveName(prm.getName),
List(
CppDoc.Function.Param(
CppDoc.Type("NATIVE_INT_TYPE"),
CppDoc.Type("FwEnumStoreType"),
"instance",
Some("The component instance")
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ object CppWriterState {
* default values */
val zero: Value.Integer = Value.Integer(0)
val builtInTypes: Map[String,Value.Integer] = Map(
"FwBuffSizeType" -> zero,
"FwChanIdType" -> zero,
"FwDpIdType" -> zero,
"FwDpPriorityType" -> zero,
Expand All @@ -211,17 +210,12 @@ object CppWriterState {
"FwOpcodeType" -> zero,
"FwPacketDescriptorType" -> zero,
"FwPrmIdType" -> zero,
"FwSignedSizeType" -> zero,
"FwSizeStoreType" -> zero,
"FwSizeType" -> zero,
"FwTimeBaseStoreType" -> zero,
"FwTimeContextStoreType" -> zero,
"FwTlmPacketizeIdType" -> zero,
// For compatibility with the current F Prime code.
// Eventually we should remove these machine-dependent types
// from the FPP model and from the FPP-facing interface
// in F Prime.
"NATIVE_INT_TYPE" -> zero,
"NATIVE_UINT_TYPE" -> zero,
"POINTER_CAST" -> zero,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ case class PortCppWriter (
List(
CppDocHppWriter.writeAccessTag("public"),
Line.blank :: lines(
s"""|NATIVE_UINT_TYPE getBuffCapacity() const {
s"""|Fw::Serializable::SizeType getBuffCapacity() const {
| return ${PortCppWriter.inputPortName(name)}::SERIALIZED_SIZE;
|}
|
Expand Down Expand Up @@ -271,9 +271,9 @@ case class PortCppWriter (
val compFuncParams =
line("Fw::PassiveComponentBase* callComp,") ::
(if params.isEmpty then
lines("NATIVE_INT_TYPE portNum")
lines("FwIndexType portNum")
else
line("NATIVE_INT_TYPE portNum,") ::
line("FwIndexType portNum,") ::
lines(params.map(p => {
s"${formalParamsCppWriter.getFormalParamType(p._2.data, None, List(strNamespace)).hppType} ${p._2.data.name}"
}).mkString(",\n")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ case class StringCppWriter(
None,
"getCapacity",
Nil,
CppDoc.Type("NATIVE_UINT_TYPE"),
CppDoc.Type("Fw::StringBase::SizeType"),
lines("return sizeof(this->m_buf);"),
CppDoc.Function.NonSV,
CppDoc.Function.Const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ case class StructCppWriter(
// Writes a for loop that iterates n times
private def iterateN(n: Int, ll: List[Line]) =
wrapInForLoop(
"NATIVE_UINT_TYPE i = 0",
"FwSizeType i = 0",
s"i < $n",
"i++",
ll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ case class TopHelperFns(
if (isActive(ci)) {
val name = getNameAsIdent(ci.qualifiedName)
val priority = ci.priority match {
case Some(_) => s"static_cast<NATIVE_UINT_TYPE>(Priorities::$name),"
case Some(_) => s"static_cast<Os::Task::ParamType>(Priorities::$name),"
case None => "Os::Task::TASK_DEFAULT, // Default priority"
}
val stackSize = ci.stackSize match {
case Some(_) => s"static_cast<NATIVE_UINT_TYPE>(StackSizes::$name),"
case Some(_) => s"static_cast<Os::Task::ParamType>(StackSizes::$name),"
case None => "Os::Task::TASK_DEFAULT, // Default stack size"
}
val cpu = ci.cpu match {
case Some(_) => s"static_cast<NATIVE_UINT_TYPE>(CPUs::$name),"
case Some(_) => s"static_cast<Os::Task::ParamType>(CPUs::$name),"
case None => "Os::Task::TASK_DEFAULT, // Default CPU"
}
wrapInScope(
Expand All @@ -213,7 +213,7 @@ case class TopHelperFns(
priority,
stackSize,
cpu,
s"static_cast<NATIVE_UINT_TYPE>(TaskIds::$name)",
s"static_cast<Os::Task::ParamType>(TaskIds::$name)",
)
).map(line),
");"
Expand Down
3 changes: 2 additions & 1 deletion compiler/scripts/fprime-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ case "$os" in
;;
esac

g++ --std=c++11 -Wall -Wextra -Wconversion $os_flags -DTGT_OS_TYPE_$os_type -I $FPRIME -I $FPRIME/config -I $FPRIME/cmake/platform/types -I . $FPRIME_GCC_FLAGS $@
# Removing -Wconversion because of many implicit casts of size type in F Prime
g++ --std=c++11 -Wall -Wextra $os_flags -DTGT_OS_TYPE_$os_type -I $FPRIME -I $FPRIME/config -I $FPRIME/cmake/platform/types -I . $FPRIME_GCC_FLAGS $@
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace M {
return this->m_buf;
}

NATIVE_UINT_TYPE S1::StringSize80 ::
Fw::StringBase::SizeType S1::StringSize80 ::
getCapacity() const
{
return sizeof(this->m_buf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace M {
//! Retrieves char buffer of string
const char* toChar() const;

NATIVE_UINT_TYPE getCapacity() const;
Fw::StringBase::SizeType getCapacity() const;

private:

Expand Down
Loading

0 comments on commit ffa08b7

Please sign in to comment.