Skip to content

Commit

Permalink
Merge pull request #212 from tiffany1618/issue-209-port-cpp-bugs
Browse files Browse the repository at this point in the history
Fix bugs in generated C++ for ports
  • Loading branch information
bocchino authored Jan 24, 2023
2 parents 1b3de20 + 23a2288 commit aefbc30
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 149 deletions.
71 changes: 37 additions & 34 deletions compiler/lib/src/main/scala/codegen/CppWriter/PortCppWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ case class PortCppWriter (
|this->trace();
|#endif
|
|FW_ASSERT(this->m_comp);
|FW_ASSERT(this->m_func);
|FW_ASSERT(this->m_comp != nullptr);
|FW_ASSERT(this->m_func != nullptr);
|"""
) ++
paramList.flatMap((n, tn, _) => {
Expand Down Expand Up @@ -422,8 +422,8 @@ case class PortCppWriter (
),
CppDoc.Type("void"),
lines(
"""|FW_ASSERT(callComp);
|FW_ASSERT(funcPtr);
"""|FW_ASSERT(callComp != nullptr);
|FW_ASSERT(funcPtr != nullptr);
|
|this->m_comp = callComp;
|this->m_func = funcPtr;
Expand All @@ -443,8 +443,8 @@ case class PortCppWriter (
|this->trace();
|#endif
|
|FW_ASSERT(this->m_comp);
|FW_ASSERT(this->m_func);
|FW_ASSERT(this->m_comp != nullptr);
|FW_ASSERT(this->m_func != nullptr);
|
|return this->m_func(this->m_comp, this->m_portNum${paramNames});
|"""
Expand Down Expand Up @@ -501,38 +501,48 @@ case class PortCppWriter (
}

private def getOutputPortFunctionMembers: List[CppDoc.Class.Member] = {
val paramNames = paramList.map(_._1).mkString(", ")
val invokeCall = s"this->m_port->invoke(${paramList.map(_._1).mkString(", ")});"
val invokeBody = data.returnType match {
case Some(_) => lines(
s"return this->m_port->invoke($paramNames);"
)
case None => lines(
s"""|if (this->m_port) {
| this->m_port->invoke($paramNames);
|#if FW_PORT_SERIALIZATION
|} else if (this->m_serPort) {
| Fw::SerializeStatus _status;
| ${name}PortBuffer _buffer;
s"""|
|FW_ASSERT(this->m_port != nullptr);
|return $invokeCall
|"""
) ++
)
case None => List(
lines(
s"""|
|#if FW_PORT_SERIALIZATION
|FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));
|
|if (this->m_port != nullptr) {
| $invokeCall
|}
|else {
| Fw::SerializeStatus _status;
| ${name}PortBuffer _buffer;
|"""
),
paramList.flatMap((n, _, _) => {
lines(
s"""|
| _status = _buffer.serialize($n);
| FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
|"""
)
}) ++
}),
lines(
"""|
| _status = this->m_serPort->invokeSerial(_buffer);
| FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
|}
|#else
|}
|#endif
|"""
s"""|
| _status = this->m_serPort->invokeSerial(_buffer);
| FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
|}
|#else
|FW_ASSERT(this->m_port != nullptr);
|$invokeCall
|#endif
|"""
)
).flatten
}

List(
Expand Down Expand Up @@ -577,7 +587,7 @@ case class PortCppWriter (
),
CppDoc.Type("void"),
lines(
"""|FW_ASSERT(callPort);
"""|FW_ASSERT(callPort != nullptr);
|
|this->m_port = callPort;
|this->m_connObj = callPort;
Expand All @@ -599,13 +609,6 @@ case class PortCppWriter (
s"""|#if FW_PORT_TRACING == 1
|this->trace();
|#endif
|
|#if FW_PORT_SERIALIZATION
|FW_ASSERT(this->m_port || this->m_serPort);
|#else
|FW_ASSERT(this->m_port);
|#endif
|
|"""
) ++
invokeBody
Expand Down
29 changes: 14 additions & 15 deletions compiler/tools/fpp-to-cpp/test/port/AbsTypePortAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void InputAbsTypePort ::
CompFuncPtr funcPtr
)
{
FW_ASSERT(callComp);
FW_ASSERT(funcPtr);
FW_ASSERT(callComp != nullptr);
FW_ASSERT(funcPtr != nullptr);

this->m_comp = callComp;
this->m_func = funcPtr;
Expand All @@ -80,8 +80,8 @@ void InputAbsTypePort ::
this->trace();
#endif

FW_ASSERT(this->m_comp);
FW_ASSERT(this->m_func);
FW_ASSERT(this->m_comp != nullptr);
FW_ASSERT(this->m_func != nullptr);

return this->m_func(this->m_comp, this->m_portNum, t, tRef);
}
Expand All @@ -97,8 +97,8 @@ Fw::SerializeStatus InputAbsTypePort ::
this->trace();
#endif

FW_ASSERT(this->m_comp);
FW_ASSERT(this->m_func);
FW_ASSERT(this->m_comp != nullptr);
FW_ASSERT(this->m_func != nullptr);

T t;
_status = _buffer.deserialize(t);
Expand Down Expand Up @@ -140,7 +140,7 @@ void OutputAbsTypePort ::
void OutputAbsTypePort ::
addCallPort(InputAbsTypePort* callPort)
{
FW_ASSERT(callPort);
FW_ASSERT(callPort != nullptr);

this->m_port = callPort;
this->m_connObj = callPort;
Expand All @@ -161,14 +161,12 @@ void OutputAbsTypePort ::
#endif

#if FW_PORT_SERIALIZATION
FW_ASSERT(this->m_port || this->m_serPort);
#else
FW_ASSERT(this->m_port);
#endif
if (this->m_port) {
FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));

if (this->m_port != nullptr) {
this->m_port->invoke(t, tRef);
#if FW_PORT_SERIALIZATION
} else if (this->m_serPort) {
}
else {
Fw::SerializeStatus _status;
AbsTypePortBuffer _buffer;

Expand All @@ -182,6 +180,7 @@ void OutputAbsTypePort ::
FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
}
#else
}
FW_ASSERT(this->m_port != nullptr);
this->m_port->invoke(t, tRef);
#endif
}
29 changes: 14 additions & 15 deletions compiler/tools/fpp-to-cpp/test/port/BuiltInTypePortAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void InputBuiltInTypePort ::
CompFuncPtr funcPtr
)
{
FW_ASSERT(callComp);
FW_ASSERT(funcPtr);
FW_ASSERT(callComp != nullptr);
FW_ASSERT(funcPtr != nullptr);

this->m_comp = callComp;
this->m_func = funcPtr;
Expand All @@ -80,8 +80,8 @@ void InputBuiltInTypePort ::
this->trace();
#endif

FW_ASSERT(this->m_comp);
FW_ASSERT(this->m_func);
FW_ASSERT(this->m_comp != nullptr);
FW_ASSERT(this->m_func != nullptr);

return this->m_func(this->m_comp, this->m_portNum, t, tRef);
}
Expand All @@ -97,8 +97,8 @@ Fw::SerializeStatus InputBuiltInTypePort ::
this->trace();
#endif

FW_ASSERT(this->m_comp);
FW_ASSERT(this->m_func);
FW_ASSERT(this->m_comp != nullptr);
FW_ASSERT(this->m_func != nullptr);

FwOpcodeType t;
_status = _buffer.deserialize(t);
Expand Down Expand Up @@ -140,7 +140,7 @@ void OutputBuiltInTypePort ::
void OutputBuiltInTypePort ::
addCallPort(InputBuiltInTypePort* callPort)
{
FW_ASSERT(callPort);
FW_ASSERT(callPort != nullptr);

this->m_port = callPort;
this->m_connObj = callPort;
Expand All @@ -161,14 +161,12 @@ void OutputBuiltInTypePort ::
#endif

#if FW_PORT_SERIALIZATION
FW_ASSERT(this->m_port || this->m_serPort);
#else
FW_ASSERT(this->m_port);
#endif
if (this->m_port) {
FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));

if (this->m_port != nullptr) {
this->m_port->invoke(t, tRef);
#if FW_PORT_SERIALIZATION
} else if (this->m_serPort) {
}
else {
Fw::SerializeStatus _status;
BuiltInTypePortBuffer _buffer;

Expand All @@ -182,6 +180,7 @@ void OutputBuiltInTypePort ::
FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
}
#else
}
FW_ASSERT(this->m_port != nullptr);
this->m_port->invoke(t, tRef);
#endif
}
29 changes: 14 additions & 15 deletions compiler/tools/fpp-to-cpp/test/port/EmptyPortAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void InputEmptyPort ::
CompFuncPtr funcPtr
)
{
FW_ASSERT(callComp);
FW_ASSERT(funcPtr);
FW_ASSERT(callComp != nullptr);
FW_ASSERT(funcPtr != nullptr);

this->m_comp = callComp;
this->m_func = funcPtr;
Expand All @@ -73,8 +73,8 @@ void InputEmptyPort ::
this->trace();
#endif

FW_ASSERT(this->m_comp);
FW_ASSERT(this->m_func);
FW_ASSERT(this->m_comp != nullptr);
FW_ASSERT(this->m_func != nullptr);

return this->m_func(this->m_comp, this->m_portNum);
}
Expand All @@ -90,8 +90,8 @@ Fw::SerializeStatus InputEmptyPort ::
this->trace();
#endif

FW_ASSERT(this->m_comp);
FW_ASSERT(this->m_func);
FW_ASSERT(this->m_comp != nullptr);
FW_ASSERT(this->m_func != nullptr);

this->m_func(this->m_comp, this->m_portNum);

Expand Down Expand Up @@ -121,7 +121,7 @@ void OutputEmptyPort ::
void OutputEmptyPort ::
addCallPort(InputEmptyPort* callPort)
{
FW_ASSERT(callPort);
FW_ASSERT(callPort != nullptr);

this->m_port = callPort;
this->m_connObj = callPort;
Expand All @@ -139,21 +139,20 @@ void OutputEmptyPort ::
#endif

#if FW_PORT_SERIALIZATION
FW_ASSERT(this->m_port || this->m_serPort);
#else
FW_ASSERT(this->m_port);
#endif
if (this->m_port) {
FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));

if (this->m_port != nullptr) {
this->m_port->invoke();
#if FW_PORT_SERIALIZATION
} else if (this->m_serPort) {
}
else {
Fw::SerializeStatus _status;
EmptyPortBuffer _buffer;

_status = this->m_serPort->invokeSerial(_buffer);
FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
}
#else
}
FW_ASSERT(this->m_port != nullptr);
this->m_port->invoke();
#endif
}
Loading

0 comments on commit aefbc30

Please sign in to comment.