From ad5f67d33015bf9c2ae5f29c01232528941c8744 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Wed, 23 Nov 2022 17:42:23 +0100 Subject: [PATCH] Add support of more complex logic of attribute --- VulkanHppGenerator.cpp | 63 +++++++++++++++++++++++++----------------- VulkanHppGenerator.hpp | 2 +- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index bc9db91..663f15c 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -53,6 +53,7 @@ std::string stripPrefix( std::string const std::string toCamelCase( std::string const & value ); std::string toUpperCase( std::string const & name ); std::vector tokenize( std::string const & tokenString, std::string const & separator ); +std::vector tokenizeAny( std::string const & tokenString, std::string const & separators ); std::string toString( tinyxml2::XMLError error ); std::string trim( std::string const & input ); std::string trimEnd( std::string const & input ); @@ -11115,7 +11116,8 @@ void VulkanHppGenerator::readExtensionsExtension( tinyxml2::XMLElement const * e } else if ( ( attribute.first == "depends" ) || ( attribute.first == "requires" ) ) { - depends = tokenize( attribute.second, "," ); + // we don't care about the logical implications of ',' and '+' here, we're just interested to get the depends strings + depends = tokenizeAny( attribute.second, ",+" ); } else if ( attribute.first == "requiresCore" ) { @@ -11266,39 +11268,29 @@ void VulkanHppGenerator::readExtensionsExtensionRequire( tinyxml2::XMLElement co std::vector children = getChildElements( element ); checkElements( line, children, {}, { "command", "comment", "enum", "type" } ); - std::string depends; + std::vector depends; for ( auto const & attribute : attributes ) { - if ( attribute.first == "depends" ) + if ( ( attribute.first == "depends" ) || ( attribute.first == "extension" ) ) { assert( depends.empty() ); - depends = attribute.second; - checkForError( std::find_if( extensionIt->second.requireData.begin(), - extensionIt->second.requireData.end(), - [&depends]( RequireData const & rd ) { - return std::find( rd.depends.begin(), rd.depends.end(), depends ) != rd.depends.end(); - } ) == extensionIt->second.requireData.end(), - line, - "required extension <" + depends + "> already listed" ); - } - else if ( attribute.first == "extension" ) - { - assert( depends.empty() ); - depends = attribute.second; - checkForError( std::find_if( extensionIt->second.requireData.begin(), - extensionIt->second.requireData.end(), - [&depends]( RequireData const & rd ) { - return std::find( rd.depends.begin(), rd.depends.end(), depends ) != rd.depends.end(); - } ) == extensionIt->second.requireData.end(), - line, - "required extension <" + depends + "> already listed" ); + depends = tokenizeAny( attribute.second, ",+" ); + for ( auto const & d : depends ) + { + checkForError( std::find_if( extensionIt->second.requireData.begin(), + extensionIt->second.requireData.end(), + [&d]( RequireData const & rd ) { return std::find( rd.depends.begin(), rd.depends.end(), d ) != rd.depends.end(); } ) == + extensionIt->second.requireData.end(), + line, + "required extension <" + d + "> already listed" ); + } } else { assert( attribute.first == "feature" ); checkForError( m_features.find( attribute.second ) != m_features.end(), line, "unknown feature <" + attribute.second + ">" ); assert( depends.empty() ); - depends = attribute.second; + depends.push_back( attribute.second ); } } @@ -11449,7 +11441,7 @@ void VulkanHppGenerator::readFeatureRequire( tinyxml2::XMLElement const * elemen std::vector children = getChildElements( element ); checkElements( line, children, {}, { "command", "comment", "enum", "type" } ); - RequireData requireData( line, "" ); + RequireData requireData( line, { "" } ); bool requireDataEmpty = true; for ( auto child : children ) { @@ -13150,7 +13142,7 @@ std::string VulkanHppGenerator::TypeInfo::compose( std::string const & nameSpace ( postfix.empty() ? "" : " " ) + postfix; } -VulkanHppGenerator::RequireData::RequireData( int line, std::string const & depends_ ) : depends( tokenize( depends_, "," ) ), xmlLine( line ) {} +VulkanHppGenerator::RequireData::RequireData( int line, std::vector const & depends_ ) : depends( depends_ ), xmlLine( line ) {} // // VulkanHppGenerator local functions @@ -13603,6 +13595,25 @@ std::vector tokenize( std::string const & tokenString, std::string return tokens; } +std::vector tokenizeAny( std::string const & tokenString, std::string const & separators ) +{ + std::vector tokens; + if ( !tokenString.empty() ) + { + size_t start = 0, end; + do + { + end = tokenString.find_first_of( separators, start ); + if ( start != end ) + { + tokens.push_back( trim( tokenString.substr( start, end - start ) ) ); + } + start = end + 1; + } while ( end != std::string::npos ); + } + return tokens; +} + std::string trim( std::string const & input ) { std::string result = input; diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 5551765..b6733f0 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -168,7 +168,7 @@ private: struct RequireData { - RequireData( int line, std::string const & depends_ ); + RequireData( int line, std::vector const & depends_ ); std::vector depends; std::vector commands;