Merge pull request #540 from asuessenbach/arraySize

Add support of array-sized function arguments
This commit is contained in:
Andreas Süßenbach 2020-03-10 15:46:50 +01:00 committed by GitHub
commit 97b2a52d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -796,9 +796,9 @@ void VulkanHppGenerator::appendArgumentVector(std::string & str, size_t paramInd
void VulkanHppGenerator::appendArgumentVulkanType(std::string & str, ParamData const& paramData) const void VulkanHppGenerator::appendArgumentVulkanType(std::string & str, ParamData const& paramData) const
{ {
// this parameter is a vulkan type // this parameter is a vulkan type
if (!paramData.type.postfix.empty()) if (!paramData.type.postfix.empty() || !paramData.arraySizes.empty())
{ {
assert(paramData.type.postfix.back() == '*'); assert((paramData.type.postfix.empty() || (paramData.type.postfix.back() == '*')) && (paramData.arraySizes.empty() || (paramData.arraySizes.size() == 1)));
// it's a pointer -> needs a reinterpret cast to the vulkan type // it's a pointer -> needs a reinterpret cast to the vulkan type
std::string parameterName = startLowerCase(stripPrefix(paramData.name, "p")); std::string parameterName = startLowerCase(stripPrefix(paramData.name, "p"));
appendReinterpretCast(str, paramData.type.prefix.find("const") != std::string::npos, paramData.type.type, false); appendReinterpretCast(str, paramData.type.prefix.find("const") != std::string::npos, paramData.type.type, false);
@ -811,7 +811,7 @@ void VulkanHppGenerator::appendArgumentVulkanType(std::string & str, ParamData c
else else
{ {
// other parameters can just use the pointer // other parameters can just use the pointer
str += "&" + parameterName; str += (paramData.arraySizes.empty() ? "&" : "") + parameterName;
} }
str += " )"; str += " )";
} }
@ -2040,25 +2040,25 @@ void VulkanHppGenerator::appendFunctionBodyStandard(std::string & str, std::stri
{ {
str += ", "; str += ", ";
} }
appendFunctionBodyStandardArgument(str, commandData.second.params[i].type, commandData.second.params[i].name); appendFunctionBodyStandardArgument(str, commandData.second.params[i].type, commandData.second.params[i].name, commandData.second.params[i].arraySizes);
} }
str += std::string(" )") + (returnData.first ? " )" : "") + ";\n"; str += std::string(" )") + (returnData.first ? " )" : "") + ";\n";
} }
void VulkanHppGenerator::appendFunctionBodyStandardArgument(std::string & str, TypeData const& typeData, std::string const& name) const void VulkanHppGenerator::appendFunctionBodyStandardArgument(std::string & str, TypeData const& typeData, std::string const& name, std::vector<std::string> const& arraySizes) const
{ {
if (beginsWith(typeData.type, "Vk")) if (beginsWith(typeData.type, "Vk"))
{ {
// the parameter is a vulkan type // the parameter is a vulkan type
if (!typeData.postfix.empty()) if (!typeData.postfix.empty() || !arraySizes.empty())
{ {
assert(typeData.postfix.back() == '*'); assert((typeData.postfix.empty() || (typeData.postfix.back() == '*')) && (arraySizes.empty() || (arraySizes.size() == 1)));
// it's a pointer -> need to reinterpret_cast it // it's a pointer -> need to reinterpret_cast it
appendReinterpretCast(str, typeData.prefix.find("const") == 0, typeData.type, typeData.postfix.find("* const") != std::string::npos); appendReinterpretCast(str, typeData.prefix.find("const") == 0, typeData.type, typeData.postfix.find("* const") != std::string::npos);
} }
else else
{ {
// it's a value -> need to static_cast ist // it's a value -> need to static_cast it
str += "static_cast<" + typeData.type + ">"; str += "static_cast<" + typeData.type + ">";
} }
str += "( " + name + " )"; str += "( " + name + " )";

View File

@ -240,7 +240,7 @@ class VulkanHppGenerator
void appendFunctionBodyEnhancedVectorOfStructureChain(std::string & str, std::string const& indentation, std::pair<std::string,CommandData> const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool withAllocator) const; void appendFunctionBodyEnhancedVectorOfStructureChain(std::string & str, std::string const& indentation, std::pair<std::string,CommandData> const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool withAllocator) const;
void appendFunctionBodyEnhancedVectorOfUniqueHandles(std::string & str, std::string const& indentation, std::string const& commandName, std::pair<std::string, CommandData> const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool singular, bool withAllocator) const; void appendFunctionBodyEnhancedVectorOfUniqueHandles(std::string & str, std::string const& indentation, std::string const& commandName, std::pair<std::string, CommandData> const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool singular, bool withAllocator) const;
void appendFunctionBodyStandard(std::string & str, std::string const& indentation, std::pair<std::string, CommandData> const& commandData) const; void appendFunctionBodyStandard(std::string & str, std::string const& indentation, std::pair<std::string, CommandData> const& commandData) const;
void appendFunctionBodyStandardArgument(std::string & str, TypeData const& typeData, std::string const& name) const; void appendFunctionBodyStandardArgument(std::string & str, TypeData const& typeData, std::string const& name, std::vector<std::string> const& arraySizes) const;
bool appendFunctionHeaderArgumentEnhanced(std::string & str, ParamData const& param, size_t paramIndex, std::map<size_t, size_t> const& vectorParamIndices, bool skip, bool argEncountered, bool isTemplateParam, bool isLastArgument, bool singular, bool withDefaults, bool withAllocator) const; bool appendFunctionHeaderArgumentEnhanced(std::string & str, ParamData const& param, size_t paramIndex, std::map<size_t, size_t> const& vectorParamIndices, bool skip, bool argEncountered, bool isTemplateParam, bool isLastArgument, bool singular, bool withDefaults, bool withAllocator) const;
void appendFunctionHeaderArgumentEnhancedPointer(std::string & str, ParamData const& param, std::string const& strippedParameterName, bool withDefaults, bool withAllocator) const; void appendFunctionHeaderArgumentEnhancedPointer(std::string & str, ParamData const& param, std::string const& strippedParameterName, bool withDefaults, bool withAllocator) const;
void appendFunctionHeaderArgumentEnhancedSimple(std::string & str, ParamData const& param, bool lastArgument, bool withDefaults, bool withAllocator) const; void appendFunctionHeaderArgumentEnhancedSimple(std::string & str, ParamData const& param, bool lastArgument, bool withDefaults, bool withAllocator) const;