From bcc02a1cb0c2653883b88725f7321b2d7ca27a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 1 Apr 2019 09:30:06 +0200 Subject: [PATCH] Cleanup on platform protection handling. (#312) --- VulkanHppGenerator.cpp | 107 ++++++++++++++--------------------------- VulkanHppGenerator.hpp | 2 +- 2 files changed, 38 insertions(+), 71 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index e4a886f..cf09ca6 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -34,13 +34,11 @@ std::string createEnumValueName(std::string const& name, std::string const& pref std::string determineCommandName(std::string const& vulkanCommandName, std::string const& firstArgumentType); std::set determineSkippedParams(size_t returnParamIndex, std::map const& vectorParamIndices); bool determineStructureChaining(std::string const& structType, std::set const& extendedStructs, std::map const& structureAliases); -void enterProtect(std::ostream &os, std::string const& protect); std::string findTag(std::set const& tags, std::string const& name, std::string const& postfix = ""); std::map getAttributes(tinyxml2::XMLElement const* element); std::vector getChildElements(tinyxml2::XMLElement const* element); std::string getEnumPostfix(std::string const& name, std::set const& tags, std::string & prefix); std::string getEnumPrefix(std::string const& name, bool bitmask); -void leaveProtect(std::ostream &os, std::string const& protect); std::string readArraySize(tinyxml2::XMLNode const* node); void readStructStructExtends(std::map const& attributes, std::vector & structExtends, std::set & extendedStructs); std::string readTypePostfix(tinyxml2::XMLNode const* node); @@ -248,14 +246,6 @@ bool determineStructureChaining(std::string const& structType, std::set const& tags, std::string const& name, std::string const& postfix) { auto tagIt = std::find_if(tags.begin(), tags.end(), [&name, &postfix](std::string const& t) { return endsWith(name, t + postfix); }); @@ -342,14 +332,6 @@ std::string extractTag(std::string const& name, std::set const& tag return tag; } -void leaveProtect(std::ostream &os, std::string const& protect) -{ - if (!protect.empty()) - { - os << "#endif /*" << protect << "*/" << std::endl; - } -} - std::string readArraySize(tinyxml2::XMLNode const* node) { if (node && node->ToText()) @@ -1569,10 +1551,9 @@ void VulkanHppGenerator::readExtensionRequireType(tinyxml2::XMLElement const* el auto stit = m_structures.find(name); if (stit != m_structures.end()) { - assert(stit->second.protect.empty()); assert(m_handles.find(name) == m_handles.end()); - std::string protect = m_platforms.find(platform)->second; - stit->second.protect = protect; + assert(stit->second.platform.empty()); + stit->second.platform = platform; } else { @@ -2255,11 +2236,6 @@ void VulkanHppGenerator::writeBitmasks(std::ostream & os) const void VulkanHppGenerator::writeCommand(std::ostream & os, std::string const& indentation, std::string const& name, std::pair const& commandData, bool definition) const { - os << std::endl; - assert(m_platforms.find(commandData.second.platform) != m_platforms.end()); - std::string const& protect = m_platforms.find(commandData.second.platform)->second; - enterProtect(os, protect); - bool twoStep = isTwoStepAlgorithm(commandData.second.params); std::map vectorParamIndices = determineVectorParamIndices(commandData.second.params); @@ -2354,8 +2330,6 @@ void VulkanHppGenerator::writeCommand(std::ostream & os, std::string const& inde << enhancedString << "#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/" << std::endl; } - - leaveProtect(os, protect); } void VulkanHppGenerator::writeDispatchLoaderDynamic(std::ostream &os) @@ -2369,10 +2343,9 @@ void VulkanHppGenerator::writeDispatchLoaderDynamic(std::ostream &os) { for (auto const& command : handle.second.commands) { - std::string const& protect = m_platforms.find(command.second.platform)->second; - enterProtect(os, protect); + writePlatformEnter(os, command.second.platform); os << " PFN_" << command.first << " " << command.first << " = 0;" << std::endl; - leaveProtect(os, protect); + writePlatformLeave(os, command.second.platform); } } @@ -2414,8 +2387,7 @@ void VulkanHppGenerator::writeDispatchLoaderDynamic(std::ostream &os) { if ((command.first != "vkGetDeviceProcAddr") && (command.first != "vkGetInstanceProcAddr")) { - std::string const& protect = m_platforms.find(command.second.platform)->second; - enterProtect(os, protect); + writePlatformEnter(os, command.second.platform); if (!command.second.params.empty() && m_handles.find(command.second.params[0].type.type) != m_handles.end() && command.second.params[0].type.type != "VkInstance" @@ -2428,7 +2400,7 @@ void VulkanHppGenerator::writeDispatchLoaderDynamic(std::ostream &os) { os << " " << command.first << " = PFN_" << command.first << "( vkGetInstanceProcAddr( instance, \"" << command.first << "\" ) );" << std::endl; } - leaveProtect(os, protect); + writePlatformLeave(os, command.second.platform); } } } @@ -2438,12 +2410,12 @@ void VulkanHppGenerator::writeDispatchLoaderDynamic(std::ostream &os) void VulkanHppGenerator::writeDispatchLoaderStatic(std::ostream &os) { - static const std::string commandTemplate = R"(${enterProtect} - ${returnType} vk${commandName}( ${parameterList} ) const + static const std::string commandTemplate = + R"( ${returnType} vk${commandName}( ${parameterList} ) const { return ::vk${commandName}( ${parameters} ); } -${leaveProtect})"; +)"; std::ostringstream commands; for (auto const& handle : m_handles) @@ -2468,16 +2440,16 @@ ${leaveProtect})"; firstParam = false; } - std::string const& protect = m_platforms.find(command.second.platform)->second; + commands << std::endl; + writePlatformEnter(commands, command.second.platform); commands << replaceWithMap(commandTemplate, { - { "enterProtect", protect.empty() ? "" : ("\n#ifdef " + protect) }, { "returnType", command.second.returnType }, { "commandName", stripPrefix(command.first, "vk") }, { "parameterList", parameterList }, { "parameters", parameters }, - { "leaveProtect", protect.empty() ? "" : ("#endif /*" + protect + "*/\n") } }); + writePlatformLeave(commands, command.second.platform); } } @@ -2581,13 +2553,13 @@ void VulkanHppGenerator::writeForwardDeclarations(std::ostream & os) const os << std::endl; for (auto const& structure : m_structures) { - enterProtect(os, structure.second.protect); + writePlatformEnter(os, structure.second.platform); os << " " << (structure.second.isUnion ? "union" : "struct") << " " << stripPrefix(structure.first, "Vk") << ";" << std::endl; for (std::string const& alias : structure.second.aliases) { os << " using " << stripPrefix(alias, "Vk") << " = " << stripPrefix(structure.first, "Vk") << ";" << std::endl; } - leaveProtect(os, structure.second.protect); + writePlatformLeave(os, structure.second.platform); } } @@ -3405,7 +3377,10 @@ void VulkanHppGenerator::writeHandle(std::ostream & os, std::pairsecond.protect) + if (structure.second.platform != itExtend->second.platform) { - enterProtect(os, itExtend->second.protect); + writePlatformEnter(os, itExtend->second.platform); } os << " template <> struct isStructureChainValid<" << stripPrefix(extendName, "Vk") << ", " << stripPrefix(structure.first, "Vk") << ">{ enum { value = true }; };" << std::endl; - if (structure.second.protect != itExtend->second.protect) + if (structure.second.platform != itExtend->second.platform) { - leaveProtect(os, itExtend->second.protect); + writePlatformLeave(os, itExtend->second.platform); } } - leaveProtect(os, structure.second.protect); + writePlatformLeave(os, structure.second.platform); } } } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 808e0b8..9fc46a4 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -137,7 +137,7 @@ class VulkanHppGenerator bool returnedOnly; bool isUnion; std::vector members; - std::string protect; + std::string platform; std::vector structExtends; std::vector aliases; std::string subStruct;