Refactored gathering initializers for enhanced struct constructors. (#1781)

This commit is contained in:
Andreas Süßenbach 2024-02-02 18:22:51 +01:00 committed by GitHub
parent 78bfb316aa
commit 7bd7372016
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10602,9 +10602,9 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
} }
} }
std::string arguments, initializers; std::string arguments;
std::vector<std::string> initializersList;
bool listedArgument = false; bool listedArgument = false;
bool firstArgument = true;
bool arrayListed = false; bool arrayListed = false;
std::string templateHeader, sizeChecks, copyOps; std::string templateHeader, sizeChecks, copyOps;
for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit ) for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit )
@ -10612,8 +10612,7 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
// gather the initializers // gather the initializers
if ( mit->name == "pNext" ) // for pNext, we just get the initializer... the argument is added at the end if ( mit->name == "pNext" ) // for pNext, we just get the initializer... the argument is added at the end
{ {
initializers += std::string( firstArgument ? ":" : "," ) + " pNext( pNext_ )"; initializersList.push_back( "pNext( pNext_ )" );
firstArgument = false;
} }
else if ( mit->value.empty() ) // skip constant members else if ( mit->value.empty() ) // skip constant members
{ {
@ -10621,8 +10620,7 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
if ( litit != lenIts.end() ) if ( litit != lenIts.end() )
{ {
// len arguments just have an initalizer, from the array size // len arguments just have an initalizer, from the array size
initializers += initializersList.push_back( mit->name + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )" );
( firstArgument ? ": " : ", " ) + mit->name + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )";
sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), structData.second.mutualExclusiveLens ); sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), structData.second.mutualExclusiveLens );
} }
else if ( hasLen( *mit ) ) else if ( hasLen( *mit ) )
@ -10670,7 +10668,7 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
if ( mit->type.isPointer() ) if ( mit->type.isPointer() )
{ {
initializers += ( firstArgument ? ": " : ", " ) + mit->name + "( " + argumentName + ".data() )"; initializersList.push_back( mit->name + "( " + argumentName + ".data() )" );
} }
else else
{ {
@ -10697,9 +10695,8 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
listedArgument = true; listedArgument = true;
arguments += argument; arguments += argument;
} }
initializers += ( firstArgument ? ": " : ", " ) + mit->name + "( " + mit->name + "_ )"; initializersList.push_back( mit->name + "( " + mit->name + "_ )" );
} }
firstArgument = false;
} }
} }
@ -10711,6 +10708,16 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
arguments += std::string( listedArgument ? ", " : "" ) + pNextIt->type.compose( "VULKAN_HPP_NAMESPACE" ) + " pNext_ = nullptr"; arguments += std::string( listedArgument ? ", " : "" ) + pNextIt->type.compose( "VULKAN_HPP_NAMESPACE" ) + " pNext_ = nullptr";
} }
std::string initializers;
if ( !initializersList.empty() )
{
initializers = ": " + initializersList[0];
for ( size_t i = 1; i < initializersList.size(); ++i )
{
initializers += ", " + initializersList[i];
}
}
static const std::string constructorTemplate = R"( static const std::string constructorTemplate = R"(
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) #if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE )
${templateHeader} ${structName}( ${arguments} ) ${templateHeader} ${structName}( ${arguments} )