Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp: Store compounds real bit size with its pos #658

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler/extensions/cpp/freemarker/Choice.cpp.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ ${I}return {};
</#if>
}

size_t realBitSizeOf() const override
{
<#if withBitPositionCode>
return m_object.realBitSizeOf();
<#else>
throw ::zserio::CppRuntimeException("Reflectable '${name}': ") <<
"Bit position code is disabled by '-withoutBitPositionCode' zserio option!";
</#if>
}

private:
<#if isConst>const </#if>${fullName}& m_object;
};
Expand Down Expand Up @@ -591,6 +601,11 @@ size_t ${name}::bitPosition() const
{
return m_bitPosition;
}

size_t ${name}::realBitSizeOf() const
{
return m_realBitSize;
}
</#if>
<#if fieldList?has_content>

Expand Down
17 changes: 16 additions & 1 deletion compiler/extensions/cpp/freemarker/Choice.h.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,21 @@ public:
*/
</#if>
size_t bitPosition() const;

<#if withCodeComments>
/**
* Get the bit size of the parsed blob after reading. This size can differ
* from the one returned by getBitSizeOf() if compression took place.
*
* This feature is experimental and can be removed without any warning!
*
* \note Note that the returned bit size is valid only directly after read! If the Zserio object
* has been changed after reading, the result is unspecified!
*
* \return Size of the object as it was stored in the blob in bits.
*/
</#if>
size_t realBitSizeOf() const;
</#if>

private:
Expand All @@ -360,7 +375,7 @@ private:
<@compound_constructor_members compoundConstructorsData/>
<#if withBitPositionCode>
<#-- Bit position must be before m_objectChoice in order to get initialized first. -->
size_t m_bitPosition;
size_t m_bitPosition, m_realBitSize;
</#if>
<#if fieldList?has_content>
${types.anyHolder.name} m_objectChoice;
Expand Down
20 changes: 20 additions & 0 deletions compiler/extensions/cpp/freemarker/CompoundConstructor.inc.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
</#if>
<#if withBitPositionCode>
m_bitPosition(0)
m_realBitSize(0)
</#if>
<#if memberInitializationMacroName != "">
<#if (numExtendedFields > 0)>
Expand Down Expand Up @@ -102,6 +103,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
</#if>
<#if withBitPositionCode>
m_bitPosition(in.getBitPosition())
m_realBitSize(0)
</#if>
<#if memberInitializationMacroName != "">
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
Expand All @@ -111,6 +113,14 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
</#if>
</@cpp_initializer_list>
{
<#-- Determine the real bit size after member initialization took place. -->
<#if withBitPositionCode>
<#if packed>
m_realBitSize = bitSizeOf(context, m_bitPosition);
<#else>
m_realBitSize = bitSizeOf();
</#if>
</#if>
}
</#macro>

