Skip to content

Commit

Permalink
Mark deprecated enum values as deprecated (#1955)
Browse files Browse the repository at this point in the history
  • Loading branch information
asuessenbach authored Sep 3, 2024
1 parent 2fcbcfb commit fbb6216
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 30 deletions.
47 changes: 40 additions & 7 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,15 @@ void VulkanHppGenerator::generateToStringHppFile() const

#include <vulkan/${api}_enums.hpp>

// ignore warnings on using deprecated enum values in this header
#if defined( __clang__ ) || defined( __GNUC__ )
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined( _MSC_VER )
# pragma warning( push )
# pragma warning( disable : 4996 )
#endif

#if __cpp_lib_format
# include <format> // std::format
#else
Expand All @@ -771,6 +780,13 @@ namespace VULKAN_HPP_NAMESPACE
${bitmasksToString}
${enumsToString}
} // namespace VULKAN_HPP_NAMESPACE

#if defined( __clang__ ) || defined( __GNUC__ )
# pragma GCC diagnostic pop
#elif defined( _MSC_VER )
# pragma warning( pop )
#endif

#endif
)";

Expand Down Expand Up @@ -6763,7 +6779,12 @@ std::string VulkanHppGenerator::generateEnum( std::pair<std::string, EnumData> c
{
enumValues += previousLeave + enter;
}
enumValues += " " + valueName + " = " + value.name + ",\n";
enumValues += " " + valueName;
if ( value.deprecated )
{
enumValues += " VULKAN_HPP_DEPRECATED_17( \"" + valueName + " is deprecated, but no reason was given in the API XML\" )";
}
enumValues += " = " + value.name + ",\n";

for ( auto const & valueAlias : value.aliases )
{
Expand Down Expand Up @@ -13464,6 +13485,7 @@ void VulkanHppGenerator::readEnumsConstants( tinyxml2::XMLElement const * elemen
void VulkanHppGenerator::readEnumsEnum( tinyxml2::XMLElement const * element, std::map<std::string, EnumData>::iterator enumIt )
{
const int line = element->GetLineNum();
bool deprecated = false;
std::map<std::string, std::string> attributes = getAttributes( element );
if ( attributes.contains( "alias" ) )
{
Expand All @@ -13484,7 +13506,7 @@ void VulkanHppGenerator::readEnumsEnum( tinyxml2::XMLElement const * element, st
}
else if ( attribute.first == "deprecated" )
{
// the enum value is marked as deprecated/aliased but still exisits -> no modifications needed here
deprecated = true;
}
else if ( attribute.first == "name" )
{
Expand Down Expand Up @@ -13524,7 +13546,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, value, true );
enumIt->second.addEnumValue( line, name, "", bitpos, value, true, deprecated );
}
}

Expand Down Expand Up @@ -14365,6 +14387,7 @@ void VulkanHppGenerator::readRequireEnum(
{ { "api", { "vulkan", "vulkansc" } },
{ "bitpos", {} },
{ "comment", {} },
{ "deprecated", { "true" } },
{ "dir", { "-" } },
{ "extends", {} },
{ "extnumber", {} },
Expand All @@ -14374,6 +14397,7 @@ void VulkanHppGenerator::readRequireEnum(
{ "value", {} } } );

std::string api, bitpos, extends, name, offset, protect, type, value;
bool deprecated = false;
for ( auto const & attribute : attributes )
{
if ( attribute.first == "api" )
Expand All @@ -14384,6 +14408,10 @@ void VulkanHppGenerator::readRequireEnum(
{
bitpos = attribute.second;
}
else if ( attribute.first == "deprecated" )
{
deprecated = true;
}
else if ( attribute.first == "extends" )
{
extends = attribute.second;
Expand Down Expand Up @@ -14451,8 +14479,13 @@ void VulkanHppGenerator::readRequireEnum(
auto enumIt = findByNameOrAlias( m_enums, extends );
assert( enumIt != m_enums.end() );

enumIt->second.addEnumValue(
line, name, protect.empty() ? getProtectFromPlatform( platform ) : protect, bitpos + offset, value, ( api.empty() || ( api == m_api ) ) && supported );
enumIt->second.addEnumValue( line,
name,
protect.empty() ? getProtectFromPlatform( platform ) : protect,
bitpos + offset,
value,
( api.empty() || ( api == m_api ) ) && supported,
deprecated );
}
}
}
Expand Down Expand Up @@ -16244,12 +16277,12 @@ void VulkanHppGenerator::EnumData::addEnumAlias( int line, std::string const & n
}

void VulkanHppGenerator::EnumData::addEnumValue(
int line, std::string const & name, std::string const & protect, std::string const & bitpos, std::string const & value, bool supported )
int line, std::string const & name, std::string const & protect, std::string const & bitpos, std::string const & value, bool supported, bool deprecated )
{
auto valueIt = findByName( values, name );
if ( valueIt == values.end() )
{
values.push_back( { {}, bitpos, name, protect, supported, value, line } );
values.push_back( { {}, bitpos, deprecated, name, protect, supported, value, line } );
}
else if ( supported ) // only for supported enum values, we need to check for consistency!
{
Expand Down
10 changes: 8 additions & 2 deletions VulkanHppGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class VulkanHppGenerator
{
std::map<std::string, int> aliases = {};
std::string bitpos = {};
bool deprecated = {};
std::string name = {};
std::string protect = {};
bool supported = {};
Expand All @@ -157,8 +158,13 @@ class VulkanHppGenerator
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, std::string const & bitpos, std::string const & value, bool supported );
void addEnumValue( int line,
std::string const & valueName,
std::string const & protect,
std::string const & bitpos,
std::string const & value,
bool supported,
bool deprecated );

std::map<std::string, int> aliases = {};
std::string bitwidth = {};
Expand Down
6 changes: 6 additions & 0 deletions snippets/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@
# define VULKAN_HPP_DEPRECATED( msg )
#endif

#if 17 <= VULKAN_HPP_CPP_VERSION
# define VULKAN_HPP_DEPRECATED_17( msg ) [[deprecated( msg )]]
#else
# define VULKAN_HPP_DEPRECATED_17( msg )
#endif

#if ( 17 <= VULKAN_HPP_CPP_VERSION ) && !defined( VULKAN_HPP_NO_NODISCARD_WARNINGS )
# define VULKAN_HPP_NODISCARD [[nodiscard]]
# if defined( VULKAN_HPP_NO_EXCEPTIONS )
Expand Down
14 changes: 7 additions & 7 deletions vulkan/vulkan_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4501,13 +4501,13 @@ namespace VULKAN_HPP_NAMESPACE
eBt709NonlinearEXT = VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
eBt2020LinearEXT = VK_COLOR_SPACE_BT2020_LINEAR_EXT,
eHdr10St2084EXT = VK_COLOR_SPACE_HDR10_ST2084_EXT,
eDolbyvisionEXT = VK_COLOR_SPACE_DOLBYVISION_EXT,
eHdr10HlgEXT = VK_COLOR_SPACE_HDR10_HLG_EXT,
eAdobergbLinearEXT = VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
eAdobergbNonlinearEXT = VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
ePassThroughEXT = VK_COLOR_SPACE_PASS_THROUGH_EXT,
eExtendedSrgbNonlinearEXT = VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT,
eDisplayNativeAMD = VK_COLOR_SPACE_DISPLAY_NATIVE_AMD
eDolbyvisionEXT VULKAN_HPP_DEPRECATED_17( "eDolbyvisionEXT is deprecated, but no reason was given in the API XML" ) = VK_COLOR_SPACE_DOLBYVISION_EXT,
eHdr10HlgEXT = VK_COLOR_SPACE_HDR10_HLG_EXT,
eAdobergbLinearEXT = VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
eAdobergbNonlinearEXT = VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
ePassThroughEXT = VK_COLOR_SPACE_PASS_THROUGH_EXT,
eExtendedSrgbNonlinearEXT = VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT,
eDisplayNativeAMD = VK_COLOR_SPACE_DISPLAY_NATIVE_AMD
};

enum class CompositeAlphaFlagBitsKHR : VkCompositeAlphaFlagsKHR
Expand Down
6 changes: 6 additions & 0 deletions vulkan/vulkan_hpp_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
# define VULKAN_HPP_DEPRECATED( msg )
#endif

#if 17 <= VULKAN_HPP_CPP_VERSION
# define VULKAN_HPP_DEPRECATED_17( msg ) [[deprecated( msg )]]
#else
# define VULKAN_HPP_DEPRECATED_17( msg )
#endif

#if ( 17 <= VULKAN_HPP_CPP_VERSION ) && !defined( VULKAN_HPP_NO_NODISCARD_WARNINGS )
# define VULKAN_HPP_NODISCARD [[nodiscard]]
# if defined( VULKAN_HPP_NO_EXCEPTIONS )
Expand Down
16 changes: 16 additions & 0 deletions vulkan/vulkan_to_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

#include <vulkan/vulkan_enums.hpp>

// ignore warnings on using deprecated enum values in this header
#if defined( __clang__ ) || defined( __GNUC__ )
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined( _MSC_VER )
# pragma warning( push )
# pragma warning( disable : 4996 )
#endif

#if __cpp_lib_format
# include <format> // std::format
#else
Expand Down Expand Up @@ -9146,4 +9155,11 @@ namespace VULKAN_HPP_NAMESPACE
}

} // namespace VULKAN_HPP_NAMESPACE

#if defined( __clang__ ) || defined( __GNUC__ )
# pragma GCC diagnostic pop
#elif defined( _MSC_VER )
# pragma warning( pop )
#endif

#endif
28 changes: 14 additions & 14 deletions vulkan/vulkansc_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3166,20 +3166,20 @@ namespace VULKAN_HPP_NAMESPACE

enum class ColorSpaceKHR
{
eSrgbNonlinear = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
eDisplayP3NonlinearEXT = VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
eExtendedSrgbLinearEXT = VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
eDisplayP3LinearEXT = VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
eDciP3NonlinearEXT = VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT,
eBt709LinearEXT = VK_COLOR_SPACE_BT709_LINEAR_EXT,
eBt709NonlinearEXT = VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
eBt2020LinearEXT = VK_COLOR_SPACE_BT2020_LINEAR_EXT,
eHdr10St2084EXT = VK_COLOR_SPACE_HDR10_ST2084_EXT,
eDolbyvisionEXT = VK_COLOR_SPACE_DOLBYVISION_EXT,
eHdr10HlgEXT = VK_COLOR_SPACE_HDR10_HLG_EXT,
eAdobergbLinearEXT = VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
eAdobergbNonlinearEXT = VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
ePassThroughEXT = VK_COLOR_SPACE_PASS_THROUGH_EXT,
eSrgbNonlinear = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
eDisplayP3NonlinearEXT = VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT,
eExtendedSrgbLinearEXT = VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT,
eDisplayP3LinearEXT = VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT,
eDciP3NonlinearEXT = VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT,
eBt709LinearEXT = VK_COLOR_SPACE_BT709_LINEAR_EXT,
eBt709NonlinearEXT = VK_COLOR_SPACE_BT709_NONLINEAR_EXT,
eBt2020LinearEXT = VK_COLOR_SPACE_BT2020_LINEAR_EXT,
eHdr10St2084EXT = VK_COLOR_SPACE_HDR10_ST2084_EXT,
eDolbyvisionEXT VULKAN_HPP_DEPRECATED_17( "eDolbyvisionEXT is deprecated, but no reason was given in the API XML" ) = VK_COLOR_SPACE_DOLBYVISION_EXT,
eHdr10HlgEXT = VK_COLOR_SPACE_HDR10_HLG_EXT,
eAdobergbLinearEXT = VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT,
eAdobergbNonlinearEXT = VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT,
ePassThroughEXT = VK_COLOR_SPACE_PASS_THROUGH_EXT,
eExtendedSrgbNonlinearEXT = VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT
};

Expand Down
6 changes: 6 additions & 0 deletions vulkan/vulkansc_hpp_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
# define VULKAN_HPP_DEPRECATED( msg )
#endif

#if 17 <= VULKAN_HPP_CPP_VERSION
# define VULKAN_HPP_DEPRECATED_17( msg ) [[deprecated( msg )]]
#else
# define VULKAN_HPP_DEPRECATED_17( msg )
#endif

#if ( 17 <= VULKAN_HPP_CPP_VERSION ) && !defined( VULKAN_HPP_NO_NODISCARD_WARNINGS )
# define VULKAN_HPP_NODISCARD [[nodiscard]]
# if defined( VULKAN_HPP_NO_EXCEPTIONS )
Expand Down
16 changes: 16 additions & 0 deletions vulkan/vulkansc_to_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

#include <vulkan/vulkansc_enums.hpp>

// ignore warnings on using deprecated enum values in this header
#if defined( __clang__ ) || defined( __GNUC__ )
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined( _MSC_VER )
# pragma warning( push )
# pragma warning( disable : 4996 )
#endif

#if __cpp_lib_format
# include <format> // std::format
#else
Expand Down Expand Up @@ -4411,4 +4420,11 @@ namespace VULKAN_HPP_NAMESPACE
}

} // namespace VULKAN_HPP_NAMESPACE

#if defined( __clang__ ) || defined( __GNUC__ )
# pragma GCC diagnostic pop
#elif defined( _MSC_VER )
# pragma warning( pop )
#endif

#endif

0 comments on commit fbb6216

Please sign in to comment.