Extend check against protect attribute for types that are required by multiple extensions.

This commit is contained in:
asuessenbach 2020-06-15 10:09:07 +02:00
parent 4d97c949c3
commit f87c9330e7
2 changed files with 29 additions and 21 deletions

View File

@ -3296,8 +3296,8 @@ void VulkanHppGenerator::appendHandlesCommandDefintions( std::string & str ) con
// special handling for destroy functions // special handling for destroy functions
std::string commandName = determineCommandName( commandIt->first, commandIt->second.params[0].type.type ); std::string commandName = determineCommandName( commandIt->first, commandIt->second.params[0].type.type );
if ( commandIt->second.alias.empty() && if ( commandIt->second.alias.empty() &&
( ( commandIt->first.substr( 2, 7 ) == "Destroy" ) && ( commandName != "destroy" ) ) || ( ( ( commandIt->first.substr( 2, 7 ) == "Destroy" ) && ( commandName != "destroy" ) ) ||
( commandIt->first.substr( 2, 4 ) == "Free" ) ) ( commandIt->first.substr( 2, 4 ) == "Free" ) ) )
{ {
std::string destroyCommandString; std::string destroyCommandString;
appendCommand( destroyCommandString, " ", commandIt->first, commandIt->second, true ); appendCommand( destroyCommandString, " ", commandIt->first, commandIt->second, true );
@ -4650,29 +4650,21 @@ std::string const & VulkanHppGenerator::getVulkanLicenseHeader() const
std::pair<std::string, std::string> std::pair<std::string, std::string>
VulkanHppGenerator::generateProtection( std::string const & feature, std::set<std::string> const & extensions ) const VulkanHppGenerator::generateProtection( std::string const & feature, std::set<std::string> const & extensions ) const
{ {
if ( feature.empty() ) if ( feature.empty() && !extensions.empty() )
{ {
std::string protect; assert( getPlatforms( extensions ).size() == 1 );
for ( auto const & extension : extensions ) std::string platform = *getPlatforms( extensions ).begin();
if ( !platform.empty() )
{ {
auto extensionIt = m_extensions.find( extension ); auto platformIt = m_platforms.find( platform );
assert( extensionIt != m_extensions.end() );
if ( !extensionIt->second.platform.empty() )
{
auto platformIt = m_platforms.find( extensionIt->second.platform );
assert( platformIt != m_platforms.end() ); assert( platformIt != m_platforms.end() );
if ( !platformIt->second.protect.empty() ) std::string const & protect = platformIt->second.protect;
{
assert( protect.empty() );
protect = platformIt->second.protect;
}
}
}
if ( !protect.empty() ) if ( !protect.empty() )
{ {
return std::make_pair( "#ifdef " + protect + "\n", "#endif /*" + protect + "*/\n" ); return std::make_pair( "#ifdef " + protect + "\n", "#endif /*" + protect + "*/\n" );
} }
} }
}
return std::make_pair( "", "" ); return std::make_pair( "", "" );
} }
@ -4691,6 +4683,18 @@ std::pair<std::string, std::string> VulkanHppGenerator::generateProtection( std:
} }
} }
std::set<std::string> VulkanHppGenerator::getPlatforms( std::set<std::string> const & extensions ) const
{
std::set<std::string> platforms;
for ( auto const & e : extensions )
{
auto extensionIt = m_extensions.find( e );
assert( extensionIt != m_extensions.end() );
platforms.insert( extensionIt->second.platform );
}
return platforms;
}
bool VulkanHppGenerator::holdsSType( std::string const & type ) const bool VulkanHppGenerator::holdsSType( std::string const & type ) const
{ {
auto it = m_structures.find( type ); auto it = m_structures.find( type );
@ -5714,6 +5718,9 @@ void VulkanHppGenerator::readExtensionRequireType( tinyxml2::XMLElement const *
auto typeIt = m_types.find( name ); auto typeIt = m_types.find( name );
check( typeIt != m_types.end(), line, "failed to find required type <" + name + ">" ); check( typeIt != m_types.end(), line, "failed to find required type <" + name + ">" );
typeIt->second.extensions.insert( extension ); typeIt->second.extensions.insert( extension );
check( getPlatforms( typeIt->second.extensions ).size() == 1,
line,
"type <" + name + "> is protected by more than one platform" );
} }
void VulkanHppGenerator::readExtensions( tinyxml2::XMLElement const * element ) void VulkanHppGenerator::readExtensions( tinyxml2::XMLElement const * element )

View File

@ -515,6 +515,7 @@ private:
std::pair<std::string, std::string> generateProtection( std::string const & feature, std::pair<std::string, std::string> generateProtection( std::string const & feature,
std::set<std::string> const & extension ) const; std::set<std::string> const & extension ) const;
std::pair<std::string, std::string> generateProtection( std::string const & type, bool isAliased ) const; std::pair<std::string, std::string> generateProtection( std::string const & type, bool isAliased ) const;
std::set<std::string> getPlatforms( std::set<std::string> const & extensions ) const;
bool holdsSType( std::string const & type ) const; bool holdsSType( std::string const & type ) const;
bool isParam( std::string const & name, std::vector<ParamData> const & params ) const; bool isParam( std::string const & name, std::vector<ParamData> const & params ) const;
bool isParamIndirect( std::string const & name, std::vector<ParamData> const & params ) const; bool isParamIndirect( std::string const & name, std::vector<ParamData> const & params ) const;