refactor: Fix readability-use-concise-preprocessor-directives

This commit is contained in:
Lars Toenning
2025-10-25 23:04:01 +02:00
parent 7579ce8ba4
commit 707eaf0495
16 changed files with 31 additions and 30 deletions

View File

@@ -48,6 +48,7 @@ Checks: >
cppcoreguidelines-init-variables, cppcoreguidelines-init-variables,
readability-static-accessed-through-instance, readability-static-accessed-through-instance,
readability-simplify-boolean-expr, readability-simplify-boolean-expr,
readability-use-concise-preprocessor-directives,
CheckOptions: CheckOptions:
- key: readability-identifier-naming.ClassCase - key: readability-identifier-naming.ClassCase

View File

@@ -14,7 +14,7 @@
*/ */
#ifndef WITH_STATIC #ifndef WITH_STATIC
# if defined(BUILD_SWIFT_CORE_LIB) # ifdef BUILD_SWIFT_CORE_LIB
# define SWIFT_CORE_EXPORT Q_DECL_EXPORT # define SWIFT_CORE_EXPORT Q_DECL_EXPORT
# else # else
# define SWIFT_CORE_EXPORT Q_DECL_IMPORT # define SWIFT_CORE_EXPORT Q_DECL_IMPORT

View File

@@ -13,7 +13,7 @@
* Export a class or function from the library * Export a class or function from the library
*/ */
#ifndef WITH_STATIC #ifndef WITH_STATIC
# if defined(BUILD_SWIFT_GUI_LIB) # ifdef BUILD_SWIFT_GUI_LIB
# define SWIFT_GUI_EXPORT Q_DECL_EXPORT # define SWIFT_GUI_EXPORT Q_DECL_EXPORT
# else # else
# define SWIFT_GUI_EXPORT Q_DECL_IMPORT # define SWIFT_GUI_EXPORT Q_DECL_IMPORT

View File

