CppEditor: Fix codemodel highlighting for QNX

The code model will get the necessary bits so that it can successfully
parse the QNX code.

Fixes: QTCREATORBUG-23483
Change-Id: Id9488f644ace23952edf7a7cb5da7ca138182134
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Cristian Adam
2021-12-03 13:52:21 +01:00
parent 41fe7eec65
commit 5a6c625c5e
3 changed files with 25 additions and 3 deletions

View File

@@ -35,6 +35,8 @@
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacro.h> #include <projectexplorer/projectmacro.h>
#include <qnx/qnxconstants.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/cpplanguage_details.h> #include <utils/cpplanguage_details.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
@@ -152,6 +154,7 @@ QStringList CompilerOptionsBuilder::build(ProjectFile::Kind fileKind,
undefineClangVersionMacrosForMsvc(); undefineClangVersionMacrosForMsvc();
undefineCppLanguageFeatureMacrosForMsvc2015(); undefineCppLanguageFeatureMacrosForMsvc2015();
addDefineFunctionMacrosMsvc(); addDefineFunctionMacrosMsvc();
addDefineFunctionMacrosQnx();
addHeaderPathOptions(); addHeaderPathOptions();
@@ -404,8 +407,8 @@ void CompilerOptionsBuilder::addProjectMacros()
static const int useMacros = qEnvironmentVariableIntValue("QTC_CLANG_USE_TOOLCHAIN_MACROS"); static const int useMacros = qEnvironmentVariableIntValue("QTC_CLANG_USE_TOOLCHAIN_MACROS");
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CUSTOM_TOOLCHAIN_TYPEID if (m_projectPart.toolchainType == ProjectExplorer::Constants::CUSTOM_TOOLCHAIN_TYPEID
|| m_projectPart.toolchainType.name().contains("BareMetal") || m_projectPart.toolchainType == Qnx::Constants::QNX_TOOLCHAIN_ID
|| useMacros) { || m_projectPart.toolchainType.name().contains("BareMetal") || useMacros) {
addMacros(m_projectPart.toolChainMacros); addMacros(m_projectPart.toolChainMacros);
} }
@@ -771,6 +774,17 @@ void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
} }
} }
void CompilerOptionsBuilder::addDefineFunctionMacrosQnx()
{
// QNX 7.0+ uses GCC with LIBCPP from Clang, and in that context GCC is giving
// the builtin operator new and delete.
//
// In our case we have only Clang and need to instruct LIBCPP that it doesn't
// have these operators. This makes the code model happy and doesn't produce errors.
if (m_projectPart.toolchainType == Qnx::Constants::QNX_TOOLCHAIN_ID)
addMacros({{"_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE"}});
}
void CompilerOptionsBuilder::reset() void CompilerOptionsBuilder::reset()
{ {
m_options.clear(); m_options.clear();

View File

@@ -84,6 +84,8 @@ public:
void addProjectConfigFileInclude(); void addProjectConfigFileInclude();
void undefineClangVersionMacrosForMsvc(); void undefineClangVersionMacrosForMsvc();
void addDefineFunctionMacrosQnx();
// Add custom options // Add custom options
void add(const QString &arg, bool gccOnlyOption = false); void add(const QString &arg, bool gccOnlyOption = false);
void prepend(const QString &arg); void prepend(const QString &arg);

View File

@@ -185,7 +185,13 @@ void QnxToolChain::setCpuDir(const QString &cpuDir)
GccToolChain::DetectedAbisResult QnxToolChain::detectSupportedAbis() const GccToolChain::DetectedAbisResult QnxToolChain::detectSupportedAbis() const
{ {
return detectTargetAbis(m_sdpPath); // "unknown-qnx-gnu"is needed to get the "--target=xxx" parameter sent code model,
// which gets translated as "x86_64-qnx-gnu", which gets Clang to happily parse
// the QNX code.
//
// Without it on Windows Clang defaults to a MSVC mode, which breaks with
// the QNX code, which is mostly GNU based.
return GccToolChain::DetectedAbisResult{detectTargetAbis(m_sdpPath), "unknown-qnx-gnu"};
} }
bool QnxToolChain::operator ==(const ToolChain &other) const bool QnxToolChain::operator ==(const ToolChain &other) const