Refactor command classification code.

This commit is contained in:
asuessenbach 2020-10-06 09:54:18 +02:00
parent 0884cf31c7
commit b8b620b118
2 changed files with 119 additions and 92 deletions

View File

@ -1226,12 +1226,15 @@ void VulkanHppGenerator::appendCommand( std::string & str,
bool appendedFunction = false;
std::map<size_t, size_t> vectorParamIndices = determineVectorParamIndicesNew( commandData.params );
std::vector<size_t> nonConstPointerParamIndices = determineNonConstPointerParamIndices( commandData.params );
if ( nonConstPointerParamIndices.empty() )
switch ( nonConstPointerParamIndices.size() )
{
case 0:
// no return parameter
{
std::vector<size_t> constPointerParamIndices = determineConstPointerParamIndices( commandData.params );
if ( vectorParamIndices.empty() &&
std::find_if( constPointerParamIndices.begin(), constPointerParamIndices.end(), [&commandData]( size_t idx ) {
if ( vectorParamIndices.empty() && std::find_if( constPointerParamIndices.begin(),
constPointerParamIndices.end(),
[&commandData]( size_t idx ) {
return commandData.params[idx].type.type != "void";
} ) == constPointerParamIndices.end() )
{
@ -1279,12 +1282,12 @@ void VulkanHppGenerator::appendCommand( std::string & str,
}
}
}
else
break;
case 1:
// one return parameter
if ( vectorParamIndices.find( *nonConstPointerParamIndices.begin() ) == vectorParamIndices.end() )
{
switch ( vectorParamIndices.size() )
{
case 0:
assert( nonConstPointerParamIndices.size() == 1 );
// the return parameter is not a vector
if ( ( commandData.returnType == "VkResult" ) &&
!isChainableStructure( commandData.params[*nonConstPointerParamIndices.begin()].type.type ) &&
!isHandleType( commandData.params[*nonConstPointerParamIndices.begin()].type.type ) )
@ -1292,32 +1295,58 @@ void VulkanHppGenerator::appendCommand( std::string & str,
appendCommandGetValue( str, name, commandData, nonConstPointerParamIndices.front(), definition );
appendedFunction = true;
}
break;
}
else
{
// the return parameter is a vector
switch ( vectorParamIndices.size() )
{
case 1:
{
// just one vector parameter
// the return parameter is the only vector parameter
auto vectorParamIndexIt = vectorParamIndices.begin();
if ( ( commandData.params[vectorParamIndexIt->second].type.isValue() ) &&
( commandData.params[vectorParamIndexIt->first].type.type == "void" ) )
assert( vectorParamIndexIt->first == *nonConstPointerParamIndices.begin() );
assert( commandData.params[vectorParamIndexIt->second].type.isValue() );
if ( commandData.params[vectorParamIndexIt->first].type.type == "void" )
{
// the size of the vector parameter is given by a value -> just get that stuff
assert( commandData.params[vectorParamIndexIt->first].type.isNonConstPointer() );
appendCommandGetVector( str, name, commandData, vectorParamIndices, definition );
appendedFunction = true;
}
else if ( ( commandData.returnType == "void" ) &&
}
break;
default: break;
}
}
break;
case 2:
// two return parameters
switch ( vectorParamIndices.size() )
{
case 1:
{
// two returns but just one vector -> the size is a return value as well -> enumerate the values
auto vectorParamIndexIt = vectorParamIndices.begin();
assert( ( vectorParamIndexIt->second == *nonConstPointerParamIndices.begin() ) &&
( vectorParamIndexIt->first == *std::next( nonConstPointerParamIndices.begin() ) ) );
if ( ( commandData.returnType == "void" ) &&
!determineStructureChaining(
commandData.params[vectorParamIndexIt->first].type.type, m_extendedStructs, m_structureAliases ) )
{
// the size of the vector parameter itself is a pointer -> enumerate the values
assert( commandData.params[vectorParamIndexIt->first].type.isNonConstPointer() );
assert( commandData.params[vectorParamIndexIt->first].type.type != "void" );
appendCommandEnumerateVoid( str, name, commandData, *vectorParamIndexIt, definition );
appendedFunction = true;
}
}
break;
case 2:
}
break;
case 3:
// three return parameters
assert( ( vectorParamIndices.size() == 2 ) &&
( vectorParamIndices.begin()->second == nonConstPointerParamIndices[0] ) &&
( vectorParamIndices.begin()->first == nonConstPointerParamIndices[1] ) &&
( std::next( vectorParamIndices.begin() )->first == nonConstPointerParamIndices[2] ) );
{
// two vector parameters
auto firstVectorParam = vectorParamIndices.begin();
@ -1340,7 +1369,6 @@ void VulkanHppGenerator::appendCommand( std::string & str,
break;
default: break;
}
}
if ( appendedFunction )
{
@ -2981,7 +3009,6 @@ bool VulkanHppGenerator::appendFunctionHeaderArgumentEnhanced( std::string &
bool skip,
bool argEncountered,
bool isTemplateParam,
bool isLastArgument,
bool singular,
bool withDefaults,
bool withAllocator ) const
@ -4738,8 +4765,8 @@ std::string VulkanHppGenerator::constructCommandSimpleVoid( std::string const &
d.${vkCommand}( ${callArguments} );
})";
str = replaceWithMap(
functionTemplate,
str =
replaceWithMap( functionTemplate,
std::map<std::string, std::string>(
{ { "argumentList", argumentList },
{ "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) },
@ -4748,7 +4775,9 @@ std::string VulkanHppGenerator::constructCommandSimpleVoid( std::string const &
{ "noexcept", noexceptString },
{ "typenameT", typenameT },
{ "vectorSizeCheck",
vectorSizeCheck.first ? constructVectorSizeCheck( name, commandData, vectorSizeCheck.second, skippedParameters ) : "" },
vectorSizeCheck.first
? constructVectorSizeCheck( name, commandData, vectorSizeCheck.second, skippedParameters )
: "" },
{ "vkCommand", name } } ) );
}
else
@ -5127,7 +5156,6 @@ std::string
skippedParams.find( i ) != skippedParams.end(),
argEncountered,
( templateParamIndex == i ),
( lastArgument == i ),
singular,
withDefaults,
withAllocator );

View File

@ -455,7 +455,6 @@ private:
bool skip,
bool argEncountered,
bool isTemplateParam,
bool isLastArgument,
bool singular,
bool withDefaults,
bool withAllocator ) const;