Revise C++ code gen for arrays

This commit is contained in:
Rob Bocchino 2025-11-16 13:59:10 -08:00
parent d16c2b2588
commit c018bea624
8 changed files with 24 additions and 21 deletions

View File

@ -163,16 +163,13 @@ case class ArrayCppWriter (
private val initElementsCall = guardedList (hasStringEltType) (lines("this->initElements();"))
private val defaultElementInitialization: Boolean = {
if hasStringEltType then false
else {
val elements = arrayType.getDefaultValue.get.anonArray.elements
val elementType = arrayType.anonArray.eltType.getDefaultValue
elementType match {
case None => false
case Some(elementTypeDefault) =>
elements.head == elementTypeDefault &&
elements.tail.forall(_ == elements.head)
}
val elements = arrayType.getDefaultValue.get.anonArray.elements
val elementType = arrayType.anonArray.eltType.getDefaultValue
elementType match {
case None => false
case Some(elementTypeDefault) =>
elements.head == elementTypeDefault &&
elements.tail.forall(_ == elements.head)
}
}
@ -180,9 +177,9 @@ case class ArrayCppWriter (
val defaultValueConstructor = constructorClassMember(
Some("Constructor (default value)"),
Nil,
List.concat(
List("Serializable()"),
guardedList(defaultElementInitialization) (List("elements{}"))
List(
"Serializable()",
"elements{}"
),
List.concat(
initElementsCall,

View File

@ -13,7 +13,8 @@
AliasType ::
AliasType() :
Serializable()
Serializable(),
elements{}
{
*this = AliasType({0, 2, 3});
}

View File

@ -13,7 +13,8 @@
Enum1 ::
Enum1() :
Serializable()
Serializable(),
elements{}
{
*this = Enum1({M::E1::X, M::E1::Y});
}

View File

@ -15,7 +15,8 @@ namespace M {
PrimitiveF32e ::
PrimitiveF32e() :
Serializable()
Serializable(),
elements{}
{
*this = M::PrimitiveF32e(1.0f);
}

View File

@ -15,7 +15,8 @@ namespace M {
PrimitiveF64 ::
PrimitiveF64() :
Serializable()
Serializable(),
elements{}
{
*this = M::PrimitiveF64({1.0, 2.0, 3.0, 4.0, 5.0});
}

View File

@ -15,7 +15,8 @@ namespace M {
PrimitiveU16 ::
PrimitiveU16() :
Serializable()
Serializable(),
elements{}
{
*this = M::PrimitiveU16({1, 2, 3});
}

View File

@ -13,10 +13,10 @@
String1 ::
String1() :
Serializable()
Serializable(),
elements{}
{
this->initElements();
*this = String1(Fw::String(""));
}
String1 ::

View File

@ -13,7 +13,8 @@
String2 ::
String2() :
Serializable()
Serializable(),
elements{}
{
this->initElements();
*this = String2({Fw::String("\"\\"), Fw::String("abc\ndef\n")});