Introduce default initializers for member variables, simplify default values for constructor arguments (#455)

This commit is contained in:
Andreas Süßenbach 2019-12-12 11:40:21 +01:00 committed by GitHub
parent 3f82338d9f
commit 0b01a8a74c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 3882 additions and 3912 deletions

View File

@ -2666,12 +2666,13 @@ bool VulkanHppGenerator::appendStructConstructorArgument(std::string & str, bool
str += (listedArgument ? (",\n" + indentation) : "");
if (memberData.arraySize.empty())
{
str += memberData.type.compose() + " " + memberData.name + "_ = " + ((!memberData.type.postfix.empty() && memberData.type.postfix.back() == '*') ? "nullptr" : defaultValue(memberData.type.type));
str += memberData.type.compose() + " ";
}
else
{
str += "std::array<" + memberData.type.compose() + "," + memberData.arraySize + "> const& " + memberData.name + "_ = { { " + defaultValue(memberData.type.type) + " } }";
str += "std::array<" + memberData.type.compose() + "," + memberData.arraySize + "> const& ";
}
str += memberData.name + "_ = {}";
listedArgument = true;
}
return listedArgument;
@ -2716,14 +2717,20 @@ void VulkanHppGenerator::appendStructMembers(std::string & str, std::pair<std::s
assert(nameIt != enumIt->second.values.end());
str += " = StructureType::" + nameIt->vkValue;
}
else
{
// special handling for those nasty structs with an unspecified value for sType
str += " = {}";
}
}
else if (member.name == "pNext") // special handling for pNext
else
{
str += " = nullptr";
}
else if (!member.arraySize.empty()) // special handling for arrays
{
str += "[" + member.arraySize + "]";
if (!member.arraySize.empty())
{
str += "[" + member.arraySize + "]";
}
// as we don't have any meaningful default initialization values, everything can be initialized by just '{}' !
str += " = {}";
}
str += ";\n";
}
@ -2917,8 +2924,7 @@ void VulkanHppGenerator::appendUnion(std::string & str, std::pair<std::string, S
// just the very first constructor gets default arguments
if (firstTime)
{
std::string value = defaultValue(member.type.type);
str += (member.arraySize.empty() ? (" = " + value) : (" = { { " + value + " } }"));
str += " = {}";
firstTime = false;
}
str += " )\n"
@ -3059,48 +3065,6 @@ void VulkanHppGenerator::checkCorrectness()
}
}
std::string VulkanHppGenerator::defaultValue(std::string const& type) const
{
if (beginsWith(type, "PFN_vk") || (type == "LPCWSTR"))
{
return "nullptr";
}
else if (beginsWith(type, "Vk"))
{
auto const baseTypeIt = m_baseTypes.find(type);
if (baseTypeIt != m_baseTypes.end())
{
return "0";
}
else
{
auto const& bitmaskBitIt = m_bitmaskBits.find(type);
if (bitmaskBitIt != m_bitmaskBits.end())
{
return "VULKAN_HPP_NAMESPACE::" + stripPrefix(type, "Vk") + (bitmaskBitIt->second.values.empty() ? "()" : ("::" + bitmaskBitIt->second.values.front().vkValue));
}
else
{
auto const& enumIt = m_enums.find(type);
if (enumIt != m_enums.end())
{
return "VULKAN_HPP_NAMESPACE::" + stripPrefix(type, "Vk") + (enumIt->second.values.empty() ? "()" : ("::" + enumIt->second.values.front().vkValue));
}
else
{
assert((m_bitmasks.find(type) != m_bitmasks.end()) || (m_handles.find(type) != m_handles.end()) || (m_structures.find(type) != m_structures.end()));
return "VULKAN_HPP_NAMESPACE::" + stripPrefix(type, "Vk") + "()";
}
}
}
}
else
{
assert(m_defaultZeroTypes.find(type) != m_defaultZeroTypes.end());
return "0";
}
}
std::string VulkanHppGenerator::determineEnhancedReturnType(CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool isStructureChain) const
{
assert((returnParamIndex == INVALID_INDEX) || (returnParamIndex < commandData.params.size()));
@ -4067,8 +4031,6 @@ void VulkanHppGenerator::readRequires(tinyxml2::XMLElement const* element, std::
auto nameIt = attributes.find("name");
assert(nameIt != attributes.end());
assert(m_defaultZeroTypes.find(nameIt->second) == m_defaultZeroTypes.end());
m_defaultZeroTypes.insert(nameIt->second);
}
#endif
@ -4278,7 +4240,6 @@ void VulkanHppGenerator::readType(tinyxml2::XMLElement const* element)
else
{
assert((attributes.size() == 1) && (attributes.begin()->first == "name") && (attributes.begin()->second == "int"));
m_defaultZeroTypes.insert("int");
}
}
#endif

