From 35a43611f84eb995fbe9022d1c2235a461969874 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Wed, 4 Aug 2021 15:28:59 +0200 Subject: [PATCH] Improved some checks on structures/aliases --- VulkanHppGenerator.cpp | 31 ++++++++++++++++++++----------- VulkanHppGenerator.hpp | 4 ++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 527638c..11b6bbb 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1098,7 +1098,7 @@ void VulkanHppGenerator::checkCommandCorrectness() const } } -void VulkanHppGenerator::checkCorrectness() const +void VulkanHppGenerator::checkCorrectness() { check( !m_vulkanLicenseHeader.empty(), -1, "missing license header" ); checkBitmaskCorrectness(); @@ -1366,7 +1366,7 @@ void VulkanHppGenerator::checkHandleCorrectness() const } } -void VulkanHppGenerator::checkStructCorrectness() const +void VulkanHppGenerator::checkStructCorrectness() { std::set sTypeValues; for ( auto const & structure : m_structures ) @@ -1382,7 +1382,12 @@ void VulkanHppGenerator::checkStructCorrectness() const // 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(), + 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() ), structure.second.xmlLine, "struct <" + structure.first + "> extends unknown <" + extend + ">" ); } @@ -1411,6 +1416,15 @@ void VulkanHppGenerator::checkStructCorrectness() const } } assert( sTypeValues.empty() ); + + for ( auto const & structAlias : m_structureAliases ) + { + auto structIt = m_structures.find( structAlias.second.alias ); + 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 + ">" ); + } } void VulkanHppGenerator::checkStructMemberCorrectness( std::string const & structureName, @@ -1451,7 +1465,7 @@ void VulkanHppGenerator::checkStructMemberCorrectness( std::string const & unionIt->second.members.end(), [selectorValue]( MemberData const & md ) { return md.selection == selectorValue.name; } ) != unionIt->second.members.end(), - selectorEnumIt->second.xmlLine, + selectorValue.xmlLine, "enum <" + selectorEnumIt->first + "> has value <" + selectorValue.name + "> that is not used by corresponding union <" + unionIt->first + ">" ); } @@ -12994,8 +13008,8 @@ void VulkanHppGenerator::readEnum( tinyxml2::XMLElement const * el std::string prefix = generateEnumSuffixes( enumIt->first, enumIt->second.isBitmask, m_tags ).first; check( beginsWith( name, prefix ), - line, - "encountered enum value <" + name + "> that does not begin with expected prefix <" + prefix + ">" ); + line, + "encountered enum value <" + name + "> that does not begin with expected prefix <" + prefix + ">" ); check( bitpos.empty() ^ value.empty(), line, "invalid set of attributes for enum <" + name + ">" ); enumIt->second.addEnumValue( line, name, protect, !bitpos.empty(), "" ); @@ -14442,11 +14456,6 @@ void VulkanHppGenerator::readStructAlias( tinyxml2::XMLElement const * check( m_structureAliases.insert( std::make_pair( name, StructureAliasData( alias, line ) ) ).second, line, "structure alias <" + name + "> already used" ); - auto structIt = m_structures.find( alias ); - check( structIt != m_structures.end(), line, "unknown struct alias <" + alias + ">" ); - check( structIt->second.aliases.insert( name ).second, - structIt->second.xmlLine, - "struct <" + alias + "> already uses alias <" + name + ">" ); 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 0a9a7c6..9221938 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -350,7 +350,7 @@ private: std::string & instanceMembers ) const; void checkBitmaskCorrectness() const; void checkCommandCorrectness() const; - void checkCorrectness() const; + void checkCorrectness(); void checkEnumCorrectness() const; void checkEnumCorrectness( std::vector const & requireData ) const; bool checkEquivalentSingularConstructor( @@ -360,7 +360,7 @@ private: void checkExtensionCorrectness() const; void checkFuncPointerCorrectness() const; void checkHandleCorrectness() const; - void checkStructCorrectness() const; + void checkStructCorrectness(); void checkStructMemberCorrectness( std::string const & structureName, std::vector const & members, std::set & sTypeValues ) const;