Merge pull request #763 from asuessenbach/refactor

Refactor command classification code.
This commit is contained in:
Andreas Süßenbach 2020-10-06 10:43:42 +02:00 committed by GitHub
commit e280c5b8c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 119 additions and 92 deletions

View File

@ -1226,65 +1226,68 @@ void VulkanHppGenerator::appendCommand( std::string & str,
bool appendedFunction = false; bool appendedFunction = false;
std::map<size_t, size_t> vectorParamIndices = determineVectorParamIndicesNew( commandData.params ); std::map<size_t, size_t> vectorParamIndices = determineVectorParamIndicesNew( commandData.params );
std::vector<size_t> nonConstPointerParamIndices = determineNonConstPointerParamIndices( commandData.params ); std::vector<size_t> nonConstPointerParamIndices = determineNonConstPointerParamIndices( commandData.params );
if ( nonConstPointerParamIndices.empty() ) switch ( nonConstPointerParamIndices.size() )
{ {
// no return parameter case 0:
std::vector<size_t> constPointerParamIndices = determineConstPointerParamIndices( commandData.params ); // no return parameter
if ( vectorParamIndices.empty() &&
std::find_if( constPointerParamIndices.begin(), constPointerParamIndices.end(), [&commandData]( size_t idx ) {
return commandData.params[idx].type.type != "void";
} ) == constPointerParamIndices.end() )
{
// no vector paramter and no non-void const-pointer
if ( commandData.returnType == "void" )
{ {
// void functions std::vector<size_t> constPointerParamIndices = determineConstPointerParamIndices( commandData.params );
appendCommandTrivialVoid( str, name, commandData, definition ); if ( vectorParamIndices.empty() && std::find_if( constPointerParamIndices.begin(),
appendedFunction = true; constPointerParamIndices.end(),
} [&commandData]( size_t idx ) {
else if ( commandData.successCodes.size() == 1 ) return commandData.params[idx].type.type != "void";
{ } ) == constPointerParamIndices.end() )
assert( commandData.returnType == "VkResult" );
// function returning something
appendCommandTrivial( str, name, commandData, definition );
appendedFunction = true;
}
}
else
{
// with const-pointers that might be changed to by-reference arguments
if ( commandData.returnType == "void" )
{
appendCommandSimpleVoid( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
}
else if ( ( commandData.returnType == "VkResult" ) && ( vectorParamIndices.size() < 2 ) )
{
// returns VkResult, but there's just one success code
appendCommandSimple( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
}
else if ( ( vectorParamIndices.size() == 2 ) && ( vectorParamIndices.begin()->second != INVALID_INDEX ) &&
( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second ) )
{
assert( commandData.params[vectorParamIndices.begin()->second].type.isValue() );
if ( commandData.params[vectorParamIndices.begin()->second].type.isValue() &&
( commandData.returnType == "void" ) )
{ {
// size is given by value and the vectors are const pointers, that is input parameters; function returns // no vector paramter and no non-void const-pointer
// void if ( commandData.returnType == "void" )
appendCommandTwoVectorsVoid( str, name, commandData, vectorParamIndices, definition ); {
appendedFunction = true; // void functions
appendCommandTrivialVoid( str, name, commandData, definition );
appendedFunction = true;
}
else if ( commandData.successCodes.size() == 1 )
{
assert( commandData.returnType == "VkResult" );
// function returning something
appendCommandTrivial( str, name, commandData, definition );
appendedFunction = true;
}
}
else
{
// with const-pointers that might be changed to by-reference arguments
if ( commandData.returnType == "void" )
{
appendCommandSimpleVoid( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
}
else if ( ( commandData.returnType == "VkResult" ) && ( vectorParamIndices.size() < 2 ) )
{
// returns VkResult, but there's just one success code
appendCommandSimple( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
}
else if ( ( vectorParamIndices.size() == 2 ) && ( vectorParamIndices.begin()->second != INVALID_INDEX ) &&
( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second ) )
{
assert( commandData.params[vectorParamIndices.begin()->second].type.isValue() );
if ( commandData.params[vectorParamIndices.begin()->second].type.isValue() &&
( commandData.returnType == "void" ) )
{
// size is given by value and the vectors are const pointers, that is input parameters; function returns
// void
appendCommandTwoVectorsVoid( str, name, commandData, vectorParamIndices, definition );
appendedFunction = true;
}
}
} }
} }
} break;
} case 1:
else // one return parameter
{ if ( vectorParamIndices.find( *nonConstPointerParamIndices.begin() ) == vectorParamIndices.end() )
switch ( vectorParamIndices.size() ) {
{ // the return parameter is not a vector
case 0:
assert( nonConstPointerParamIndices.size() == 1 );
if ( ( commandData.returnType == "VkResult" ) && if ( ( commandData.returnType == "VkResult" ) &&
!isChainableStructure( commandData.params[*nonConstPointerParamIndices.begin()].type.type ) && !isChainableStructure( commandData.params[*nonConstPointerParamIndices.begin()].type.type ) &&
!isHandleType( 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 ); appendCommandGetValue( str, name, commandData, nonConstPointerParamIndices.front(), definition );
appendedFunction = true; appendedFunction = true;
} }
break; }
case 1: else
{ {
// just one vector parameter // the return parameter is a vector
auto vectorParamIndexIt = vectorParamIndices.begin(); switch ( vectorParamIndices.size() )
if ( ( commandData.params[vectorParamIndexIt->second].type.isValue() ) &&
( commandData.params[vectorParamIndexIt->first].type.type == "void" ) )
{ {
// the size of the vector parameter is given by a value -> just get that stuff case 1:
assert( commandData.params[vectorParamIndexIt->first].type.isNonConstPointer() ); {
appendCommandGetVector( str, name, commandData, vectorParamIndices, definition ); // the return parameter is the only vector parameter
appendedFunction = true; auto vectorParamIndexIt = vectorParamIndices.begin();
} assert( vectorParamIndexIt->first == *nonConstPointerParamIndices.begin() );
else if ( ( commandData.returnType == "void" ) && assert( commandData.params[vectorParamIndexIt->second].type.isValue() );
!determineStructureChaining( if ( commandData.params[vectorParamIndexIt->first].type.type == "void" )
commandData.params[vectorParamIndexIt->first].type.type, m_extendedStructs, m_structureAliases ) ) {
{ // the size of the vector parameter is given by a value -> just get that stuff
// the size of the vector parameter itself is a pointer -> enumerate the values appendCommandGetVector( str, name, commandData, vectorParamIndices, definition );
assert( commandData.params[vectorParamIndexIt->first].type.isNonConstPointer() ); appendedFunction = true;
assert( commandData.params[vectorParamIndexIt->first].type.type != "void" ); }
appendCommandEnumerateVoid( str, name, commandData, *vectorParamIndexIt, definition ); }
appendedFunction = true; break;
default: break;
} }
} }
break; break;
case 2: 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 ) )
{
assert( commandData.params[vectorParamIndexIt->first].type.type != "void" );
appendCommandEnumerateVoid( str, name, commandData, *vectorParamIndexIt, definition );
appendedFunction = true;
}
}
break;
}
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 // two vector parameters
auto firstVectorParam = vectorParamIndices.begin(); auto firstVectorParam = vectorParamIndices.begin();
@ -1338,8 +1367,7 @@ void VulkanHppGenerator::appendCommand( std::string & str,
} }
} }
break; break;
default: break; default: break;
}
} }
if ( appendedFunction ) if ( appendedFunction )
@ -2981,7 +3009,6 @@ bool VulkanHppGenerator::appendFunctionHeaderArgumentEnhanced( std::string &
bool skip, bool skip,
bool argEncountered, bool argEncountered,
bool isTemplateParam, bool isTemplateParam,
bool isLastArgument,
bool singular, bool singular,
bool withDefaults, bool withDefaults,
bool withAllocator ) const bool withAllocator ) const
@ -4738,18 +4765,20 @@ std::string VulkanHppGenerator::constructCommandSimpleVoid( std::string const &
d.${vkCommand}( ${callArguments} ); d.${vkCommand}( ${callArguments} );
})"; })";
str = replaceWithMap( str =
functionTemplate, replaceWithMap( functionTemplate,
std::map<std::string, std::string>( std::map<std::string, std::string>(
{ { "argumentList", argumentList }, { { "argumentList", argumentList },
{ "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) }, { "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) },
{ "className", stripPrefix( commandData.handle, "Vk" ) }, { "className", stripPrefix( commandData.handle, "Vk" ) },
{ "commandName", commandName }, { "commandName", commandName },
{ "noexcept", noexceptString }, { "noexcept", noexceptString },
{ "typenameT", typenameT }, { "typenameT", typenameT },
{ "vectorSizeCheck", { "vectorSizeCheck",
vectorSizeCheck.first ? constructVectorSizeCheck( name, commandData, vectorSizeCheck.second, skippedParameters ) : "" }, vectorSizeCheck.first
{ "vkCommand", name } } ) ); ? constructVectorSizeCheck( name, commandData, vectorSizeCheck.second, skippedParameters )
: "" },
{ "vkCommand", name } } ) );
} }
else else
{ {
@ -5127,7 +5156,6 @@ std::string
skippedParams.find( i ) != skippedParams.end(), skippedParams.find( i ) != skippedParams.end(),
argEncountered, argEncountered,
( templateParamIndex == i ), ( templateParamIndex == i ),
( lastArgument == i ),
singular, singular,
withDefaults, withDefaults,
withAllocator ); withAllocator );

View File

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