From 4e055c376de624a5a0b4f4e3c444c77efafabeb2 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Tue, 21 Sep 2021 14:20:24 +0200 Subject: [PATCH] Move argument type check of func pointers to final check. --- VulkanHppGenerator.cpp | 27 ++++++++++++++++++++++----- VulkanHppGenerator.hpp | 13 +++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 3f67c77..9145223 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1332,6 +1332,12 @@ void VulkanHppGenerator::checkFuncPointerCorrectness() const funcPointer.second.xmlLine, "funcpointer requires unknown <" + funcPointer.second.requirements + ">" ); } + for ( auto const & argument : funcPointer.second.arguments ) + { + check( m_types.find( argument.type ) != m_types.end(), + argument.xmlLine, + "funcpointer argument of unknown type <" + argument.type + ">" ); + } } } @@ -7262,7 +7268,7 @@ std::pair VulkanHppGenerator::generateRAIIHandleConstr assert( constructorIt->second.successCodes[1] == "VK_INCOMPLETE" ); auto lenParamIt = constructorIt->second.params.begin() + returnParamIndices[0]; auto handleParamIt = constructorIt->second.params.begin() + returnParamIndices[1]; - arrayConstructor = generateRAIIHandleConstructorEnumerate( + arrayConstructor = generateRAIIHandleConstructorEnumerate( handle, constructorIt, handleParamIt, lenParamIt, enter, leave ); } } @@ -13595,6 +13601,8 @@ void VulkanHppGenerator::readFuncpointer( tinyxml2::XMLElement const * } } + auto funcPointerIt = m_funcPointers.end(); + std::set argumentNames; for ( auto const & child : children ) { std::string value = child->Value(); @@ -13603,20 +13611,29 @@ void VulkanHppGenerator::readFuncpointer( tinyxml2::XMLElement const * { std::string name = child->GetText(); check( !name.empty(), childLine, "funcpointer with empty name" ); - check( m_funcPointers.insert( std::make_pair( name, FuncPointerData( requirements, line ) ) ).second, + check( m_funcPointers.find( name ) == m_funcPointers.end(), childLine, "funcpointer <" + name + "> already specified" ); + funcPointerIt = m_funcPointers.insert( std::make_pair( name, FuncPointerData( requirements, line ) ) ).first; check( m_types.insert( std::make_pair( name, TypeCategory::FuncPointer ) ).second, childLine, "funcpointer <" + name + "> already specified as a type" ); } else if ( value == "type" ) { + assert( funcPointerIt != m_funcPointers.end() ); std::string type = child->GetText(); - check( !type.empty(), childLine, "funcpointer argument with empty type" ); - check( ( m_types.find( type ) != m_types.end() ) || ( type == requirements ), + funcPointerIt->second.arguments.push_back( { type, childLine } ); + + auto sibling = child->NextSibling(); + char const * siblingValue = sibling->Value(); + assert( siblingValue != nullptr ); + std::string argumentName = siblingValue; + argumentName = argumentName.substr( argumentName.find_first_not_of( "* " ) ); + argumentName = argumentName.substr( 0, argumentName.find_first_of( ",)" ) ); + check( argumentNames.insert( argumentName ).second, childLine, - "funcpointer argument of unknown type <" + type + ">" ); + "funcpointer <" + funcPointerIt->first + "> already has an argument named <" + argumentName + ">" ); } } } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 37234ff..01f4270 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -228,12 +228,21 @@ private: int xmlLine; }; + struct FuncPointerArgumentData + { + FuncPointerArgumentData( std::string const & t, int line ) : type( t ), xmlLine( line ) {} + + std::string type; + int xmlLine; + }; + struct FuncPointerData { FuncPointerData( std::string const & r, int line ) : requirements( r ), xmlLine( line ) {} - std::string requirements; - int xmlLine; + std::vector arguments; + std::string requirements; + int xmlLine; }; struct HandleData