From 00485f94bf60435c0046d36ae52abee262a12ddb Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Thu, 24 Jun 2021 11:09:49 +0200 Subject: [PATCH] Improve filtering of aliases of enum values that map to the very same vk:: enum value. --- VulkanHppGenerator.cpp | 53 +++++++++++++++++++----- VulkanHppGenerator.hpp | 91 +++++++++++++++++++++--------------------- 2 files changed, 88 insertions(+), 56 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 7a6866f..4b11987 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1843,8 +1843,8 @@ void VulkanHppGenerator::appendEnum( std::string & str, std::pairfirst; } - std::string enumList, previousEnter, previousLeave; - std::set valueNames; + std::string enumList, previousEnter, previousLeave; + std::map valueToNameMap; for ( auto const & value : enumData.second.values ) { std::string enter, leave; @@ -1855,8 +1855,8 @@ void VulkanHppGenerator::appendEnum( std::string & str, std::pairsecond.name ); while ( nextAliasIt != enumData.second.aliases.end() ) { - aliasIt = nextAliasIt; + aliasIt = nextAliasIt; nextAliasIt = enumData.second.aliases.find( aliasIt->second.name ); } enumIt = std::find_if( enumData.second.values.begin(), @@ -1898,7 +1896,27 @@ void VulkanHppGenerator::appendEnum( std::string & str, std::pairextension.empty() || generateProtection( enumIt->extension ).first.empty() ); #endif enumList += " " + aliasName + " = " + alias.first + ",\n"; + + // map the aliasName to the name of the base + std::string baseName = findBaseName( alias.second.name, enumData.second.aliases ); + assert( std::find_if( enumData.second.values.begin(), + enumData.second.values.end(), + [&baseName]( EnumValueData const & evd ) + { return evd.name == baseName; } ) != enumData.second.values.end() ); + valueToNameMap[aliasName] = baseName; } +#if !defined( NDEBUG ) + else + { + // verify, that the identical value represents the identical name + std::string baseName = findBaseName( alias.second.name, enumData.second.aliases ); + assert( std::find_if( enumData.second.values.begin(), + enumData.second.values.end(), + [&baseName]( EnumValueData const & evd ) + { return evd.name == baseName; } ) != enumData.second.values.end() ); + assert( baseName == valueToNameIt->second ); + } +#endif } if ( enumList.empty() ) { @@ -10489,7 +10507,7 @@ void VulkanHppGenerator::checkCorrectness() { return evd.name == alias.second.name; } ) != e.second.values.end() ) || ( e.second.aliases.find( alias.second.name ) != e.second.aliases.end() ), alias.second.xmlLine, - "enum <" + alias.first+ "> uses unknown alias <" + alias.second.name + ">" ); + "enum <" + alias.first + "> uses unknown alias <" + alias.second.name + ">" ); } } @@ -11231,6 +11249,19 @@ std::string const & VulkanHppGenerator::getVulkanLicenseHeader() const return m_vulkanLicenseHeader; } +std::string VulkanHppGenerator::findBaseName( std::string aliasName, + std::map const & aliases ) const +{ + std::string baseName = aliasName; + auto aliasIt = aliases.find( baseName ); + while ( aliasIt != aliases.end() ) + { + baseName = aliasIt->second.name; + aliasIt = aliases.find( baseName ); + } + return baseName; +} + std::string VulkanHppGenerator::generateBitmask( std::map::const_iterator bitmaskIt ) const { auto bitmaskBits = m_enums.find( bitmaskIt->second.requirements ); diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 6dbdcec..ea19157 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -156,8 +156,8 @@ private: void addEnumAlias( int line, std::string const & name, std::string const & alias ); void addEnumValue( int line, std::string const & valueName, bool bitpos, std::string const & extension ); - std::string alias; // alias for this enum - std::map aliases; + std::string alias; // alias for this enum + std::map aliases; // aliases for the values std::string bitwidth; bool isBitmask = false; std::vector values; @@ -996,52 +996,53 @@ private: std::vector determineNonConstPointerParamIndices( std::vector const & params ) const; std::map determineVectorParamIndicesNew( std::vector const & params ) const; void distributeSecondLevelCommands( std::set const & specialFunctions ); - std::string generateBitmask( std::map::const_iterator bitmaskIt ) const; - std::string generateCommand( std::string const & name, + std::string findBaseName( std::string aliasName, std::map const & aliases ) const; + std::string generateBitmask( std::map::const_iterator bitmaskIt ) const; + std::string generateCommand( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition ) const; + std::string generateCommandDefinitions( std::string const & command, std::string const & handle ) const; + std::string generateCommandResult( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition ) const; + std::string generateCommandResult0Return( std::string const & name, CommandData const & commandData, size_t initialSkipCount, bool definition ) const; - std::string generateCommandDefinitions( std::string const & command, std::string const & handle ) const; - std::string generateCommandResult( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition ) const; - std::string generateCommandResult0Return( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition ) const; - std::string generateCommandResult1Return( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - size_t returnParamIndex ) const; - std::string generateCommandResult2Return( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - std::vector const & returnParamIndices ) const; - std::string generateCommandResult3Return( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - std::vector const & returnParamIndices ) const; - std::string generateCommandSetStandard( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition ) const; - std::string generateCommandSetStandardAndEnhanced( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices ) const; - std::string generateCommandSetStandardEnhancedDeprecatedAllocator( - std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices ) const; + std::string generateCommandResult1Return( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + size_t returnParamIndex ) const; + std::string generateCommandResult2Return( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::vector const & returnParamIndices ) const; + std::string generateCommandResult3Return( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::vector const & returnParamIndices ) const; + std::string generateCommandSetStandard( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition ) const; + std::string generateCommandSetStandardAndEnhanced( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::map const & vectorParamIndices, + std::vector const & nonConstPointerParamIndices ) const; + std::string generateCommandSetStandardEnhancedDeprecatedAllocator( + std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::map const & vectorParamIndices, + std::vector const & nonConstPointerParamIndices ) const; std::string generateCommandSetStandardOrEnhanced( std::string const & name, CommandData const & commandData, size_t initialSkipCount,