diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index adefcb6..0ce3b5f 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -375,13 +375,17 @@ std::string VulkanHppGenerator::generateHandles() const std::string str; for ( auto const & structure : m_structures ) { + auto inverseIt = m_structureAliasesInverse.find( structure.first ); std::string enter, leave; - std::tie( enter, leave ) = generateProtection( structure.first, !structure.second.aliases.empty() ); + std::tie( enter, leave ) = generateProtection( structure.first, inverseIt != m_structureAliasesInverse.end() ); str += enter + ( structure.second.isUnion ? " union " : " struct " ) + stripPrefix( structure.first, "Vk" ) + ";\n" + leave; - for ( auto const & alias : structure.second.aliases ) + if ( inverseIt != m_structureAliasesInverse.end() ) { - str += " using " + stripPrefix( alias, "Vk" ) + " = " + stripPrefix( structure.first, "Vk" ) + ";\n"; + for ( auto alias : inverseIt->second ) + { + str += " using " + stripPrefix( alias, "Vk" ) + " = " + stripPrefix( structure.first, "Vk" ) + ";\n"; + } } } @@ -1098,7 +1102,7 @@ void VulkanHppGenerator::checkCommandCorrectness() const } } -void VulkanHppGenerator::checkCorrectness() +void VulkanHppGenerator::checkCorrectness() const { check( !m_vulkanLicenseHeader.empty(), -1, "missing license header" ); checkBitmaskCorrectness(); @@ -1366,7 +1370,7 @@ void VulkanHppGenerator::checkHandleCorrectness() const } } -void VulkanHppGenerator::checkStructCorrectness() +void VulkanHppGenerator::checkStructCorrectness() const { for ( auto const & structAlias : m_structureAliases ) { @@ -1374,9 +1378,20 @@ void VulkanHppGenerator::checkStructCorrectness() check( structIt != m_structures.end(), structAlias.second.xmlLine, "unknown struct alias <" + structAlias.second.alias + ">" ); - check( structIt->second.aliases.insert( structAlias.first ).second, - structIt->second.xmlLine, - "struct <" + structIt->first + "> already uses alias <" + structAlias.first + ">" ); + } + + for ( auto const & structAliasInverse : m_structureAliasesInverse ) + { + auto structIt = m_structures.find( structAliasInverse.first ); + if ( structIt == m_structures.end() ) + { + assert( !structAliasInverse.second.empty() ); + auto aliasIt = m_structureAliases.find( *structAliasInverse.second.begin() ); + assert( aliasIt != m_structureAliases.end() ); + check( false, + aliasIt->second.xmlLine, + "struct <" + aliasIt->first + "> uses unknown alias <" + aliasIt->second.alias + ">" ); + } } std::set sTypeValues; @@ -1393,12 +1408,8 @@ void VulkanHppGenerator::checkStructCorrectness() // check for existence of all structs that are extended by this struct for ( auto const & extend : structure.second.structExtends ) { - check( m_structures.find( extend ) != m_structures.end() || - ( std::find_if( m_structures.begin(), - m_structures.end(), - [&extend]( std::pair const & sd ) { - return sd.second.aliases.find( extend ) != sd.second.aliases.end(); - } ) != m_structures.end() ), + check( ( m_structures.find( extend ) != m_structures.end() ) || + ( m_structureAliases.find( extend ) != m_structureAliases.end() ), structure.second.xmlLine, "struct <" + structure.first + "> extends unknown <" + extend + ">" ); } @@ -11638,33 +11649,17 @@ std::string VulkanHppGenerator::generateStructExtendsStructs( std::vector does not specify a struct in structextends field."; - - // check if symbol name is an alias to a struct - auto itAlias = - std::find_if( m_structures.begin(), - m_structures.end(), - [&extendName]( std::pair const & it ) -> bool { - return std::find( it.second.aliases.begin(), it.second.aliases.end(), extendName ) != - it.second.aliases.end(); - } ); - if ( itAlias != m_structures.end() ) + auto aliasIt = m_structureAliases.find( extendName ); + if ( aliasIt != m_structureAliases.end() ) { - errorString += " The symbol is an alias and maps to <" + itAlias->first + ">."; + itExtend = m_structures.find( aliasIt->second.alias ); + assert( itExtend != m_structures.end() ); } - check( false, structIt->second.xmlLine, errorString ); } std::string subEnter, subLeave; - std::tie( subEnter, subLeave ) = generateProtection( itExtend->first, !itExtend->second.aliases.empty() ); + std::tie( subEnter, subLeave ) = generateProtection( + itExtend->first, m_structureAliasesInverse.find( itExtend->first ) != m_structureAliasesInverse.end() ); if ( enter != subEnter ) { @@ -11918,7 +11913,8 @@ std::string VulkanHppGenerator::generateStructSubConstructor( std::pair const & structure ) const { std::string enter, leave; - std::tie( enter, leave ) = generateProtection( structure.first, !structure.second.aliases.empty() ); + std::tie( enter, leave ) = generateProtection( + structure.first, m_structureAliasesInverse.find( structure.first ) != m_structureAliasesInverse.end() ); std::string str = "\n" + enter; @@ -12007,9 +12003,13 @@ ${members} str += replaceWithMap( cppTypeTemplate, { { "sTypeValue", sTypeValue }, { "structureName", structureName } } ); } - for ( std::string const & alias : structure.second.aliases ) + auto aliasIt = m_structureAliasesInverse.find( structure.first ); + if ( aliasIt != m_structureAliasesInverse.end() ) { - str += " using " + stripPrefix( alias, "Vk" ) + " = " + stripPrefix( structure.first, "Vk" ) + ";\n"; + for ( std::string const & alias : aliasIt->second ) + { + str += " using " + stripPrefix( alias, "Vk" ) + " = " + structureName + ";\n"; + } } str += leave; @@ -12082,10 +12082,9 @@ std::string VulkanHppGenerator::generateType( std::string const & typeName, std: auto structIt = m_structures.find( typeName ); if ( structIt == m_structures.end() ) { - structIt = std::find_if( m_structures.begin(), - m_structures.end(), - [&typeName]( std::pair const & sd ) - { return sd.second.aliases.find( typeName ) != sd.second.aliases.end(); } ); + auto aliasIt = m_structureAliases.find( typeName ); + assert( aliasIt != m_structureAliases.end() ); + structIt = m_structures.find( aliasIt->second.alias ); assert( structIt != m_structures.end() ); if ( listedTypes.find( structIt->first ) == listedTypes.end() ) { @@ -12107,7 +12106,8 @@ std::string VulkanHppGenerator::generateType( std::string const & typeName, std: std::string VulkanHppGenerator::generateUnion( std::pair const & structure ) const { std::string enter, leave; - std::tie( enter, leave ) = generateProtection( structure.first, !structure.second.aliases.empty() ); + std::tie( enter, leave ) = generateProtection( + structure.first, m_structureAliasesInverse.find( structure.first ) != m_structureAliasesInverse.end() ); std::string str = "\n" + enter; std::string unionName = stripPrefix( structure.first, "Vk" ); @@ -12524,10 +12524,11 @@ bool VulkanHppGenerator::isStructureChainAnchor( std::string const & type ) cons auto it = m_structures.find( type ); if ( it == m_structures.end() ) { - it = std::find_if( m_structures.begin(), - m_structures.end(), - [&type]( std::pair const & sd ) - { return sd.second.aliases.find( type ) != sd.second.aliases.end(); } ); + auto aliasIt = m_structureAliases.find( type ); + if ( aliasIt != m_structureAliases.end() ) + { + it = m_structures.find( aliasIt->second.alias ); + } } if ( it != m_structures.end() ) { @@ -13362,10 +13363,14 @@ void VulkanHppGenerator::readExtensionDisabledType( tinyxml2::XMLElement const * { auto structIt = m_structures.find( name ); check( structIt != m_structures.end(), line, "trying to remove unknown struct <" + name + ">" ); - check( structIt->second.aliases.empty(), - line, - "trying to remove disabled structure <" + name + "> which has " + - std::to_string( structIt->second.aliases.size() ) + "aliases" ); + auto inverseAliasIt = m_structureAliasesInverse.find( name ); + if ( inverseAliasIt != m_structureAliasesInverse.end() ) + { + check( false, + line, + "trying to remove disabled structure <" + name + "> which has " + + std::to_string( inverseAliasIt->second.size() ) + "aliases" ); + } m_structures.erase( structIt ); } break; @@ -14458,6 +14463,9 @@ void VulkanHppGenerator::readStructAlias( tinyxml2::XMLElement const * check( m_structureAliases.insert( std::make_pair( name, StructureAliasData( alias, line ) ) ).second, line, "structure alias <" + name + "> already used" ); + check( m_structureAliasesInverse[alias].insert( name ).second, + line, + "structure alias <" + name + "> already used with structure <" + alias + ">" ); check( m_types.insert( std::make_pair( name, TypeCategory::Struct ) ).second, line, "struct <" + name + "> already specified as a type" ); diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 9221938..39f4c15 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -299,7 +299,6 @@ private: bool mutualExclusiveLens = false; std::vector members; std::vector structExtends; - std::set aliases; std::string subStruct; int xmlLine; }; @@ -350,7 +349,7 @@ private: std::string & instanceMembers ) const; void checkBitmaskCorrectness() const; void checkCommandCorrectness() const; - void checkCorrectness(); + void checkCorrectness() const; void checkEnumCorrectness() const; void checkEnumCorrectness( std::vector const & requireData ) const; bool checkEquivalentSingularConstructor( @@ -360,7 +359,7 @@ private: void checkExtensionCorrectness() const; void checkFuncPointerCorrectness() const; void checkHandleCorrectness() const; - void checkStructCorrectness(); + void checkStructCorrectness() const; void checkStructMemberCorrectness( std::string const & structureName, std::vector const & members, std::set & sTypeValues ) const; @@ -1247,8 +1246,9 @@ private: std::set m_includes; std::map m_platforms; std::set m_RAIISpecialFunctions; - std::map m_structureAliases; std::map m_structures; + std::map m_structureAliases; + std::map> m_structureAliasesInverse; std::set m_tags; std::map m_types; std::string m_typesafeCheck;