From 2518f528c01366b554aa30c08a88d8bfed621061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 6 May 2024 10:31:43 +0200 Subject: [PATCH] Simplify handling of structextends (#1866) --- VulkanHppGenerator.cpp | 19 +++++++++++++++---- VulkanHppGenerator.hpp | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 8ef22de..348f235 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -12531,7 +12531,7 @@ bool VulkanHppGenerator::isStructureChainAnchor( std::string const & type ) cons auto it = findByNameOrAlias( m_structs, type ); if ( it != m_structs.end() ) { - return m_extendedStructs.contains( it->first ); + return it->second.isExtended; } } return false; @@ -12605,6 +12605,19 @@ bool VulkanHppGenerator::isTypeUsed( std::string const & type ) const return false; } +void VulkanHppGenerator::markExtendedStructs() +{ + for (auto const& s : m_structs) + { + for (auto const& extends : s.second.structExtends) + { + auto structIt = m_structs.find( extends ); + checkForError( structIt != m_structs.end(), s.second.xmlLine, "struct <" + s.first + "> extends unknown struct <" + extends + ">" ); + structIt->second.isExtended = true; + } + } +} + bool VulkanHppGenerator::needsStructureChainResize( std::map const & vectorParams, std::vector const & chainedReturnParams ) const { @@ -13760,6 +13773,7 @@ void VulkanHppGenerator::readRegistry( tinyxml2::XMLElement const * element ) else if ( value == "types" ) { readTypes( child ); + markExtendedStructs(); } } } @@ -14954,7 +14968,6 @@ void VulkanHppGenerator::readTypeStruct( tinyxml2::XMLElement const * element, b checkForError( m_types.insert( { name, TypeData{ TypeCategory::Struct, {}, line } } ).second, line, "struct <" + name + "> already specified" ); checkForError( m_structsAliases.insert( { name, { alias, line } } ).second, line, "struct alias <" + name + "> already listed" ); } - else { checkAttributes( line, @@ -15075,8 +15088,6 @@ void VulkanHppGenerator::readTypeStruct( tinyxml2::XMLElement const * element, b } } } - - m_extendedStructs.insert( structureData.structExtends.begin(), structureData.structExtends.end() ); } } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 860f49f..93cd9de 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -366,6 +366,7 @@ private: { std::map aliases = {}; bool allowDuplicate = {}; + bool isExtended = {}; bool isUnion = {}; bool returnedOnly = {}; bool mutualExclusiveLens = {}; @@ -953,6 +954,7 @@ private: bool isSupportedFeature( std::string const & name ) const; bool isTypeRequired( std::string const & type ) const; bool isTypeUsed( std::string const & type ) const; + void markExtendedStructs(); bool needsStructureChainResize( std::map const & vectorParams, std::vector const & chainedReturnParams ) const; std::pair>> needsVectorSizeCheck( std::vector const & params, std::map const & vectorParams, @@ -1042,7 +1044,6 @@ private: std::map m_defines; DefinesPartition m_definesPartition; // partition defined macros into mutually-exclusive sets of callees, callers, and values std::map m_enums; - std::set m_extendedStructs; // structs which are referenced by the structextends tag std::vector m_extensions; std::map m_externalTypes; std::vector m_features;