From 707eaf049567eb67a7abd4e39056fad7afb0983d Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Sat, 25 Oct 2025 23:04:01 +0200 Subject: [PATCH] refactor: Fix readability-use-concise-preprocessor-directives --- .clang-tidy | 1 + src/core/swiftcoreexport.h | 2 +- src/gui/swiftguiexport.h | 2 +- src/input/joystick.cpp | 4 ++-- src/input/keyboard.cpp | 4 ++-- src/input/swiftinputexport.h | 2 +- src/misc/atomicfile.cpp | 8 ++++---- src/misc/cputime.cpp | 4 ++-- src/misc/processinfo.cpp | 4 ++-- src/misc/simulation/xplane/xplaneutil.cpp | 6 +++--- src/misc/stacktrace.cpp | 6 +++--- src/misc/swiftmiscexport.h | 2 +- src/misc/verify.cpp | 8 ++++---- .../simulator/plugincommon/simulatorplugincommonexport.h | 2 +- src/sound/swiftsoundexport.h | 2 +- src/swiftguistandard/swiftguistd.cpp | 4 ++-- 16 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index febf5ff1e..4870e6c38 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -48,6 +48,7 @@ Checks: > cppcoreguidelines-init-variables, readability-static-accessed-through-instance, readability-simplify-boolean-expr, + readability-use-concise-preprocessor-directives, CheckOptions: - key: readability-identifier-naming.ClassCase diff --git a/src/core/swiftcoreexport.h b/src/core/swiftcoreexport.h index 6a9204fd0..99ca1bd08 100644 --- a/src/core/swiftcoreexport.h +++ b/src/core/swiftcoreexport.h @@ -14,7 +14,7 @@ */ #ifndef WITH_STATIC -# if defined(BUILD_SWIFT_CORE_LIB) +# ifdef BUILD_SWIFT_CORE_LIB # define SWIFT_CORE_EXPORT Q_DECL_EXPORT # else # define SWIFT_CORE_EXPORT Q_DECL_IMPORT diff --git a/src/gui/swiftguiexport.h b/src/gui/swiftguiexport.h index d4b612ae2..0bb5b234d 100644 --- a/src/gui/swiftguiexport.h +++ b/src/gui/swiftguiexport.h @@ -13,7 +13,7 @@ * Export a class or function from the library */ #ifndef WITH_STATIC -# if defined(BUILD_SWIFT_GUI_LIB) +# ifdef BUILD_SWIFT_GUI_LIB # define SWIFT_GUI_EXPORT Q_DECL_EXPORT # else # define SWIFT_GUI_EXPORT Q_DECL_IMPORT diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp index 4bc0dc1b7..cd0a7cf0e 100644 --- a/src/input/joystick.cpp +++ b/src/input/joystick.cpp @@ -3,7 +3,7 @@ #include "joystick.h" -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN # include "win/joystickwindows.h" #elif defined(Q_OS_LINUX) # include "linux/joysticklinux.h" @@ -20,7 +20,7 @@ namespace swift::input std::unique_ptr IJoystick::create(QObject *parent) { -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN std::unique_ptr ptr(new CJoystickWindows(parent)); #elif defined(Q_OS_LINUX) std::unique_ptr ptr(new CJoystickLinux(parent)); diff --git a/src/input/keyboard.cpp b/src/input/keyboard.cpp index b634bac42..09e0a147d 100644 --- a/src/input/keyboard.cpp +++ b/src/input/keyboard.cpp @@ -3,7 +3,7 @@ #include "keyboard.h" -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN # include "win/keyboardwindows.h" #elif defined(Q_OS_LINUX) # include "linux/keyboardlinux.h" @@ -19,7 +19,7 @@ namespace swift::input std::unique_ptr IKeyboard::create(QObject *parent) { -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN std::unique_ptr ptr(new CKeyboardWindows(parent)); #elif defined(Q_OS_LINUX) std::unique_ptr ptr(new CKeyboardLinux(parent)); diff --git a/src/input/swiftinputexport.h b/src/input/swiftinputexport.h index f00a10e43..9cae8e84d 100644 --- a/src/input/swiftinputexport.h +++ b/src/input/swiftinputexport.h @@ -14,7 +14,7 @@ */ #ifndef WITH_STATIC -# if defined(BUILD_SWIFT_INPUT_LIB) +# ifdef BUILD_SWIFT_INPUT_LIB # define SWIFT_INPUT_EXPORT Q_DECL_EXPORT # else # define SWIFT_INPUT_EXPORT Q_DECL_IMPORT diff --git a/src/misc/atomicfile.cpp b/src/misc/atomicfile.cpp index b03fe578d..daa58665f 100644 --- a/src/misc/atomicfile.cpp +++ b/src/misc/atomicfile.cpp @@ -12,7 +12,7 @@ #include "misc/algorithm.h" -#if defined(Q_OS_POSIX) +#ifdef Q_OS_POSIX # include # include #elif defined(Q_OS_WIN32) @@ -29,7 +29,7 @@ namespace swift::misc { bool ok = true; { -#if defined(Q_OS_WIN32) +#ifdef Q_OS_WIN32 QNtfsPermissionCheckGuard permissionGuard; #endif if ((mode & CAtomicFile::ReadOnly) && !fileInfo.isReadable()) { ok = false; } @@ -71,7 +71,7 @@ namespace swift::misc { if (!isOpen()) { return; } -#if defined(Q_OS_WIN32) +#ifdef Q_OS_WIN32 FlushFileBuffers(reinterpret_cast(_get_osfhandle(handle()))); #endif @@ -118,7 +118,7 @@ namespace swift::misc 36, QChar('0')); } -#if defined(Q_OS_POSIX) +#ifdef Q_OS_POSIX void CAtomicFile::replaceOriginal() { auto result = ::rename(qPrintable(fileName()), qPrintable(m_originalFilename)); diff --git a/src/misc/cputime.cpp b/src/misc/cputime.cpp index 7f61796d8..486ea651b 100644 --- a/src/misc/cputime.cpp +++ b/src/misc/cputime.cpp @@ -5,7 +5,7 @@ #include -#if defined(Q_OS_WIN32) +#ifdef Q_OS_WIN32 # include #elif defined(Q_OS_UNIX) # include @@ -14,7 +14,7 @@ namespace swift::misc { -#if defined(Q_OS_WIN32) +#ifdef Q_OS_WIN32 static int getCpuTimeMs(const FILETIME &kernelTime, const FILETIME &userTime) { diff --git a/src/misc/processinfo.cpp b/src/misc/processinfo.cpp index 75af0599b..39b7ae25d 100644 --- a/src/misc/processinfo.cpp +++ b/src/misc/processinfo.cpp @@ -8,7 +8,7 @@ #include #include -#if defined(Q_OS_MACOS) +#ifdef Q_OS_MACOS # include #elif defined(Q_OS_WIN) # ifndef NOMINMAX @@ -30,7 +30,7 @@ namespace swift::misc return QStringLiteral("{ %1, %2 }").arg(QString::number(m_pid), m_name); } -#if defined(Q_OS_LINUX) +#ifdef Q_OS_LINUX QString CProcessInfo::processNameFromId(qint64 pid) { QString path = QFileInfo(QStringLiteral("/proc/%1/exe").arg(pid)).symLinkTarget(); diff --git a/src/misc/simulation/xplane/xplaneutil.cpp b/src/misc/simulation/xplane/xplaneutil.cpp index 07f2efc3c..66d2832b4 100644 --- a/src/misc/simulation/xplane/xplaneutil.cpp +++ b/src/misc/simulation/xplane/xplaneutil.cpp @@ -15,7 +15,7 @@ #include "misc/fileutils.h" #include "misc/swiftdirectories.h" -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN # include #endif @@ -47,7 +47,7 @@ namespace swift::misc::simulation::xplane return lastLine; } -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN QString getWindowsLocalAppDataPath() { QString result; @@ -85,7 +85,7 @@ namespace swift::misc::simulation::xplane { //! \fixme KB 8/17 we could also use the runtime CBuildConfig decision here, which looks nicer (I personally //! always try to avoid ifdef) -#if defined(Q_OS_WIN) +#ifdef Q_OS_WIN return CFileUtils::appendFilePathsAndFixUnc(getWindowsLocalAppDataPath(), xplaneInstallFile); #elif defined(Q_OS_LINUX) static const QString xp(".x-plane"); diff --git a/src/misc/stacktrace.cpp b/src/misc/stacktrace.cpp index 818b2c82b..6622a4703 100644 --- a/src/misc/stacktrace.cpp +++ b/src/misc/stacktrace.cpp @@ -12,7 +12,7 @@ #include #include -#if defined(Q_CC_MSVC) +#ifdef Q_CC_MSVC # include # pragma warning(push) @@ -33,13 +33,13 @@ namespace swift::misc { -#if defined(QT_DEBUG) +#ifdef QT_DEBUG QStringList getStackTrace() { return getStackTraceAlways(); } #else QStringList getStackTrace() { return { "No stack trace with release build" }; } #endif -#if defined(Q_OS_WIN32) +#ifdef Q_OS_WIN32 QStringList getStackTraceAlways() { static QMutex mutex; diff --git a/src/misc/swiftmiscexport.h b/src/misc/swiftmiscexport.h index 680a0ee23..bd7515ad9 100644 --- a/src/misc/swiftmiscexport.h +++ b/src/misc/swiftmiscexport.h @@ -13,7 +13,7 @@ * Export a class or function from the library */ #ifndef WITH_STATIC -# if defined(BUILD_SWIFT_MISC_LIB) +# ifdef BUILD_SWIFT_MISC_LIB # define SWIFT_MISC_EXPORT Q_DECL_EXPORT # else # define SWIFT_MISC_EXPORT Q_DECL_IMPORT diff --git a/src/misc/verify.cpp b/src/misc/verify.cpp index cae3498c5..3a5de9760 100644 --- a/src/misc/verify.cpp +++ b/src/misc/verify.cpp @@ -13,12 +13,12 @@ # include "crashpad/client/simulate_crash.h" #endif -#if defined(Q_CC_MSVC) +#ifdef Q_CC_MSVC # include # include #endif -#if defined(Q_CC_CLANG) +#ifdef Q_CC_CLANG # if __has_builtin(__builtin_debugtrap) # define SWIFT_BUILTIN_DEBUGTRAP __builtin_debugtrap # elif __has_builtin(__builtin_debugger) @@ -39,8 +39,8 @@ namespace swift::misc::private_ns Q_UNUSED(message) Q_UNUSED(audit) -#if defined(QT_DEBUG) -# if defined(Q_CC_MSVC) +#ifdef QT_DEBUG +# ifdef Q_CC_MSVC if (!audit || IsDebuggerPresent()) { __debugbreak(); diff --git a/src/plugins/simulator/plugincommon/simulatorplugincommonexport.h b/src/plugins/simulator/plugincommon/simulatorplugincommonexport.h index ea7bb5fdf..a827226ac 100644 --- a/src/plugins/simulator/plugincommon/simulatorplugincommonexport.h +++ b/src/plugins/simulator/plugincommon/simulatorplugincommonexport.h @@ -14,7 +14,7 @@ */ #ifndef WITH_STATIC -# if defined(BUILD_SIMULATORPLUGINCOMMON_LIB) +# ifdef BUILD_SIMULATORPLUGINCOMMON_LIB # define SIMULATORPLUGINCOMMON_EXPORT Q_DECL_EXPORT # else # define SIMULATORPLUGINCOMMON_EXPORT Q_DECL_IMPORT diff --git a/src/sound/swiftsoundexport.h b/src/sound/swiftsoundexport.h index 02a8b9a16..3426bec9e 100644 --- a/src/sound/swiftsoundexport.h +++ b/src/sound/swiftsoundexport.h @@ -14,7 +14,7 @@ */ #ifndef WITH_STATIC -# if defined(BUILD_SWIFT_SOUND_LIB) +# ifdef BUILD_SWIFT_SOUND_LIB # define SWIFT_SOUND_EXPORT Q_DECL_EXPORT # else # define SWIFT_SOUND_EXPORT Q_DECL_IMPORT diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index ff4442190..95b5b960b 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -26,7 +26,7 @@ #include "misc/logmessage.h" #include "misc/threadutils.h" -#if defined(Q_OS_MACOS) +#ifdef Q_OS_MACOS # include "input/macos/macosinpututils.h" #endif @@ -422,7 +422,7 @@ void SwiftGuiStd::verifyPrerequisites() } else { msgs.push_back(sGui->getIContextSimulator()->verifyPrerequisites()); } -#if defined(Q_OS_MACOS) +#ifdef Q_OS_MACOS if (!swift::input::CMacOSInputUtils::hasAccess()) { // A log message about missing permissions is already emitted when initializing the keyboard.