Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions compiler/lib/src/main/scala/codegen/CppWriter/ArrayCppWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,18 @@ case class ArrayCppWriter (
CppDoc.Lines.Both
) :: writeOstreamOperator(
name,
lines(
"""|Fw::String s;
|obj.toString(s);
|os << s;
|return os;"""
List.concat(
lines(s"""|os << "[";
|constexpr auto SIZE = $name::SIZE;"""),
indexIterator(lines(
s"""|if (index > 0) {
| os << ", ";
|}
|
|os << obj.elements[index];
""")),
lines("""|os << "]";
|return os;""")
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,36 @@ case class StructCppWriter(
scalarConstructor
}

private def writeOstreamBody: List[Line] = {
val memberOutputs = memberList.zipWithIndex.flatMap { case ((n, tn), idx) =>
val prefix = if idx > 0 then lines("""os << ", ";""") else Nil
val fieldLabel = lines(s"""os << "$n = ";""")

val fieldValue = if sizes.contains(n) then
List.concat(
lines("""os << "[ ";"""),
iterateN(sizes(n), lines(
"""|if (i > 0) {
| os << ", ";
|}
|os << obj.m_""" + n + "[i];"
)),
lines("""os << " ]";""")
)
else
lines(s"os << obj.m_$n;")

List.concat(prefix, fieldLabel, fieldValue)
}

List.concat(
lines("""os << "{ ";"""),
memberOutputs,
lines("""os << " }";"""),
lines("return os;")
)
}

private def getOperatorMembers: List[CppDoc.Class.Member] = {
val nonArrayMemberCheck = lines(
nonArrayMemberNames.map(n => s"(this->m_$n == obj.m_$n)"
Expand Down Expand Up @@ -363,12 +393,7 @@ case class StructCppWriter(
CppDoc.Lines.Both
) :: writeOstreamOperator(
name,
lines(
"""|Fw::String s;
|obj.toString(s);
|os << s.toChar();
|return os;"""
)
writeOstreamBody
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ bool Abs ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const Abs& obj) {
Fw::String s;
obj.toString(s);
os << s.toChar();
os << "{ ";
os << "A = ";
os << obj.m_A;
os << " }";
return os;
}

Expand Down
16 changes: 13 additions & 3 deletions compiler/tools/fpp-to-cpp/test/alias/BasicSerializableAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ bool Basic ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const Basic& obj) {
Fw::String s;
obj.toString(s);
os << s.toChar();
os << "{ ";
os << "A = ";
os << obj.m_A;
os << ", ";
os << "B = ";
os << obj.m_B;
os << ", ";
os << "C = ";
os << obj.m_C;
os << ", ";
os << "D = ";
os << obj.m_D;
os << " }";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/alias/C_AArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool C_A ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const C_A& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = C_A::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,19 @@ bool Namespace ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const Namespace& obj) {
Fw::String s;
obj.toString(s);
os << s.toChar();
os << "{ ";
os << "A = ";
os << obj.m_A;
os << ", ";
os << "B = ";
os << obj.m_B;
os << ", ";
os << "C = ";
os << obj.m_C;
os << ", ";
os << "D = ";
os << obj.m_D;
os << " }";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/alias/SM_AArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool SM_A ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const SM_A& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = SM_A::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/AArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool A ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const A& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = A::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/AbsTypeArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool AbsType ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const AbsType& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = AbsType::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/AliasTypeArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool AliasType ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const AliasType& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = AliasType::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/C_AArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool C_A ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const C_A& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = C_A::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/Enum1ArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool Enum1 ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const Enum1& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = Enum1::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/Enum2ArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool Enum2 ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const Enum2& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = Enum2::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool HeaderPath ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const HeaderPath& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = HeaderPath::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/LargeSizeArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool LargeSize ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const LargeSize& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = LargeSize::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/PrimitiveArrayArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ bool PrimitiveArray ::
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const PrimitiveArray& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = PrimitiveArray::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/tools/fpp-to-cpp/test/array/PrimitiveBoolArrayAc.ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,17 @@ namespace M {
#ifdef BUILD_UT

std::ostream& operator<<(std::ostream& os, const PrimitiveBool& obj) {
Fw::String s;
obj.toString(s);
os << s;
os << "[";
constexpr auto SIZE = PrimitiveBool::SIZE;
for (FwSizeType index = 0; index < SIZE; index++) {
if (index > 0) {
os << ", ";
}

os << obj.elements[index];

}
os << "]";
return os;
}

Expand Down
Loading