From a2e240c7e7d88e7d7047e21bc09f4a63b72d23d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 4 Sep 2023 12:31:50 +0200 Subject: [PATCH] Relax check for constants as array size: also allow potentially externally defined constants (#1652) --- VulkanHppGenerator.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 14740f2..064984a 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -46,6 +46,7 @@ std::string generateStandardArrayWrapper( std::s std::map getAttributes( tinyxml2::XMLElement const * element ); template std::vector getChildElements( ElementContainer const * element ); +bool isAllUpper( std::string const & name ); bool isNumber( std::string const & name ); std::pair, std::string> readModifiers( tinyxml2::XMLNode const * node ); std::string readSnippet( std::string const & snippetFile ); @@ -1485,12 +1486,16 @@ void VulkanHppGenerator::checkStructMemberCorrectness( std::string const & // check that each member type is known checkForError( m_types.contains( member.type.type ), member.xmlLine, "struct member uses unknown type <" + member.type.type + ">" ); - // check that any used constant is a known constant + // check that any used constant is a known constant or some potentially externally defined constant for ( auto const & arraySize : member.arraySizes ) { - checkForError( ( arraySize.find_first_not_of( "0123456789" ) == std::string::npos ) || m_constants.contains( arraySize ), - member.xmlLine, - "struct member array size uses unknown constant <" + arraySize + ">" ); + if ( !isNumber( arraySize ) && !m_constants.contains( arraySize ) ) + { + auto typeIt = m_types.find( arraySize ); + checkForError( ( typeIt != m_types.end() ) && isAllUpper( arraySize ) && ( typeIt->second.category == TypeCategory::ExternalType ), + member.xmlLine, + "struct member array size uses unknown constant <" + arraySize + ">" ); + } } // checks if a value is specified @@ -1516,8 +1521,7 @@ void VulkanHppGenerator::checkStructMemberCorrectness( std::string const & } else if ( member.type.type == "uint32_t" ) { - // check that a value for a uint32_t is all digits - checkForError( member.value.find_first_not_of( "0123456789" ) == std::string::npos, + checkForError( isNumber( member.value ), member.xmlLine, "value <" + member.value + "> for member <" + member.name + "> in structure <" + structureName + "> of type <" + member.type.type + "> is not a number" ); @@ -15047,6 +15051,11 @@ std::string generateStandardArray( std::string const & type, std::vector