Reordered listing of structures and handles

-> no need to forward declare the structures any more
This commit is contained in:
asuessenbach 2020-07-22 10:20:05 +02:00
parent fba2516d9c
commit 0ff1e674ee
3 changed files with 35187 additions and 35815 deletions

View File

@ -1919,24 +1919,6 @@ void VulkanHppGenerator::appendEnumToString( std::string &
str += " }\n";
}
void VulkanHppGenerator::appendForwardDeclarations( std::string & str ) const
{
str += "\n";
for ( auto const & structure : m_structures )
{
std::string enter, leave;
std::tie( enter, leave ) = generateProtection( structure.first, !structure.second.aliases.empty() );
str += enter + " " + ( structure.second.isUnion ? "union" : "struct" ) + " " +
stripPrefix( structure.first, "Vk" ) + ";\n";
for ( std::string const & alias : structure.second.aliases )
{
str += " using " + stripPrefix( alias, "Vk" ) + " = " + stripPrefix( structure.first, "Vk" ) + ";\n";
}
str += leave;
}
}
bool needsMultiVectorSizeCheck( size_t returnParamIndex, std::map<size_t, size_t> const & vectorParamIndices )
{
for ( std::map<size_t, size_t>::const_iterator it0 = vectorParamIndices.begin(); it0 != vectorParamIndices.end();
@ -3101,13 +3083,12 @@ void VulkanHppGenerator::appendFunctionHeaderTemplate( std::string & str,
str += std::string( "typename Dispatch" ) + ( withDefault ? " = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE" : "" ) + ">\n";
}
void VulkanHppGenerator::appendHandle( std::string & str,
std::pair<std::string, HandleData> const & handleData,
std::set<std::string> & listedHandles ) const
void VulkanHppGenerator::appendHandle( std::string & str, std::pair<std::string, HandleData> const & handleData )
{
if ( listedHandles.find( handleData.first ) == listedHandles.end() )
{
listedHandles.insert( handleData.first );
assert( m_listingTypes.find( handleData.first ) == m_listingTypes.end() );
m_listingTypes.insert( handleData.first );
assert( m_listedTypes.find( handleData.first ) == m_listedTypes.end() );
// first check for any handle that needs to be listed before this one
for ( auto const & command : handleData.second.commands )
@ -3116,11 +3097,9 @@ void VulkanHppGenerator::appendHandle( std::string &
assert( commandIt != m_commands.end() );
for ( auto const & parameter : commandIt->second.params )
{
std::string typeName = parameter.type.type;
auto handlesIt = m_handles.find( typeName );
if ( ( handlesIt != m_handles.end() ) && ( listedHandles.find( typeName ) == listedHandles.end() ) )
if ( handleData.first != parameter.type.type ) // the commands use this handleData type !
{
appendHandle( str, *handlesIt, listedHandles );
appendType( str, parameter.type.type );
}
}
}
@ -3308,20 +3287,27 @@ ${commands}
if ( !handleData.second.alias.empty() )
{
str += " using " + stripPrefix( handleData.second.alias, "Vk" ) + " = " +
stripPrefix( handleData.first, "Vk" ) + ";\n";
str += " using " + stripPrefix( handleData.second.alias, "Vk" ) + " = " + stripPrefix( handleData.first, "Vk" ) +
";\n";
}
str += leave;
}
}
m_listingTypes.erase( handleData.first );
m_listedTypes.insert( handleData.first );
}
void VulkanHppGenerator::appendHandles( std::string & str ) const
void VulkanHppGenerator::appendHandles( std::string & str )
{
std::set<std::string> listedHandles;
for ( auto const & handle : m_handles )
{
appendHandle( str, handle, listedHandles );
if ( m_listedTypes.find( handle.first ) == m_listedTypes.end() )
{
assert( m_listingTypes.empty() );
appendHandle( str, handle );
assert( m_listingTypes.empty() );
}
}
}
@ -3483,29 +3469,27 @@ void VulkanHppGenerator::appendResultExceptions( std::string & str ) const
str += "\n";
}
void VulkanHppGenerator::appendStruct( std::string & str,
std::pair<std::string, StructureData> const & structure,
std::set<std::string> & listedStructures ) const
void VulkanHppGenerator::appendStruct( std::string & str, std::pair<std::string, StructureData> const & structure )
{
if ( listedStructures.find( structure.first ) == listedStructures.end() )
{
listedStructures.insert( structure.first );
assert( m_listingTypes.find( structure.first ) == m_listingTypes.end() );
m_listingTypes.insert( structure.first );
assert( m_listedTypes.find( structure.first ) == m_listedTypes.end() );
for ( auto const & member : structure.second.members )
{
auto structureIt = m_structures.find( member.type.type );
if ( ( structureIt != m_structures.end() ) &&
( listedStructures.find( member.type.type ) == listedStructures.end() ) )
if ( structure.first != member.type.type ) // some structures hold a pointer to the very same structure type
{
appendStruct( str, *structureIt, listedStructures );
appendType( str, member.type.type );
}
}
if ( !structure.second.subStruct.empty() )
{
auto structureIt = m_structures.find( structure.second.subStruct );
if ( ( structureIt != m_structures.end() ) &&
( listedStructures.find( structureIt->first ) == listedStructures.end() ) )
if ( ( structureIt != m_structures.end() ) && ( m_listedTypes.find( structureIt->first ) == m_listedTypes.end() ) )
{
appendStruct( str, *structureIt, listedStructures );
appendStruct( str, *structureIt );
}
}
@ -3517,7 +3501,9 @@ void VulkanHppGenerator::appendStruct( std::string &
{
appendStructure( str, structure );
}
}
m_listingTypes.erase( structure.first );
m_listedTypes.insert( structure.first );
}
void VulkanHppGenerator::appendStructAssignmentOperators( std::string & str,
@ -3899,12 +3885,16 @@ std::string VulkanHppGenerator::appendStructMembers( std::string &
return sTypeValue;
}
void VulkanHppGenerator::appendStructs( std::string & str ) const
void VulkanHppGenerator::appendStructs( std::string & str )
{
std::set<std::string> listedStructures;
for ( auto const & structure : m_structures )
{
appendStruct( str, structure, listedStructures );
if ( m_listedTypes.find( structure.first ) == m_listedTypes.end() )
{
assert( m_listingTypes.empty() );
appendStruct( str, structure );
assert( m_listingTypes.empty() );
}
}
}
@ -4144,6 +4134,12 @@ ${members}
)";
str += replaceWithMap( cppTypeTemplate, { { "sTypeValue", sTypeValue }, { "structureName", structureName } } );
}
for ( std::string const & alias : structure.second.aliases )
{
str += " using " + stripPrefix( alias, "Vk" ) + " = " + stripPrefix( structure.first, "Vk" ) + ";\n";
}
str += leave;
}
@ -4234,6 +4230,62 @@ void VulkanHppGenerator::appendThrowExceptions( std::string & str ) const
" }\n";
}
void VulkanHppGenerator::appendType( std::string & str, std::string const & typeName )
{
if ( m_listedTypes.find( typeName ) == m_listedTypes.end() )
{
auto typeIt = m_types.find( typeName );
assert( typeIt != m_types.end() );
switch ( typeIt->second.category )
{
case TypeCategory::Handle:
{
auto handleIt = m_handles.find( typeName );
if ( handleIt == m_handles.end() )
{
handleIt = std::find_if(
m_handles.begin(), m_handles.end(), [&typeName]( std::pair<std::string, HandleData> const & hd ) {
return hd.second.alias == typeName;
} );
assert( handleIt != m_handles.end() );
if ( m_listedTypes.find( handleIt->first ) == m_listedTypes.end() )
{
appendHandle( str, *handleIt );
}
}
else
{
appendHandle( str, *handleIt );
}
}
break;
case TypeCategory::Struct:
case TypeCategory::Union:
{
auto structIt = m_structures.find( typeName );
if ( structIt == m_structures.end() )
{
structIt = std::find_if(
m_structures.begin(), m_structures.end(), [&typeName]( std::pair<std::string, StructureData> const & sd ) {
return sd.second.aliases.find( typeName ) != sd.second.aliases.end();
} );
assert( structIt != m_structures.end() );
if ( m_listedTypes.find( structIt->first ) == m_listedTypes.end() )
{
appendStruct( str, *structIt );
}
}
else
{
appendStruct( str, *structIt );
}
}
break;
default: m_listedTypes.insert( typeIt->first ); break;
}
}
}
void VulkanHppGenerator::appendUnion( std::string & str, std::pair<std::string, StructureData> const & structure ) const
{
std::string enter, leave;
@ -8911,9 +8963,8 @@ namespace std
generator.appendResultExceptions( str );
generator.appendThrowExceptions( str );
str += "#endif\n" + structResultValue;
generator.appendForwardDeclarations( str );
generator.appendHandles( str );
generator.appendStructs( str );
generator.appendHandles( str );
generator.appendHandlesCommandDefintions( str );
generator.appendStructureChainValidation( str );
generator.appendDispatchLoaderDynamic( str );

View File

@ -32,12 +32,11 @@ public:
void appendDispatchLoaderDefault(
std::string & str ); // typedef to DispatchLoaderStatic or undefined type, based on VK_NO_PROTOTYPES
void appendEnums( std::string & str ) const;
void appendForwardDeclarations( std::string & str ) const;
void appendHandles( std::string & str ) const;
void appendHandles( std::string & str );
void appendHandlesCommandDefintions( std::string & str ) const;
void appendHashStructures( std::string & str ) const;
void appendResultExceptions( std::string & str ) const;
void appendStructs( std::string & str ) const;
void appendStructs( std::string & str );
void appendStructureChainValidation( std::string & str );
void appendThrowExceptions( std::string & str ) const;
void appendIndexTypeTraits( std::string & str ) const;
@ -469,11 +468,9 @@ private:
bool withDefault,
bool isStructureChain ) const;
void appendHandle( std::string & str,
std::pair<std::string, HandleData> const & handle,
std::set<std::string> & listedHandles ) const;
std::pair<std::string, HandleData> const & handle );
void appendStruct( std::string & str,
std::pair<std::string, StructureData> const & structure,
std::set<std::string> & listedStructures ) const;
std::pair<std::string, StructureData> const & structure );
void appendStructAssignmentOperators( std::string & str,
std::pair<std::string, StructureData> const & structure,
std::string const & prefix ) const;
@ -499,6 +496,7 @@ private:
std::pair<std::string, StructureData> const & structData,
std::string const & prefix ) const;
void appendStructure( std::string & str, std::pair<std::string, StructureData> const & structure ) const;
void appendType( std::string & str, std::string const & typeName );
void appendUnion( std::string & str, std::pair<std::string, StructureData> const & structure ) const;
void appendUniqueTypes( std::string & str,
std::string const & parentType,
@ -625,6 +623,8 @@ private:
std::map<std::string, FuncPointerData> m_funcPointers;
std::map<std::string, HandleData> m_handles;
std::set<std::string> m_includes;
std::set<std::string> m_listedTypes;
std::set<std::string> m_listingTypes;
std::map<std::string, PlatformData> m_platforms;
std::map<std::string, std::string> m_structureAliases;
std::map<std::string, StructureData> m_structures;

File diff suppressed because it is too large Load Diff