Skip to content

Commit 182e1b5

Browse files
committed
Merge branch 'clang-tidy-rb2' into clang-tidy-porting
2 parents c0e3308 + 5d6b62a commit 182e1b5

24 files changed

+1057
-890
lines changed

src/api_layers/api_dump.cpp

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@
1717
// Author: Mark Young <[email protected]>
1818
//
1919

20-
#include <iostream>
20+
#include "hex_and_handles.h"
21+
#include "loader_interfaces.h"
22+
#include "platform_utils.hpp"
23+
#include "xr_generated_api_dump.hpp"
24+
#include "xr_generated_dispatch_table.h"
25+
26+
#include <openxr/openxr.h>
27+
28+
#include <algorithm>
29+
#include <cctype>
30+
#include <cstring>
2131
#include <fstream>
32+
#include <iostream>
33+
#include <mutex>
2234
#include <sstream>
23-
#include <cstring>
35+
#include <stdexcept>
2436
#include <string>
25-
#include <mutex>
37+
#include <tuple>
2638
#include <unordered_map>
27-
#include <algorithm>
28-
#include <cctype>
29-
30-
#include "xr_generated_api_dump.hpp"
31-
#include "xr_generated_dispatch_table.h"
32-
#include "loader_interfaces.h"
33-
#include "platform_utils.hpp"
34-
#include "hex_and_handles.h"
39+
#include <utility>
40+
#include <vector>
3541

3642
#if defined(__GNUC__) && __GNUC__ >= 4
3743
#define LAYER_EXPORT __attribute__((visibility("default")))
@@ -59,7 +65,7 @@ static ApiDumpRecordInfo g_record_info = {};
5965
static std::mutex g_record_mutex = {};
6066

