Skip to content

Commit aefbc30

Browse files
authored
Merge pull request #212 from tiffany1618/issue-209-port-cpp-bugs
Fix bugs in generated C++ for ports
2 parents 1b3de20 + 23a2288 commit aefbc30

File tree

9 files changed

+141
-149
lines changed

9 files changed

+141
-149
lines changed

compiler/lib/src/main/scala/codegen/CppWriter/PortCppWriter.scala

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ case class PortCppWriter (
351351
|this->trace();
352352
|#endif
353353
|
354-
|FW_ASSERT(this->m_comp);
355-
|FW_ASSERT(this->m_func);
354+
|FW_ASSERT(this->m_comp != nullptr);
355+
|FW_ASSERT(this->m_func != nullptr);
356356
|"""
357357
) ++
358358
paramList.flatMap((n, tn, _) => {
@@ -422,8 +422,8 @@ case class PortCppWriter (
422422
),
423423
CppDoc.Type("void"),
424424
lines(
425-
"""|FW_ASSERT(callComp);
426-
|FW_ASSERT(funcPtr);
425+
"""|FW_ASSERT(callComp != nullptr);
426+
|FW_ASSERT(funcPtr != nullptr);
427427
|
428428
|this->m_comp = callComp;
429429
|this->m_func = funcPtr;
@@ -443,8 +443,8 @@ case class PortCppWriter (
443443
|this->trace();
444444
|#endif
445445
|
446-
|FW_ASSERT(this->m_comp);
447-
|FW_ASSERT(this->m_func);
446+
|FW_ASSERT(this->m_comp != nullptr);
447+
|FW_ASSERT(this->m_func != nullptr);
448448
|
449449
|return this->m_func(this->m_comp, this->m_portNum${paramNames});
450450
|"""
@@ -501,38 +501,48 @@ case class PortCppWriter (
501501
}
502502

503503
private def getOutputPortFunctionMembers: List[CppDoc.Class.Member] = {
504-
val paramNames = paramList.map(_._1).mkString(", ")
504+
val invokeCall = s"this->m_port->invoke(${paramList.map(_._1).mkString(", ")});"
505505
val invokeBody = data.returnType match {
506506
case Some(_) => lines(
507-
s"return this->m_port->invoke($paramNames);"
508-
)
509-
case None => lines(
510-
s"""|if (this->m_port) {
511-
| this->m_port->invoke($paramNames);
512-
|#if FW_PORT_SERIALIZATION
513-
|} else if (this->m_serPort) {
514-
| Fw::SerializeStatus _status;
515-
| ${name}PortBuffer _buffer;
507+
s"""|
508+
|FW_ASSERT(this->m_port != nullptr);
509+
|return $invokeCall
516510
|"""
517-
) ++
511+
)
512+
case None => List(
513+
lines(
514+
s"""|
515+
|#if FW_PORT_SERIALIZATION
516+
|FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));
517+
|
518+
|if (this->m_port != nullptr) {
519+
| $invokeCall
520+
|}
521+
|else {
522+
| Fw::SerializeStatus _status;
523+
| ${name}PortBuffer _buffer;
524+
|"""
525+
),
518526
paramList.flatMap((n, _, _) => {
519527
lines(
520528
s"""|
521529
| _status = _buffer.serialize($n);
522530
| FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
523531
|"""
524532
)
525-
}) ++
533+
}),
526534
lines(
527-
"""|
528-
| _status = this->m_serPort->invokeSerial(_buffer);
529-
| FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
530-
|}
531-
|#else
532-
|}
533-
|#endif
534-
|"""
535+
s"""|
536+
| _status = this->m_serPort->invokeSerial(_buffer);
537+
| FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
538+
|}
539+
|#else
540+
|FW_ASSERT(this->m_port != nullptr);
541+
|$invokeCall
542+
|#endif
543+
|"""
535544
)
545+
).flatten
536546
}
537547

538548
List(
@@ -577,7 +587,7 @@ case class PortCppWriter (
577587
),
578588
CppDoc.Type("void"),
579589
lines(
580-
"""|FW_ASSERT(callPort);
590+
"""|FW_ASSERT(callPort != nullptr);
581591
|
582592
|this->m_port = callPort;
583593
|this->m_connObj = callPort;
@@ -599,13 +609,6 @@ case class PortCppWriter (
599609
s"""|#if FW_PORT_TRACING == 1
600610
|this->trace();
601611
|#endif
602-
|
603-
|#if FW_PORT_SERIALIZATION
604-
|FW_ASSERT(this->m_port || this->m_serPort);
605-
|#else
606-
|FW_ASSERT(this->m_port);
607-
|#endif
608-
|
609612
|"""
610613
) ++
611614
invokeBody

compiler/tools/fpp-to-cpp/test/port/AbsTypePortAc.ref.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void InputAbsTypePort ::
6262
CompFuncPtr funcPtr
6363
)
6464
{
65-
FW_ASSERT(callComp);
66-
FW_ASSERT(funcPtr);
65+
FW_ASSERT(callComp != nullptr);
66+
FW_ASSERT(funcPtr != nullptr);
6767

6868
this->m_comp = callComp;
6969
this->m_func = funcPtr;
@@ -80,8 +80,8 @@ void InputAbsTypePort ::
8080
this->trace();
8181
#endif
8282

83-
FW_ASSERT(this->m_comp);
84-
FW_ASSERT(this->m_func);
83+
FW_ASSERT(this->m_comp != nullptr);
84+
FW_ASSERT(this->m_func != nullptr);
8585

8686
return this->m_func(this->m_comp, this->m_portNum, t, tRef);
8787
}
@@ -97,8 +97,8 @@ Fw::SerializeStatus InputAbsTypePort ::
9797
this->trace();
9898
#endif
9999

100-
FW_ASSERT(this->m_comp);
101-
FW_ASSERT(this->m_func);
100+
FW_ASSERT(this->m_comp != nullptr);
101+
FW_ASSERT(this->m_func != nullptr);
102102

103103
T t;
104104
_status = _buffer.deserialize(t);
@@ -140,7 +140,7 @@ void OutputAbsTypePort ::
140140
void OutputAbsTypePort ::
141141
addCallPort(InputAbsTypePort* callPort)
142142
{
143-
FW_ASSERT(callPort);
143+
FW_ASSERT(callPort != nullptr);
144144

145145
this->m_port = callPort;
146146
this->m_connObj = callPort;
@@ -161,14 +161,12 @@ void OutputAbsTypePort ::
161161
#endif
162162

163163
#if FW_PORT_SERIALIZATION
164-
FW_ASSERT(this->m_port || this->m_serPort);
165-
#else
166-
FW_ASSERT(this->m_port);
167-
#endif
168-
if (this->m_port) {
164+
FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));
165+
166+
if (this->m_port != nullptr) {
169167
this->m_port->invoke(t, tRef);
170-
#if FW_PORT_SERIALIZATION
171-
} else if (this->m_serPort) {
168+
}
169+
else {
172170
Fw::SerializeStatus _status;
173171
AbsTypePortBuffer _buffer;
174172

@@ -182,6 +180,7 @@ void OutputAbsTypePort ::
182180
FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
183181
}
184182
#else
185-
}
183+
FW_ASSERT(this->m_port != nullptr);
184+
this->m_port->invoke(t, tRef);
186185
#endif
187186
}

compiler/tools/fpp-to-cpp/test/port/BuiltInTypePortAc.ref.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void InputBuiltInTypePort ::
6262
CompFuncPtr funcPtr
6363
)
6464
{
65-
FW_ASSERT(callComp);
66-
FW_ASSERT(funcPtr);
65+
FW_ASSERT(callComp != nullptr);
66+
FW_ASSERT(funcPtr != nullptr);
6767

6868
this->m_comp = callComp;
6969
this->m_func = funcPtr;
@@ -80,8 +80,8 @@ void InputBuiltInTypePort ::
8080
this->trace();
8181
#endif
8282

83-
FW_ASSERT(this->m_comp);
84-
FW_ASSERT(this->m_func);
83+
FW_ASSERT(this->m_comp != nullptr);
84+
FW_ASSERT(this->m_func != nullptr);
8585

8686
return this->m_func(this->m_comp, this->m_portNum, t, tRef);
8787
}
@@ -97,8 +97,8 @@ Fw::SerializeStatus InputBuiltInTypePort ::
9797
this->trace();
9898
#endif
9999

100-
FW_ASSERT(this->m_comp);
101-
FW_ASSERT(this->m_func);
100+
FW_ASSERT(this->m_comp != nullptr);
101+
FW_ASSERT(this->m_func != nullptr);
102102

103103
FwOpcodeType t;
104104
_status = _buffer.deserialize(t);
@@ -140,7 +140,7 @@ void OutputBuiltInTypePort ::
140140
void OutputBuiltInTypePort ::
141141
addCallPort(InputBuiltInTypePort* callPort)
142142
{
143-
FW_ASSERT(callPort);
143+
FW_ASSERT(callPort != nullptr);
144144

145145
this->m_port = callPort;
146146
this->m_connObj = callPort;
@@ -161,14 +161,12 @@ void OutputBuiltInTypePort ::
161161
#endif
162162

163163
#if FW_PORT_SERIALIZATION
164-
FW_ASSERT(this->m_port || this->m_serPort);
165-
#else
166-
FW_ASSERT(this->m_port);
167-
#endif
168-
if (this->m_port) {
164+
FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));
165+
166+
if (this->m_port != nullptr) {
169167
this->m_port->invoke(t, tRef);
170-
#if FW_PORT_SERIALIZATION
171-
} else if (this->m_serPort) {
168+
}
169+
else {
172170
Fw::SerializeStatus _status;
173171
BuiltInTypePortBuffer _buffer;
174172

@@ -182,6 +180,7 @@ void OutputBuiltInTypePort ::
182180
FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
183181
}
184182
#else
185-
}
183+
FW_ASSERT(this->m_port != nullptr);
184+
this->m_port->invoke(t, tRef);
186185
#endif
187186
}

compiler/tools/fpp-to-cpp/test/port/EmptyPortAc.ref.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ void InputEmptyPort ::
5858
CompFuncPtr funcPtr
5959
)
6060
{
61-
FW_ASSERT(callComp);
62-
FW_ASSERT(funcPtr);
61+
FW_ASSERT(callComp != nullptr);
62+
FW_ASSERT(funcPtr != nullptr);
6363

6464
this->m_comp = callComp;
6565
this->m_func = funcPtr;
@@ -73,8 +73,8 @@ void InputEmptyPort ::
7373
this->trace();
7474
#endif
7575

76-
FW_ASSERT(this->m_comp);
77-
FW_ASSERT(this->m_func);
76+
FW_ASSERT(this->m_comp != nullptr);
77+
FW_ASSERT(this->m_func != nullptr);
7878

7979
return this->m_func(this->m_comp, this->m_portNum);
8080
}
@@ -90,8 +90,8 @@ Fw::SerializeStatus InputEmptyPort ::
9090
this->trace();
9191
#endif
9292

93-
FW_ASSERT(this->m_comp);
94-
FW_ASSERT(this->m_func);
93+
FW_ASSERT(this->m_comp != nullptr);
94+
FW_ASSERT(this->m_func != nullptr);
9595

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

@@ -121,7 +121,7 @@ void OutputEmptyPort ::
121121
void OutputEmptyPort ::
122122
addCallPort(InputEmptyPort* callPort)
123123
{
124-
FW_ASSERT(callPort);
124+
FW_ASSERT(callPort != nullptr);
125125

126126
this->m_port = callPort;
127127
this->m_connObj = callPort;
@@ -139,21 +139,20 @@ void OutputEmptyPort ::
139139
#endif
140140

141141
#if FW_PORT_SERIALIZATION
142-
FW_ASSERT(this->m_port || this->m_serPort);
143-
#else
144-
FW_ASSERT(this->m_port);
145-
#endif
146-
if (this->m_port) {
142+
FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));
143+
144+
if (this->m_port != nullptr) {
147145
this->m_port->invoke();
148-
#if FW_PORT_SERIALIZATION
149-
} else if (this->m_serPort) {
146+
}
147+
else {
150148
Fw::SerializeStatus _status;
151149
EmptyPortBuffer _buffer;
152150

153151
_status = this->m_serPort->invokeSerial(_buffer);
154152
FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
155153
}
156154
#else
157-
}
155+
FW_ASSERT(this->m_port != nullptr);
156+
this->m_port->invoke();
158157
#endif
159158
}

0 commit comments

Comments
 (0)