From 5929d441dec81180ecde75dd2c58fa1108da97bf Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sat, 24 Aug 2024 22:18:15 +0200 Subject: [PATCH] C++: fix translation of large integers in the set of enum values Fixes test EnumLongRangeS for `cpp_stl_11/{clang3.4,clang11}-linux-x86_64` Probably also fixes EnumLongRangeS for `cpp_stl_11/clang14-macos-x86_64` - untested, but seems very likely, given that the build error looks exactly the same as in `cpp_stl_11/clang11-linux-x86_64`. Hopefully also fixes the Enum{Int,Long}Range{S,U} tests for `cpp_stl_11/msvc141-windows-x64` - I haven't tested that locally, so let's see the result in CI. --- .../src/main/scala/io/kaitai/struct/languages/CppCompiler.scala | 2 +- .../src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala index 0b0ab4814..8a75414d5 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/CppCompiler.scala @@ -905,7 +905,7 @@ class CppCompiler( outHdr.puts(s"static const std::set::type> _values_$enumClass;") val enumClassAbs = types2class(curClass ++ List(enumName)) val valuesSetAbsRef = s"${types2class(curClass)}::_values_$enumClass" - val setEntriesStr = enumColl.map { case (id, _) => s"$id" }.mkString(", ") + val setEntriesStr = enumColl.map { case (id, _) => translator.doIntLiteral(id) }.mkString(", ") outSrc.puts(s"const std::set::type> $valuesSetAbsRef{$setEntriesStr};") } } diff --git a/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala index 20453406f..884737312 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/PHPCompiler.scala @@ -440,7 +440,7 @@ class PHPCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.puts(s"const ${value2Const(label.name)} = ${translator.doIntLiteral(id)};") } out.puts - val arrayEntriesStr = enumColl.map { case (id, _) => s"$id => true" }.mkString(", ") + val arrayEntriesStr = enumColl.map { case (id, _) => s"${translator.doIntLiteral(id)} => true" }.mkString(", ") out.puts(s"private const _VALUES = [$arrayEntriesStr];") out.puts out.puts("public static function isDefined(int $v): bool {")