From 1ab5fa6550983bbd645f890b2c31ae2e9c3a53b7 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Mon, 24 Oct 2022 10:39:19 +0200 Subject: [PATCH] Support structs holding arrays of data, where the data size is given by a pointer-type. In that case, no improved constructor and no improved setters are generated. Plus some minor cleanup. --- VulkanHppGenerator.cpp | 43 +++++++++++++++++++++++------------------- VulkanHppGenerator.hpp | 1 + vulkan/vulkan_raii.hpp | 5 ++--- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 7b24032..03f82f6 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -118,10 +118,8 @@ ${indexTypeTraits} #endif )"; - std::string str = replaceWithMap( vulkanEnumsHppTemplate, - { { "enums", generateEnums() }, - { "indexTypeTraits", generateIndexTypeTraits() }, - { "licenseHeader", m_vulkanLicenseHeader } } ); + std::string str = replaceWithMap( + vulkanEnumsHppTemplate, { { "enums", generateEnums() }, { "indexTypeTraits", generateIndexTypeTraits() }, { "licenseHeader", m_vulkanLicenseHeader } } ); writeToFile( str, vulkan_enums_hpp ); } @@ -161,7 +159,7 @@ void VulkanHppGenerator::generateVulkanFuncsHppFile() const namespace VULKAN_HPP_NAMESPACE { ${commandDefinitions} - } // namespace VULKAN_HPP_NAMESPACE +} // namespace VULKAN_HPP_NAMESPACE #endif )"; @@ -184,7 +182,7 @@ namespace VULKAN_HPP_NAMESPACE { ${structForwardDeclarations} ${handles} - } // namespace VULKAN_HPP_NAMESPACE +} // namespace VULKAN_HPP_NAMESPACE #endif )"; @@ -368,7 +366,7 @@ void VulkanHppGenerator::generateVulkanRAIIHppFile() const std::string const vulkanHandlesHppTemplate = R"(${licenseHeader} #ifndef VULKAN_RAII_HPP -# define VULKAN_RAII_HPP +#define VULKAN_RAII_HPP #include #include // std::exchange, std::forward @@ -378,12 +376,11 @@ void VulkanHppGenerator::generateVulkanRAIIHppFile() const # define VULKAN_HPP_RAII_NAMESPACE raii #endif +#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined(VULKAN_HPP_NO_EXCEPTIONS) namespace VULKAN_HPP_NAMESPACE { namespace VULKAN_HPP_RAII_NAMESPACE { -#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined(VULKAN_HPP_NO_EXCEPTIONS) - template VULKAN_HPP_CONSTEXPR_14 VULKAN_HPP_INLINE T exchange( T & obj, U && newValue ) { @@ -399,10 +396,10 @@ namespace VULKAN_HPP_NAMESPACE ${RAIIDispatchers} ${RAIIHandles} ${RAIICommandDefinitions} -#endif } // namespace VULKAN_HPP_RAII_NAMESPACE } // namespace VULKAN_HPP_NAMESPACE #endif +#endif )"; std::string str = replaceWithMap( vulkanHandlesHppTemplate, @@ -9149,16 +9146,15 @@ std::string VulkanHppGenerator::generateStructConstructors( std::pair const & structData ) const { - auto hasLen = []( MemberData const & md ) - { return !md.len.empty() && !( md.len[0] == "null-terminated" ) && ( ( altLens.find( md.len[0] ) == altLens.end() ) || ( md.len[0] == "codeSize / 4" ) ); }; - - if ( std::find_if( structData.second.members.begin(), structData.second.members.end(), hasLen ) != structData.second.members.end() ) + if ( std::find_if( structData.second.members.begin(), + structData.second.members.end(), + [this, &structData]( MemberData const & md ) { return hasLen( structData.second.members, md ); } ) != structData.second.members.end() ) { // map from len-members to all the array members using that len std::map::const_iterator, std::vector::const_iterator>> lenIts; for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit ) { - if ( hasLen( *mit ) ) + if ( hasLen( structData.second.members, *mit ) ) { std::string lenName = ( mit->len.front() == "codeSize / 4" ) ? "codeSize" : mit->len.front(); auto lenIt = findStructMemberIt( lenName, structData.second.members ); @@ -9190,7 +9186,7 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pairname + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )"; sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), structData.second.mutualExclusiveLens ); } - else if ( hasLen( *mit ) ) + else if ( hasLen( structData.second.members, *mit ) ) { assert( mit->name.starts_with( "p" ) ); std::string argumentName = startLowerCase( stripPrefix( mit->name, "p" ) ) + "_"; @@ -9814,8 +9810,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const & struct { "reference", ( member.type.postfix.empty() && ( m_structures.find( member.type.type ) != m_structures.end() ) ) ? "const & " : "" }, { "structureName", structureName } } ); - if ( !member.len.empty() && ( member.len[0] != "null-terminated" ) && - ( ( altLens.find( member.len[0] ) == altLens.end() ) || ( member.len[0] == "codeSize / 4" ) ) ) + if ( hasLen( memberData, member ) ) { assert( member.name.front() == 'p' ); std::string arrayName = startLowerCase( stripPrefix( member.name, "p" ) ); @@ -10444,6 +10439,16 @@ std::string VulkanHppGenerator::getVectorSize( std::vector const & return vectorSize; } +bool VulkanHppGenerator::hasLen( std::vector const & members, MemberData const & md ) const +{ + if ( !md.len.empty() && !( md.len[0] == "null-terminated" ) && ( ( altLens.find( md.len[0] ) == altLens.end() ) || ( md.len[0] == "codeSize / 4" ) ) ) + { + auto lenIt = findStructMemberIt( md.len.front(), members ); + return ( lenIt == members.end() ) || lenIt->type.isValue(); + } + return false; +} + bool VulkanHppGenerator::hasParentHandle( std::string const & handle, std::string const & parent ) const { std::string candidate = handle; @@ -12815,7 +12820,7 @@ void VulkanHppGenerator::readTypesTypeStructMember( tinyxml2::XMLElement const * "member attribute holds unknown value <" + memberData.len[0] + ">" ); if ( lenMember != members.end() ) { - checkForError( lenMember->type.prefix.empty() && lenMember->type.postfix.empty(), + checkForError( lenMember->type.prefix.empty(), line, "member attribute references a member of unexpected type <" + lenMember->type.compose( "VULKAN_HPP_NAMESPACE" ) + ">" ); } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index bac5385..7e1f231 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -935,6 +935,7 @@ private: size_t returnParam, std::string const & returnParamType, std::set const & templatedParams ) const; + bool hasLen( std::vector const & members, MemberData const & md ) const; bool hasParentHandle( std::string const & handle, std::string const & parent ) const; bool isDeviceCommand( CommandData const & commandData ) const; bool isHandleType( std::string const & type ) const; diff --git a/vulkan/vulkan_raii.hpp b/vulkan/vulkan_raii.hpp index 80217dd..30344f6 100644 --- a/vulkan/vulkan_raii.hpp +++ b/vulkan/vulkan_raii.hpp @@ -16,12 +16,11 @@ # define VULKAN_HPP_RAII_NAMESPACE raii #endif +#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined( VULKAN_HPP_NO_EXCEPTIONS ) namespace VULKAN_HPP_NAMESPACE { namespace VULKAN_HPP_RAII_NAMESPACE { -#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined( VULKAN_HPP_NO_EXCEPTIONS ) - template VULKAN_HPP_CONSTEXPR_14 VULKAN_HPP_INLINE T exchange( T & obj, U && newValue ) { @@ -18607,7 +18606,7 @@ namespace VULKAN_HPP_NAMESPACE return properties; } -#endif } // namespace VULKAN_HPP_RAII_NAMESPACE } // namespace VULKAN_HPP_NAMESPACE #endif +#endif