From fe614bd960dd5478158b28592081723d4634ee70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Wed, 20 Mar 2019 17:39:51 +0100 Subject: [PATCH] Add platform specific protection for enum classes listed in a platform-protected extension. (#310) --- VulkanHppGenerator.cpp | 34 ++++++++++++++++++++++++---------- VulkanHppGenerator.hpp | 3 ++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 28799d3..2e5ab13 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1587,26 +1587,35 @@ void VulkanHppGenerator::readExtensionRequireType(tinyxml2::XMLElement const* el { std::string name = attributes.find("name")->second; - assert(m_handles.find(name) == m_handles.end()); - std::string protect = m_platforms.find(platform)->second; - auto bmit = m_bitmasks.find(name); if (bmit != m_bitmasks.end()) { + assert(bmit->second.platform.empty()); bmit->second.platform = platform; assert(m_bitmaskBits.find(bmit->second.requires) != m_bitmaskBits.end()); } else { - std::string strippedName = stripPrefix(name, "Vk"); - std::map::iterator stit = m_structures.find(name); - if (stit != m_structures.end()) + auto eit = m_enums.find(name); + if (eit != m_enums.end()) { - stit->second.protect = protect; + assert(eit->second.platform.empty()); + eit->second.platform = platform; } else { - assert((m_defines.find(strippedName) != m_defines.end()) || (m_enums.find(name) != m_enums.end())); + 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; + } + else + { + assert((m_defines.find(name) != m_defines.end())); + } } } } @@ -2548,13 +2557,18 @@ void VulkanHppGenerator::writeEnum(std::ostream & os, std::pairsecond; + + static const std::string enumTemplate = R"(${enterProtect} enum class ${name} {${values}}; -)"; +${leaveProtect})"; os << replaceWithMap(enumTemplate, { + { "enterProtect", protect.empty() ? "" : ("\n#ifdef " + protect) }, + { "leaveProtect", protect.empty() ? "" : ("#endif /*" + protect + "*/\n") }, { "name", stripPrefix(enumData.first, "Vk") }, { "values", values }, }); diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 430b667..cdf8f5d 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -106,8 +106,9 @@ class VulkanHppGenerator { void addEnumValue(std::string const& valueName, bool bitmask, std::string const& prefix, std::string const& postfix, std::string const& tag); - std::vector> values; // pairs of vulkan enum value and corresponding vk::-namespace enum value std::vector> aliases; // pairs of vulkan enum value and corresponding vk::-namespace enum value + std::string platform; + std::vector> values; // pairs of vulkan enum value and corresponding vk::-namespace enum value }; struct HandleData