From c7838676bd5c98996031f75f9c2ecdc71efd53b2 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Mon, 25 Oct 2021 11:22:02 +0200 Subject: [PATCH] Minor cleanup work. --- VulkanHppGenerator.cpp | 152 ++++++++++++++++------------------------- VulkanHppGenerator.hpp | 16 ++--- 2 files changed, 62 insertions(+), 106 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index f335e5e..0e839ec 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -3934,17 +3934,13 @@ std::string VulkanHppGenerator::generateCommandResultGetVectorOfHandlesUnique( std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, vectorParamIndices, { returnParamIndex }, false ); - std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, {}, definition, withAllocator, false, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); std::string handleType = stripPrefix( commandData.params[returnParamIndex].type.type, "Vk" ); - std::string returnType = - ( commandData.successCodes.size() == 1 ) - ? ( "typename ResultValueType, " + handleType + - "Allocator>>::type" ) - : ( "ResultValue, " + handleType + "Allocator>>" ); + std::string returnType = generateReturnType( + commandData.successCodes, "std::vector, " + handleType + "Allocator>" ); if ( definition ) { @@ -3985,7 +3981,6 @@ std::string VulkanHppGenerator::generateCommandResultGetVectorOfHandlesUnique( assert( !poolType.empty() ); poolType = stripPrefix( poolType, "Vk" ); poolName = startLowerCase( stripPrefix( lenParts[0], "p" ) ) + "." + poolName; - deleterDefinition = "PoolFree<" + className + ", " + poolType + ", Dispatch> deleter( *this, " + poolName + ", d )"; } @@ -4055,15 +4050,12 @@ std::string VulkanHppGenerator::generateCommandResultGetVectorOfHandlesUniqueSin std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, vectorParamIndices, { returnParamIndex }, true ); std::set singularParams = determineSingularParams( returnParamIndex, vectorParamIndices ); - - std::string argumentList = + std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, singularParams, definition, false, false, true ); std::string commandName = stripPluralS( generateCommandName( name, commandData.params, initialSkipCount, m_tags ) ); std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); std::string handleType = stripPrefix( commandData.params[returnParamIndex].type.type, "Vk" ); - std::string returnType = ( commandData.successCodes.size() == 1 ) - ? ( "typename ResultValueType>::type" ) - : ( "ResultValue>" ); + std::string returnType = generateReturnType( commandData.successCodes, "UniqueHandle<" + handleType + ", Dispatch>" ); if ( definition ) { @@ -4125,8 +4117,7 @@ std::string std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, vectorParamIndices, { returnParamIndex }, true ); std::set singularParams = determineSingularParams( returnParamIndex, vectorParamIndices ); - - std::string argumentList = + std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, {}, definition, false, false, true ); std::string commandName = stripPluralS( generateCommandName( name, commandData.params, initialSkipCount, m_tags ) ); std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); @@ -4565,7 +4556,12 @@ std::string VulkanHppGenerator::generateCommandResultSingleSuccessWithErrors1Ret bool definition, size_t returnParamIndex ) const { - if ( isHandleType( commandData.params[returnParamIndex].type.type ) ) + if ( commandData.params[returnParamIndex].type.type == "void" ) + { + return generateCommandResultSingleSuccessWithErrors1ReturnVoid( + name, commandData, initialSkipCount, definition, returnParamIndex ); + } + else if ( isHandleType( commandData.params[returnParamIndex].type.type ) ) { return generateCommandResultSingleSuccessWithErrors1ReturnHandle( name, commandData, initialSkipCount, definition, returnParamIndex ); @@ -4575,11 +4571,6 @@ std::string VulkanHppGenerator::generateCommandResultSingleSuccessWithErrors1Ret return generateCommandResultSingleSuccessWithErrors1ReturnChain( name, commandData, initialSkipCount, definition, returnParamIndex ); } - else if ( commandData.params[returnParamIndex].type.type == "void" ) - { - return generateCommandResultSingleSuccessWithErrors1ReturnVoid( - name, commandData, initialSkipCount, definition, returnParamIndex ); - } else { return generateCommandResultSingleSuccessWithErrors1ReturnValue( @@ -4617,8 +4608,11 @@ std::string switch ( vectorParamIndices.size() ) { case 0: - return generateCommandResultSingleSuccessWithErrors1ReturnHandle0Vector( - name, commandData, initialSkipCount, definition, returnParamIndex ); + return generateCommandSetStandardEnhancedUnique( + definition, + generateCommandStandard( name, commandData, initialSkipCount, definition ), + generateCommandResultGetValue( name, commandData, initialSkipCount, definition, returnParamIndex ), + generateCommandResultGetHandleUnique( name, commandData, initialSkipCount, definition, returnParamIndex ) ); break; case 1: return generateCommandResultSingleSuccessWithErrors1ReturnHandle1Vector( @@ -4632,20 +4626,6 @@ std::string return ""; } -std::string - VulkanHppGenerator::generateCommandResultSingleSuccessWithErrors1ReturnHandle0Vector( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - size_t returnParamIndex ) const -{ - return generateCommandSetStandardEnhancedUnique( - definition, - generateCommandStandard( name, commandData, initialSkipCount, definition ), - generateCommandResultGetValue( name, commandData, initialSkipCount, definition, returnParamIndex ), - generateCommandResultGetHandleUnique( name, commandData, initialSkipCount, definition, returnParamIndex ) ); -} - std::string VulkanHppGenerator::generateCommandResultSingleSuccessWithErrors1ReturnHandle1Vector( std::string const & name, CommandData const & commandData, @@ -5262,8 +5242,7 @@ std::string VulkanHppGenerator::generateCommandType( std::string const & name, commandData.successCodes.empty() && commandData.errorCodes.empty() ); std::set skippedParameters = determineSkippedParams( commandData.params, initialSkipCount, {}, {}, false ); - - std::string argumentList = + std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParameters, {}, definition, false, false, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); @@ -5348,7 +5327,6 @@ std::string VulkanHppGenerator::generateCommandVoid( std::string const & std::set skippedParameters = determineSkippedParams( commandData.params, initialSkipCount, vectorParamIndices, {}, false ); - std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParameters, {}, definition, false, false, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); @@ -5627,7 +5605,6 @@ std::string VulkanHppGenerator::generateCommandVoidEnumerate( std::string const std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, { vectorParamIndex }, returnParamIndices, false ); - std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, {}, definition, withAllocators, false, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); @@ -5709,13 +5686,11 @@ std::string VulkanHppGenerator::generateCommandVoidEnumerateChained( std::string std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, { vectorParamIndex }, returnParamIndices, false ); - std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, {}, definition, withAllocators, true, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); - assert( beginsWith( commandData.params[vectorParamIndex.first].type.type, "Vk" ) ); std::string vectorElementType = - "VULKAN_HPP_NAMESPACE::" + stripPrefix( commandData.params[vectorParamIndex.first].type.type, "Vk" ); + stripPostfix( commandData.params[vectorParamIndex.first].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" ); if ( definition ) { @@ -5786,20 +5761,18 @@ std::string VulkanHppGenerator::generateCommandVoidGetChain( std::string const & CommandData const & commandData, size_t initialSkipCount, bool definition, - size_t nonConstPointerIndex ) const + size_t returnParamIndex ) const { assert( ( commandData.returnType == "void" ) && commandData.successCodes.empty() && commandData.errorCodes.empty() ); std::set skippedParams = - determineSkippedParams( commandData.params, initialSkipCount, {}, { nonConstPointerIndex }, false ); - + determineSkippedParams( commandData.params, initialSkipCount, {}, { returnParamIndex }, false ); std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, {}, definition, false, false, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); - assert( beginsWith( commandData.params[nonConstPointerIndex].type.type, "Vk" ) ); std::string returnType = - "VULKAN_HPP_NAMESPACE::" + stripPrefix( commandData.params[nonConstPointerIndex].type.type, "Vk" ); + stripPostfix( commandData.params[returnParamIndex].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" ); if ( definition ) { @@ -5822,7 +5795,7 @@ std::string VulkanHppGenerator::generateCommandVoidGetChain( std::string const & initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "" }, { "classSeparator", commandData.handle.empty() ? "" : "::" }, { "commandName", commandName }, - { "returnVariable", startLowerCase( stripPrefix( commandData.params[nonConstPointerIndex].name, "p" ) ) }, + { "returnVariable", startLowerCase( stripPrefix( commandData.params[returnParamIndex].name, "p" ) ) }, { "returnType", returnType }, { "vkCommand", name } } ); } @@ -5850,14 +5823,12 @@ std::string VulkanHppGenerator::generateCommandVoidGetValue( std::string const & std::set skippedParameters = determineSkippedParams( commandData.params, initialSkipCount, {}, { returnParamIndex }, false ); - std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParameters, {}, definition, false, false, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); std::string returnType = stripPostfix( commandData.params[returnParamIndex].type.compose( "VULKAN_HPP_NAMESPACE" ), "*" ); - bool needsVectorSizeCheck = !vectorParamIndices.empty() && isLenByStructMember( commandData.params[vectorParamIndices.begin()->first].len, commandData.params[vectorParamIndices.begin()->second] ); @@ -5882,6 +5853,7 @@ std::string VulkanHppGenerator::generateCommandVoidGetValue( std::string const & throw LogicError( VULKAN_HPP_NAMESPACE_STRING "::${className}${classSeparator}${commandName}: ${vectorName}.size() != ${sizeValue}" ); } #endif /*VULKAN_HPP_NO_EXCEPTIONS*/)"; + std::vector lenParts = tokenize( commandData.params[vectorParamIndices.begin()->first].len, "->" ); assert( lenParts.size() == 2 ); @@ -6035,8 +6007,7 @@ std::string VulkanHppGenerator::generateDispatchLoaderStaticCommands( std::vecto assert( !commandIt->second.params.empty() ); for ( auto param : commandIt->second.params ) { - parameterList += param.type.prefix + ( param.type.prefix.empty() ? "" : " " ) + param.type.type + - param.type.postfix + " " + param.name + generateCArraySizes( param.arraySizes ) + ", "; + parameterList += param.type.compose( "" ) + " " + param.name + generateCArraySizes( param.arraySizes ) + ", "; parameters += param.name + ", "; } assert( endsWith( parameterList, ", " ) && endsWith( parameters, ", " ) ); @@ -7189,7 +7160,7 @@ std::string VulkanHppGenerator::generateRAIICommandDefinitions( std::vector const & specialFunctions, - bool definition ) const +std::string VulkanHppGenerator::generateRAIIHandleCommand( std::string const & command, + size_t initialSkipCount, + bool definition ) const { std::string str; - if ( specialFunctions.find( command ) == specialFunctions.end() ) + if ( m_RAIISpecialFunctions.find( command ) == m_RAIISpecialFunctions.end() ) { auto commandIt = m_commands.find( command ); assert( commandIt != m_commands.end() ); @@ -7378,7 +7345,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommand( std::string const & if ( str.empty() ) { - throw std::runtime_error( "Never encountered a str like <" + commandIt->first + "> !" ); + throw std::runtime_error( "Never encountered a command like <" + commandIt->first + "> !" ); } } return str; @@ -7477,10 +7444,10 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE bool definition, size_t returnParamIndex ) const { - std::string str; - std::map vectorParamIndices = determineVectorParamIndices( commandIt->second.params ); + std::string str; if ( commandIt->second.params[returnParamIndex].type.type == "void" ) { + std::map vectorParamIndices = determineVectorParamIndices( commandIt->second.params ); if ( vectorParamIndices.size() == 1 ) { if ( returnParamIndex == vectorParamIndices.begin()->first ) @@ -7497,6 +7464,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE } else if ( isHandleType( commandIt->second.params[returnParamIndex].type.type ) ) { + std::map vectorParamIndices = determineVectorParamIndices( commandIt->second.params ); if ( vectorParamIndices.size() == 2 ) { if ( returnParamIndex == std::next( vectorParamIndices.begin() )->first ) @@ -7516,6 +7484,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE } else if ( !isStructureChainAnchor( commandIt->second.params[returnParamIndex].type.type ) ) { + std::map vectorParamIndices = determineVectorParamIndices( commandIt->second.params ); if ( vectorParamIndices.empty() ) { str = generateRAIIHandleCommandResultMultiSuccessWithErrors1ReturnValue( @@ -7529,16 +7498,16 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE std::map::const_iterator commandIt, size_t initialSkipCount, std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices, + std::vector const & returnParamIndices, bool definition ) const { - std::set skippedParameters = determineSkippedParams( - commandIt->second.params, initialSkipCount, vectorParamIndices, nonConstPointerParamIndices, false ); + std::set skippedParameters = + determineSkippedParams( commandIt->second.params, initialSkipCount, vectorParamIndices, returnParamIndices, false ); std::string argumentList = generateArgumentListEnhanced( commandIt->second.params, skippedParameters, {}, definition, false, false, false ); std::string commandName = generateCommandName( commandIt->first, commandIt->second.params, initialSkipCount, m_tags ); - std::string returnType = stripPostfix( - commandIt->second.params[nonConstPointerParamIndices[0]].type.compose( "VULKAN_HPP_NAMESPACE" ), "*" ); + std::string returnType = + stripPostfix( commandIt->second.params[returnParamIndices[0]].type.compose( "VULKAN_HPP_NAMESPACE" ), "*" ); if ( definition ) { @@ -7557,8 +7526,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE )"; std::string callArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, {}, true ); - std::string valueName = - startLowerCase( stripPrefix( commandIt->second.params[nonConstPointerParamIndices[0]].name, "p" ) ); + std::string valueName = startLowerCase( stripPrefix( commandIt->second.params[returnParamIndices[0]].name, "p" ) ); return replaceWithMap( definitionTemplate, @@ -7592,13 +7560,13 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE std::map::const_iterator commandIt, size_t initialSkipCount, std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices, + std::vector const & returnParamIndices, bool definition ) const { - assert( nonConstPointerParamIndices.size() == 1 ); - std::set skippedParameters = determineSkippedParams( - commandIt->second.params, initialSkipCount, vectorParamIndices, nonConstPointerParamIndices, true ); - std::set singularParams = determineSingularParams( nonConstPointerParamIndices[0], vectorParamIndices ); + assert( returnParamIndices.size() == 1 ); + std::set skippedParameters = + determineSkippedParams( commandIt->second.params, initialSkipCount, vectorParamIndices, returnParamIndices, true ); + std::set singularParams = determineSingularParams( returnParamIndices[0], vectorParamIndices ); std::string argumentList = generateArgumentListEnhanced( commandIt->second.params, skippedParameters, singularParams, definition, false, false, false ); std::string commandName = @@ -7623,8 +7591,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE std::string callArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, singularParams, true ); - std::string dataName = - startLowerCase( stripPrefix( commandIt->second.params[nonConstPointerParamIndices[0]].name, "p" ) ); + std::string dataName = startLowerCase( stripPrefix( commandIt->second.params[returnParamIndices[0]].name, "p" ) ); return replaceWithMap( singularDefinitionTemplate, @@ -7656,11 +7623,11 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE std::map::const_iterator commandIt, size_t initialSkipCount, std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices, + std::vector const & returnParamIndices, bool definition ) const { - std::set skippedParameters = determineSkippedParams( - commandIt->second.params, initialSkipCount, vectorParamIndices, nonConstPointerParamIndices, false ); + std::set skippedParameters = + determineSkippedParams( commandIt->second.params, initialSkipCount, vectorParamIndices, returnParamIndices, false ); std::string argumentList = generateArgumentListEnhanced( commandIt->second.params, skippedParameters, {}, definition, false, false, false ); std::string commandName = generateCommandName( commandIt->first, commandIt->second.params, initialSkipCount, m_tags ); @@ -7684,8 +7651,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE )"; std::string callArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, {}, true ); - std::string dataName = - startLowerCase( stripPrefix( commandIt->second.params[nonConstPointerParamIndices[0]].name, "p" ) ); + std::string dataName = startLowerCase( stripPrefix( commandIt->second.params[returnParamIndices[0]].name, "p" ) ); return replaceWithMap( definitionTemplate, @@ -7694,7 +7660,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE { "className", stripPrefix( commandIt->second.params[initialSkipCount - 1].type.type, "Vk" ) }, { "commandName", commandName }, { "dataName", dataName }, - { "dataSize", commandIt->second.params[nonConstPointerParamIndices[0]].len }, + { "dataSize", commandIt->second.params[returnParamIndices[0]].len }, { "failureCheck", generateFailureCheck( commandIt->second.successCodes ) }, { "functionPointerCheck", generateFunctionPointerCheck( commandIt->first, commandIt->second.referencedIn ) }, { "vkCommand", commandIt->first } } ); @@ -14996,13 +14962,12 @@ std::string functionDeclarations += "\n //=== " + feature.first + " ===\n"; for ( auto const & command : firstLevelCommands ) { - functionDeclarations += - generateRAIIHandleCommand( command, handle.first.empty() ? 0 : 1, specialFunctions, false ); + functionDeclarations += generateRAIIHandleCommand( command, handle.first.empty() ? 0 : 1, false ); } for ( auto const & command : secondLevelCommands ) { assert( !handle.first.empty() ); - functionDeclarations += generateRAIIHandleCommand( command, 2, specialFunctions, false ); + functionDeclarations += generateRAIIHandleCommand( command, 2, false ); } } } @@ -15040,13 +15005,12 @@ std::string functionDeclarations += "\n" + enter + " //=== " + extIt.second->first + " ===\n"; for ( auto const & command : firstLevelCommands ) { - functionDeclarations += - generateRAIIHandleCommand( command, handle.first.empty() ? 0 : 1, specialFunctions, false ); + functionDeclarations += generateRAIIHandleCommand( command, handle.first.empty() ? 0 : 1, false ); } for ( auto const & command : secondLevelCommands ) { assert( !handle.first.empty() ); - functionDeclarations += generateRAIIHandleCommand( command, 2, specialFunctions, false ); + functionDeclarations += generateRAIIHandleCommand( command, 2, false ); } functionDeclarations += leave; } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 64a3a0e..e4e286a 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -612,11 +612,6 @@ private: size_t initialSkipCount, bool definition, size_t returnParamIndex ) const; - std::string generateCommandResultSingleSuccessWithErrors1ReturnHandle0Vector( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - size_t returnParamIndex ) const; std::string generateCommandResultSingleSuccessWithErrors1ReturnHandle1Vector( std::string const & name, CommandData const & commandData, @@ -877,10 +872,7 @@ private: std::string generateRAIIHandle( std::pair const & handle, std::set & listedHandles, std::set const & specialFunctions ) const; - std::string generateRAIIHandleCommand( std::string const & command, - size_t initialSkipCount, - std::set const & specialFunctions, - bool definition ) const; + std::string generateRAIIHandleCommand( std::string const & command, size_t initialSkipCount, bool definition ) const; std::string generateRAIIHandleCommandDeclarations( std::pair const & handle, std::set const & specialFunctions ) const; std::string generateRAIIHandleCommandFactory( std::map::const_iterator commandIt, @@ -927,19 +919,19 @@ private: std::map::const_iterator commandIt, size_t initialSkipCount, std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices, + std::vector const & returnParamIndices, bool definition ) const; std::string generateRAIIHandleCommandResultMultiSuccessWithErrors1ReturnVoidSingular( std::map::const_iterator commandIt, size_t initialSkipCount, std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices, + std::vector const & returnParamIndices, bool definition ) const; std::string generateRAIIHandleCommandResultMultiSuccessWithErrors1ReturnVoidVector( std::map::const_iterator commandIt, size_t initialSkipCount, std::map const & vectorParamIndices, - std::vector const & nonConstPointerParamIndices, + std::vector const & returnParamIndices, bool definition ) const; std::string generateRAIIHandleCommandResultMultiSuccessWithErrors2Return( std::map::const_iterator commandIt,