6167
// HTML utilities
62-
bool ApiDumpLayerWriteHtmlHeader(void) {
68+
bool ApiDumpLayerWriteHtmlHeader() {
6369
try {
6470
std::unique_lock<std::mutex> mlock(g_record_mutex);
6571
std::ofstream html_file;
@@ -168,7 +174,7 @@ bool ApiDumpLayerWriteHtmlHeader(void) {
168174
}
169175
}
170176

171-
bool ApiDumpLayerWriteHtmlFooter(void) {
177+
bool ApiDumpLayerWriteHtmlFooter() {
172178
try {
173179
std::unique_lock<std::mutex> mlock(g_record_mutex);
174180
std::ofstream html_file;
@@ -211,15 +217,15 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
211217
uint32_t count = 0;
212218
switch (g_record_info.type) {
213219
case RECORD_TEXT_COUT: {
214-
for (auto content : contents) {
220+
for (const auto &content : contents) {
215221
std::string content_type;
216222
std::string content_name;
217223
std::string content_value;
218224
std::tie(content_type, content_name, content_value) = content;
219225
if (count++ != 0) {
220226
std::cout << " ";
221227
}
222-
if (content_value.size() > 0) {
228+
if (!content_value.empty()) {
223229
std::cout << content_type << " " << content_name << " = " << content_value << "\n";
224230
} else {
225231
std::cout << content_type << " " << content_name << "\n";
@@ -231,15 +237,15 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
231237
case RECORD_TEXT_FILE: {
232238
std::ofstream text_file;
233239
text_file.open(g_record_info.file_name, std::ios::out | std::ios::app);
234-
for (auto content : contents) {
240+
for (const auto &content : contents) {
235241
std::string content_type;
236242
std::string content_name;
237243
std::string content_value;
238244
std::tie(content_type, content_name, content_value) = content;
239245
if (count++ != 0) {
240246
text_file << " ";
241247
}
242-
if (content_value.size() > 0) {
248+
if (!content_value.empty()) {
243249
text_file << content_type << " " << content_name << " = " << content_value << "\n";
244250
} else {
245251
text_file << content_type << " " << content_name << "\n";
@@ -278,7 +284,7 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
278284
}
279285
// Now look for array dereferences
280286
start = 0;
281-
while ((start = content_name.find("[", start)) != std::string::npos) {
287+
while ((start = content_name.find('[', start)) != std::string::npos) {
282288
++cur_deref_count;
283289
start++;
284290
}
@@ -300,7 +306,7 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
300306
}
301307
// Now look for array dereferences
302308
start = 0;
303-
while ((start = next_content_name.find("[", start)) != std::string::npos) {
309+
while ((start = next_content_name.find('[', start)) != std::string::npos) {
304310
++next_deref_count;
305311
start++;
306312
}
@@ -310,7 +316,7 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
310316
// to close up those detail sections.
311317
if (cur_deref_count < last_deref_count) {
312318
uint32_t diff_count = last_deref_count - cur_deref_count;
313-
while (diff_count--) {
319+
while ((diff_count--) != 0u) {
314320
text_file << " </details>\n";
315321
prefixes.pop_back();
316322
}
@@ -359,7 +365,7 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
359365
value_needs_printing = false;
360366
}
361367
}
362-
if (content_value.size() > 0 && value_needs_printing) {
368+
if (!content_value.empty() && value_needs_printing) {
363369
text_file << " <div class='val'>" << content_value << "</div>";
364370
}
365371
text_file << "\n";
@@ -377,8 +383,8 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
377383
}
378384

379385
// Wrap up any remaining items
380-
if (last_deref_count) {
381-
while (last_deref_count--) {
386+
if (last_deref_count != 0u) {
387+
while ((last_deref_count--) != 0u) {
382388
text_file << " </details>\n";
383389
prefixes.pop_back();
384390
}
@@ -393,7 +399,7 @@ bool ApiDumpLayerRecordContent(std::vector<std::tuple<std::string, std::string,
393399
return success;
394400
}
395401

396-
XrResult ApiDumpLayerXrCreateInstance(const XrInstanceCreateInfo *info, XrInstance *instance) {
402+
XrResult ApiDumpLayerXrCreateInstance(const XrInstanceCreateInfo * /*info*/, XrInstance * /*instance*/) {
397403
if (!g_record_info.initialized) {
398404
g_record_info.initialized = true;
399405
g_record_info.type = RECORD_TEXT_COUT;
@@ -429,7 +435,7 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
429435
[](unsigned char c) { return std::tolower(c); });
430436

431437
if (string_export_type == "text") {
432-
if (g_record_info.file_name.size() > 0) {
438+
if (!g_record_info.file_name.empty()) {
433439
g_record_info.type = RECORD_TEXT_FILE;
434440
} else {
435441
g_record_info.type = RECORD_TEXT_COUT;
@@ -460,11 +466,11 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
460466

461467
// Generate output for this command as if it were the standard xrCreateInstance
462468
std::vector<std::tuple<std::string, std::string, std::string>> contents;
463-
contents.push_back(std::make_tuple("XrResult", "xrCreateInstance", ""));
464-
contents.push_back(std::make_tuple("const XrInstanceCreateInfo*", "info", PointerToHexString(info)));
469+
contents.emplace_back("XrResult", "xrCreateInstance", "");
470+
contents.emplace_back("const XrInstanceCreateInfo*", "info", PointerToHexString(info));
465471
if (nullptr != info) {
466472
std::string prefix = "info->";
467-
contents.push_back(std::make_tuple("XrStructureType", "info->type", std::to_string(info->type)));
473+
contents.emplace_back("XrStructureType", "info->type", std::to_string(info->type));
468474
std::string next_prefix = prefix;
469475
next_prefix += "next";
470476
// Decode the next chain if it exists
@@ -473,7 +479,7 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
473479
}
474480
std::string flags_prefix = prefix;
475481
flags_prefix += "createFlags";
476-
contents.push_back(std::make_tuple("XrInstanceCreateFlags", flags_prefix, std::to_string(info->createFlags)));
482+
contents.emplace_back("XrInstanceCreateFlags", flags_prefix, std::to_string(info->createFlags));
477483
std::string applicationinfo_prefix = prefix;
478484
applicationinfo_prefix += "applicationInfo";
479485
if (!ApiDumpOutputXrStruct(nullptr, &info->applicationInfo, applicationinfo_prefix, "XrApplicationInfo", true,
@@ -484,13 +490,12 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
484490
enabledapilayercount_prefix += "enabledApiLayerCount";
485491
std::ostringstream oss_enabledApiLayerCount;
486492
oss_enabledApiLayerCount << "0x" << std::hex << (info->enabledApiLayerCount);
487-
contents.push_back(std::make_tuple("uint32_t", enabledapilayercount_prefix, oss_enabledApiLayerCount.str()));
493+
contents.emplace_back("uint32_t", enabledapilayercount_prefix, oss_enabledApiLayerCount.str());
488494
std::string enabledapilayernames_prefix = prefix;
489495
enabledapilayernames_prefix += "enabledApiLayerNames";
490496
std::ostringstream oss_enabledApiLayerNames_array;
491497
oss_enabledApiLayerNames_array << "0x" << std::hex << (info->enabledApiLayerNames);
492-
contents.push_back(
493-
std::make_tuple("const char* const*", enabledapilayernames_prefix, oss_enabledApiLayerNames_array.str()));
498+
contents.emplace_back("const char* const*", enabledapilayernames_prefix, oss_enabledApiLayerNames_array.str());
494499
for (uint32_t info_enabledapilayernames_inc = 0; info_enabledapilayernames_inc < info->enabledApiLayerCount;
495500
++info_enabledapilayernames_inc) {
496501
std::string enabledapilayernames_array_prefix = enabledapilayernames_prefix;
@@ -499,20 +504,18 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
499504
enabledapilayernames_array_prefix += "]";
500505
std::ostringstream oss_enabledApiLayerNames;
501506
oss_enabledApiLayerNames << "0x" << std::hex << (*info->enabledApiLayerNames[info_enabledapilayernames_inc]);
502-
contents.push_back(
503-
std::make_tuple("const char* const*", enabledapilayernames_array_prefix, oss_enabledApiLayerNames.str()));
507+
contents.emplace_back("const char* const*", enabledapilayernames_array_prefix, oss_enabledApiLayerNames.str());
504508
}
505509
std::string enabledextensioncount_prefix = prefix;
506510
enabledextensioncount_prefix += "enabledExtensionCount";
507511
std::ostringstream oss_enabledExtensionCount;
508512
oss_enabledExtensionCount << "0x" << std::hex << (info->enabledExtensionCount);
509-
contents.push_back(std::make_tuple("uint32_t", enabledextensioncount_prefix, oss_enabledExtensionCount.str()));
513+
contents.emplace_back("uint32_t", enabledextensioncount_prefix, oss_enabledExtensionCount.str());
510514
std::string enabledextensionnames_prefix = prefix;
511515
enabledextensionnames_prefix += "enabledExtensionNames";
512516
std::ostringstream oss_enabledExtensionNames_array;
513517
oss_enabledExtensionNames_array << "0x" << std::hex << (info->enabledExtensionNames);
514-
contents.push_back(
515-
std::make_tuple("const char* const*", enabledextensionnames_prefix, oss_enabledExtensionNames_array.str()));
518+
contents.emplace_back("const char* const*", enabledextensionnames_prefix, oss_enabledExtensionNames_array.str());
516519
for (uint32_t info_enabledextensionnames_inc = 0; info_enabledextensionnames_inc < info->enabledExtensionCount;
517520
++info_enabledextensionnames_inc) {
518521
std::string enabledextensionnames_array_prefix = enabledextensionnames_prefix;
@@ -521,12 +524,11 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
521524
enabledextensionnames_array_prefix += "]";
522525
std::ostringstream oss_enabledExtensionNames;
523526
oss_enabledExtensionNames << "0x" << std::hex << (*info->enabledExtensionNames[info_enabledextensionnames_inc]);
524-
contents.push_back(
525-
std::make_tuple("const char* const*", enabledextensionnames_array_prefix, oss_enabledExtensionNames.str()));
527+
contents.emplace_back("const char* const*", enabledextensionnames_array_prefix, oss_enabledExtensionNames.str());
526528
}
527529
}
528530

529-
contents.push_back(std::make_tuple("XrInstance*", "instance", PointerToHexString(instance)));
531+
contents.emplace_back("XrInstance*", "instance", PointerToHexString(instance));
530532
ApiDumpLayerRecordContent(contents);
531533

532534
// Copy the contents of the layer info struct, but then move the next info up by
@@ -544,7 +546,7 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
544546
*instance = returned_instance;
545547

546548
// Create the dispatch table to the next levels
547-
XrGeneratedDispatchTable *next_dispatch = new XrGeneratedDispatchTable();
549+
auto *next_dispatch = new XrGeneratedDispatchTable();
548550
GeneratedXrPopulateDispatchTable(next_dispatch, returned_instance, next_get_instance_proc_addr);
549551

550552
std::unique_lock<std::mutex> mlock(g_instance_dispatch_mutex);
@@ -559,8 +561,8 @@ XrResult ApiDumpLayerXrCreateApiLayerInstance(const XrInstanceCreateInfo *info,
559561
XrResult ApiDumpLayerXrDestroyInstance(XrInstance instance) {
560562
// Generate output for this command
561563
std::vector<std::tuple<std::string, std::string, std::string>> contents;
562-
contents.push_back(std::make_tuple("XrResult", "xrDestroyInstance", ""));
563-
contents.push_back(std::make_tuple("XrInstance", "instance", HandleToHexString(instance)));
564+
contents.emplace_back("XrResult", "xrDestroyInstance", "");
565+
contents.emplace_back("XrInstance", "instance", HandleToHexString(instance));
564566
ApiDumpLayerRecordContent(contents);
565567

566568
std::unique_lock<std::mutex> mlock(g_instance_dispatch_mutex);
@@ -579,7 +581,7 @@ XrResult ApiDumpLayerXrDestroyInstance(XrInstance instance) {
579581
ApiDumpCleanUpMapsForTable(next_dispatch);
580582

581583
// Write out the HTML footer if we destroy the last instance
582-
if (g_instance_dispatch_map.size() == 0 && g_record_info.type == RECORD_HTML_FILE) {
584+
if (g_instance_dispatch_map.empty() && g_record_info.type == RECORD_HTML_FILE) {
583585
ApiDumpLayerWriteHtmlFooter();
584586
}
585587
return XR_SUCCESS;
@@ -589,7 +591,7 @@ extern "C" {
589591

590592
// Function used to negotiate an interface betewen the loader and an API layer. Each library exposing one or
591593
// more API layers needs to expose at least this function.
592-
LAYER_EXPORT XrResult xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo *loaderInfo, const char *apiLayerName,
594+
LAYER_EXPORT XrResult xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo *loaderInfo, const char * /*apiLayerName*/,
593595
XrNegotiateApiLayerRequest *apiLayerRequest) {
594596
if (nullptr == loaderInfo || nullptr == apiLayerRequest || loaderInfo->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO ||
595597
loaderInfo->structVersion != XR_LOADER_INFO_STRUCT_VERSION || loaderInfo->structSize != sizeof(XrNegotiateLoaderInfo) ||

src/api_layers/api_layer_platform_defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
#define XR_USE_GRAPHICS_API_METAL 1 // Metal exists
4444
#endif // XR_OS_APPLE_MACOS
4545

46-
#include "xr_dependencies.h"
46+
#include "xr_dependencies.h" // IWYU pragma: export
4747

4848
#endif // API_LAYER_PLATFORM_DEFINES_H_

0 commit comments

Comments
 (0)