mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
More constexpr support!
This commit is contained in:
parent
75b8e97bcd
commit
4017a99055
@ -5892,14 +5892,12 @@ std::string VulkanHppGenerator::generateCommandVoidGetValue( std::string const &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string VulkanHppGenerator::generateConstexprString( std::pair<std::string, StructureData> const & structData,
|
std::string VulkanHppGenerator::generateConstexprString( std::string const & structName ) const
|
||||||
bool assignmentOperator ) const
|
|
||||||
{
|
{
|
||||||
// structs with a union (and VkBaseInStructure and VkBaseOutStructure) can't be a constexpr!
|
// structs with a VkBaseInStructure and VkBaseOutStructure can't be a constexpr!
|
||||||
bool isConstExpression = !containsUnion( structData.first ) && ( structData.first != "VkBaseInStructure" ) &&
|
bool isConstExpression = ( structName != "VkBaseInStructure" ) && ( structName != "VkBaseOutStructure" );
|
||||||
( structData.first != "VkBaseOutStructure" );
|
|
||||||
return isConstExpression ? ( std::string( "VULKAN_HPP_CONSTEXPR" ) +
|
return isConstExpression ? ( std::string( "VULKAN_HPP_CONSTEXPR" ) +
|
||||||
( ( containsArray( structData.first ) || assignmentOperator ) ? "_14 " : " " ) )
|
( ( containsUnion( structName ) || containsArray( structName ) ) ? "_14 " : " " ) )
|
||||||
: "";
|
: "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10889,7 +10887,7 @@ std::string
|
|||||||
|
|
||||||
std::string str = replaceWithMap( constructors,
|
std::string str = replaceWithMap( constructors,
|
||||||
{ { "arguments", arguments },
|
{ { "arguments", arguments },
|
||||||
{ "constexpr", generateConstexprString( structData, false ) },
|
{ "constexpr", generateConstexprString( structData.first ) },
|
||||||
{ "initializers", initializers },
|
{ "initializers", initializers },
|
||||||
{ "structName", stripPrefix( structData.first, "Vk" ) } } );
|
{ "structName", stripPrefix( structData.first, "Vk" ) } } );
|
||||||
|
|
||||||
@ -11315,7 +11313,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const &
|
|||||||
if ( member.type.type != "VkStructureType" ) // filter out StructureType, which is supposed to be immutable !
|
if ( member.type.type != "VkStructureType" ) // filter out StructureType, which is supposed to be immutable !
|
||||||
{
|
{
|
||||||
static const std::string templateString = R"(
|
static const std::string templateString = R"(
|
||||||
${structureName} & set${MemberName}( ${memberType} ${reference}${memberName}_ ) VULKAN_HPP_NOEXCEPT
|
${constexpr}${structureName} & set${MemberName}( ${memberType} ${reference}${memberName}_ ) VULKAN_HPP_NOEXCEPT
|
||||||
{
|
{
|
||||||
${assignment};
|
${assignment};
|
||||||
return *this;
|
return *this;
|
||||||
@ -11326,8 +11324,9 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const &
|
|||||||
member.arraySizes.empty()
|
member.arraySizes.empty()
|
||||||
? member.type.compose( "VULKAN_HPP_NAMESPACE" )
|
? member.type.compose( "VULKAN_HPP_NAMESPACE" )
|
||||||
: generateStandardArray( member.type.compose( "VULKAN_HPP_NAMESPACE" ), member.arraySizes );
|
: generateStandardArray( member.type.compose( "VULKAN_HPP_NAMESPACE" ), member.arraySizes );
|
||||||
|
bool isReinterpretation = !member.bitCount.empty() && beginsWith( member.type.type, "Vk" );
|
||||||
std::string assignment;
|
std::string assignment;
|
||||||
if ( !member.bitCount.empty() && beginsWith( member.type.type, "Vk" ) )
|
if ( isReinterpretation )
|
||||||
{
|
{
|
||||||
assignment = member.name + " = " + "*reinterpret_cast<" + member.type.type + "*>(&" + member.name + "_)";
|
assignment = member.name + " = " + "*reinterpret_cast<" + member.type.type + "*>(&" + member.name + "_)";
|
||||||
}
|
}
|
||||||
@ -11339,6 +11338,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const &
|
|||||||
str += replaceWithMap(
|
str += replaceWithMap(
|
||||||
templateString,
|
templateString,
|
||||||
{ { "assignment", assignment },
|
{ { "assignment", assignment },
|
||||||
|
{ "constexpr", isReinterpretation ? "" : "VULKAN_HPP_CONSTEXPR_14 " },
|
||||||
{ "memberName", member.name },
|
{ "memberName", member.name },
|
||||||
{ "MemberName", startUpperCase( member.name ) },
|
{ "MemberName", startUpperCase( member.name ) },
|
||||||
{ "memberType", memberType },
|
{ "memberType", memberType },
|
||||||
@ -11540,8 +11540,10 @@ std::string VulkanHppGenerator::generateUnion( std::pair<std::string, StructureD
|
|||||||
: ( "const " +
|
: ( "const " +
|
||||||
generateStandardArray( memberIt->type.compose( "VULKAN_HPP_NAMESPACE" ), memberIt->arraySizes ) + "&" );
|
generateStandardArray( memberIt->type.compose( "VULKAN_HPP_NAMESPACE" ), memberIt->arraySizes ) + "&" );
|
||||||
|
|
||||||
|
// In a majority of cases this can be constexpr in C++11 as well, however, determining when exactly
|
||||||
|
// that is the case is a lot more involved and probably not worth it.
|
||||||
static const std::string constructorTemplate = R"(
|
static const std::string constructorTemplate = R"(
|
||||||
${unionName}( ${memberType} ${argumentName}_${defaultAssignment} )
|
VULKAN_HPP_CONSTEXPR_14 ${unionName}( ${memberType} ${argumentName}_${defaultAssignment} )
|
||||||
: ${memberName}( ${argumentName}_ )
|
: ${memberName}( ${argumentName}_ )
|
||||||
{})";
|
{})";
|
||||||
|
|
||||||
@ -11610,10 +11612,6 @@ ${enter} union ${unionName}
|
|||||||
{
|
{
|
||||||
using NativeType = Vk${unionName};
|
using NativeType = Vk${unionName};
|
||||||
#if !defined( VULKAN_HPP_NO_UNION_CONSTRUCTORS )
|
#if !defined( VULKAN_HPP_NO_UNION_CONSTRUCTORS )
|
||||||
${unionName}( VULKAN_HPP_NAMESPACE::${unionName} const & rhs ) VULKAN_HPP_NOEXCEPT
|
|
||||||
{
|
|
||||||
memcpy( static_cast<void *>( this ), &rhs, sizeof( VULKAN_HPP_NAMESPACE::${unionName} ) );
|
|
||||||
}
|
|
||||||
${constructors}
|
${constructors}
|
||||||
#endif /*VULKAN_HPP_NO_UNION_CONSTRUCTORS*/
|
#endif /*VULKAN_HPP_NO_UNION_CONSTRUCTORS*/
|
||||||
|
|
||||||
@ -11621,12 +11619,6 @@ ${constructors}
|
|||||||
${setters}
|
${setters}
|
||||||
#endif /*VULKAN_HPP_NO_UNION_SETTERS*/
|
#endif /*VULKAN_HPP_NO_UNION_SETTERS*/
|
||||||
|
|
||||||
VULKAN_HPP_NAMESPACE::${unionName} & operator=( VULKAN_HPP_NAMESPACE::${unionName} const & rhs ) VULKAN_HPP_NOEXCEPT
|
|
||||||
{
|
|
||||||
memcpy( static_cast<void*>( this ), &rhs, sizeof( VULKAN_HPP_NAMESPACE::${unionName} ) );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator Vk${unionName} const &() const
|
operator Vk${unionName} const &() const
|
||||||
{
|
{
|
||||||
return *reinterpret_cast<const Vk${unionName}*>( this );
|
return *reinterpret_cast<const Vk${unionName}*>( this );
|
||||||
|
@ -769,8 +769,7 @@ private:
|
|||||||
bool definition,
|
bool definition,
|
||||||
std::map<size_t, size_t> const & vectorParamIndices,
|
std::map<size_t, size_t> const & vectorParamIndices,
|
||||||
size_t returnParamIndex ) const;
|
size_t returnParamIndex ) const;
|
||||||
std::string generateConstexprString( std::pair<std::string, StructureData> const & structData,
|
std::string generateConstexprString( std::string const & structName ) const;
|
||||||
bool assignmentOperator ) const;
|
|
||||||
std::string generateDestroyCommand( std::string const & name, CommandData const & commandData ) const;
|
std::string generateDestroyCommand( std::string const & name, CommandData const & commandData ) const;
|
||||||
std::string generateDispatchLoaderDynamicCommandAssignment( std::string const & commandName,
|
std::string generateDispatchLoaderDynamicCommandAssignment( std::string const & commandName,
|
||||||
CommandData const & commandData,
|
CommandData const & commandData,
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user