Extend enum value alias handling. (#2004)

This commit is contained in:
Andreas Süßenbach 2024-12-02 13:50:53 +01:00 committed by GitHub
parent 1e92bf4fcd
commit 265b317356
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 72 additions and 53 deletions

View File

@ -1048,7 +1048,7 @@ void VulkanHppGenerator::checkCommandCorrectness() const
resultCodes.insert( rc.name ); resultCodes.insert( rc.name );
for ( auto ac : rc.aliases ) for ( auto ac : rc.aliases )
{ {
resultCodes.insert( ac.first ); resultCodes.insert( ac.name );
} }
} }
// some special handling needed for vulkansc!! // some special handling needed for vulkansc!!
@ -1450,9 +1450,9 @@ void VulkanHppGenerator::checkStructCorrectness() const
} }
else else
{ {
checkForError( !enumValue.supported || ( sTypeValues.erase( enumValue.name ) == 1 ), checkForWarning( !enumValue.supported || ( sTypeValues.erase( enumValue.name ) == 1 ),
enumValue.xmlLine, enumValue.xmlLine,
"VkStructureType enum value <" + enumValue.name + "> never used" ); "VkStructureType enum value <" + enumValue.name + "> never used" );
} }
} }
assert( sTypeValues.empty() ); assert( sTypeValues.empty() );
@ -1665,8 +1665,12 @@ std::string VulkanHppGenerator::combineDataTypes( std::map<size_t, VectorParamDa
bool VulkanHppGenerator::contains( std::vector<EnumValueData> const & enumValues, std::string const & name ) const bool VulkanHppGenerator::contains( std::vector<EnumValueData> const & enumValues, std::string const & name ) const
{ {
return std::any_of( return std::any_of( enumValues.begin(),
enumValues.begin(), enumValues.end(), [&name]( EnumValueData const & ev ) { return ( ev.name == name ) || ev.aliases.contains( name ); } ); enumValues.end(),
[&name]( EnumValueData const & ev ) {
return ( ev.name == name ) ||
std::any_of( ev.aliases.begin(), ev.aliases.end(), [&name]( auto const & eav ) { return eav.name == name; } );
} );
} }
bool VulkanHppGenerator::containsArray( std::string const & type ) const bool VulkanHppGenerator::containsArray( std::string const & type ) const
@ -2185,15 +2189,12 @@ void VulkanHppGenerator::distributeEnumValueAliases()
valueIt = findByName( e.second.values, aliasIt->alias ); valueIt = findByName( e.second.values, aliasIt->alias );
} }
checkForError( valueIt != e.second.values.end(), a.xmlLine, "enum value alias <" + a.name + "> aliases non-existent enum value <" + a.alias + ">" ); checkForError( valueIt != e.second.values.end(), a.xmlLine, "enum value alias <" + a.name + "> aliases non-existent enum value <" + a.alias + ">" );
if ( a.supported && valueIt->supported ) checkForError(
{ a.protect == valueIt->protect, a.xmlLine, "enum value alias <" + a.name + "> aliases enum value <" + a.alias + "> with different properties" );
// only supported enum values need to be kept! checkForError( std::none_of( valueIt->aliases.begin(), valueIt->aliases.end(), [&a]( auto const & eav ) { return a.name == eav.name; } ),
checkForError( a.xmlLine,
a.protect == valueIt->protect, a.xmlLine, "enum value alias <" + a.name + "> aliases enum value <" + a.alias + "> with different properties" ); "enum value alias <" + a.name + "> already contained as alias for enum value <" + a.alias + ">" );
checkForError( valueIt->aliases.insert( { a.name, a.xmlLine } ).second, valueIt->aliases.push_back( a );
a.xmlLine,
"enum value alias <" + a.name + "> already contained as alias for enum value <" + a.alias + ">" );
}
} }
e.second.valueAliases.clear(); e.second.valueAliases.clear();
} }
@ -6988,33 +6989,40 @@ std::string VulkanHppGenerator::generateEnum( std::pair<std::string, EnumData> c
for ( auto const & valueAlias : value.aliases ) for ( auto const & valueAlias : value.aliases )
{ {
std::string enumName = enumData.first; // only generate supported aliases
for ( auto aliasIt = enumData.second.aliases.begin(); ( aliasIt != enumData.second.aliases.end() ) && ( enumName == enumData.first ); ++aliasIt ) if ( valueAlias.supported )
{ {
auto enumAliasIt = enumData.second.aliases.begin(); std::string enumName = enumData.first;
std::string enumTag = findTag( enumData.first ); for ( auto aliasIt = enumData.second.aliases.begin(); ( aliasIt != enumData.second.aliases.end() ) && ( enumName == enumData.first ); ++aliasIt )
std::string aliasTag = findTag( enumAliasIt->first );
std::string valueTag = findTag( valueAlias.first );
if ( ( stripPostfix( enumData.first, enumTag ) == stripPostfix( enumAliasIt->first, aliasTag ) ) && ( aliasTag == valueTag ) )
{ {
enumName = enumAliasIt->first; auto enumAliasIt = enumData.second.aliases.begin();
std::string enumTag = findTag( enumData.first );
std::string aliasTag = findTag( enumAliasIt->first );
std::string valueTag = findTag( valueAlias.name );
if ( ( stripPostfix( enumData.first, enumTag ) == stripPostfix( enumAliasIt->first, aliasTag ) ) && ( aliasTag == valueTag ) )
{
enumName = enumAliasIt->first;
}
} }
}
std::string aliasName = generateEnumValueName( enumName, valueAlias.first, enumData.second.isBitmask ); std::string aliasName = generateEnumValueName( enumName, valueAlias.name, enumData.second.isBitmask );
auto [mapIt, inserted] = valueToNameMap.insert( { aliasName, valueAlias.first } ); std::map<std::string, std::string>::const_iterator mapIt;
if ( inserted ) bool inserted;
{ std::tie( mapIt, inserted ) = valueToNameMap.insert( { aliasName, valueAlias.name } );
enumValues += " " + aliasName + " = " + valueAlias.first + ",\n"; if ( inserted )
} {
else enumValues += " " + aliasName + " = " + valueAlias.name + ",\n";
{ }
// some aliases are so close to the original, that no new entry can be generated! else
assert( mapIt->second != valueAlias.first ); {
checkForError( ( mapIt->second == value.name ) || value.aliases.contains( mapIt->second ), // some aliases are so close to the original, that no new entry can be generated!
valueAlias.second, assert( mapIt->second != valueAlias.name );
"generated enum alias value name <" + aliasName + ">, generated from <" + valueAlias.first + checkForError( ( mapIt->second == value.name ) ||
"> is already generated from different enum value <" + mapIt->second + ">" ); std::any_of( value.aliases.begin(), value.aliases.end(), [mapIt]( auto const & eav ) { return eav.name == mapIt->second; } ),
valueAlias.xmlLine,
"generated enum alias value name <" + aliasName + ">, generated from <" + valueAlias.name +
"> is already generated from different enum value <" + mapIt->second + ">" );
}
} }
} }
@ -16615,9 +16623,15 @@ void VulkanHppGenerator::EnumData::addEnumValue(
} }
else if ( supported ) // only for supported enum values, we need to check for consistency! else if ( supported ) // only for supported enum values, we need to check for consistency!
{ {
checkForError( ( bitpos == valueIt->bitpos ) && ( protect == valueIt->protect ) && ( supported == valueIt->supported ) && ( value == valueIt->value ), checkForError( ( bitpos == valueIt->bitpos ) && ( protect == valueIt->protect ) && ( value == valueIt->value ),
line, line,
"enum value <" + name + "> already listed with different properties" ); "enum value <" + name + "> already listed with different properties" );
// if a previous version was not supported, make it supported now
if ( !valueIt->supported )
{
valueIt->supported = true;
valueIt->xmlLine = line;
}
} }
} }
@ -16674,7 +16688,12 @@ namespace
template <typename T> template <typename T>
typename std::vector<T>::const_iterator findByNameOrAlias( std::vector<T> const & values, std::string const & name ) typename std::vector<T>::const_iterator findByNameOrAlias( std::vector<T> const & values, std::string const & name )
{ {
return std::find_if( values.begin(), values.end(), [&name]( T const & value ) { return ( value.name == name ) || value.aliases.contains( name ); } ); return std::find_if( values.begin(),
values.end(),
[&name]( T const & value ) {
return ( value.name == name ) ||
std::any_of( value.aliases.begin(), value.aliases.end(), [&name]( auto const & eav ) { return eav.name == name; } );
} );
} }
template <typename T> template <typename T>

