From f87c9330e7751f0ea28f106e743b08adb7f6fddd Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Mon, 15 Jun 2020 10:09:07 +0200 Subject: [PATCH] Extend check against protect attribute for types that are required by multiple extensions. --- VulkanHppGenerator.cpp | 45 ++++++++++++++++++++++++------------------ VulkanHppGenerator.hpp | 5 +++-- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index c119abe..0b2ec26 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -3296,8 +3296,8 @@ void VulkanHppGenerator::appendHandlesCommandDefintions( std::string & str ) con // special handling for destroy functions std::string commandName = determineCommandName( commandIt->first, commandIt->second.params[0].type.type ); if ( commandIt->second.alias.empty() && - ( ( commandIt->first.substr( 2, 7 ) == "Destroy" ) && ( commandName != "destroy" ) ) || - ( commandIt->first.substr( 2, 4 ) == "Free" ) ) + ( ( ( commandIt->first.substr( 2, 7 ) == "Destroy" ) && ( commandName != "destroy" ) ) || + ( commandIt->first.substr( 2, 4 ) == "Free" ) ) ) { std::string destroyCommandString; appendCommand( destroyCommandString, " ", commandIt->first, commandIt->second, true ); @@ -4650,28 +4650,20 @@ std::string const & VulkanHppGenerator::getVulkanLicenseHeader() const std::pair VulkanHppGenerator::generateProtection( std::string const & feature, std::set const & extensions ) const { - if ( feature.empty() ) + if ( feature.empty() && !extensions.empty() ) { - std::string protect; - for ( auto const & extension : extensions ) + assert( getPlatforms( extensions ).size() == 1 ); + std::string platform = *getPlatforms( extensions ).begin(); + if ( !platform.empty() ) { - auto extensionIt = m_extensions.find( extension ); - assert( extensionIt != m_extensions.end() ); - if ( !extensionIt->second.platform.empty() ) + auto platformIt = m_platforms.find( platform ); + assert( platformIt != m_platforms.end() ); + std::string const & protect = platformIt->second.protect; + if ( !protect.empty() ) { - auto platformIt = m_platforms.find( extensionIt->second.platform ); - assert( platformIt != m_platforms.end() ); - if ( !platformIt->second.protect.empty() ) - { - assert( protect.empty() ); - protect = platformIt->second.protect; - } + return std::make_pair( "#ifdef " + protect + "\n", "#endif /*" + protect + "*/\n" ); } } - if ( !protect.empty() ) - { - return std::make_pair( "#ifdef " + protect + "\n", "#endif /*" + protect + "*/\n" ); - } } return std::make_pair( "", "" ); } @@ -4691,6 +4683,18 @@ std::pair VulkanHppGenerator::generateProtection( std: } } +std::set VulkanHppGenerator::getPlatforms( std::set const & extensions ) const +{ + std::set platforms; + for ( auto const & e : extensions ) + { + auto extensionIt = m_extensions.find( e ); + assert( extensionIt != m_extensions.end() ); + platforms.insert( extensionIt->second.platform ); + } + return platforms; +} + bool VulkanHppGenerator::holdsSType( std::string const & type ) const { auto it = m_structures.find( type ); @@ -5714,6 +5718,9 @@ void VulkanHppGenerator::readExtensionRequireType( tinyxml2::XMLElement const * auto typeIt = m_types.find( name ); check( typeIt != m_types.end(), line, "failed to find required type <" + name + ">" ); typeIt->second.extensions.insert( extension ); + check( getPlatforms( typeIt->second.extensions ).size() == 1, + line, + "type <" + name + "> is protected by more than one platform" ); } void VulkanHppGenerator::readExtensions( tinyxml2::XMLElement const * element ) diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index af8b39d..bcad59b 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -515,10 +515,11 @@ private: std::pair generateProtection( std::string const & feature, std::set const & extension ) const; std::pair generateProtection( std::string const & type, bool isAliased ) const; + std::set getPlatforms( std::set const & extensions ) const; bool holdsSType( std::string const & type ) const; bool isParam( std::string const & name, std::vector const & params ) const; - bool isParamIndirect( std::string const & name, std::vector const & params ) const; - bool isTwoStepAlgorithm( std::vector const & params ) const; + bool isParamIndirect( std::string const & name, std::vector const & params ) const; + bool isTwoStepAlgorithm( std::vector const & params ) const; void readBaseType( tinyxml2::XMLElement const * element, std::map const & attributes ); void readBitmask( tinyxml2::XMLElement const * element, std::map const & attributes ); void readBitmaskAlias( tinyxml2::XMLElement const * element, std::map const & attributes );