Skip to content

Commit

Permalink
C++: generate correct null check for special properties _root and `…
Browse files Browse the repository at this point in the history
…_parent`
  • Loading branch information
Mingun committed Jul 19, 2024
1 parent deec84c commit ab9083f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions spec/cpp_stl_11/test_nested_types_import.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions spec/cpp_stl_98/test_nested_types_import.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.kaitai.struct.testtranslator.specgenerators

import io.kaitai.struct.datatype.{DataType, KSError}
import io.kaitai.struct.exprlang.Ast
import io.kaitai.struct.format.Identifier
import io.kaitai.struct.languages.CppCompiler
import io.kaitai.struct.testtranslator.{Main, TestAssert, TestEquals, TestSpec}
import io.kaitai.struct.translators.CppTranslator
Expand Down Expand Up @@ -75,9 +76,19 @@ class CppStlSG(spec: TestSpec, provider: ClassTypeProvider, cppConfig: CppRuntim
override def nullAssert(actual: Ast.expr): Unit = {
val nullCheckStr = actual match {
case Ast.expr.Attribute(x, Ast.identifier(attrName)) =>
translateAct(x) + s"->_is_null_$attrName()"
val expr = translateAct(x)
attrName match {
case Identifier.PARENT | Identifier.ROOT =>
config.cppConfig.pointers match {
case CppRuntimeConfig.UniqueAndRawPointers =>
out.puts(s"BOOST_CHECK_EQUAL($expr->$attrName(), nullptr);")
case CppRuntimeConfig.RawPointers =>
out.puts(s"BOOST_CHECK(!$expr->$attrName());")
}
case _ =>
out.puts(s"BOOST_CHECK($expr->_is_null_$attrName());")
}
}
out.puts(s"BOOST_CHECK($nullCheckStr);")
}

override def trueArrayEquality(check: TestEquals, elType: DataType, elts: Seq[Ast.expr]): Unit = {
Expand Down

0 comments on commit ab9083f

Please sign in to comment.