View File

@ -145,14 +145,14 @@ private:
struct EnumValueData struct EnumValueData
{ {
std::map<std::string, int> aliases = {}; std::vector<EnumValueAlias> aliases = {};
std::string bitpos = {}; std::string bitpos = {};
bool deprecated = {}; bool deprecated = {};
std::string name = {}; std::string name = {};
std::string protect = {}; std::string protect = {};
bool supported = {}; bool supported = {};
std::string value = {}; std::string value = {};
int xmlLine = {}; int xmlLine = {};
}; };
struct EnumData struct EnumData

View File

@ -256,8 +256,8 @@ namespace VULKAN_HPP_NAMESPACE
eErrorInvalidDeviceAddressEXT = VK_ERROR_INVALID_DEVICE_ADDRESS_EXT, eErrorInvalidDeviceAddressEXT = VK_ERROR_INVALID_DEVICE_ADDRESS_EXT,
eErrorInvalidOpaqueCaptureAddressKHR = VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR, eErrorInvalidOpaqueCaptureAddressKHR = VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR,
ePipelineCompileRequired = VK_PIPELINE_COMPILE_REQUIRED, ePipelineCompileRequired = VK_PIPELINE_COMPILE_REQUIRED,
eErrorPipelineCompileRequiredEXT = VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT,
ePipelineCompileRequiredEXT = VK_PIPELINE_COMPILE_REQUIRED_EXT, ePipelineCompileRequiredEXT = VK_PIPELINE_COMPILE_REQUIRED_EXT,
eErrorPipelineCompileRequiredEXT = VK_ERROR_PIPELINE_COMPILE_REQUIRED_EXT,
eErrorSurfaceLostKHR = VK_ERROR_SURFACE_LOST_KHR, eErrorSurfaceLostKHR = VK_ERROR_SURFACE_LOST_KHR,
eErrorNativeWindowInUseKHR = VK_ERROR_NATIVE_WINDOW_IN_USE_KHR, eErrorNativeWindowInUseKHR = VK_ERROR_NATIVE_WINDOW_IN_USE_KHR,
eSuboptimalKHR = VK_SUBOPTIMAL_KHR, eSuboptimalKHR = VK_SUBOPTIMAL_KHR,
@ -412,8 +412,8 @@ namespace VULKAN_HPP_NAMESPACE
ePhysicalDeviceMultiviewProperties = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES, ePhysicalDeviceMultiviewProperties = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES,
ePhysicalDeviceMultiviewPropertiesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR, ePhysicalDeviceMultiviewPropertiesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR,
ePhysicalDeviceVariablePointersFeatures = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES, ePhysicalDeviceVariablePointersFeatures = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES,
ePhysicalDeviceVariablePointersFeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES_KHR,
ePhysicalDeviceVariablePointerFeatures = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES, ePhysicalDeviceVariablePointerFeatures = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES,
ePhysicalDeviceVariablePointersFeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES_KHR,
ePhysicalDeviceVariablePointerFeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR, ePhysicalDeviceVariablePointerFeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR,
eProtectedSubmitInfo = VK_STRUCTURE_TYPE_PROTECTED_SUBMIT_INFO, eProtectedSubmitInfo = VK_STRUCTURE_TYPE_PROTECTED_SUBMIT_INFO,
ePhysicalDeviceProtectedMemoryFeatures = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES, ePhysicalDeviceProtectedMemoryFeatures = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES,
@ -494,8 +494,8 @@ namespace VULKAN_HPP_NAMESPACE
ePhysicalDeviceShaderAtomicInt64Features = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES, ePhysicalDeviceShaderAtomicInt64Features = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES,
ePhysicalDeviceShaderAtomicInt64FeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR, ePhysicalDeviceShaderAtomicInt64FeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR,
ePhysicalDeviceShaderFloat16Int8Features = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES, ePhysicalDeviceShaderFloat16Int8Features = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES,
ePhysicalDeviceFloat16Int8FeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
ePhysicalDeviceShaderFloat16Int8FeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR, ePhysicalDeviceShaderFloat16Int8FeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR,
ePhysicalDeviceFloat16Int8FeaturesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
ePhysicalDeviceFloatControlsProperties = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES, ePhysicalDeviceFloatControlsProperties = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES,
ePhysicalDeviceFloatControlsPropertiesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR, ePhysicalDeviceFloatControlsPropertiesKHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR,
eDescriptorSetLayoutBindingFlagsCreateInfo = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO, eDescriptorSetLayoutBindingFlagsCreateInfo = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
@ -3443,9 +3443,9 @@ namespace VULKAN_HPP_NAMESPACE
eStore = VK_ATTACHMENT_STORE_OP_STORE, eStore = VK_ATTACHMENT_STORE_OP_STORE,
eDontCare = VK_ATTACHMENT_STORE_OP_DONT_CARE, eDontCare = VK_ATTACHMENT_STORE_OP_DONT_CARE,
eNone = VK_ATTACHMENT_STORE_OP_NONE, eNone = VK_ATTACHMENT_STORE_OP_NONE,
eNoneEXT = VK_ATTACHMENT_STORE_OP_NONE_EXT,
eNoneKHR = VK_ATTACHMENT_STORE_OP_NONE_KHR, eNoneKHR = VK_ATTACHMENT_STORE_OP_NONE_KHR,
eNoneQCOM = VK_ATTACHMENT_STORE_OP_NONE_QCOM eNoneQCOM = VK_ATTACHMENT_STORE_OP_NONE_QCOM,
eNoneEXT = VK_ATTACHMENT_STORE_OP_NONE_EXT
}; };
enum class DependencyFlagBits : VkDependencyFlags enum class DependencyFlagBits : VkDependencyFlags