mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Simplify alias handling for handles. (#1857)
This commit is contained in:
parent
79307b6253
commit
da28afe109
@ -5668,10 +5668,10 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
|
|||||||
auto const [enterDisableEnhanced, leaveDisableEnhanced] = generateProtection( "VULKAN_HPP_DISABLE_ENHANCED_MODE", false );
|
auto const [enterDisableEnhanced, leaveDisableEnhanced] = generateProtection( "VULKAN_HPP_DISABLE_ENHANCED_MODE", false );
|
||||||
usings += "\n" + enterDisableEnhanced + replaceWithMap( usingTemplate, { { "className", "StructExtends" } } ) + leaveDisableEnhanced + "\n";
|
usings += "\n" + enterDisableEnhanced + replaceWithMap( usingTemplate, { { "className", "StructExtends" } } ) + leaveDisableEnhanced + "\n";
|
||||||
|
|
||||||
auto const dynamicLoaderUsing = std::string{R"(#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
|
auto const dynamicLoaderUsing = std::string{ R"(#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
|
||||||
using VULKAN_HPP_NAMESPACE::DynamicLoader;
|
using VULKAN_HPP_NAMESPACE::DynamicLoader;
|
||||||
#endif /*VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL*/
|
#endif /*VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL*/
|
||||||
)"};
|
)" };
|
||||||
usings += dynamicLoaderUsing;
|
usings += dynamicLoaderUsing;
|
||||||
|
|
||||||
usings += generateCppModuleFormatTraitsUsings();
|
usings += generateCppModuleFormatTraitsUsings();
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,16 +322,17 @@ private:
|
|||||||
|
|
||||||
struct HandleData
|
struct HandleData
|
||||||
{
|
{
|
||||||
std::set<std::string> childrenHandles = {};
|
std::map<std::string, int> aliases = {};
|
||||||
std::set<std::string> commands = {};
|
std::set<std::string> childrenHandles = {};
|
||||||
std::string deleteCommand = {};
|
std::set<std::string> commands = {};
|
||||||
std::string deletePool = {};
|
std::string deleteCommand = {};
|
||||||
std::string destructorType = {};
|
std::string deletePool = {};
|
||||||
std::string objTypeEnum = {};
|
std::string destructorType = {};
|
||||||
std::string parent = {};
|
std::string objTypeEnum = {};
|
||||||
std::set<std::string> secondLevelCommands = {};
|
std::string parent = {};
|
||||||
bool isDispatchable = {};
|
std::set<std::string> secondLevelCommands = {};
|
||||||
int xmlLine = {};
|
bool isDispatchable = {};
|
||||||
|
int xmlLine = {};
|
||||||
|
|
||||||
// RAII data
|
// RAII data
|
||||||
std::map<std::string, CommandData>::const_iterator destructorIt = {};
|
std::map<std::string, CommandData>::const_iterator destructorIt = {};
|
||||||
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user