Make the default value on "other" types dynamic by reading those types from <type> "requires" in vk.xml. (#306)

This commit is contained in:
Andreas Süßenbach 2019-03-19 15:34:00 +01:00 committed by Markus Tavenrath
parent 48ceca69f3
commit 3f20016ba9
3 changed files with 39 additions and 13 deletions

@ -1 +1 @@
Subproject commit 4ad4fd17161efd9bfd1125c0c9d17db6fb276216 Subproject commit 8cc971fb3e1c25afb949cdc49d6a6de63f19c5c6

View File

@ -758,6 +758,13 @@ std::pair<bool, std::string> writeFunctionBodyStandardReturn(std::string const&
return std::make_pair(castReturn, ret); return std::make_pair(castReturn, ret);
} }
VulkanHppGenerator::VulkanHppGenerator()
{
m_handles.insert(std::make_pair("", HandleData())); // insert the default "handle" without class (for createInstance, and such)
#if !defined(NDEBUG)
#endif
}
bool VulkanHppGenerator::containsUnion(std::string const& type) const bool VulkanHppGenerator::containsUnion(std::string const& type) const
{ {
// a simple recursive check if a type is or contains a union // a simple recursive check if a type is or contains a union
@ -826,13 +833,7 @@ std::string VulkanHppGenerator::defaultValue(std::string const& type) const
} }
else else
{ {
#if !defined(NDEBUG) assert(m_defaultZeroTypes.find(type) != m_defaultZeroTypes.end());
static const std::set<std::string> otherTypes =
{
"DWORD", "float", "HANDLE", "HINSTANCE", "HWND", "int", "int32_t", "size_t", "uint32_t", "uint64_t", "uint8_t", "Window", "xcb_window_t", "zx_handle_t"
};
assert(otherTypes.find(type) != otherTypes.end());
#endif
return "0"; return "0";
} }
} }
@ -1817,6 +1818,19 @@ void VulkanHppGenerator::readRequireEnum(tinyxml2::XMLElement const* element, st
} }
} }
#if !defined(NDEBUG)
void VulkanHppGenerator::readRequires(tinyxml2::XMLElement const* element, std::map<std::string, std::string> const& attributes)
{
checkAttributes(attributes, element->GetLineNum(), { {"name", {}}, { "requires", {}} }, {});
checkElements(getChildElements(element), {});
auto nameIt = attributes.find("name");
assert(nameIt != attributes.end());
assert(m_defaultZeroTypes.find(nameIt->second) == m_defaultZeroTypes.end());
m_defaultZeroTypes.insert(nameIt->second);
}
#endif
void VulkanHppGenerator::readStruct(tinyxml2::XMLElement const* element, bool isUnion, std::map<std::string, std::string> const& attributes) void VulkanHppGenerator::readStruct(tinyxml2::XMLElement const* element, bool isUnion, std::map<std::string, std::string> const& attributes)
{ {
checkAttributes(attributes, element->GetLineNum(), checkAttributes(attributes, element->GetLineNum(),
@ -2016,10 +2030,21 @@ void VulkanHppGenerator::readType(tinyxml2::XMLElement const* element)
throw std::runtime_error("Spec error on line " + lineNumber + ": unknown category <" + categoryIt->second + ">"); throw std::runtime_error("Spec error on line " + lineNumber + ": unknown category <" + categoryIt->second + ">");
} }
} }
#if !defined(NDEBUG)
else else
{ {
assert(attributes.find("name") != attributes.end()); auto requiresIt = attributes.find("requires");
if (requiresIt != attributes.end())
{
readRequires(element, attributes);
} }
else
{
assert((attributes.size() == 1) && (attributes.begin()->first == "name") && (attributes.begin()->second == "int"));
m_defaultZeroTypes.insert("int");
}
}
#endif
} }
void VulkanHppGenerator::readTypes(tinyxml2::XMLElement const* element) void VulkanHppGenerator::readTypes(tinyxml2::XMLElement const* element)

View File

@ -23,10 +23,7 @@
class VulkanHppGenerator class VulkanHppGenerator
{ {
public: public:
VulkanHppGenerator() VulkanHppGenerator();
{
m_handles.insert(std::make_pair("", HandleData())); // insert the default "handle" without class (for createInstance, and such)
}
void checkCorrectness(); void checkCorrectness();
std::string const& getTypesafeCheck() const; std::string const& getTypesafeCheck() const;
@ -222,6 +219,9 @@ class VulkanHppGenerator
void writeStructure(std::ostream & os, std::pair<std::string, StructureData> const& structure) const; void writeStructure(std::ostream & os, std::pair<std::string, StructureData> const& structure) const;
void writeUnion(std::ostream & os, std::pair<std::string, StructureData> const& structure) const; void writeUnion(std::ostream & os, std::pair<std::string, StructureData> const& structure) const;
void writeUniqueTypes(std::ostream &os, std::string const& parentType, std::set<std::string> const& childrenTypes) const; void writeUniqueTypes(std::ostream &os, std::string const& parentType, std::set<std::string> const& childrenTypes) const;
#if !defined(NDEBUG)
void readRequires(tinyxml2::XMLElement const* element, std::map<std::string, std::string> const& attributes);
#endif
private: private:
std::map<std::string, std::string> m_baseTypes; std::map<std::string, std::string> m_baseTypes;
@ -239,6 +239,7 @@ class VulkanHppGenerator
std::string m_version; std::string m_version;
std::string m_vulkanLicenseHeader; std::string m_vulkanLicenseHeader;
#if !defined(NDEBUG) #if !defined(NDEBUG)
std::set<std::string> m_defaultZeroTypes;
std::set<std::string> m_defines; // just used for verfication in readExtensionType std::set<std::string> m_defines; // just used for verfication in readExtensionType
#endif #endif
}; };