View File

@ -146,6 +146,7 @@ class VulkanHppGenerator
{
StructureData()
: returnedOnly(false)
, isUnion(false)
{}
bool returnedOnly;
@ -205,7 +206,6 @@ class VulkanHppGenerator
void appendUniqueTypes(std::string &str, std::string const& parentType, std::set<std::string> const& childrenTypes) const;
bool containsArray(std::string const& type) const;
bool containsUnion(std::string const& type) const;
std::string defaultValue(std::string const& type) const;
std::string determineEnhancedReturnType(CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool isStructureChain) const;
size_t determineReturnParamIndex(CommandData const& commandData, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep) const;
std::string determineSubStruct(std::pair<std::string, StructureData> const& structure) const;
@ -262,7 +262,6 @@ class VulkanHppGenerator
std::string m_version;
std::string m_vulkanLicenseHeader;
#if !defined(NDEBUG)
std::set<std::string> m_defaultZeroTypes;
std::set<std::string> m_defines; // just used for verfication in readExtensionType
#endif
};

View File

@ -188,19 +188,27 @@ namespace vk
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
#endif
#if !defined(NDEBUG)
std::vector<vk::LayerProperties> layerProperties = vk::enumerateInstanceLayerProperties();
std::vector<vk::ExtensionProperties> extensionProperties = vk::enumerateInstanceExtensionProperties();
#endif
std::vector<char const*> enabledLayers;
enabledLayers.reserve(layers.size());
for (auto const& layer : layers)
{
assert(std::find_if(layerProperties.begin(), layerProperties.end(), [layer](vk::LayerProperties const& lp) { return layer == lp.layerName; }) != layerProperties.end());
enabledLayers.push_back(layer.data());
}
#if !defined(NDEBUG)
// Enable standard validation layer to find as much errors as possible!
if (std::find(layers.begin(), layers.end(), "VK_LAYER_KHRONOS_validation") == layers.end())
if (std::find(layers.begin(), layers.end(), "VK_LAYER_KHRONOS_validation") == layers.end()
&& std::find_if(layerProperties.begin(), layerProperties.end(), [](vk::LayerProperties const& lp) { return (strcmp("VK_LAYER_KHRONOS_validation", lp.layerName) == 0); }) != layerProperties.end())
{
enabledLayers.push_back("VK_LAYER_KHRONOS_validation");
}
if (std::find(layers.begin(), layers.end(), "VK_LAYER_LUNARG_assistant_layer") == layers.end())
if (std::find(layers.begin(), layers.end(), "VK_LAYER_LUNARG_assistant_layer") == layers.end()
&& std::find_if(layerProperties.begin(), layerProperties.end(), [](vk::LayerProperties const& lp) { return (strcmp("VK_LAYER_LUNARG_assistant_layer", lp.layerName) == 0); }) != layerProperties.end())
{
enabledLayers.push_back("VK_LAYER_LUNARG_assistant_layer");
}
@ -210,10 +218,12 @@ namespace vk
enabledExtensions.reserve(extensions.size());
for (auto const& ext : extensions)
{
assert(std::find_if(extensionProperties.begin(), extensionProperties.end(), [ext](vk::ExtensionProperties const& ep) { return ext == ep.extensionName; }) != extensionProperties.end());
enabledExtensions.push_back(ext.data());
}
#if !defined(NDEBUG)
if (std::find(extensions.begin(), extensions.end(), VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == extensions.end())
if (std::find(extensions.begin(), extensions.end(), VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == extensions.end()
&& std::find_if(extensionProperties.begin(), extensionProperties.end(), [](vk::ExtensionProperties const& ep) { return (strcmp(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, ep.extensionName) == 0); }) != extensionProperties.end())
{
enabledExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}

File diff suppressed because it is too large Load Diff