@@ -3,7 +3,7 @@
#include "joystick.h" #include "joystick.h"
#if defined(Q_OS_WIN) #ifdef Q_OS_WIN
# include "win/joystickwindows.h" # include "win/joystickwindows.h"
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
# include "linux/joysticklinux.h" # include "linux/joysticklinux.h"
@@ -20,7 +20,7 @@ namespace swift::input
std::unique_ptr<IJoystick> IJoystick::create(QObject *parent) std::unique_ptr<IJoystick> IJoystick::create(QObject *parent)
{ {
#if defined(Q_OS_WIN) #ifdef Q_OS_WIN
std::unique_ptr<IJoystick> ptr(new CJoystickWindows(parent)); std::unique_ptr<IJoystick> ptr(new CJoystickWindows(parent));
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
std::unique_ptr<IJoystick> ptr(new CJoystickLinux(parent)); std::unique_ptr<IJoystick> ptr(new CJoystickLinux(parent));

View File

@@ -3,7 +3,7 @@
#include "keyboard.h" #include "keyboard.h"
#if defined(Q_OS_WIN) #ifdef Q_OS_WIN
# include "win/keyboardwindows.h" # include "win/keyboardwindows.h"
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
# include "linux/keyboardlinux.h" # include "linux/keyboardlinux.h"
@@ -19,7 +19,7 @@ namespace swift::input
std::unique_ptr<IKeyboard> IKeyboard::create(QObject *parent) std::unique_ptr<IKeyboard> IKeyboard::create(QObject *parent)
{ {
#if defined(Q_OS_WIN) #ifdef Q_OS_WIN
std::unique_ptr<IKeyboard> ptr(new CKeyboardWindows(parent)); std::unique_ptr<IKeyboard> ptr(new CKeyboardWindows(parent));
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
std::unique_ptr<IKeyboard> ptr(new CKeyboardLinux(parent)); std::unique_ptr<IKeyboard> ptr(new CKeyboardLinux(parent));

View File

@@ -14,7 +14,7 @@
*/ */
#ifndef WITH_STATIC #ifndef WITH_STATIC
# if defined(BUILD_SWIFT_INPUT_LIB) # ifdef BUILD_SWIFT_INPUT_LIB
# define SWIFT_INPUT_EXPORT Q_DECL_EXPORT # define SWIFT_INPUT_EXPORT Q_DECL_EXPORT
# else # else
# define SWIFT_INPUT_EXPORT Q_DECL_IMPORT # define SWIFT_INPUT_EXPORT Q_DECL_IMPORT

View File

@@ -12,7 +12,7 @@
#include "misc/algorithm.h" #include "misc/algorithm.h"
#if defined(Q_OS_POSIX) #ifdef Q_OS_POSIX
# include <errno.h> # include <errno.h>
# include <stdio.h> # include <stdio.h>
#elif defined(Q_OS_WIN32) #elif defined(Q_OS_WIN32)
@@ -29,7 +29,7 @@ namespace swift::misc
{ {
bool ok = true; bool ok = true;
{ {
#if defined(Q_OS_WIN32) #ifdef Q_OS_WIN32
QNtfsPermissionCheckGuard permissionGuard; QNtfsPermissionCheckGuard permissionGuard;
#endif #endif
if ((mode & CAtomicFile::ReadOnly) && !fileInfo.isReadable()) { ok = false; } if ((mode & CAtomicFile::ReadOnly) && !fileInfo.isReadable()) { ok = false; }
@@ -71,7 +71,7 @@ namespace swift::misc
{ {
if (!isOpen()) { return; } if (!isOpen()) { return; }
#if defined(Q_OS_WIN32) #ifdef Q_OS_WIN32
FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(handle()))); FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(handle())));
#endif #endif
@@ -118,7 +118,7 @@ namespace swift::misc
36, QChar('0')); 36, QChar('0'));
} }
#if defined(Q_OS_POSIX) #ifdef Q_OS_POSIX
void CAtomicFile::replaceOriginal() void CAtomicFile::replaceOriginal()
{ {
auto result = ::rename(qPrintable(fileName()), qPrintable(m_originalFilename)); auto result = ::rename(qPrintable(fileName()), qPrintable(m_originalFilename));

View File

@@ -5,7 +5,7 @@
#include <QtGlobal> #include <QtGlobal>
#if defined(Q_OS_WIN32) #ifdef Q_OS_WIN32
# include <windows.h> # include <windows.h>
#elif defined(Q_OS_UNIX) #elif defined(Q_OS_UNIX)
# include <ctime> # include <ctime>
@@ -14,7 +14,7 @@
namespace swift::misc namespace swift::misc
{ {
#if defined(Q_OS_WIN32) #ifdef Q_OS_WIN32
static int getCpuTimeMs(const FILETIME &kernelTime, const FILETIME &userTime) static int getCpuTimeMs(const FILETIME &kernelTime, const FILETIME &userTime)
{ {

View File

@@ -8,7 +8,7 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#if defined(Q_OS_MACOS) #ifdef Q_OS_MACOS
# include <libproc.h> # include <libproc.h>
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
# ifndef NOMINMAX # ifndef NOMINMAX
@@ -30,7 +30,7 @@ namespace swift::misc
return QStringLiteral("{ %1, %2 }").arg(QString::number(m_pid), m_name); 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 CProcessInfo::processNameFromId(qint64 pid)
{ {
QString path = QFileInfo(QStringLiteral("/proc/%1/exe").arg(pid)).symLinkTarget(); QString path = QFileInfo(QStringLiteral("/proc/%1/exe").arg(pid)).symLinkTarget();

View File

@@ -15,7 +15,7 @@
#include "misc/fileutils.h" #include "misc/fileutils.h"
#include "misc/swiftdirectories.h" #include "misc/swiftdirectories.h"
#if defined(Q_OS_WIN) #ifdef Q_OS_WIN
# include <ShlObj.h> # include <ShlObj.h>
#endif #endif
@@ -47,7 +47,7 @@ namespace swift::misc::simulation::xplane
return lastLine; return lastLine;
} }
#if defined(Q_OS_WIN) #ifdef Q_OS_WIN
QString getWindowsLocalAppDataPath() QString getWindowsLocalAppDataPath()
{ {
QString result; 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 //! \fixme KB 8/17 we could also use the runtime CBuildConfig decision here, which looks nicer (I personally
//! always try to avoid ifdef) //! always try to avoid ifdef)
#if defined(Q_OS_WIN) #ifdef Q_OS_WIN
return CFileUtils::appendFilePathsAndFixUnc(getWindowsLocalAppDataPath(), xplaneInstallFile); return CFileUtils::appendFilePathsAndFixUnc(getWindowsLocalAppDataPath(), xplaneInstallFile);
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
static const QString xp(".x-plane"); static const QString xp(".x-plane");

View File

@@ -12,7 +12,7 @@
#include <QMutexLocker> #include <QMutexLocker>
#include <QStringBuilder> #include <QStringBuilder>
#if defined(Q_CC_MSVC) #ifdef Q_CC_MSVC
# include <Windows.h> # include <Windows.h>
# pragma warning(push) # pragma warning(push)
@@ -33,13 +33,13 @@
namespace swift::misc namespace swift::misc
{ {
#if defined(QT_DEBUG) #ifdef QT_DEBUG
QStringList getStackTrace() { return getStackTraceAlways(); } QStringList getStackTrace() { return getStackTraceAlways(); }
#else #else
QStringList getStackTrace() { return { "No stack trace with release build" }; } QStringList getStackTrace() { return { "No stack trace with release build" }; }
#endif #endif
#if defined(Q_OS_WIN32) #ifdef Q_OS_WIN32
QStringList getStackTraceAlways() QStringList getStackTraceAlways()
{ {
static QMutex mutex; static QMutex mutex;

View File

@@ -13,7 +13,7 @@
* Export a class or function from the library * Export a class or function from the library
*/ */
#ifndef WITH_STATIC #ifndef WITH_STATIC
# if defined(BUILD_SWIFT_MISC_LIB) # ifdef BUILD_SWIFT_MISC_LIB
# define SWIFT_MISC_EXPORT Q_DECL_EXPORT # define SWIFT_MISC_EXPORT Q_DECL_EXPORT
# else # else
# define SWIFT_MISC_EXPORT Q_DECL_IMPORT # define SWIFT_MISC_EXPORT Q_DECL_IMPORT

View File

@@ -13,12 +13,12 @@
# include "crashpad/client/simulate_crash.h" # include "crashpad/client/simulate_crash.h"
#endif #endif
#if defined(Q_CC_MSVC) #ifdef Q_CC_MSVC
# include <Windows.h> # include <Windows.h>
# include <intrin.h> # include <intrin.h>
#endif #endif
#if defined(Q_CC_CLANG) #ifdef Q_CC_CLANG
# if __has_builtin(__builtin_debugtrap) # if __has_builtin(__builtin_debugtrap)
# define SWIFT_BUILTIN_DEBUGTRAP __builtin_debugtrap # define SWIFT_BUILTIN_DEBUGTRAP __builtin_debugtrap
# elif __has_builtin(__builtin_debugger) # elif __has_builtin(__builtin_debugger)
@@ -39,8 +39,8 @@ namespace swift::misc::private_ns
Q_UNUSED(message) Q_UNUSED(message)
Q_UNUSED(audit) Q_UNUSED(audit)
#if defined(QT_DEBUG) #ifdef QT_DEBUG
# if defined(Q_CC_MSVC) # ifdef Q_CC_MSVC
if (!audit || IsDebuggerPresent()) if (!audit || IsDebuggerPresent())
{ {
__debugbreak(); __debugbreak();

View File

@@ -14,7 +14,7 @@
*/ */
#ifndef WITH_STATIC #ifndef WITH_STATIC
# if defined(BUILD_SIMULATORPLUGINCOMMON_LIB) # ifdef BUILD_SIMULATORPLUGINCOMMON_LIB
# define SIMULATORPLUGINCOMMON_EXPORT Q_DECL_EXPORT # define SIMULATORPLUGINCOMMON_EXPORT Q_DECL_EXPORT
# else # else
# define SIMULATORPLUGINCOMMON_EXPORT Q_DECL_IMPORT # define SIMULATORPLUGINCOMMON_EXPORT Q_DECL_IMPORT

View File

@@ -14,7 +14,7 @@
*/ */
#ifndef WITH_STATIC #ifndef WITH_STATIC
# if defined(BUILD_SWIFT_SOUND_LIB) # ifdef BUILD_SWIFT_SOUND_LIB
# define SWIFT_SOUND_EXPORT Q_DECL_EXPORT # define SWIFT_SOUND_EXPORT Q_DECL_EXPORT
# else # else
# define SWIFT_SOUND_EXPORT Q_DECL_IMPORT # define SWIFT_SOUND_EXPORT Q_DECL_IMPORT

View File

@@ -26,7 +26,7 @@
#include "misc/logmessage.h" #include "misc/logmessage.h"
#include "misc/threadutils.h" #include "misc/threadutils.h"
#if defined(Q_OS_MACOS) #ifdef Q_OS_MACOS
# include "input/macos/macosinpututils.h" # include "input/macos/macosinpututils.h"
#endif #endif
@@ -422,7 +422,7 @@ void SwiftGuiStd::verifyPrerequisites()
} }
else { msgs.push_back(sGui->getIContextSimulator()->verifyPrerequisites()); } else { msgs.push_back(sGui->getIContextSimulator()->verifyPrerequisites()); }
#if defined(Q_OS_MACOS) #ifdef Q_OS_MACOS
if (!swift::input::CMacOSInputUtils::hasAccess()) if (!swift::input::CMacOSInputUtils::hasAccess())
{ {
// A log message about missing permissions is already emitted when initializing the keyboard. // A log message about missing permissions is already emitted when initializing the keyboard.