mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Merge pull request #1398 from asuessenbach/function
Add support for functions returning more than one success code and getting two values.
This commit is contained in:
commit
689e082bc8
@ -3027,7 +3027,7 @@ std::string VulkanHppGenerator::generateCommandEnhanced( std::string const &
|
||||
generateAllocatorTemplates( returnParams, dataTypes, vectorParams, definition, singular, unique, chained );
|
||||
std::string typenameCheck = generateTypenameCheck( returnParams, vectorParams, definition, dataTypes, singular, withAllocator, unique, chained );
|
||||
std::string nodiscard = generateNoDiscard( !returnParams.empty(), 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() );
|
||||
std::string returnType = generateReturnType( commandData, returnParams, unique, chained, false, dataType );
|
||||
std::string returnType = generateReturnType( commandData, returnParams, vectorParams, unique, chained, false, dataType );
|
||||
std::string className = initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "";
|
||||
std::string classSeparator = commandData.handle.empty() ? "" : "::";
|
||||
std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags, singular, unique );
|
||||
@ -4269,11 +4269,37 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
{
|
||||
assert( dataTypes.size() == returnParams.size() );
|
||||
|
||||
std::string dataDeclarations;
|
||||
switch ( returnParams.size() )
|
||||
{
|
||||
case 0: break;
|
||||
case 0: return ""; // no returnParams -> no data declarations
|
||||
case 1:
|
||||
return generateDataDeclarations1Return(
|
||||
commandData, returnParams, vectorParams, templatedParams, singular, withAllocator, chained, unique, dataTypes, dataType, returnType, returnVariable );
|
||||
case 2:
|
||||
assert( !unique );
|
||||
return generateDataDeclarations2Returns(
|
||||
commandData, returnParams, vectorParams, singular, withAllocator, chained, raii, dataTypes, dataType, returnVariable );
|
||||
case 3:
|
||||
assert( ( vectorParams.size() == 2 ) && ( returnParams[0] == vectorParams.begin()->second ) && ( returnParams[1] == vectorParams.begin()->first ) &&
|
||||
( returnParams[2] == std::next( vectorParams.begin() )->first ) && ( returnParams[0] == std::next( vectorParams.begin() )->second ) &&
|
||||
templatedParams.empty() && !chained && !singular && !unique );
|
||||
return generateDataDeclarations3Returns( commandData, returnParams, withAllocator, raii, dataTypes );
|
||||
default: assert( false ); return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string VulkanHppGenerator::generateDataDeclarations1Return( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
std::map<size_t, size_t> const & vectorParams,
|
||||
std::set<size_t> const & templatedParams,
|
||||
bool singular,
|
||||
bool withAllocator,
|
||||
bool chained,
|
||||
bool unique,
|
||||
std::vector<std::string> const & dataTypes,
|
||||
std::string const & dataType,
|
||||
std::string const & returnType,
|
||||
std::string const & returnVariable ) const
|
||||
{
|
||||
auto vectorParamIt = vectorParams.find( returnParams[0] );
|
||||
if ( !chained )
|
||||
@ -4282,7 +4308,7 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
{
|
||||
std::string const dataDeclarationsTemplate = R"(${returnType} ${returnVariable};)";
|
||||
|
||||
dataDeclarations = replaceWithMap( dataDeclarationsTemplate, { { "returnType", dataType }, { "returnVariable", returnVariable } } );
|
||||
return replaceWithMap( dataDeclarationsTemplate, { { "returnType", dataType }, { "returnVariable", returnVariable } } );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4292,7 +4318,7 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
|
||||
std::string const dataDeclarationsTemplate = R"(${dataType} ${returnVariable}( ${vectorSize}${vectorAllocator} );)";
|
||||
|
||||
dataDeclarations = replaceWithMap(
|
||||
return replaceWithMap(
|
||||
dataDeclarationsTemplate,
|
||||
{ { "dataType", dataType }, { "returnVariable", returnVariable }, { "vectorAllocator", vectorAllocator }, { "vectorSize", vectorSize } } );
|
||||
}
|
||||
@ -4306,30 +4332,56 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
std::string const dataDeclarationsTemplate = R"(${returnType} ${returnVariable};
|
||||
${dataType} & ${dataVariable} = ${returnVariable}.template get<${dataType}>();)";
|
||||
|
||||
dataDeclarations = replaceWithMap( dataDeclarationsTemplate,
|
||||
return replaceWithMap( dataDeclarationsTemplate,
|
||||
{ { "dataType", dataTypes[0] },
|
||||
{ "dataVariable", dataVariable },
|
||||
{ "returnType", ( commandData.returnType == "void" ) ? returnType : "StructureChain<X, Y, Z...>" },
|
||||
{ "returnVariable", returnVariable } } );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if ( vectorParams.size() == 1 )
|
||||
{
|
||||
assert( ( returnParams[0] == vectorParams.begin()->second ) && ( returnParams[1] == vectorParams.begin()->first ) && !singular && !unique );
|
||||
|
||||
std::string VulkanHppGenerator::generateDataDeclarations2Returns( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
std::map<size_t, size_t> const & vectorParams,
|
||||
bool singular,
|
||||
bool withAllocator,
|
||||
bool chained,
|
||||
bool raii,
|
||||
std::vector<std::string> const & dataTypes,
|
||||
std::string const & dataType,
|
||||
std::string const & returnVariable ) const
|
||||
{
|
||||
switch ( vectorParams.size() )
|
||||
{
|
||||
case 0:
|
||||
assert( !singular && !chained );
|
||||
{
|
||||
std::string firstDataVariable = startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) );
|
||||
std::string secondDataVariable = startLowerCase( stripPrefix( commandData.params[returnParams[1]].name, "p" ) );
|
||||
|
||||
std::string const dataDeclarationTemplate = R"(std::pair<${firstDataType},${secondDataType}> data;
|
||||
${firstDataType} & ${firstDataVariable} = data.first;
|
||||
${secondDataType} & ${secondDataVariable} = data.second;)";
|
||||
|
||||
return replaceWithMap( dataDeclarationTemplate,
|
||||
{ { "firstDataType", dataTypes[0] },
|
||||
{ "firstDataVariable", firstDataVariable },
|
||||
{ "secondDataType", dataTypes[1] },
|
||||
{ "secondDataVariable", secondDataVariable } } );
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
assert( ( returnParams[0] == vectorParams.begin()->second ) && ( returnParams[1] == vectorParams.begin()->first ) && !singular );
|
||||
{
|
||||
std::string counterVariable = startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) );
|
||||
if ( !chained )
|
||||
{
|
||||
std::string vectorAllocator =
|
||||
withAllocator ? ( "( " + startLowerCase( stripPrefix( dataTypes[1], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator )" ) : "";
|
||||
std::string vectorAllocator = withAllocator ? ( "( " + startLowerCase( stripPrefix( dataTypes[1], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator )" ) : "";
|
||||
|
||||
std::string const dataDeclarationTemplate = R"(${returnType} ${returnVariable}${vectorAllocator};
|
||||
${counterType} ${counterVariable};)";
|
||||
|
||||
dataDeclarations = replaceWithMap( dataDeclarationTemplate,
|
||||
return replaceWithMap( dataDeclarationTemplate,
|
||||
{ { "counterType", dataTypes[0] },
|
||||
{ "counterVariable", counterVariable },
|
||||
{ "returnType", dataType },
|
||||
@ -4342,11 +4394,12 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
std::string structureChainInitializer = withAllocator ? ( "( structureChainAllocator )" ) : "";
|
||||
std::string vectorVariable = startLowerCase( stripPrefix( commandData.params[returnParams[1]].name, "p" ) );
|
||||
|
||||
std::string const dataDeclarationTemplate = R"(std::vector<StructureChain${structureChainAllocator}> structureChains${structureChainInitializer};
|
||||
std::string const dataDeclarationTemplate =
|
||||
R"(std::vector<StructureChain${structureChainAllocator}> structureChains${structureChainInitializer};
|
||||
std::vector<${vectorElementType}> ${vectorVariable};
|
||||
${counterType} ${counterVariable};)";
|
||||
|
||||
dataDeclarations = replaceWithMap( dataDeclarationTemplate,
|
||||
return replaceWithMap( dataDeclarationTemplate,
|
||||
{
|
||||
{ "counterType", dataTypes[0] },
|
||||
{ "counterVariable", counterVariable },
|
||||
@ -4357,11 +4410,10 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
} );
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
case 2:
|
||||
assert( ( returnParams[0] == std::next( vectorParams.begin() )->first ) && ( vectorParams.find( returnParams[1] ) == vectorParams.end() ) && !chained );
|
||||
{
|
||||
assert( ( vectorParams.size() == 2 ) && ( returnParams[0] == std::next( vectorParams.begin() )->first ) &&
|
||||
( vectorParams.find( returnParams[1] ) == vectorParams.end() ) && !chained && !unique );
|
||||
|
||||
std::string firstDataVariable = startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) );
|
||||
std::string secondDataVariable = startLowerCase( stripPrefix( commandData.params[returnParams[1]].name, "p" ) );
|
||||
if ( singular )
|
||||
@ -4372,7 +4424,7 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
${firstDataType} & ${firstDataVariable} = data.first;
|
||||
${secondDataType} & ${secondDataVariable} = data.second;)";
|
||||
|
||||
dataDeclarations = replaceWithMap( dataDeclarationTemplate,
|
||||
return replaceWithMap( dataDeclarationTemplate,
|
||||
{ { "firstDataType", dataTypes[0] },
|
||||
{ "firstDataVariable", firstDataVariable },
|
||||
{ "secondDataType", dataTypes[1] },
|
||||
@ -4393,7 +4445,7 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
std::vector<${firstDataType}${allocatorType}> & ${firstDataVariable} = data.first;
|
||||
${secondDataType} & ${secondDataVariable} = data.second;)";
|
||||
|
||||
dataDeclarations = replaceWithMap( dataDeclarationTemplate,
|
||||
return replaceWithMap( dataDeclarationTemplate,
|
||||
{ { "allocateInitializer", allocateInitializer },
|
||||
{ "allocatorType", allocatorType },
|
||||
{ "firstDataType", dataTypes[0] },
|
||||
@ -4403,14 +4455,14 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
{ "vectorSize", vectorSize } } );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
assert( ( vectorParams.size() == 2 ) && ( returnParams[0] == vectorParams.begin()->second ) && ( returnParams[1] == vectorParams.begin()->first ) &&
|
||||
( returnParams[2] == std::next( vectorParams.begin() )->first ) && ( returnParams[0] == std::next( vectorParams.begin() )->second ) &&
|
||||
templatedParams.empty() && !singular && !chained && !unique );
|
||||
default: assert( false ); return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string VulkanHppGenerator::generateDataDeclarations3Returns(
|
||||
CommandData const & commandData, std::vector<size_t> const & returnParams, bool withAllocator, bool raii, std::vector<std::string> const & dataTypes ) const
|
||||
{
|
||||
std::string counterVariable = startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) );
|
||||
std::string firstVectorVariable = startLowerCase( stripPrefix( commandData.params[returnParams[1]].name, "p" ) );
|
||||
std::string secondVectorVariable = startLowerCase( stripPrefix( commandData.params[returnParams[2]].name, "p" ) );
|
||||
@ -4432,7 +4484,7 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
std::vector<${secondVectorElementType}${secondVectorAllocatorType}> & ${secondVectorVariable} = data.second;
|
||||
${counterType} ${counterVariable};)";
|
||||
|
||||
dataDeclarations = replaceWithMap( dataDeclarationsTemplate,
|
||||
return replaceWithMap( dataDeclarationsTemplate,
|
||||
{ { "counterType", dataTypes[0] },
|
||||
{ "counterVariable", counterVariable },
|
||||
{ "firstVectorAllocatorType", firstVectorAllocatorType },
|
||||
@ -4443,11 +4495,6 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
|
||||
{ "secondVectorElementType", dataTypes[2] },
|
||||
{ "secondVectorVariable", secondVectorVariable } } );
|
||||
}
|
||||
break;
|
||||
default: assert( false ); break;
|
||||
}
|
||||
return dataDeclarations;
|
||||
}
|
||||
|
||||
std::string VulkanHppGenerator::generateDataPreparation( CommandData const & commandData,
|
||||
size_t initialSkipCount,
|
||||
@ -6418,7 +6465,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommand( std::string const & c
|
||||
|
||||
if ( str.empty() )
|
||||
{
|
||||
throw std::runtime_error( "Never encountered a command like <" + commandIt->first + "> !" );
|
||||
throw std::runtime_error( "Never encountered a command like <" + command + "> !" );
|
||||
}
|
||||
}
|
||||
return str;
|
||||
@ -6544,7 +6591,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandEnhanced( std::map<std:
|
||||
std::pair<bool, std::map<size_t, std::vector<size_t>>> vectorSizeCheck =
|
||||
needsVectorSizeCheck( commandIt->second.params, vectorParams, returnParams, singularParams );
|
||||
std::string noexceptString = generateNoExcept( commandIt->second.errorCodes, returnParams, vectorParams, singular, vectorSizeCheck.first, true );
|
||||
std::string returnType = generateReturnType( commandIt->second, returnParams, false, chained, true, dataType );
|
||||
std::string returnType = generateReturnType( commandIt->second, returnParams, vectorParams, false, chained, true, dataType );
|
||||
|
||||
if ( definition )
|
||||
{
|
||||
@ -6851,8 +6898,20 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE
|
||||
( commandIt->second.successCodes[1] == "VK_INCOMPLETE" ) )
|
||||
{
|
||||
std::map<size_t, size_t> vectorParams = determineVectorParams( commandIt->second.params );
|
||||
if ( vectorParams.size() == 1 )
|
||||
switch ( vectorParams.size() )
|
||||
{
|
||||
case 0:
|
||||
if ( ( commandIt->second.params[returnParams[0]].type.type != "void" ) && !isHandleType( commandIt->second.params[returnParams[0]].type.type ) &&
|
||||
!isStructureChainAnchor( commandIt->second.params[returnParams[0]].type.type ) )
|
||||
{
|
||||
if ( ( commandIt->second.params[returnParams[1]].type.type != "void" ) && !isHandleType( commandIt->second.params[returnParams[1]].type.type ) &&
|
||||
!isStructureChainAnchor( commandIt->second.params[returnParams[1]].type.type ) )
|
||||
{
|
||||
return generateRAIIHandleCommandEnhanced( commandIt, initialSkipCount, returnParams, vectorParams, definition, false, false );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ( returnParams[0] == vectorParams.begin()->second )
|
||||
{
|
||||
if ( returnParams[1] == vectorParams.begin()->first )
|
||||
@ -6876,6 +6935,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
@ -8645,8 +8705,13 @@ std::string VulkanHppGenerator::generateReturnStatement( std::string const & com
|
||||
return returnStatement;
|
||||
}
|
||||
|
||||
std::string VulkanHppGenerator::generateReturnType(
|
||||
CommandData const & commandData, std::vector<size_t> const & returnParams, bool unique, bool chained, bool raii, std::string const & dataType ) const
|
||||
std::string VulkanHppGenerator::generateReturnType( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
std::map<size_t, size_t> const & vectorParams,
|
||||
bool unique,
|
||||
bool chained,
|
||||
bool raii,
|
||||
std::string const & dataType ) const
|
||||
{
|
||||
std::string modifiedDataType = dataType;
|
||||
if ( chained )
|
||||
@ -8707,7 +8772,7 @@ std::string VulkanHppGenerator::generateReturnType(
|
||||
{
|
||||
assert( commandData.returnType == "VkResult" );
|
||||
assert( !commandData.successCodes.empty() && ( commandData.successCodes[0] == "VK_SUCCESS" ) );
|
||||
if ( ( 1 < commandData.successCodes.size() ) && ( returnParams.size() == 1 ) )
|
||||
if ( ( 1 < commandData.successCodes.size() ) && ( ( returnParams.size() == 1 ) || ( ( returnParams.size() == 2 ) && vectorParams.empty() ) ) )
|
||||
{
|
||||
assert( !commandData.errorCodes.empty() && !chained );
|
||||
returnType = ( raii ? "std::pair<VULKAN_HPP_NAMESPACE::Result, " : "ResultValue<" ) + modifiedDataType + ">";
|
||||
|
@ -624,6 +624,33 @@ private:
|
||||
std::string const & dataType,
|
||||
std::string const & returnType,
|
||||
std::string const & returnVariable ) const;
|
||||
std::string generateDataDeclarations1Return( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
std::map<size_t, size_t> const & vectorParams,
|
||||
std::set<size_t> const & templatedParams,
|
||||
bool singular,
|
||||
bool withAllocator,
|
||||
bool chained,
|
||||
bool unique,
|
||||
std::vector<std::string> const & dataTypes,
|
||||
std::string const & dataType,
|
||||
std::string const & returnType,
|
||||
std::string const & returnVariable ) const;
|
||||
std::string generateDataDeclarations2Returns( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
std::map<size_t, size_t> const & vectorParams,
|
||||
bool singular,
|
||||
bool withAllocator,
|
||||
bool chained,
|
||||
bool raii,
|
||||
std::vector<std::string> const & dataTypes,
|
||||
std::string const & dataType,
|
||||
std::string const & returnVariable ) const;
|
||||
std::string generateDataDeclarations3Returns( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
bool withAllocator,
|
||||
bool raii,
|
||||
std::vector<std::string> const & dataTypes ) const;
|
||||
std::string generateDataPreparation( CommandData const & commandData,
|
||||
size_t initialSkipCount,
|
||||
std::vector<size_t> const & returnParams,
|
||||
@ -829,8 +856,13 @@ private:
|
||||
bool unique,
|
||||
bool enumerating,
|
||||
bool raii ) const;
|
||||
std::string generateReturnType(
|
||||
CommandData const & commandData, std::vector<size_t> const & returnParams, bool unique, bool chained, bool raii, std::string const & dataType ) const;
|
||||
std::string generateReturnType( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
std::map<size_t, size_t> const & vectorParams,
|
||||
bool unique,
|
||||
bool chained,
|
||||
bool raii,
|
||||
std::string const & dataType ) const;
|
||||
std::string generateReturnVariable( CommandData const & commandData,
|
||||
std::vector<size_t> const & returnParams,
|
||||
std::map<size_t, size_t> const & vectorParams,
|
||||
|
Loading…
Reference in New Issue
Block a user