Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored gathering initializers for enhanced struct constructors. #1781

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10602,27 +10602,25 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
}
}

std::string arguments, initializers;
bool listedArgument = false;
bool firstArgument = true;
bool arrayListed = false;
std::string templateHeader, sizeChecks, copyOps;
std::string arguments;
std::vector<std::string> initializersList;
bool listedArgument = false;
bool arrayListed = false;
std::string templateHeader, sizeChecks, copyOps;
for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit )
{
// gather the initializers
if ( mit->name == "pNext" ) // for pNext, we just get the initializer... the argument is added at the end
{
initializers += std::string( firstArgument ? ":" : "," ) + " pNext( pNext_ )";
firstArgument = false;
initializersList.push_back( "pNext( pNext_ )" );
}
else if ( mit->value.empty() ) // skip constant members
{
auto litit = lenIts.find( mit );
if ( litit != lenIts.end() )
{
// len arguments just have an initalizer, from the array size
initializers +=
( firstArgument ? ": " : ", " ) + mit->name + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )";
initializersList.push_back( mit->name + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )" );
sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), structData.second.mutualExclusiveLens );
}
else if ( hasLen( *mit ) )
Expand Down Expand Up @@ -10670,7 +10668,7 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st

if ( mit->type.isPointer() )
{
initializers += ( firstArgument ? ": " : ", " ) + mit->name + "( " + argumentName + ".data() )";
initializersList.push_back( mit->name + "( " + argumentName + ".data() )" );
}
else
{
Expand All @@ -10697,9 +10695,8 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
listedArgument = true;
arguments += argument;
}
initializers += ( firstArgument ? ": " : ", " ) + mit->name + "( " + mit->name + "_ )";
initializersList.push_back( mit->name + "( " + mit->name + "_ )" );
}
firstArgument = false;
}
}

Expand All @@ -10711,6 +10708,16 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
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"(
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE )
${templateHeader} ${structName}( ${arguments} )
Expand Down
Loading