Simplify alias handling for handles. (#1857)

This commit is contained in:
Andreas Süßenbach 2024-04-30 09:12:25 +02:00 committed by GitHub
parent 79307b6253
commit da28afe109
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 44 deletions

View File

@ -7539,10 +7539,9 @@ std::string VulkanHppGenerator::generateHandle( std::pair<std::string, HandleDat
assert( contains( enumIt->second.values, handleData.second.objTypeEnum ) ); assert( contains( enumIt->second.values, handleData.second.objTypeEnum ) );
std::string usingAlias; std::string usingAlias;
auto aliasIt = findAlias( handleData.first, m_handleAliases ); for ( auto const & alias : handleData.second.aliases )
if ( aliasIt != m_handleAliases.end() )
{ {
usingAlias += " using " + stripPrefix( aliasIt->first, "Vk" ) + " = " + stripPrefix( handleData.first, "Vk" ) + ";\n"; usingAlias += " using " + stripPrefix( alias.first, "Vk" ) + " = " + stripPrefix( handleData.first, "Vk" ) + ";\n";
} }
const std::string typesafeExplicitKeyword = handleData.second.isDispatchable ? "" : "VULKAN_HPP_TYPESAFE_EXPLICIT "; const std::string typesafeExplicitKeyword = handleData.second.isDispatchable ? "" : "VULKAN_HPP_TYPESAFE_EXPLICIT ";
@ -11812,12 +11811,11 @@ std::string VulkanHppGenerator::generateUniqueHandle( std::pair<std::string, Han
{ {
std::string type = stripPrefix( handleData.first, "Vk" ); std::string type = stripPrefix( handleData.first, "Vk" );
std::string aliasHandle; std::string aliasHandle;
auto aliasIt = findAlias( handleData.first, m_handleAliases ); for ( auto const & alias : handleData.second.aliases )
if ( aliasIt != m_handleAliases.end() )
{ {
static const std::string aliasHandleTemplate = R"( using Unique${aliasType} = UniqueHandle<${type}, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>;)"; static const std::string aliasHandleTemplate = R"( using Unique${aliasType} = UniqueHandle<${type}, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>;)";
aliasHandle += replaceWithMap( aliasHandleTemplate, { { "aliasType", stripPrefix( aliasIt->first, "Vk" ) }, { "type", type } } ); aliasHandle += replaceWithMap( aliasHandleTemplate, { { "aliasType", stripPrefix( alias.first, "Vk" ) }, { "type", type } } );
} }
static const std::string uniqueHandleTemplate = R"( template <typename Dispatch> static const std::string uniqueHandleTemplate = R"( template <typename Dispatch>
@ -11889,12 +11887,11 @@ std::string VulkanHppGenerator::generateSharedHandle( std::pair<std::string, Han
{ {
std::string type = stripPrefix( handleData.first, "Vk" ); std::string type = stripPrefix( handleData.first, "Vk" );
std::string aliasHandle; std::string aliasHandle;
auto aliasIt = findAlias( handleData.first, m_handleAliases ); for ( auto const & alias : handleData.second.aliases )
if ( aliasIt != m_handleAliases.end() )
{ {
static const std::string aliasHandleTemplate = R"( using Shared${aliasType} = SharedHandle<${type}>;)"; static const std::string aliasHandleTemplate = R"( using Shared${aliasType} = SharedHandle<${type}>;)";
aliasHandle += replaceWithMap( aliasHandleTemplate, { { "aliasType", stripPrefix( aliasIt->first, "Vk" ) }, { "type", type } } ); aliasHandle += replaceWithMap( aliasHandleTemplate, { { "aliasType", stripPrefix( alias.first, "Vk" ) }, { "type", type } } );
} }
static const std::string sharedHandleTemplate = R"( template <> static const std::string sharedHandleTemplate = R"( template <>
@ -11925,12 +11922,11 @@ std::string VulkanHppGenerator::generateSharedHandleNoDestroy( std::pair<std::st
{ {
std::string type = stripPrefix( handleData.first, "Vk" ); std::string type = stripPrefix( handleData.first, "Vk" );
std::string aliasHandle; std::string aliasHandle;
auto aliasIt = findAlias( handleData.first, m_handleAliases ); for ( auto const & alias : handleData.second.aliases )
if ( aliasIt != m_handleAliases.end() )
{ {
static const std::string aliasHandleTemplate = R"( using Shared${aliasType} = SharedHandle<${type}>;)"; static const std::string aliasHandleTemplate = R"( using Shared${aliasType} = SharedHandle<${type}>;)";
aliasHandle += replaceWithMap( aliasHandleTemplate, { { "aliasType", stripPrefix( aliasIt->first, "Vk" ) }, { "type", type } } ); aliasHandle += replaceWithMap( aliasHandleTemplate, { { "aliasType", stripPrefix( alias.first, "Vk" ) }, { "type", type } } );
} }
static const std::string sharedHandleTemplate = R"( static const std::string sharedHandleTemplate = R"(
@ -12470,21 +12466,7 @@ bool VulkanHppGenerator::isFeature( std::string const & name ) const
bool VulkanHppGenerator::isHandleType( std::string const & type ) const bool VulkanHppGenerator::isHandleType( std::string const & type ) const
{ {
if ( type.starts_with( "Vk" ) ) return type.starts_with( "Vk" ) && ( findByNameOrAlias( m_handles, type ) != m_handles.end() );
{
auto it = m_handles.find( type );
if ( it == m_handles.end() )
{
auto aliasIt = m_handleAliases.find( type );
if ( aliasIt != m_handleAliases.end() )
{
it = m_handles.find( aliasIt->second.name );
assert( it != m_handles.end() );
}
}
return ( it != m_handles.end() );
}
return false;
} }
bool VulkanHppGenerator::isLenByStructMember( std::string const & name, std::vector<ParamData> const & params ) const bool VulkanHppGenerator::isLenByStructMember( std::string const & name, std::vector<ParamData> const & params ) const
@ -14901,10 +14883,11 @@ void VulkanHppGenerator::readTypeHandle( tinyxml2::XMLElement const * element, s
std::string alias = aliasIt->second; std::string alias = aliasIt->second;
std::string name = attributes.find( "name" )->second; std::string name = attributes.find( "name" )->second;
checkForError( m_handles.contains( alias ), line, "handle <" + name + "> uses unknown alias <" + alias + ">." );
checkForError( m_types.insert( { name, TypeData{ TypeCategory::Handle, {}, line } } ).second, line, "handle <" + name + "> already specified" ); checkForError( m_types.insert( { name, TypeData{ TypeCategory::Handle, {}, line } } ).second, line, "handle <" + name + "> already specified" );
assert( !m_handleAliases.contains( name ) );
m_handleAliases[name] = { alias, line }; auto handleIt = m_handles.find( alias );
checkForError( handleIt != m_handles.end(), line, "handle <" + name + "> uses unknown alias <" + alias + ">." );
checkForError( handleIt->second.aliases.insert( { name, line } ).second, line, "handle <" + name + "> already listed as alias for handle <" + alias + ">" );
} }
else else
{ {
@ -15437,7 +15420,6 @@ namespace
it = std::find_if( it = std::find_if(
values.begin(), values.end(), [&name]( auto const & value ) { return ( value.first == name ) || value.second.aliases.contains( name ); } ); values.begin(), values.end(), [&name]( auto const & value ) { return ( value.first == name ) || value.second.aliases.contains( name ); } );
} }
assert( it != values.end() );
return it; return it;
} }

View File

@ -322,6 +322,7 @@ private:
struct HandleData struct HandleData
{ {
std::map<std::string, int> aliases = {};
std::set<std::string> childrenHandles = {}; std::set<std::string> childrenHandles = {};
std::set<std::string> commands = {}; std::set<std::string> commands = {};
std::string deleteCommand = {}; std::string deleteCommand = {};
@ -1045,7 +1046,6 @@ private:
std::vector<FeatureData> m_features; std::vector<FeatureData> m_features;
std::map<std::string, FormatData> m_formats; std::map<std::string, FormatData> m_formats;
std::map<std::string, FuncPointerData> m_funcPointers; std::map<std::string, FuncPointerData> m_funcPointers;
std::map<std::string, AliasData> m_handleAliases;
std::map<std::string, HandleData> m_handles; std::map<std::string, HandleData> m_handles;
std::map<std::string, IncludeData> m_includes; std::map<std::string, IncludeData> m_includes;
std::map<std::string, PlatformData> m_platforms; std::map<std::string, PlatformData> m_platforms;