Skip to content

Commit 89f1b68

Browse files
committed
validation layer: Move repeated code out of generated code.
Noticed because clang-tidy wanted to modernize the for loop.
1 parent adcf497 commit 89f1b68

3 files changed

Lines changed: 21 additions & 29 deletions

File tree

src/api_layers/core_validation.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,24 @@ void InvalidStructureType(GenValidUsageXrInstanceInfo *instance_info, const std:
426426
}
427427
}
428428

429+
std::string StructTypesToString(GenValidUsageXrInstanceInfo *instance_info, const std::vector<XrStructureType> &structs) {
430+
char struct_type_buffer[XR_MAX_STRUCTURE_NAME_SIZE];
431+
std::string error_message;
432+
if (nullptr == instance_info) {
433+
error_message = "UNKNOWN - no instance info available";
434+
return error_message;
435+
}
436+
bool wrote_struct = false;
437+
for (auto &s : structs)
438+
if (XR_SUCCESS == instance_info->dispatch_table->StructureTypeToString(instance_info->instance, s, struct_type_buffer)) {
439+
if (wrote_struct) {
440+
error_message += ", ";
441+
}
442+
wrote_struct = true;
443+
error_message += struct_type_buffer;
444+
}
445+
return error_message;
446+
}
429447
// NOTE: Can't validate the following VUIDs since the command never enters a layer:
430448
// Command: xrEnumerateApiLayerProperties
431449
// VUIDs: "VUID-xrEnumerateApiLayerProperties-propertyCountOutput-parameter"

src/api_layers/validation_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ void InvalidStructureType(GenValidUsageXrInstanceInfo *instance_info, const std:
208208
const char *vuid = nullptr, XrStructureType expected = XrStructureType(0),
209209
const char *expected_name = "");
210210

211+
std::string StructTypesToString(GenValidUsageXrInstanceInfo *instance_info, const std::vector<XrStructureType> &structs);
212+
211213
// -- Only implementations of templates follow --//
212214

213215
template <typename HT, typename IT>

src/scripts/validation_layer_generator.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,35 +1007,7 @@ def writeValidateStructNextCheck(self, struct_type, struct_name, member, indent)
10071007
validate_struct_next += self.writeIndent(indent + 1)
10081008
validate_struct_next += 'error_message += "%s : ";\n' % struct_type
10091009
validate_struct_next += self.writeIndent(indent + 1)
1010-
validate_struct_next += 'if (nullptr != instance_info) {\n'
1011-
validate_struct_next += self.writeIndent(indent + 2)
1012-
validate_struct_next += 'bool wrote_struct = false;\n'
1013-
validate_struct_next += self.writeIndent(indent + 2)
1014-
validate_struct_next += 'for (uint32_t dup = 0; dup < duplicate_ext_structs.size(); ++dup) {\n'
1015-
validate_struct_next += self.writeIndent(indent + 3)
1016-
validate_struct_next += 'if (XR_SUCCESS == instance_info->dispatch_table->StructureTypeToString(instance_info->instance,\n'
1017-
validate_struct_next += self.writeIndent(indent + 3)
1018-
validate_struct_next += ' duplicate_ext_structs[dup],\n'
1019-
validate_struct_next += self.writeIndent(indent + 3)
1020-
validate_struct_next += ' struct_type_buffer)) {\n'
1021-
validate_struct_next += self.writeIndent(indent + 4)
1022-
validate_struct_next += 'if (wrote_struct) {\n'
1023-
validate_struct_next += self.writeIndent(indent + 5)
1024-
validate_struct_next += 'error_message += ", ";\n'
1025-
validate_struct_next += self.writeIndent(indent + 4)
1026-
validate_struct_next += '} else {\n'
1027-
validate_struct_next += self.writeIndent(indent + 5)
1028-
validate_struct_next += 'wrote_struct = true;\n'
1029-
validate_struct_next += self.writeIndent(indent + 4)
1030-
validate_struct_next += '}\n'
1031-
validate_struct_next += self.writeIndent(indent + 4)
1032-
validate_struct_next += 'error_message += struct_type_buffer;\n'
1033-
validate_struct_next += self.writeIndent(indent + 3)
1034-
validate_struct_next += '}\n'
1035-
validate_struct_next += self.writeIndent(indent + 2)
1036-
validate_struct_next += '}\n'
1037-
validate_struct_next += self.writeIndent(indent + 1)
1038-
validate_struct_next += '}\n'
1010+
validate_struct_next += 'error_message += StructTypesToString(instance_info, duplicate_ext_structs);\n'
10391011
validate_struct_next += self.writeIndent(indent + 1)
10401012
validate_struct_next += 'CoreValidLogMessage(instance_info, "VUID-%s-next-unique",\n' % struct_type
10411013
validate_struct_next += self.writeIndent(indent + 1)

0 commit comments

Comments
 (0)