Skip to content

Commit

Permalink
Merge pull request #368 from SMorettini/Resolve-Warning-array-of-size…
Browse files Browse the repository at this point in the history
…-zero

Resolve warning array of size zero
  • Loading branch information
bocchino authored Jan 18, 2024
2 parents ad806c3 + c54083c commit 10fcded
Show file tree
Hide file tree
Showing 52 changed files with 4,846 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,23 @@ case class ComponentCppWriter (
private def getAnonymousNamespaceMembers: List[CppDoc.Class.Member] =
data.kind match {
case Ast.ComponentKind.Passive => Nil
case _ => List(
linesClassMember(
Line.blank :: wrapInAnonymousNamespace(
intersperseBlankLines(
List(
getMsgTypeEnum,
getBuffUnion,
getComponentIpcSerializableBufferClass
case _ => {
val buffUnion = getBuffUnion
List(
linesClassMember(
Line.blank :: wrapInAnonymousNamespace(
intersperseBlankLines(
List(
getMsgTypeEnum,
buffUnion,
getComponentIpcSerializableBufferClass(buffUnion)
)
)
)
),
CppDoc.Lines.Cpp
),
CppDoc.Lines.Cpp
)
)
)
}
}

private def getMsgTypeEnum: List[Line] = {
Expand All @@ -298,9 +301,14 @@ case class ComponentCppWriter (
private def getBuffUnion: List[Line] = {
// Collect the serialized sizes of all the async port arguments
// For each one, add a byte array of that size as a member
val internalPortsWithFormalParams: List[PortInstance.Internal] =
internalPorts.filter(p => getPortParams(p).size > 0)
val asyncInputPortsWithFormalParams =
(dataProductAsyncInputPorts ++ typedAsyncInputPorts).
filter(p => getPortParams(p).size > 0)
val members = List.concat(
// Data product and typed async input ports
(dataProductAsyncInputPorts ++ typedAsyncInputPorts).flatMap(p => {
asyncInputPortsWithFormalParams.flatMap(p => {
val portName = p.getUnqualifiedName
val portTypeName = getQualifiedPortTypeName(p, p.getDirection.get)
lines(s"BYTE ${portName}PortSize[${portTypeName}::SERIALIZED_SIZE];")
Expand All @@ -310,72 +318,67 @@ case class ComponentCppWriter (
(lines(s"BYTE cmdPortSize[Fw::InputCmdPort::SERIALIZED_SIZE];")),
// Internal ports
// Sum the sizes of the port arguments
internalPorts.flatMap(p =>
internalPortsWithFormalParams.flatMap(p =>
line(s"// Size of ${p.getUnqualifiedName} argument list") ::
(p.aNode._2.data.params match {
case Nil => lines("// [ no port arguments ]")
case _ => wrapInScope(
s"BYTE ${p.getUnqualifiedName}IntIfSize[",
lines(
p.aNode._2.data.params.map(param =>
s.getSerializedSizeExpr(
s.a.typeMap(param._2.data.typeName.id),
writeInternalPortParamType(param._2.data)
)
).mkString(" +\n")
),
"];"
)
})
wrapInScope(
s"BYTE ${p.getUnqualifiedName}IntIfSize[",
lines(
p.aNode._2.data.params.map(param =>
s.getSerializedSizeExpr(
s.a.typeMap(param._2.data.typeName.id),
writeInternalPortParamType(param._2.data)
)
).mkString(" +\n")
),
"];"
)
)
)
List.concat(
lines("""|// Get the max size by constructing a union of the async input, command, and
|// internal port serialization sizes"""),
wrapInScope(
"union BuffUnion {",
members,
"};"
)
wrapInScope(
"""|// Get the max size by constructing a union of the async input, command, and
|// internal port serialization sizes
|union BuffUnion {""",
members,
"};"
)
}

private def getComponentIpcSerializableBufferClass: List[Line] = {
private def getComponentIpcSerializableBufferClass(buffUnion: List[Line]): List[Line] = {
lines(
"""|// Define a message buffer class large enough to handle all the
|// asynchronous inputs to the component
|class ComponentIpcSerializableBuffer :
| public Fw::SerializeBufferBase
|{
|
| public:
|
| enum {
| // Max. message size = size of data + message id + port
| SERIALIZATION_SIZE =
| sizeof(BuffUnion) +
| sizeof(NATIVE_INT_TYPE) +
| sizeof(NATIVE_INT_TYPE)
| };
|
| NATIVE_UINT_TYPE getBuffCapacity() const {
| return sizeof(m_buff);
| }
|
| U8* getBuffAddr() {
| return m_buff;
| }
|
| const U8* getBuffAddr() const {
| return m_buff;
| }
|
| private:
| // Should be the max of all the input ports serialized sizes...
| U8 m_buff[SERIALIZATION_SIZE];
|
|};
|"""
s"""|// Define a message buffer class large enough to handle all the
|// asynchronous inputs to the component
|class ComponentIpcSerializableBuffer :
| public Fw::SerializeBufferBase
|{
|
| public:
|
| enum {
| // 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)
| };
|
| NATIVE_UINT_TYPE getBuffCapacity() const {
| return sizeof(m_buff);
| }
|
| U8* getBuffAddr() {
| return m_buff;
| }
|
| const U8* getBuffAddr() const {
| return m_buff;
| }
|
| private:
| // Should be the max of all the input ports serialized sizes...
| U8 m_buff[SERIALIZATION_SIZE];
|
|};
|"""
)
}

Expand Down
7 changes: 7 additions & 0 deletions compiler/tools/fpp-to-cpp/test/component/active.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,10 @@ active component ActiveAsyncProductPortsOnly {
include "include/product_ports_async.fppi"

}

@ An active component with only ports without arguments
active component ActiveNoArgsPortsOnly {

include "include/typed_ports_no_args.fppi"

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace {
// internal port serialization sizes
union BuffUnion {
BYTE productRecvInPortSize[Fw::InputDpResponsePort::SERIALIZED_SIZE];
BYTE noArgsAsyncPortSize[Ports::InputNoArgsPort::SERIALIZED_SIZE];
BYTE typedAsyncPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncAssertPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncBlockPriorityPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace {
// Get the max size by constructing a union of the async input, command, and
// internal port serialization sizes
union BuffUnion {
BYTE noArgsAsyncPortSize[Ports::InputNoArgsPort::SERIALIZED_SIZE];
BYTE typedAsyncPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncAssertPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncBlockPriorityPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace {
// Get the max size by constructing a union of the async input, command, and
// internal port serialization sizes
union BuffUnion {
BYTE noArgsAsyncPortSize[Ports::InputNoArgsPort::SERIALIZED_SIZE];
BYTE typedAsyncPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncAssertPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncBlockPriorityPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace {
// Get the max size by constructing a union of the async input, command, and
// internal port serialization sizes
union BuffUnion {
BYTE noArgsAsyncPortSize[Ports::InputNoArgsPort::SERIALIZED_SIZE];
BYTE typedAsyncPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncAssertPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncBlockPriorityPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace {
// Get the max size by constructing a union of the async input, command, and
// internal port serialization sizes
union BuffUnion {
BYTE noArgsAsyncPortSize[Ports::InputNoArgsPort::SERIALIZED_SIZE];
BYTE typedAsyncPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncAssertPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
BYTE typedAsyncBlockPriorityPortSize[Ports::InputTypedPort::SERIALIZED_SIZE];
Expand Down
Loading

0 comments on commit 10fcded

Please sign in to comment.