2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
#include "clangutils.h"
|
|
|
|
|
|
2023-01-19 09:51:10 +01:00
|
|
|
#include "clangcodemodeltr.h"
|
|
|
|
|
|
2013-12-10 14:37:32 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/idocument.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <cppeditor/baseeditordocumentparser.h>
|
2022-05-19 14:48:09 +02:00
|
|
|
#include <cppeditor/clangdiagnosticconfigsmodel.h>
|
2024-03-15 16:02:50 +01:00
|
|
|
#include <cppeditor/clangdsettings.h>
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <cppeditor/compileroptionsbuilder.h>
|
|
|
|
|
#include <cppeditor/cppmodelmanager.h>
|
|
|
|
|
#include <cppeditor/cpptoolsreuse.h>
|
|
|
|
|
#include <cppeditor/editordocumenthandle.h>
|
|
|
|
|
#include <cppeditor/projectpart.h>
|
2018-07-10 15:53:51 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2023-08-11 09:18:56 +02:00
|
|
|
#include <projectexplorer/kitaspects.h>
|
2015-11-17 16:25:02 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2018-07-10 15:53:51 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2021-06-18 16:30:03 +02:00
|
|
|
#include <texteditor/codeassist/textdocumentmanipulatorinterface.h>
|
2018-02-09 13:51:39 +01:00
|
|
|
|
2021-06-18 16:30:03 +02:00
|
|
|
#include <cplusplus/SimpleLexer.h>
|
2018-02-09 13:51:39 +01:00
|
|
|
#include <utils/algorithm.h>
|
2018-07-10 15:53:51 +02:00
|
|
|
#include <utils/fileutils.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2014-01-21 14:57:00 +01:00
|
|
|
#include <QDir>
|
2013-12-10 14:37:32 +01:00
|
|
|
#include <QFile>
|
2018-07-10 15:53:51 +02:00
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
2015-11-27 18:21:46 +01:00
|
|
|
#include <QStringList>
|
2018-02-01 13:27:50 +01:00
|
|
|
#include <QTextBlock>
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
2021-08-30 10:58:08 +02:00
|
|
|
using namespace CppEditor;
|
2020-02-18 18:25:26 +01:00
|
|
|
using namespace ProjectExplorer;
|
2020-07-06 15:49:35 +02:00
|
|
|
using namespace Utils;
|
2013-12-10 14:37:32 +01:00
|
|
|
|
|
|
|
|
namespace ClangCodeModel {
|
2020-07-06 15:49:35 +02:00
|
|
|
namespace Internal {
|
2013-12-10 14:37:32 +01:00
|
|
|
|
2022-11-23 19:00:38 +01:00
|
|
|
ProjectPart::ConstPtr projectPartForFile(const FilePath &filePath)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
if (const auto parser = CppEditor::BaseEditorDocumentParser::get(filePath))
|
2017-01-17 15:27:31 +01:00
|
|
|
return parser->projectPartInfo().projectPart;
|
2021-08-20 11:21:06 +02:00
|
|
|
return ProjectPart::ConstPtr();
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 15:12:01 +02:00
|
|
|
QString diagnosticCategoryPrefixRemoved(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
QString theText = text;
|
|
|
|
|
|
|
|
|
|
// Prefixes are taken from $LLVM_SOURCE_DIR/tools/clang/lib/Frontend/TextDiagnostic.cpp,
|
|
|
|
|
// function TextDiagnostic::printDiagnosticLevel (llvm-3.6.2).
|
|
|
|
|
static const QStringList categoryPrefixes = {
|
2022-08-03 14:27:18 +02:00
|
|
|
QStringLiteral("note: "),
|
|
|
|
|
QStringLiteral("remark: "),
|
|
|
|
|
QStringLiteral("warning: "),
|
|
|
|
|
QStringLiteral("error: "),
|
|
|
|
|
QStringLiteral("fatal error: ")
|
2018-05-09 15:12:01 +02:00
|
|
|
};
|
|
|
|
|
|
2022-08-03 14:27:18 +02:00
|
|
|
for (const QString &fullPrefix : categoryPrefixes) {
|
2018-05-09 15:12:01 +02:00
|
|
|
if (theText.startsWith(fullPrefix)) {
|
|
|
|
|
theText.remove(0, fullPrefix.length());
|
|
|
|
|
return theText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 10:22:16 +01:00
|
|
|
static QStringList projectPartArguments(const ProjectPart &projectPart)
|
2018-07-10 15:53:51 +02:00
|
|
|
{
|
2019-03-13 10:22:16 +01:00
|
|
|
QStringList args;
|
2021-05-07 16:10:07 +02:00
|
|
|
args << projectPart.compilerFilePath.toString();
|
2019-03-13 10:22:16 +01:00
|
|
|
args << "-c";
|
|
|
|
|
if (projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
2024-01-18 16:09:25 +01:00
|
|
|
args << "--target=" + projectPart.toolchainTargetTriple;
|
|
|
|
|
if (projectPart.toolchainAbi.architecture() == Abi::X86Architecture)
|
|
|
|
|
args << QLatin1String(projectPart.toolchainAbi.wordWidth() == 64 ? "-m64" : "-m32");
|
2019-03-13 10:22:16 +01:00
|
|
|
}
|
|
|
|
|
args << projectPart.compilerFlags;
|
|
|
|
|
for (const ProjectExplorer::HeaderPath &headerPath : projectPart.headerPaths) {
|
|
|
|
|
if (headerPath.type == ProjectExplorer::HeaderPathType::User) {
|
|
|
|
|
args << "-I" + headerPath.path;
|
|
|
|
|
} else if (headerPath.type == ProjectExplorer::HeaderPathType::System) {
|
|
|
|
|
args << (projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID
|
|
|
|
|
? "-I"
|
|
|
|
|
: "-isystem")
|
|
|
|
|
+ headerPath.path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const ProjectExplorer::Macro ¯o : projectPart.projectMacros) {
|
|
|
|
|
args.append(QString::fromUtf8(
|
|
|
|
|
macro.toKeyValue(macro.type == ProjectExplorer::MacroType::Define ? "-D" : "-U")));
|
|
|
|
|
}
|
2018-07-10 15:53:51 +02:00
|
|
|
|
2019-03-13 10:22:16 +01:00
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 15:49:35 +02:00
|
|
|
static QJsonObject createFileObject(const FilePath &buildDir,
|
2019-03-13 10:22:16 +01:00
|
|
|
const QStringList &arguments,
|
|
|
|
|
const ProjectPart &projectPart,
|
2021-02-23 13:51:41 +01:00
|
|
|
const ProjectFile &projFile,
|
2021-05-07 16:10:07 +02:00
|
|
|
CompilationDbPurpose purpose,
|
2022-05-05 17:34:31 +02:00
|
|
|
const QJsonArray &projectPartOptions,
|
2022-07-06 12:21:04 +02:00
|
|
|
UsePrecompiledHeaders usePch,
|
|
|
|
|
bool clStyle)
|
2019-03-13 10:22:16 +01:00
|
|
|
{
|
2018-07-10 15:53:51 +02:00
|
|
|
QJsonObject fileObject;
|
2022-11-24 19:16:47 +01:00
|
|
|
fileObject["file"] = projFile.path.toString();
|
2021-02-23 13:51:41 +01:00
|
|
|
QJsonArray args;
|
|
|
|
|
|
|
|
|
|
if (purpose == CompilationDbPurpose::Project) {
|
|
|
|
|
args = QJsonArray::fromStringList(arguments);
|
|
|
|
|
|
2022-11-24 19:16:47 +01:00
|
|
|
const ProjectFile::Kind kind = ProjectFile::classify(projFile.path.path());
|
2021-02-23 13:51:41 +01:00
|
|
|
if (projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID
|
|
|
|
|
|| projectPart.toolchainType == ProjectExplorer::Constants::CLANG_CL_TOOLCHAIN_TYPEID) {
|
2022-11-28 12:28:54 +01:00
|
|
|
if (!ProjectFile::isObjC(kind)) {
|
|
|
|
|
if (ProjectFile::isC(kind))
|
|
|
|
|
args.append("/TC");
|
|
|
|
|
else if (ProjectFile::isCxx(kind))
|
|
|
|
|
args.append("/TP");
|
|
|
|
|
}
|
2021-02-23 13:51:41 +01:00
|
|
|
} else {
|
|
|
|
|
QStringList langOption
|
2022-10-27 16:31:23 +02:00
|
|
|
= createLanguageOptionGcc(projectPart.language, kind,
|
2021-02-23 13:51:41 +01:00
|
|
|
projectPart.languageExtensions
|
|
|
|
|
& LanguageExtension::ObjectiveC);
|
|
|
|
|
for (const QString &langOptionPart : langOption)
|
|
|
|
|
args.append(langOptionPart);
|
|
|
|
|
}
|
2019-03-13 10:22:16 +01:00
|
|
|
} else {
|
2022-07-06 12:21:04 +02:00
|
|
|
args = clangOptionsForFile(projFile, projectPart, projectPartOptions, usePch, clStyle);
|
2021-02-23 13:51:41 +01:00
|
|
|
args.prepend("clang"); // TODO: clang-cl for MSVC targets? Does it matter at all what we put here?
|
2019-03-13 10:22:16 +01:00
|
|
|
}
|
2021-02-23 13:51:41 +01:00
|
|
|
|
2022-11-24 19:16:47 +01:00
|
|
|
args.append(projFile.path.toUserOutput());
|
2018-07-10 15:53:51 +02:00
|
|
|
fileObject["arguments"] = args;
|
|
|
|
|
fileObject["directory"] = buildDir.toString();
|
|
|
|
|
return fileObject;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 23:41:17 +02:00
|
|
|
void generateCompilationDB(
|
|
|
|
|
QPromise<expected_str<FilePath>> &promise,
|
|
|
|
|
const QList<ProjectInfo::ConstPtr> &projectInfoList,
|
|
|
|
|
const FilePath &baseDir,
|
|
|
|
|
CompilationDbPurpose purpose,
|
|
|
|
|
const ClangDiagnosticConfig &warningsConfig,
|
|
|
|
|
const QStringList &projectOptions,
|
|
|
|
|
const FilePath &clangIncludeDir)
|
2018-07-10 15:53:51 +02:00
|
|
|
{
|
2024-05-23 23:41:17 +02:00
|
|
|
QTC_ASSERT(!baseDir.isEmpty(),
|
|
|
|
|
promise.addResult(make_unexpected(Tr::tr("Could not retrieve build directory."))); return);
|
2022-08-24 11:16:20 +02:00
|
|
|
QTC_ASSERT(!projectInfoList.isEmpty(),
|
2024-05-23 23:41:17 +02:00
|
|
|
promise.addResult(make_unexpected(Tr::tr("Could not retrieve project info."))); return);
|
2021-10-15 16:24:25 +02:00
|
|
|
QTC_CHECK(baseDir.ensureWritableDir());
|
2022-10-14 09:45:31 +02:00
|
|
|
QFile compileCommandsFile(baseDir.pathAppended("compile_commands.json").toFSPathString());
|
2018-12-03 08:26:48 +01:00
|
|
|
const bool fileOpened = compileCommandsFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
2019-03-13 17:58:06 +01:00
|
|
|
if (!fileOpened) {
|
2024-05-23 23:41:17 +02:00
|
|
|
promise.addResult(make_unexpected(Tr::tr("Could not create \"%1\": %2")
|
|
|
|
|
.arg(compileCommandsFile.fileName(), compileCommandsFile.errorString())));
|
|
|
|
|
return;
|
2019-03-13 17:58:06 +01:00
|
|
|
}
|
2018-09-20 00:42:28 +03:00
|
|
|
compileCommandsFile.write("[");
|
2018-07-10 15:53:51 +02:00
|
|
|
|
2022-05-12 11:08:06 +02:00
|
|
|
const QJsonArray jsonProjectOptions = QJsonArray::fromStringList(projectOptions);
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const ProjectInfo::ConstPtr &projectInfo : std::as_const(projectInfoList)) {
|
2022-10-19 09:48:43 +02:00
|
|
|
QTC_ASSERT(projectInfo, continue);
|
2022-08-24 11:16:20 +02:00
|
|
|
for (ProjectPart::ConstPtr projectPart : projectInfo->projectParts()) {
|
2022-10-19 09:48:43 +02:00
|
|
|
QTC_ASSERT(projectPart, continue);
|
2022-08-24 11:16:20 +02:00
|
|
|
QStringList args;
|
|
|
|
|
const CompilerOptionsBuilder optionsBuilder = clangOptionsBuilder(
|
2022-09-08 15:27:55 +02:00
|
|
|
*projectPart, warningsConfig, clangIncludeDir, {});
|
2022-08-24 11:16:20 +02:00
|
|
|
QJsonArray ppOptions;
|
|
|
|
|
if (purpose == CompilationDbPurpose::Project) {
|
|
|
|
|
args = projectPartArguments(*projectPart);
|
|
|
|
|
} else {
|
|
|
|
|
ppOptions = fullProjectPartOptions(projectPartOptions(optionsBuilder),
|
|
|
|
|
jsonProjectOptions);
|
|
|
|
|
}
|
|
|
|
|
for (const ProjectFile &projFile : projectPart->files) {
|
2024-05-23 23:41:17 +02:00
|
|
|
if (promise.isCanceled())
|
|
|
|
|
return;
|
2024-02-22 16:26:13 +01:00
|
|
|
const QJsonObject json
|
|
|
|
|
= createFileObject(baseDir,
|
|
|
|
|
args,
|
|
|
|
|
*projectPart,
|
|
|
|
|
projFile,
|
|
|
|
|
purpose,
|
|
|
|
|
ppOptions,
|
|
|
|
|
projectInfo->settings().usePrecompiledHeaders(),
|
|
|
|
|
optionsBuilder.isClStyle());
|
2022-08-24 11:16:20 +02:00
|
|
|
if (compileCommandsFile.size() > 1)
|
|
|
|
|
compileCommandsFile.write(",");
|
2022-10-07 13:25:53 +02:00
|
|
|
compileCommandsFile.write(QJsonDocument(json).toJson(QJsonDocument::Compact));
|
2022-08-24 11:16:20 +02:00
|
|
|
}
|
2018-09-20 00:42:28 +03:00
|
|
|
}
|
2018-07-10 15:53:51 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 13:25:53 +02:00
|
|
|
compileCommandsFile.write("]");
|
2018-07-10 15:53:51 +02:00
|
|
|
compileCommandsFile.close();
|
2024-05-23 23:41:17 +02:00
|
|
|
promise.addResult(FilePath::fromUserInput(compileCommandsFile.fileName()));
|
2018-07-10 15:53:51 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 19:00:38 +01:00
|
|
|
FilePath currentCppEditorDocumentFilePath()
|
2019-01-29 16:03:38 +01:00
|
|
|
{
|
2022-11-23 19:00:38 +01:00
|
|
|
FilePath filePath;
|
2019-01-29 16:03:38 +01:00
|
|
|
|
|
|
|
|
const auto currentEditor = Core::EditorManager::currentEditor();
|
2021-08-30 10:58:08 +02:00
|
|
|
if (currentEditor && CppEditor::CppModelManager::isCppEditor(currentEditor)) {
|
2022-11-23 19:00:38 +01:00
|
|
|
if (const auto currentDocument = currentEditor->document())
|
|
|
|
|
filePath = currentDocument->filePath();
|
2019-01-29 16:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 12:40:03 +01:00
|
|
|
DiagnosticTextInfo::DiagnosticTextInfo(const QString &text)
|
|
|
|
|
: m_text(text)
|
|
|
|
|
, m_squareBracketStartIndex(text.lastIndexOf('['))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QString DiagnosticTextInfo::textWithoutOption() const
|
|
|
|
|
{
|
|
|
|
|
if (m_squareBracketStartIndex == -1)
|
|
|
|
|
return m_text;
|
|
|
|
|
|
|
|
|
|
return m_text.mid(0, m_squareBracketStartIndex - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DiagnosticTextInfo::option() const
|
|
|
|
|
{
|
|
|
|
|
if (m_squareBracketStartIndex == -1)
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
const int index = m_squareBracketStartIndex + 1;
|
2023-06-06 16:58:05 +02:00
|
|
|
return m_text.mid(index, m_text.size() - index - 1);
|
2019-01-28 12:40:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DiagnosticTextInfo::category() const
|
|
|
|
|
{
|
|
|
|
|
if (m_squareBracketStartIndex == -1)
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
const int index = m_squareBracketStartIndex + 1;
|
|
|
|
|
if (isClazyOption(m_text.mid(index)))
|
2023-01-19 09:51:10 +01:00
|
|
|
return Tr::tr("Clazy Issue");
|
2019-01-28 12:40:03 +01:00
|
|
|
else
|
2023-01-19 09:51:10 +01:00
|
|
|
return Tr::tr("Clang-Tidy Issue");
|
2019-01-28 12:40:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DiagnosticTextInfo::isClazyOption(const QString &option)
|
|
|
|
|
{
|
|
|
|
|
return option.startsWith("-Wclazy");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DiagnosticTextInfo::clazyCheckName(const QString &option)
|
|
|
|
|
{
|
|
|
|
|
if (option.startsWith("-Wclazy"))
|
|
|
|
|
return option.mid(8); // Chop "-Wclazy-"
|
|
|
|
|
return option;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 17:34:31 +02:00
|
|
|
QJsonArray clangOptionsForFile(const ProjectFile &file, const ProjectPart &projectPart,
|
2022-07-06 12:21:04 +02:00
|
|
|
const QJsonArray &generalOptions, UsePrecompiledHeaders usePch,
|
|
|
|
|
bool clStyle)
|
2021-02-23 13:51:41 +01:00
|
|
|
{
|
2022-05-05 17:34:31 +02:00
|
|
|
CompilerOptionsBuilder optionsBuilder(projectPart);
|
2022-07-06 12:21:04 +02:00
|
|
|
optionsBuilder.setClStyle(clStyle);
|
2022-05-05 15:36:58 +02:00
|
|
|
ProjectFile::Kind fileKind = file.kind;
|
2022-05-04 16:48:48 +02:00
|
|
|
if (fileKind == ProjectFile::AmbiguousHeader) {
|
2022-05-05 17:34:31 +02:00
|
|
|
fileKind = projectPart.languageVersion <= LanguageVersion::LatestC
|
2022-05-04 16:48:48 +02:00
|
|
|
? ProjectFile::CHeader : ProjectFile::CXXHeader;
|
|
|
|
|
}
|
2022-05-05 15:50:46 +02:00
|
|
|
if (usePch == UsePrecompiledHeaders::Yes
|
2022-11-24 19:16:47 +01:00
|
|
|
&& projectPart.precompiledHeaders.contains(file.path.path())) {
|
2022-05-05 15:50:46 +02:00
|
|
|
usePch = UsePrecompiledHeaders::No;
|
2022-05-04 16:48:48 +02:00
|
|
|
}
|
2022-10-20 01:06:06 +02:00
|
|
|
optionsBuilder.updateFileLanguage(fileKind);
|
2022-05-05 15:50:46 +02:00
|
|
|
optionsBuilder.addPrecompiledHeaderOptions(usePch);
|
2022-05-05 17:34:31 +02:00
|
|
|
const QJsonArray specificOptions = QJsonArray::fromStringList(optionsBuilder.options());
|
|
|
|
|
QJsonArray fullOptions = generalOptions;
|
|
|
|
|
for (const QJsonValue &opt : specificOptions)
|
|
|
|
|
fullOptions << opt;
|
|
|
|
|
return fullOptions;
|
2021-05-07 16:10:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangDiagnosticConfig warningsConfigForProject(Project *project)
|
|
|
|
|
{
|
2022-05-19 14:48:09 +02:00
|
|
|
return ClangdSettings(ClangdProjectSettings(project).settings()).diagnosticConfig();
|
2021-05-07 16:10:07 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
const QStringList globalClangOptions()
|
2021-05-07 16:10:07 +02:00
|
|
|
{
|
2022-05-19 14:48:09 +02:00
|
|
|
return ClangDiagnosticConfigsModel::globalDiagnosticOptions();
|
2021-02-23 13:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-18 16:30:03 +02:00
|
|
|
// 7.3.3: using typename(opt) nested-name-specifier unqualified-id ;
|
|
|
|
|
bool isAtUsingDeclaration(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
|
|
|
|
int basePosition)
|
|
|
|
|
{
|
|
|
|
|
using namespace CPlusPlus;
|
|
|
|
|
SimpleLexer lexer;
|
|
|
|
|
lexer.setLanguageFeatures(LanguageFeatures::defaultFeatures());
|
|
|
|
|
const QString textToLex = textUntilPreviousStatement(manipulator, basePosition);
|
|
|
|
|
const Tokens tokens = lexer(textToLex);
|
|
|
|
|
if (tokens.empty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// The nested-name-specifier always ends with "::", so check for this first.
|
|
|
|
|
const Token lastToken = tokens[tokens.size() - 1];
|
|
|
|
|
if (lastToken.kind() != T_COLON_COLON)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return contains(tokens, [](const Token &token) { return token.kind() == T_USING; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString textUntilPreviousStatement(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
|
|
|
|
int startPosition)
|
|
|
|
|
{
|
|
|
|
|
static const QString stopCharacters(";{}#");
|
|
|
|
|
|
|
|
|
|
int endPosition = 0;
|
|
|
|
|
for (int i = startPosition; i >= 0 ; --i) {
|
|
|
|
|
if (stopCharacters.contains(manipulator.characterAt(i))) {
|
|
|
|
|
endPosition = i + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return manipulator.textAt(endPosition, startPosition - endPosition);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-04 16:48:48 +02:00
|
|
|
CompilerOptionsBuilder clangOptionsBuilder(const ProjectPart &projectPart,
|
2022-05-09 16:16:51 +02:00
|
|
|
const ClangDiagnosticConfig &warningsConfig,
|
2022-09-08 15:27:55 +02:00
|
|
|
const FilePath &clangIncludeDir,
|
|
|
|
|
const Macros &extraMacros)
|
2022-05-04 16:48:48 +02:00
|
|
|
{
|
|
|
|
|
const auto useBuildSystemWarnings = warningsConfig.useBuildSystemWarnings()
|
|
|
|
|
? UseBuildSystemWarnings::Yes
|
|
|
|
|
: UseBuildSystemWarnings::No;
|
|
|
|
|
CompilerOptionsBuilder optionsBuilder(projectPart, UseSystemHeader::No,
|
|
|
|
|
UseTweakedHeaderPaths::Yes, UseLanguageDefines::No,
|
2022-05-09 14:59:04 +02:00
|
|
|
useBuildSystemWarnings, clangIncludeDir);
|
2022-09-08 15:27:55 +02:00
|
|
|
Macros fullMacroList = extraMacros;
|
|
|
|
|
fullMacroList += Macro("Q_CREATOR_RUN", "1");
|
|
|
|
|
optionsBuilder.provideAdditionalMacros(fullMacroList);
|
2022-05-04 16:48:48 +02:00
|
|
|
optionsBuilder.build(ProjectFile::Unclassified, UsePrecompiledHeaders::No);
|
|
|
|
|
optionsBuilder.add("-fmessage-length=0", /*gccOnlyOption=*/true);
|
|
|
|
|
optionsBuilder.add("-fdiagnostics-show-note-include-stack", /*gccOnlyOption=*/true);
|
|
|
|
|
optionsBuilder.add("-fretain-comments-from-system-headers", /*gccOnlyOption=*/true);
|
|
|
|
|
optionsBuilder.add("-fmacro-backtrace-limit=0");
|
|
|
|
|
optionsBuilder.add("-ferror-limit=1000");
|
|
|
|
|
|
|
|
|
|
if (useBuildSystemWarnings == UseBuildSystemWarnings::No) {
|
|
|
|
|
for (const QString &opt : warningsConfig.clangOptions())
|
|
|
|
|
optionsBuilder.add(opt, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return optionsBuilder;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 17:34:31 +02:00
|
|
|
QJsonArray projectPartOptions(const CppEditor::CompilerOptionsBuilder &optionsBuilder)
|
|
|
|
|
{
|
|
|
|
|
const QStringList optionsList = optionsBuilder.options();
|
|
|
|
|
QJsonArray optionsArray;
|
|
|
|
|
for (const QString &opt : optionsList) {
|
|
|
|
|
// These will be added later by the file-specific code, and they trigger warnings
|
|
|
|
|
// if they appear twice; see QTCREATORBUG-26664.
|
|
|
|
|
if (opt != "-TP" && opt != "-TC")
|
|
|
|
|
optionsArray << opt;
|
|
|
|
|
}
|
|
|
|
|
return optionsArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonArray fullProjectPartOptions(const CppEditor::CompilerOptionsBuilder &optionsBuilder,
|
|
|
|
|
const QStringList &projectOptions)
|
|
|
|
|
{
|
|
|
|
|
return fullProjectPartOptions(projectPartOptions(optionsBuilder),
|
|
|
|
|
QJsonArray::fromStringList(projectOptions));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonArray fullProjectPartOptions(const QJsonArray &projectPartOptions,
|
|
|
|
|
const QJsonArray &projectOptions)
|
|
|
|
|
{
|
|
|
|
|
QJsonArray fullProjectPartOptions = projectPartOptions;
|
|
|
|
|
for (const QJsonValue &opt : projectOptions)
|
|
|
|
|
fullProjectPartOptions.prepend(opt);
|
|
|
|
|
return fullProjectPartOptions;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 15:49:35 +02:00
|
|
|
} // namespace Internal
|
2013-12-10 14:37:32 +01:00
|
|
|
} // namespace Clang
|