Skip to content

Commit

Permalink
Implement all builtin types tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mi-La committed Jan 13, 2025
1 parent fc63593 commit 0476871
Show file tree
Hide file tree
Showing 10 changed files with 729 additions and 22 deletions.
4 changes: 2 additions & 2 deletions extension/src/zserio/extension/cpp17/CppLiteralFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
public final class CppLiteralFormatter
{
public static String formatUInt8Literal(int value) throws ZserioExtensionException
public static String formatUInt8Literal(BigInteger value) throws ZserioExtensionException
{
return uint8Type.formatLiteral(BigInteger.valueOf(value));
return uint8Type.formatLiteral(value);
}

public static String formatStringLiteral(String value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import zserio.ast.DynamicBitFieldInstantiation;
import zserio.ast.DynamicBitFieldType;
import zserio.ast.EnumType;
import zserio.ast.Expression;
import zserio.ast.ExternType;
import zserio.ast.FloatType;
import zserio.ast.IntegerType;
import zserio.ast.StringType;
import zserio.ast.TypeInstantiation;
import zserio.ast.TypeReference;
import zserio.ast.ZserioType;
import zserio.extension.common.ExpressionFormatter;
import zserio.extension.common.ZserioExtensionException;
import zserio.extension.cpp17.types.CppNativeType;
import zserio.extension.cpp17.types.NativeDynamicBitFieldType;
Expand All @@ -31,17 +31,20 @@ public static NativeTypeInfoTemplateData create(TemplateDataContext context, Cpp
final StringBuilder typeTemplateArgBuilder = new StringBuilder();
if (nativeType instanceof NativeIntegralType)
{
final ExpressionFormatter expressionFormatter = context.getExpressionFormatter(includeCollector);
if (nativeType instanceof NativeDynamicBitFieldType &&
typeInstantiation instanceof DynamicBitFieldInstantiation)
{
typeTemplateArgBuilder.append('<');
final DynamicBitFieldInstantiation dynamicBitFieldInstantiation =
(DynamicBitFieldInstantiation)typeInstantiation;
if (dynamicBitFieldInstantiation.getLengthExpression().getIntegerValue() != null)
final Expression lengthExpression = dynamicBitFieldInstantiation.getLengthExpression();
// dynamic bit field length must be constant expression and since this is a generic expression,
// which can contain e.g. functions (which are implemented only on View),
// it's safer to use the calculated value
if (lengthExpression.getIntegerValue() != null)
{
typeTemplateArgBuilder.append(expressionFormatter.formatGetter(
dynamicBitFieldInstantiation.getLengthExpression()));
typeTemplateArgBuilder.append(
CppLiteralFormatter.formatUInt8Literal(lengthExpression.getIntegerValue()));
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions test/language/builtin_types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_library(builtin_types_zs STATIC zs/builtin_types.zs)
add_library(builtin_types_zs STATIC ${TEST_ZS_ROOT}/builtin_types.zs)
zserio_generate_cpp(
TARGET builtin_types_zs
SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs
SRC_DIR ${TEST_ZS_ROOT}
GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen
EXTRA_ARGS ${ZSERIO_EXTRA_ARGS}
GENERATED_SOURCES_VAR GENERATED_SOURCES
Expand All @@ -18,7 +18,10 @@ add_custom_test(builtin_types
DEPENDS
builtin_types_zs
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cpp/AllBuiltInTypesTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/BitFieldFunctionLengthTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/BitFieldUInt64LengthTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/DynamicBitFieldLengthBoundsTest.cpp
GENERATED_SOURCES
${GENERATED_SOURCES}
)
3 changes: 3 additions & 0 deletions test/language/builtin_types/ClangTidySuppressions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hicpp-signed-bitwise:gen/builtin_types/bitfield_function_length/Container.cpp

readability-simplify-boolean-expr:gen/builtin_types/all_builtin_types/AllBuiltInTypes.cpp
Loading

0 comments on commit 0476871

Please sign in to comment.