mirror of
https://github.com/nasa/fpp.git
synced 2025-12-11 03:05:32 -06:00
Revise code gen for port calls
This commit is contained in:
parent
d0738bb807
commit
72012e49c4
@ -58,6 +58,15 @@ case class TopComponentCppWriter (
|
||||
)
|
||||
}
|
||||
|
||||
private def writePortNumAssertion(numPorts: String) =
|
||||
lines(
|
||||
s"""|FW_ASSERT(
|
||||
| (0 <= portNum) && (portNum < $numPorts),
|
||||
| static_cast<FwAssertArgType>(portNum),
|
||||
| static_cast<FwAssertArgType>($numPorts)
|
||||
|);"""
|
||||
)
|
||||
|
||||
private def writeIsConnectedFnBody(
|
||||
portName: Name.Unqualified,
|
||||
componentInstanceMap: TopComponents.ComponentInstanceMap
|
||||
@ -65,10 +74,10 @@ case class TopComponentCppWriter (
|
||||
val portInstance = component.portMap(portName)
|
||||
val numPorts = numPortsConstantName(portInstance)
|
||||
List.concat(
|
||||
writePortNumAssertion(numPorts),
|
||||
lines(
|
||||
s"""|FW_ASSERT((0 <= portNum) && (portNum < $numPorts), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>($numPorts));
|
||||
|bool result = false;
|
||||
|const auto instance = this->getInstance();"""
|
||||
"""|bool result = false;
|
||||
|const auto instance = this->getInstance();"""
|
||||
),
|
||||
writeInstanceSwitch(
|
||||
componentInstanceMap,
|
||||
@ -100,26 +109,34 @@ case class TopComponentCppWriter (
|
||||
val portInstance = component.portMap(portName)
|
||||
val numPorts = numPortsConstantName(portInstance)
|
||||
val returnType = getInvokerReturnTypeAsString(portInstance)
|
||||
val returnsNonVoid = returnType != "void"
|
||||
val nonVoidReturn = returnType != "void"
|
||||
List.concat(
|
||||
lines(
|
||||
s"""|FW_ASSERT((0 <= portNum) && (portNum < $numPorts), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>($numPorts));
|
||||
|const auto instance = this->getInstance();"""
|
||||
),
|
||||
guardedList (returnsNonVoid) (lines(s"$returnType _result = {};")),
|
||||
writePortNumAssertion(numPorts),
|
||||
lines("const auto instance = this->getInstance();"),
|
||||
guardedList (nonVoidReturn) (lines(s"$returnType _result = {};")),
|
||||
writeInstanceSwitch(
|
||||
componentInstanceMap,
|
||||
writeOutFnCase,
|
||||
lines("FW_ASSERT(0, static_cast<FwAssertArgType>(portNum));")
|
||||
),
|
||||
guardedList (returnsNonVoid) (lines(s"return _result;"))
|
||||
guardedList (nonVoidReturn) (lines(s"return _result;"))
|
||||
)
|
||||
}
|
||||
|
||||
private def writeOutFnCase(portNum: Int, connection: Connection) = {
|
||||
val toPort = connection.to.port
|
||||
val fnName = CppWriter.writeQualifiedName(toPort.componentInstance.qualifiedName)
|
||||
lines("// TODO")
|
||||
val componentInstanceName = CppWriter.writeQualifiedName(toPort.componentInstance.qualifiedName)
|
||||
val portName = toPort.portInstance.getUnqualifiedName
|
||||
val handlerBaseName = inputPortHandlerBaseName(portName)
|
||||
val fnName = s"$componentInstanceName.$handlerBaseName"
|
||||
val returnType = getInvokerReturnTypeAsString(toPort.portInstance)
|
||||
val nonVoidReturn = returnType != "void"
|
||||
val addResultPrefix = addConditionalPrefix (nonVoidReturn) ("_result =")
|
||||
writeFunctionCall(
|
||||
addResultPrefix(fnName),
|
||||
List("portNum"),
|
||||
getPortParams(toPort.portInstance).map(_._1)
|
||||
)
|
||||
}
|
||||
|
||||
private def writeOutFnForPort(
|
||||
|
||||
@ -23,7 +23,7 @@ case class TopComponents(
|
||||
|
||||
def getMembers: List[CppDoc.Member] =
|
||||
wrapMembersInIfDirective(
|
||||
"#ifdef FW_DIRECT_PORT_CALLS",
|
||||
"#if FW_DIRECT_PORT_CALLS",
|
||||
addMemberComment(
|
||||
"Topology-dependent component implementation",
|
||||
getComponentMembers,
|
||||
|
||||
@ -160,7 +160,7 @@ namespace M {
|
||||
|
||||
}
|
||||
|
||||
#ifdef FW_DIRECT_PORT_CALLS
|
||||
#if FW_DIRECT_PORT_CALLS
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Topology-dependent component implementation
|
||||
@ -169,7 +169,11 @@ namespace M {
|
||||
namespace M {
|
||||
|
||||
bool PassiveComponentBase::isConnected_p_OutputPort(FwIndexType portNum) const {
|
||||
FW_ASSERT((0 <= portNum) && (portNum < NUM_P_OUTPUT_PORTS), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>(NUM_P_OUTPUT_PORTS));
|
||||
FW_ASSERT(
|
||||
(0 <= portNum) && (portNum < NUM_P_OUTPUT_PORTS),
|
||||
static_cast<FwAssertArgType>(portNum),
|
||||
static_cast<FwAssertArgType>(NUM_P_OUTPUT_PORTS)
|
||||
);
|
||||
bool result = false;
|
||||
const auto instance = this->getInstance();
|
||||
switch (instance) {
|
||||
@ -199,13 +203,17 @@ namespace M {
|
||||
}
|
||||
|
||||
void PassiveComponentBase::p_out(FwIndexType portNum) const {
|
||||
FW_ASSERT((0 <= portNum) && (portNum < NUM_P_OUTPUT_PORTS), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>(NUM_P_OUTPUT_PORTS));
|
||||
FW_ASSERT(
|
||||
(0 <= portNum) && (portNum < NUM_P_OUTPUT_PORTS),
|
||||
static_cast<FwAssertArgType>(portNum),
|
||||
static_cast<FwAssertArgType>(NUM_P_OUTPUT_PORTS)
|
||||
);
|
||||
const auto instance = this->getInstance();
|
||||
switch (instance) {
|
||||
case ::M::InstanceIds::M_passive1:
|
||||
switch (portNum) {
|
||||
case 0:
|
||||
// TODO
|
||||
active1.p_handlerBase(portNum);
|
||||
break;
|
||||
default:
|
||||
FW_ASSERT(0, static_cast<FwAssertArgType>(portNum));
|
||||
@ -215,7 +223,7 @@ namespace M {
|
||||
case ::M::InstanceIds::M_passive2:
|
||||
switch (portNum) {
|
||||
case 0:
|
||||
// TODO
|
||||
M::active2.p_handlerBase(portNum);
|
||||
break;
|
||||
default:
|
||||
FW_ASSERT(0, static_cast<FwAssertArgType>(portNum));
|
||||
|
||||
@ -150,7 +150,7 @@ namespace M {
|
||||
|
||||
}
|
||||
|
||||
#ifdef FW_DIRECT_PORT_CALLS
|
||||
#if FW_DIRECT_PORT_CALLS
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Topology-dependent component implementation
|
||||
@ -159,7 +159,11 @@ namespace M {
|
||||
namespace M {
|
||||
|
||||
bool CComponentBase::isConnected_pingOut_OutputPort(FwIndexType portNum) const {
|
||||
FW_ASSERT((0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS));
|
||||
FW_ASSERT(
|
||||
(0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS),
|
||||
static_cast<FwAssertArgType>(portNum),
|
||||
static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS)
|
||||
);
|
||||
bool result = false;
|
||||
const auto instance = this->getInstance();
|
||||
switch (instance) {
|
||||
@ -192,13 +196,20 @@ namespace M {
|
||||
FwIndexType portNum,
|
||||
U32 key
|
||||
) const {
|
||||
FW_ASSERT((0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS));
|
||||
FW_ASSERT(
|
||||
(0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS),
|
||||
static_cast<FwAssertArgType>(portNum),
|
||||
static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS)
|
||||
);
|
||||
const auto instance = this->getInstance();
|
||||
switch (instance) {
|
||||
case ::M::InstanceIds::M_c1:
|
||||
switch (portNum) {
|
||||
case 0:
|
||||
// TODO
|
||||
M::health.pingIn_handlerBase(
|
||||
portNum,
|
||||
key
|
||||
);
|
||||
break;
|
||||
default:
|
||||
FW_ASSERT(0, static_cast<FwAssertArgType>(portNum));
|
||||
@ -208,7 +219,10 @@ namespace M {
|
||||
case ::M::InstanceIds::M_c2:
|
||||
switch (portNum) {
|
||||
case 0:
|
||||
// TODO
|
||||
M::health.pingIn_handlerBase(
|
||||
portNum,
|
||||
key
|
||||
);
|
||||
break;
|
||||
default:
|
||||
FW_ASSERT(0, static_cast<FwAssertArgType>(portNum));
|
||||
@ -226,7 +240,11 @@ namespace M {
|
||||
namespace Svc {
|
||||
|
||||
bool HealthComponentBase::isConnected_pingOut_OutputPort(FwIndexType portNum) const {
|
||||
FW_ASSERT((0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS));
|
||||
FW_ASSERT(
|
||||
(0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS),
|
||||
static_cast<FwAssertArgType>(portNum),
|
||||
static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS)
|
||||
);
|
||||
bool result = false;
|
||||
const auto instance = this->getInstance();
|
||||
switch (instance) {
|
||||
@ -253,16 +271,26 @@ namespace Svc {
|
||||
FwIndexType portNum,
|
||||
U32 key
|
||||
) const {
|
||||
FW_ASSERT((0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS), static_cast<FwAssertArgType>(portNum), static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS));
|
||||
FW_ASSERT(
|
||||
(0 <= portNum) && (portNum < NUM_PINGOUT_OUTPUT_PORTS),
|
||||
static_cast<FwAssertArgType>(portNum),
|
||||
static_cast<FwAssertArgType>(NUM_PINGOUT_OUTPUT_PORTS)
|
||||
);
|
||||
const auto instance = this->getInstance();
|
||||
switch (instance) {
|
||||
case ::M::InstanceIds::M_health:
|
||||
switch (portNum) {
|
||||
case 0:
|
||||
// TODO
|
||||
M::c1.pingIn_handlerBase(
|
||||
portNum,
|
||||
key
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
// TODO
|
||||
M::c2.pingIn_handlerBase(
|
||||
portNum,
|
||||
key
|
||||
);
|
||||
break;
|
||||
default:
|
||||
FW_ASSERT(0, static_cast<FwAssertArgType>(portNum));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user