From e370ab5178203e84513fca499d8c1a7059df33f5 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Tue, 4 May 2021 17:08:24 +0200 Subject: [PATCH] Move check on known enum alias value from readEnum to final checkCorrectness. --- VulkanHppGenerator.cpp | 133 +++++++++++++++++++---------------------- VulkanHppGenerator.hpp | 21 +++++-- 2 files changed, 76 insertions(+), 78 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 83686c3..9d474ba 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -14,43 +14,35 @@ #include "VulkanHppGenerator.hpp" -#include #include -#include #include -#include -#include #include -void appendArgumentCount( std::string & str, - size_t vectorIndex, - std::string const & vectorName, - size_t templateParamIndex ); -void appendReinterpretCast( std::string & str, bool leadingConst, std::string const & type ); -void appendTypesafeStuff( std::string & str, std::string const & typesafeCheck ); -void appendVersionCheck( std::string & str, std::string const & version ); -bool beginsWith( std::string const & text, std::string const & prefix ); -bool endsWith( std::string const & text, std::string const & postfix ); -void check( bool condition, int line, std::string const & message ); -void checkAttributes( int line, - std::map const & attributes, - std::map> const & required, - std::map> const & optional ); -void checkElements( int line, - std::vector const & elements, - std::map const & required, - std::set const & optional = {} ); -std::string constructStandardArray( std::string const & type, std::vector const & sizes ); -std::string createEnumValueName( std::string const & name, - std::string const & prefix, - std::string const & postfix, - bool bitmask, - std::string const & tag ); -std::string createSuccessCode( std::string const & code, std::set const & tags ); -std::string determineCommandName( std::string const & vulkanCommandName, - std::string const & argumentType, - std::set const & tags ); -std::string determineNoDiscard( bool multiSuccessCodes, bool multiErrorCodes ); +void appendReinterpretCast( std::string & str, bool leadingConst, std::string const & type ); +void appendTypesafeStuff( std::string & str, std::string const & typesafeCheck ); +void appendVersionCheck( std::string & str, std::string const & version ); +bool beginsWith( std::string const & text, std::string const & prefix ); +bool endsWith( std::string const & text, std::string const & postfix ); +void check( bool condition, int line, std::string const & message ); +void checkAttributes( int line, + std::map const & attributes, + std::map> const & required, + std::map> const & optional ); +void checkElements( int line, + std::vector const & elements, + std::map const & required, + std::set const & optional = {} ); +std::string constructStandardArray( std::string const & type, std::vector const & sizes ); +std::string createEnumValueName( std::string const & name, + std::string const & prefix, + std::string const & postfix, + bool bitmask, + std::string const & tag ); +std::string createSuccessCode( std::string const & code, std::set const & tags ); +std::string determineCommandName( std::string const & vulkanCommandName, + std::string const & argumentType, + std::set const & tags ); +std::string determineNoDiscard( bool multiSuccessCodes, bool multiErrorCodes ); std::set determineSingularParams( size_t returnParamIndex, std::map const & vectorParamIndices ); std::set determineSkippedParams( size_t returnParamIndex, std::map const & vectorParamIndices ); @@ -94,24 +86,6 @@ const std::set specialPointerTypes = { "Display", "IDirectFB", "wl_display", "xcb_connection_t", "_screen_window" }; -void appendArgumentCount( std::string & str, - size_t vectorIndex, - std::string const & vectorName, - size_t templateParamIndex ) -{ - // this parameter is a count parameter for a vector parameter - // the corresponding vector parameter is not the return parameter, or it's not a two-step algorithm - // for the non-singular version, the count is the size of the vector parameter - // -> use the vector parameter name without leading 'p' to get the size (in number of elements, not in bytes) - assert( vectorName[0] == 'p' ); - str += startLowerCase( stripPrefix( vectorName, "p" ) ) + ".size() "; - if ( templateParamIndex == vectorIndex ) - { - // if the vector parameter is templatized -> multiply by the size of that type to get the size in bytes - str += "* sizeof( T ) "; - } -} - void appendReinterpretCast( std::string & str, bool leadingConst, std::string const & type ) { str += "reinterpret_cast<"; @@ -858,7 +832,17 @@ void VulkanHppGenerator::appendArguments( std::string & str, [i]( std::pair const & vpi ) { return vpi.second == i; } ); if ( it != vectorParamIndices.end() ) { - appendArgumentCount( str, it->first, commandData.params[it->first].name, templateParamIndex ); + // this parameter is a count parameter for a vector parameter + // the corresponding vector parameter is not the return parameter, or it's not a two-step algorithm + // for the non-singular version, the count is the size of the vector parameter + // -> use the vector parameter name without leading 'p' to get the size (in number of elements, not in bytes) + assert( commandData.params[it->first].name[0] == 'p' ); + str += startLowerCase( stripPrefix( commandData.params[it->first].name, "p" ) ) + ".size() "; + if ( it->first == templateParamIndex ) + { + // if the vector parameter is templatized -> multiply by the size of that type to get the size in bytes + str += "* sizeof( T ) "; + } } else if ( beginsWith( commandData.params[i].type.type, "Vk" ) ) { @@ -2674,26 +2658,26 @@ void VulkanHppGenerator::appendEnum( std::string & str, std::pairsecond.first == evd.vulkanValue; } ); + enumIt = std::find_if( enumData.second.values.begin(), + enumData.second.values.end(), + [&aliasIt]( EnumValueData const & evd ) + { return aliasIt->second.vulkanValue == evd.vulkanValue; } ); } assert( enumIt != enumData.second.values.end() ); assert( enumIt->extension.empty() || generateProtection( enumIt->extension ).first.empty() ); #endif - enumList += "\n " + alias.second.second + " = " + alias.first + ","; + enumList += "\n " + alias.second.vkValue + " = " + alias.first + ","; } } if ( !enumList.empty() ) @@ -11129,28 +11113,19 @@ void VulkanHppGenerator::EnumData::addEnumAlias( int line, std::string const & aliasName, std::string const & vkName ) { - // check that the aliasName is either a known enum value or at least a known alias - check( ( std::find_if( values.begin(), - values.end(), - [&aliasName]( EnumValueData const & evd ) - { return evd.vulkanValue == aliasName; } ) != values.end() ) || - ( aliases.find( aliasName ) != aliases.end() ), - line, - "unknown enum alias <" + aliasName + ">" ); - auto aliasIt = aliases.find( name ); - check( ( aliasIt == aliases.end() ) || ( aliasIt->second.first == aliasName ), + check( ( aliasIt == aliases.end() ) || ( aliasIt->second.vulkanValue == aliasName ), line, "enum alias <" + name + "> already listed for a different enum value" ); // only list aliases that map to different vkNames aliasIt = std::find_if( aliases.begin(), aliases.end(), - [&vkName]( std::pair> const & aliasEntry ) - { return vkName == aliasEntry.second.second; } ); + [&vkName]( std::pair const & aliasEntry ) + { return vkName == aliasEntry.second.vkValue; } ); if ( aliasIt == aliases.end() ) { - aliases.insert( std::make_pair( name, std::make_pair( aliasName, vkName ) ) ); + aliases.insert( std::make_pair( name, EnumAliasData( aliasName, vkName, line ) ) ); } } @@ -11258,6 +11233,18 @@ void VulkanHppGenerator::checkCorrectness() warn( !typeIt->second.referencedIn.empty(), e.second.xmlLine, "enum <" + e.first + "> not listed in any feature or extension" ); + + // check that the aliasNames are known enum values or known aliases + for ( auto const & alias : e.second.aliases ) + { + check( ( std::find_if( e.second.values.begin(), + e.second.values.end(), + [&alias]( EnumValueData const & evd ) + { return evd.vulkanValue == alias.second.vulkanValue; } ) != e.second.values.end() ) || + ( e.second.aliases.find( alias.second.vulkanValue ) != e.second.aliases.end() ), + alias.second.xmlLine, + "unknown enum alias <" + alias.second.vulkanValue + ">" ); + } } // extension checks diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 0fcf919..2fb6407 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -128,6 +128,17 @@ private: int xmlLine; }; + struct EnumAliasData + { + EnumAliasData( std::string const & vulkanValue_, std::string const & vkValue_, int line ) + : vulkanValue( vulkanValue_ ), vkValue( vkValue_ ), xmlLine( line ) + {} + + std::string vulkanValue; + std::string vkValue; + int xmlLine; + }; + struct EnumValueData { EnumValueData( @@ -155,11 +166,11 @@ private: std::string const & extension, std::string const & tag ); - std::string alias; // alias for this enum - std::map> aliases; // map from name to alias and vk-name - bool isBitmask = false; - std::vector values; - int xmlLine; + std::string alias; // alias for this enum + std::map aliases; + bool isBitmask = false; + std::vector values; + int xmlLine; }; struct FeatureData