Cleanup work on enum value handling. (#1573)

This commit is contained in:
Andreas Süßenbach 2023-05-04 13:35:50 +02:00 committed by GitHub
parent 3a1d6cbcab
commit f618b6bd5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 108 additions and 48 deletions

View File

@ -2467,7 +2467,7 @@ std::string VulkanHppGenerator::generateBitmaskToString( std::map<std::string, B
VULKAN_HPP_INLINE std::string to_string( ${bitmaskName} value )
{
if ( !value )
return "{}";
return "${emptyValue}";
std::string result;
${toStringChecks}
@ -2475,20 +2475,27 @@ ${toStringChecks}
}
)";
std::string emptyValue = "{}";
std::string toStringChecks;
std::string previousEnter, previousLeave;
for ( auto const & value : bitmaskBitsIt->second.values )
{
auto [enter, leave] = generateProtection( value.protect );
std::string valueName = generateEnumValueName( bitmaskBitsIt->first, value.name, true );
if ( value.singleBit )
if ( value.value == "0" )
{
assert( emptyValue == "{}" );
emptyValue = valueName.substr( 1 );
}
else if ( !value.bitpos.empty() )
{
assert( value.alias.empty() );
auto [enter, leave] = generateProtection( value.protect );
toStringChecks += ( ( previousEnter != enter ) ? ( previousLeave + enter ) : "" ) + " if ( value & " + enumName + "::" + valueName +
" ) result += \"" + valueName.substr( 1 ) + " | \";\n";
}
previousEnter = enter;
previousLeave = leave;
}
}
if ( !previousLeave.empty() )
{
assert( previousLeave.ends_with( "\n" ) );
@ -2496,7 +2503,7 @@ ${toStringChecks}
previousLeave.resize( previousLeave.size() - strlen( "\n" ) );
}
str += replaceWithMap( bitmaskToStringTemplate, { { "bitmaskName", bitmaskName }, { "toStringChecks", toStringChecks } } );
str += replaceWithMap( bitmaskToStringTemplate, { { "bitmaskName", bitmaskName }, { "emptyValue", emptyValue }, { "toStringChecks", toStringChecks } } );
}
return str;
@ -11832,7 +11839,7 @@ void VulkanHppGenerator::readEnumsEnum( tinyxml2::XMLElement const * element, st
checkForError( name.starts_with( prefix ), line, "encountered enum value <" + name + "> that does not begin with expected prefix <" + prefix + ">" );
checkForError( bitpos.empty() ^ value.empty(), line, "both or none of \"bitpos\" and \"value\" are set for enum <" + name + "> which is invalid" );
enumIt->second.addEnumValue( line, name, "", !bitpos.empty(), true );
enumIt->second.addEnumValue( line, name, "", bitpos, value, true );
}
}
@ -12669,7 +12676,7 @@ void VulkanHppGenerator::readRequireEnum( tinyxml2::XMLElement const * element,
auto enumIt = m_enums.find( extends );
assert( enumIt != m_enums.end() );
enumIt->second.addEnumValue( line, name, protect, !bitpos.empty(), ( api.empty() || ( api == m_api ) ) && supported );
enumIt->second.addEnumValue( line, name, protect, bitpos + offset, value, ( api.empty() || ( api == m_api ) ) && supported );
}
}
else
@ -13846,36 +13853,37 @@ void VulkanHppGenerator::EnumData::addEnumAlias( int line, std::string const & n
{
if ( supported )
{
checkForError( ( valueIt->alias == alias ) && ( valueIt->protect == protect ) && !valueIt->singleBit,
checkForError( ( valueIt->alias == alias ) && ( valueIt->protect == protect ) && valueIt->bitpos.empty() && valueIt->value.empty(),
line,
"enum alias <" + name + "> already specified with different attributes" );
}
else
{
checkForWarning( ( valueIt->alias == alias ) && ( valueIt->protect == protect ) && !valueIt->singleBit,
checkForWarning( ( valueIt->alias == alias ) && ( valueIt->protect == protect ) && valueIt->bitpos.empty() && valueIt->value.empty(),
line,
"enum alias <" + name + "> already specified with different attributes" );
}
}
else
{
valuesRef.push_back( { alias, name, protect, false, line } );
valuesRef.push_back( { alias, "", name, protect, "", line } );
}
}
void VulkanHppGenerator::EnumData::addEnumValue( int line, std::string const & name, std::string const & protect, bool singleBit, bool supported )
void VulkanHppGenerator::EnumData::addEnumValue(
int line, std::string const & name, std::string const & protect, std::string const & bitpos, std::string const & value, bool supported )
{
auto & valuesRef = supported ? values : unsupportedValues;
auto valueIt = std::find_if( valuesRef.begin(), valuesRef.end(), [&name]( EnumValueData const & evd ) { return evd.name == name; } );
if ( valueIt != valuesRef.end() )
{
checkForError( valueIt->alias.empty() && ( valueIt->protect == protect ) && ( valueIt->singleBit == singleBit ),
checkForError( valueIt->alias.empty() && ( valueIt->protect == protect ) && ( valueIt->bitpos == bitpos ) && ( valueIt->value == value ),
line,
"enum value <" + name + "> already specified with different attributes" );
}
else
{
valuesRef.push_back( { "", name, protect, singleBit, line } );
valuesRef.push_back( { "", bitpos, name, protect, value, line } );
}
}

View File

@ -197,16 +197,18 @@ private:
struct EnumValueData
{
std::string alias = {};
std::string bitpos = {};
std::string name = {};
std::string protect = {};
bool singleBit = false;
std::string value = {};
int xmlLine = {};
};
struct EnumData
{
void addEnumAlias( int line, std::string const & name, std::string const & alias, std::string const & protect, bool supported );
void addEnumValue( int line, std::string const & valueName, std::string const & protect, bool singleBit, bool supported );
void addEnumValue(
int line, std::string const & valueName, std::string const & protect, std::string const & bitpos, std::string const & value, bool supported );
std::string bitwidth = {};
bool isBitmask = false;

View File

@ -6001,6 +6001,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_allocationCallbacks;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -6035,6 +6040,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_allocationCallbacks;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -6073,6 +6083,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_allocationCallbacks;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -6104,6 +6119,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_owner;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -6140,6 +6160,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_pool;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT

View File

@ -325,7 +325,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( PipelineStageFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & PipelineStageFlagBits::eTopOfPipe )
@ -392,7 +392,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( ImageAspectFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & ImageAspectFlagBits::eColor )
@ -684,7 +684,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( CullModeFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & CullModeFlagBits::eFront )
@ -962,7 +962,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( AccessFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & AccessFlagBits::eIndirectCommandRead )
@ -1434,7 +1434,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( ResolveModeFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & ResolveModeFlagBits::eSampleZero )
@ -1511,7 +1511,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( PipelineStageFlags2 value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & PipelineStageFlagBits2::eTopOfPipe )
@ -1605,7 +1605,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( AccessFlags2 value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & AccessFlagBits2::eIndirectCommandRead )
@ -2012,7 +2012,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoCodecOperationFlagsKHR value )
{
if ( !value )
return "{}";
return "None";
std::string result;
#if defined( VK_ENABLE_BETA_EXTENSIONS )
@ -2032,7 +2032,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoChromaSubsamplingFlagsKHR value )
{
if ( !value )
return "{}";
return "Invalid";
std::string result;
if ( value & VideoChromaSubsamplingFlagBitsKHR::eMonochrome )
@ -2050,7 +2050,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoComponentBitDepthFlagsKHR value )
{
if ( !value )
return "{}";
return "Invalid";
std::string result;
if ( value & VideoComponentBitDepthFlagBitsKHR::e8 )
@ -2141,7 +2141,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoDecodeUsageFlagsKHR value )
{
if ( !value )
return "{}";
return "Default";
std::string result;
if ( value & VideoDecodeUsageFlagBitsKHR::eTranscoding )
@ -2339,7 +2339,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoDecodeH264PictureLayoutFlagsKHR value )
{
if ( !value )
return "{}";
return "Progressive";
std::string result;
if ( value & VideoDecodeH264PictureLayoutFlagBitsKHR::eInterlacedInterleavedLines )
@ -2817,7 +2817,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoEncodeUsageFlagsKHR value )
{
if ( !value )
return "{}";
return "Default";
std::string result;
if ( value & VideoEncodeUsageFlagBitsKHR::eTranscoding )
@ -2835,7 +2835,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoEncodeContentFlagsKHR value )
{
if ( !value )
return "{}";
return "Default";
std::string result;
if ( value & VideoEncodeContentFlagBitsKHR::eCamera )
@ -2856,7 +2856,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( VideoEncodeRateControlModeFlagsKHR value )
{
if ( !value )
return "{}";
return "Default";
std::string result;
if ( value & VideoEncodeRateControlModeFlagBitsKHR::eDisabled )
@ -2953,7 +2953,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( ImageCompressionFlagsEXT value )
{
if ( !value )
return "{}";
return "Default";
std::string result;
if ( value & ImageCompressionFlagBitsEXT::eFixedRateDefault )
@ -2969,7 +2969,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( ImageCompressionFixedRateFlagsEXT value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & ImageCompressionFixedRateFlagBitsEXT::e1Bpc )
@ -3141,7 +3141,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( OpticalFlowUsageFlagsNV value )
{
if ( !value )
return "{}";
return "Unknown";
std::string result;
if ( value & OpticalFlowUsageFlagBitsNV::eInput )
@ -3161,7 +3161,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( OpticalFlowGridSizeFlagsNV value )
{
if ( !value )
return "{}";
return "Unknown";
std::string result;
if ( value & OpticalFlowGridSizeFlagBitsNV::e1X1 )

View File

@ -3552,6 +3552,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_allocationCallbacks;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -3586,6 +3591,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_allocationCallbacks;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -3624,6 +3634,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_allocationCallbacks;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -3655,6 +3670,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_owner;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT
@ -3691,6 +3711,11 @@ namespace VULKAN_HPP_NAMESPACE
return m_pool;
}
Dispatch const & getDispatch() const VULKAN_HPP_NOEXCEPT
{
return *m_dispatch;
}
protected:
template <typename T>
void destroy( T t ) VULKAN_HPP_NOEXCEPT

View File

@ -254,7 +254,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( PipelineStageFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & PipelineStageFlagBits::eTopOfPipe )
@ -305,7 +305,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( ImageAspectFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & ImageAspectFlagBits::eColor )
@ -515,7 +515,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( CullModeFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & CullModeFlagBits::eFront )
@ -671,7 +671,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( AccessFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & AccessFlagBits::eIndirectCommandRead )
@ -1076,7 +1076,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( ResolveModeFlags value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & ResolveModeFlagBits::eSampleZero )
@ -1149,7 +1149,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( PipelineStageFlags2 value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & PipelineStageFlagBits2::eTopOfPipe )
@ -1225,7 +1225,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::string to_string( AccessFlags2 value )
{
if ( !value )
return "{}";
return "None";
std::string result;
if ( value & AccessFlagBits2::eIndirectCommandRead )