Skip to content

Commit

Permalink
C++: implement doByteArrayNonLiteral - create array from expression o…
Browse files Browse the repository at this point in the history
…f `bytes` type

Expressions of this type are created using:
- omitting the `type:` field in attributes and parse instances
- declaring parameters with `type: bytes`
- using `.as<bytes>` cast

Ghostly fixes test
```
[info]     - cpp_stl:[0 + 1, 5].as<bytes> *** FAILED ***
[info]       scala.NotImplementedError: an implementation is missing
[info]       at scala.Predef$.$qmark$qmark$qmark(Predef.scala:344)
[info]       at io.kaitai.struct.translators.BaseTranslator.doByteArrayNonLiteral(BaseTranslator.scala:179)
[info]       at io.kaitai.struct.translators.BaseTranslator.doByteArrayNonLiteral(BaseTranslator.scala:28)
[info]       at io.kaitai.struct.translators.CommonArraysAndCast.doByteArray(CommonArraysAndCast.scala:85)
[info]       at io.kaitai.struct.translators.CommonArraysAndCast.doCastOrArray(CommonArraysAndCast.scala:62)
[info]       at io.kaitai.struct.translators.CommonArraysAndCast.doCastOrArray$(CommonArraysAndCast.scala:53)
[info]       at io.kaitai.struct.translators.BaseTranslator.doCastOrArray(BaseTranslator.scala:28)
[info]       at io.kaitai.struct.translators.BaseTranslator.translate(BaseTranslator.scala:147)
[info]       at io.kaitai.struct.translators.AbstractTranslator.translate(AbstractTranslator.scala:25)
[info]       at io.kaitai.struct.translators.AbstractTranslator.translate$(AbstractTranslator.scala:25)
[info]       ...
```
(actually, test is failing because option `useListInitializers` in C++ backend is not set in tests
and code generation without it is not unimplemented right now)
  • Loading branch information
Mingun committed Mar 18, 2024
1 parent ca6d683 commit 1c22828
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class CppTranslator(provider: TypeProvider, importListSrc: CppImportList, import

override def doByteArrayLiteral(arr: Seq[Byte]): String =
"std::string(\"" + Utils.hexEscapeByteArray(arr) + "\", " + arr.length + ")"
override def doByteArrayNonLiteral(values: Seq[Ast.expr]): String =
doArrayLiteral(DataType.Int1Type(false), values)

override def numericBinOp(left: Ast.expr, op: Ast.operator, right: Ast.expr) = {
(detectType(left), detectType(right), op) match {
Expand Down

0 comments on commit 1c22828

Please sign in to comment.