Expand Down Expand Up @@ -168,6 +178,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
<@cpp_initializer_list>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields(other.m_numExtendedFields)
Expand All @@ -191,6 +202,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
m_isInitialized(false)
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields(other.m_numExtendedFields)
Expand Down Expand Up @@ -237,6 +249,7 @@ ${compoundConstructorsData.compoundName}& ${compoundConstructorsData.compoundNam
{
<#if withBitPositionCode>
m_bitPosition = other.m_bitPosition;
m_realBitSize = other.m_realBitSize;
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields = other.m_numExtendedFields;
Expand All @@ -260,6 +273,7 @@ ${compoundConstructorsData.compoundName}& ${compoundConstructorsData.compoundNam
m_isInitialized = false;
<#if withBitPositionCode>
m_bitPosition = other.m_bitPosition;
m_realBitSize = other.m_realBitSize;
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields = other.m_numExtendedFields;
Expand Down Expand Up @@ -306,6 +320,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
<@cpp_initializer_list>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields(other.m_numExtendedFields)
Expand All @@ -329,6 +344,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
m_isInitialized(false)
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields(other.m_numExtendedFields)
Expand Down Expand Up @@ -376,6 +392,7 @@ ${compoundConstructorsData.compoundName}& ${compoundConstructorsData.compoundNam
{
<#if withBitPositionCode>
m_bitPosition = other.m_bitPosition;
m_realBitSize = other.m_realBitSize;
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields = other.m_numExtendedFields;
Expand All @@ -399,6 +416,7 @@ ${compoundConstructorsData.compoundName}& ${compoundConstructorsData.compoundNam
m_isInitialized = false;
<#if withBitPositionCode>
m_bitPosition = other.m_bitPosition;
m_realBitSize = other.m_realBitSize;
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields = other.m_numExtendedFields;
Expand Down Expand Up @@ -450,6 +468,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
<@cpp_initializer_list>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields(other.m_numExtendedFields)
Expand Down Expand Up @@ -478,6 +497,7 @@ ${compoundConstructorsData.compoundName}::${compoundConstructorsData.compoundNam
m_isInitialized(false)
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
<#if (num_extended_fields(compoundConstructorsData.fieldList) > 0)>
m_numExtendedFields(other.m_numExtendedFields)
Expand Down
15 changes: 15 additions & 0 deletions compiler/extensions/cpp/freemarker/Structure.cpp.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ const ${types.typeInfo.name}& ${name}::typeInfo()
</#if>
}

size_t realBitSizeOf() const override
{
<#if withBitPositionCode>
return m_object.realBitSizeOf();
<#else>
throw ::zserio::CppRuntimeException("Reflectable '${name}': ") <<
"Bit position code is disabled by '-withoutBitPositionCode' zserio option!";
</#if>
}

private:
<#if isConst>const </#if>${fullName}& m_object;
};
Expand Down Expand Up @@ -574,6 +584,11 @@ size_t ${name}::bitPosition() const
{
return m_bitPosition;
}

size_t ${name}::realBitSizeOf() const
{
return m_realBitSize;
}
</#if>
<#if fieldList?has_content>

Expand Down
17 changes: 16 additions & 1 deletion compiler/extensions/cpp/freemarker/Structure.h.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@ public:
*/
</#if>
size_t bitPosition() const;

<#if withCodeComments>
/**
* Get the bit size of the parsed blob after reading. This size can differ
* from the one returned by getBitSizeOf() if compression took place.
*
* This feature is experimental and can be removed without any warning!
*
* \note Note that the returned bit size is valid only directly after read! If the Zserio object
* has been changed after reading, the result is unspecified!
*
* \return Size of the object as it was stored in the blob in bits.
*/
</#if>
size_t realBitSizeOf() const;
</#if>

private:
Expand Down Expand Up @@ -421,7 +436,7 @@ private:
<@compound_constructor_members compoundConstructorsData/>
<#if withBitPositionCode>
<#-- Bit position must be before field members in order to get initialized first. -->
size_t m_bitPosition;
size_t m_bitPosition, m_realBitSize;
</#if>
<#if (numExtendedFields > 0)>
uint32_t m_numExtendedFields;
Expand Down
21 changes: 21 additions & 0 deletions compiler/extensions/cpp/freemarker/Union.cpp.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ${name}::${name}(const ${name}& other)<#rt>
<@cpp_initializer_list>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
m_choiceTag(other.m_choiceTag)
<#list fieldList as field>
Expand Down Expand Up @@ -93,6 +94,7 @@ ${name}::${name}(${name}&& other)<#rt>
<@cpp_initializer_list>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
m_choiceTag(other.m_choiceTag)
<#list fieldList as field>
Expand Down Expand Up @@ -131,6 +133,7 @@ ${name}::${name}(::zserio::NoInitT, const ${name}& other)<#rt>
</#if>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
m_choiceTag(other.m_choiceTag)
<#list fieldList as field>
Expand Down Expand Up @@ -170,6 +173,7 @@ ${name}::${name}(::zserio::NoInitT, ${name}&& other)<#rt>
</#if>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
m_choiceTag(other.m_choiceTag)
<#list fieldList as field>
Expand Down Expand Up @@ -207,6 +211,7 @@ ${name}::${name}(::zserio::PropagateAllocatorT,
<@cpp_initializer_list>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
m_choiceTag(other.m_choiceTag)
<#list fieldList as field>
Expand All @@ -228,6 +233,7 @@ ${name}::${name}(::zserio::PropagateAllocatorT, ::zserio::NoInitT,
<@cpp_initializer_list>
<#if withBitPositionCode>
m_bitPosition(other.m_bitPosition)
m_realBitSize(other.m_realBitSize)
</#if>
m_choiceTag(other.m_choiceTag)
<#list fieldList as field>
Expand Down Expand Up @@ -388,6 +394,16 @@ const ${types.typeInfo.name}& ${name}::typeInfo()
</#if>
}

size_t realBitSizeOf() const override
{
<#if withBitPositionCode>
return m_object.realBitSizeOf();
<#else>
throw ::zserio::CppRuntimeException("Reflectable '${name}': ") <<
"Bit position code is disabled by '-withoutBitPositionCode' zserio option!";
</#if>
}

private:
<#if isConst>const </#if>${fullName}& m_object;
};
Expand Down Expand Up @@ -722,6 +738,11 @@ size_t ${name}::bitPosition() const
{
return m_bitPosition;
}

size_t ${name}::realBitSizeOf() const
{
return m_realBitSize;
}
</#if>
<#if fieldList?has_content>

Expand Down
17 changes: 16 additions & 1 deletion compiler/extensions/cpp/freemarker/Union.h.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,21 @@ public:
*/
</#if>
size_t bitPosition() const;

<#if withCodeComments>
/**
* Get the bit size of the parsed blob after reading. This size can differ
* from the one returned by getBitSizeOf() if compression took place.
*
* This feature is experimental and can be removed without any warning!
*
* \note Note that the returned bit size is valid only directly after read! If the Zserio object
* has been changed after reading, the result is unspecified!
*
* \return Size of the object as it was stored in the blob in bits.
*/
</#if>
size_t realBitSizeOf() const;
</#if>

private:
Expand All @@ -361,7 +376,7 @@ private:
<@compound_constructor_members compoundConstructorsData/>
<#if withBitPositionCode>
<#-- Bit position must be before m_choiceTag and m_objectChoice in order to get initialized first. -->
size_t m_bitPosition;
size_t m_bitPosition, m_realBitSize;
</#if>
ChoiceTag m_choiceTag;
<#if fieldList?has_content>
Expand Down
6 changes: 3 additions & 3 deletions compiler/extensions/cpp/runtime/ClangTidySuppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/ValidationSqliteUtil.h:99
cppcoreguidelines-pro-type-reinterpret-cast:src/zserio/ValidationSqliteUtil.h:100

# This multiple inheritance is intended and we think that to avoid it would mean much more obscure design.
fuchsia-multiple-inheritance:src/zserio/Reflectable.h:2025
fuchsia-multiple-inheritance:src/zserio/Reflectable.h:2026

# This is necessary for implementation of low level implementation to mimic standard C++17 abstractions.
google-explicit-constructor:src/zserio/OptionalHolder.h:232
Expand Down Expand Up @@ -122,8 +122,8 @@ misc-no-recursion:src/zserio/JsonParser.h:163
misc-no-recursion:src/zserio/ReflectableUtil.h:131
misc-no-recursion:src/zserio/ReflectableUtil.h:135
misc-no-recursion:src/zserio/ReflectableUtil.h:146
misc-no-recursion:src/zserio/Reflectable.h:1953
misc-no-recursion:src/zserio/Reflectable.h:1987
misc-no-recursion:src/zserio/Reflectable.h:1954
misc-no-recursion:src/zserio/Reflectable.h:1988
misc-no-recursion:src/zserio/Walker.h:73
misc-no-recursion:src/zserio/Walker.h:74
misc-no-recursion:src/zserio/Walker.h:75
Expand Down
14 changes: 14 additions & 0 deletions compiler/extensions/cpp/runtime/src/zserio/IReflectable.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,20 @@ class IBasicReflectable
* \throw CppRuntimeException If the object was compiled without the bit position feature enabled.
*/
virtual size_t bitPosition() const = 0;

/**
* Returns the bit size of the parsed blob of the reflectable object.
*
* This feature is experimental and can be removed without any warning!
*
* \note Note that the returned bit size is valid only directly after read! If the Zserio object
* has been changed after reading, the result is unspecified!
* \note The bit size is only stored for code generated using `-withBitPositionCode` option.
*
* \return The blob size of the objects in bits.
* \throw CppRuntimeException If the object was compiled without the bit position feature enabled.
*/
virtual size_t realBitSizeOf() const = 0;
};

/** Typedef to reflectable smart pointer needed for convenience in generated code. */
Expand Down
Loading
Loading