forked from qt-creator/qt-creator
ClangTools/CppTools: Code cosmetics
Mostly namespaces. Change-Id: Ife8bbcb128344cf56d444da8f9d76b1204b9fe34 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -69,10 +69,12 @@
|
|||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
using namespace ClangCodeModel;
|
using namespace CppTools;
|
||||||
using namespace ClangCodeModel::Internal;
|
|
||||||
using namespace LanguageClient;
|
using namespace LanguageClient;
|
||||||
|
|
||||||
|
namespace ClangCodeModel {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
static ClangModelManagerSupport *m_instance = nullptr;
|
static ClangModelManagerSupport *m_instance = nullptr;
|
||||||
|
|
||||||
static CppTools::CppModelManager *cppModelManager()
|
static CppTools::CppModelManager *cppModelManager()
|
||||||
@@ -651,7 +653,7 @@ void ClangModelManagerSupport::onClangdSettingsChanged()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ClangdClient * const fallbackClient = clientForProject(nullptr);
|
ClangdClient * const fallbackClient = clientForProject(nullptr);
|
||||||
const CppTools::ClangdSettings &settings = CppTools::ClangdSettings::instance();
|
const ClangdSettings &settings = ClangdSettings::instance();
|
||||||
const auto startNewFallbackClient = [this] {
|
const auto startNewFallbackClient = [this] {
|
||||||
claimNonProjectSources(createClient(nullptr, {}));
|
claimNonProjectSources(createClient(nullptr, {}));
|
||||||
};
|
};
|
||||||
@@ -743,3 +745,6 @@ CppTools::ModelManagerSupport::Ptr ClangModelManagerSupportProvider::createModel
|
|||||||
{
|
{
|
||||||
return CppTools::ModelManagerSupport::Ptr(new ClangModelManagerSupport);
|
return CppTools::ModelManagerSupport::Ptr(new ClangModelManagerSupport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // Internal
|
||||||
|
} // ClangCodeModel
|
||||||
|
@@ -37,21 +37,21 @@
|
|||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
static const char clangTidyExecutableKey[] = "ClangTidyExecutable";
|
|
||||||
static const char clazyStandaloneExecutableKey[] = "ClazyStandaloneExecutable";
|
|
||||||
|
|
||||||
static const char parallelJobsKey[] = "ParallelJobs";
|
|
||||||
static const char buildBeforeAnalysisKey[] = "BuildBeforeAnalysis";
|
|
||||||
static const char analyzeOpenFilesKey[] = "AnalyzeOpenFiles";
|
|
||||||
static const char oldDiagnosticConfigIdKey[] = "diagnosticConfigId";
|
|
||||||
|
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ClangTools {
|
namespace ClangTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static Utils::Id defaultDiagnosticId()
|
const char clangTidyExecutableKey[] = "ClangTidyExecutable";
|
||||||
|
const char clazyStandaloneExecutableKey[] = "ClazyStandaloneExecutable";
|
||||||
|
|
||||||
|
const char parallelJobsKey[] = "ParallelJobs";
|
||||||
|
const char buildBeforeAnalysisKey[] = "BuildBeforeAnalysis";
|
||||||
|
const char analyzeOpenFilesKey[] = "AnalyzeOpenFiles";
|
||||||
|
const char oldDiagnosticConfigIdKey[] = "diagnosticConfigId";
|
||||||
|
|
||||||
|
static Id defaultDiagnosticId()
|
||||||
{
|
{
|
||||||
return ClangTools::Constants::DIAG_CONFIG_TIDY_AND_CLAZY;
|
return ClangTools::Constants::DIAG_CONFIG_TIDY_AND_CLAZY;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ RunSettings::RunSettings()
|
|||||||
|
|
||||||
void RunSettings::fromMap(const QVariantMap &map, const QString &prefix)
|
void RunSettings::fromMap(const QVariantMap &map, const QString &prefix)
|
||||||
{
|
{
|
||||||
m_diagnosticConfigId = Utils::Id::fromSetting(map.value(prefix + diagnosticConfigIdKey));
|
m_diagnosticConfigId = Id::fromSetting(map.value(prefix + diagnosticConfigIdKey));
|
||||||
m_parallelJobs = map.value(prefix + parallelJobsKey).toInt();
|
m_parallelJobs = map.value(prefix + parallelJobsKey).toInt();
|
||||||
m_buildBeforeAnalysis = map.value(prefix + buildBeforeAnalysisKey).toBool();
|
m_buildBeforeAnalysis = map.value(prefix + buildBeforeAnalysisKey).toBool();
|
||||||
m_analyzeOpenFiles = map.value(prefix + analyzeOpenFilesKey).toBool();
|
m_analyzeOpenFiles = map.value(prefix + analyzeOpenFilesKey).toBool();
|
||||||
@@ -78,7 +78,7 @@ void RunSettings::toMap(QVariantMap &map, const QString &prefix) const
|
|||||||
map.insert(prefix + analyzeOpenFilesKey, m_analyzeOpenFiles);
|
map.insert(prefix + analyzeOpenFilesKey, m_analyzeOpenFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Id RunSettings::diagnosticConfigId() const
|
Id RunSettings::diagnosticConfigId() const
|
||||||
{
|
{
|
||||||
if (!diagnosticConfigsModel().hasConfigWithId(m_diagnosticConfigId))
|
if (!diagnosticConfigsModel().hasConfigWithId(m_diagnosticConfigId))
|
||||||
return defaultDiagnosticId();
|
return defaultDiagnosticId();
|
||||||
@@ -220,13 +220,12 @@ static QVersionNumber getVersionNumber(QVersionNumber &version, const FilePath &
|
|||||||
|
|
||||||
QVersionNumber ClangToolsSettings::clangTidyVersion()
|
QVersionNumber ClangToolsSettings::clangTidyVersion()
|
||||||
{
|
{
|
||||||
return getVersionNumber(instance()->m_clangTidyVersion,
|
return getVersionNumber(instance()->m_clangTidyVersion, Internal::clangTidyExecutable());
|
||||||
ClangTools::Internal::clangTidyExecutable());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVersionNumber ClangToolsSettings::clazyVersion()
|
QVersionNumber ClangToolsSettings::clazyVersion()
|
||||||
{
|
{
|
||||||
return ClazyStandaloneInfo(ClangTools::Internal::clazyStandaloneExecutable()).version;
|
return ClazyStandaloneInfo(Internal::clazyStandaloneExecutable()).version;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -41,8 +41,6 @@
|
|||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
#include <cpptools/clangdiagnosticconfigsmodel.h>
|
#include <cpptools/clangdiagnosticconfigsmodel.h>
|
||||||
|
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
@@ -53,21 +53,25 @@
|
|||||||
|
|
||||||
static Q_LOGGING_CATEGORY(LOG, "qtc.clangtools.cftr", QtWarningMsg)
|
static Q_LOGGING_CATEGORY(LOG, "qtc.clangtools.cftr", QtWarningMsg)
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
using namespace CppTools;
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ClangTools {
|
namespace ClangTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
DocumentClangToolRunner::DocumentClangToolRunner(Core::IDocument *document)
|
DocumentClangToolRunner::DocumentClangToolRunner(IDocument *document)
|
||||||
: QObject(document)
|
: QObject(document)
|
||||||
, m_document(document)
|
, m_document(document)
|
||||||
, m_temporaryDir("clangtools-single-XXXXXX")
|
, m_temporaryDir("clangtools-single-XXXXXX")
|
||||||
{
|
{
|
||||||
using namespace CppTools;
|
|
||||||
|
|
||||||
m_runTimer.setInterval(500);
|
m_runTimer.setInterval(500);
|
||||||
m_runTimer.setSingleShot(true);
|
m_runTimer.setSingleShot(true);
|
||||||
|
|
||||||
connect(m_document,
|
connect(m_document,
|
||||||
&Core::IDocument::contentsChanged,
|
&IDocument::contentsChanged,
|
||||||
this,
|
this,
|
||||||
&DocumentClangToolRunner::scheduleRun);
|
&DocumentClangToolRunner::scheduleRun);
|
||||||
connect(CppModelManager::instance(),
|
connect(CppModelManager::instance(),
|
||||||
@@ -88,7 +92,7 @@ DocumentClangToolRunner::~DocumentClangToolRunner()
|
|||||||
qDeleteAll(m_marks);
|
qDeleteAll(m_marks);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath DocumentClangToolRunner::filePath() const
|
FilePath DocumentClangToolRunner::filePath() const
|
||||||
{
|
{
|
||||||
return m_document->filePath();
|
return m_document->filePath();
|
||||||
}
|
}
|
||||||
@@ -123,10 +127,10 @@ void DocumentClangToolRunner::scheduleRun()
|
|||||||
m_runTimer.start();
|
m_runTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ProjectExplorer::Project *findProject(const Utils::FilePath &file)
|
static Project *findProject(const FilePath &file)
|
||||||
{
|
{
|
||||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::projectForFile(file);
|
Project *project = SessionManager::projectForFile(file);
|
||||||
return project ? project : ProjectExplorer::SessionManager::startupProject();
|
return project ? project : SessionManager::startupProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
static VirtualFileSystemOverlay &vfso()
|
static VirtualFileSystemOverlay &vfso()
|
||||||
@@ -135,29 +139,28 @@ static VirtualFileSystemOverlay &vfso()
|
|||||||
return overlay;
|
return overlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FileInfo getFileInfo(const Utils::FilePath &file, ProjectExplorer::Project *project)
|
static FileInfo getFileInfo(const FilePath &file, Project *project)
|
||||||
{
|
{
|
||||||
const CppTools::ProjectInfo::Ptr projectInfo
|
const ProjectInfo::Ptr projectInfo = CppModelManager::instance()->projectInfo(project);
|
||||||
= CppTools::CppModelManager::instance()->projectInfo(project);
|
|
||||||
if (!projectInfo)
|
if (!projectInfo)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
FileInfo candidate;
|
FileInfo candidate;
|
||||||
for (const CppTools::ProjectPart::Ptr &projectPart : projectInfo->projectParts()) {
|
for (const ProjectPart::Ptr &projectPart : projectInfo->projectParts()) {
|
||||||
QTC_ASSERT(projectPart, continue);
|
QTC_ASSERT(projectPart, continue);
|
||||||
|
|
||||||
for (const CppTools::ProjectFile &projectFile : qAsConst(projectPart->files)) {
|
for (const ProjectFile &projectFile : qAsConst(projectPart->files)) {
|
||||||
QTC_ASSERT(projectFile.kind != CppTools::ProjectFile::Unclassified, continue);
|
QTC_ASSERT(projectFile.kind != ProjectFile::Unclassified, continue);
|
||||||
QTC_ASSERT(projectFile.kind != CppTools::ProjectFile::Unsupported, continue);
|
QTC_ASSERT(projectFile.kind != ProjectFile::Unsupported, continue);
|
||||||
if (projectFile.path == CppTools::CppModelManager::configurationFileName())
|
if (projectFile.path == CppModelManager::configurationFileName())
|
||||||
continue;
|
continue;
|
||||||
const auto projectFilePath = Utils::FilePath::fromString(projectFile.path);
|
const auto projectFilePath = FilePath::fromString(projectFile.path);
|
||||||
if (file != projectFilePath)
|
if (file != projectFilePath)
|
||||||
continue;
|
continue;
|
||||||
if (!projectFile.active)
|
if (!projectFile.active)
|
||||||
continue;
|
continue;
|
||||||
// found the best candidate, early return
|
// found the best candidate, early return
|
||||||
if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Unknown)
|
if (projectPart->buildTargetType != BuildTargetType::Unknown)
|
||||||
return FileInfo(projectFilePath, projectFile.kind, projectPart);
|
return FileInfo(projectFilePath, projectFile.kind, projectPart);
|
||||||
// found something but keep looking for better candidates
|
// found something but keep looking for better candidates
|
||||||
if (candidate.projectPart.isNull())
|
if (candidate.projectPart.isNull())
|
||||||
@@ -168,27 +171,27 @@ static FileInfo getFileInfo(const Utils::FilePath &file, ProjectExplorer::Projec
|
|||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utils::Environment projectBuildEnvironment(ProjectExplorer::Project *project)
|
static Environment projectBuildEnvironment(Project *project)
|
||||||
{
|
{
|
||||||
Utils::Environment env;
|
Environment env;
|
||||||
if (ProjectExplorer::Target *target = project->activeTarget()) {
|
if (Target *target = project->activeTarget()) {
|
||||||
if (ProjectExplorer::BuildConfiguration *buildConfig = target->activeBuildConfiguration())
|
if (BuildConfiguration *buildConfig = target->activeBuildConfiguration())
|
||||||
env = buildConfig->environment();
|
env = buildConfig->environment();
|
||||||
}
|
}
|
||||||
if (env.size() == 0)
|
if (env.size() == 0)
|
||||||
env = Utils::Environment::systemEnvironment();
|
env = Environment::systemEnvironment();
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentClangToolRunner::run()
|
void DocumentClangToolRunner::run()
|
||||||
{
|
{
|
||||||
cancel();
|
cancel();
|
||||||
auto isEditorForCurrentDocument = [this](const Core::IEditor *editor) {
|
auto isEditorForCurrentDocument = [this](const IEditor *editor) {
|
||||||
return editor->document() == m_document;
|
return editor->document() == m_document;
|
||||||
};
|
};
|
||||||
if (Utils::anyOf(Core::EditorManager::visibleEditors(), isEditorForCurrentDocument)) {
|
if (Utils::anyOf(EditorManager::visibleEditors(), isEditorForCurrentDocument)) {
|
||||||
const Utils::FilePath filePath = m_document->filePath();
|
const FilePath filePath = m_document->filePath();
|
||||||
if (ProjectExplorer::Project *project = findProject(filePath)) {
|
if (Project *project = findProject(filePath)) {
|
||||||
m_fileInfo = getFileInfo(filePath, project);
|
m_fileInfo = getFileInfo(filePath, project);
|
||||||
if (m_fileInfo.file.exists()) {
|
if (m_fileInfo.file.exists()) {
|
||||||
const auto projectSettings = ClangToolsProjectSettings::getSettings(project);
|
const auto projectSettings = ClangToolsProjectSettings::getSettings(project);
|
||||||
@@ -207,10 +210,10 @@ void DocumentClangToolRunner::run()
|
|||||||
if (runSettings.analyzeOpenFiles()) {
|
if (runSettings.analyzeOpenFiles()) {
|
||||||
vfso().update();
|
vfso().update();
|
||||||
|
|
||||||
CppTools::ClangDiagnosticConfig config = diagnosticConfig(
|
ClangDiagnosticConfig config = diagnosticConfig(
|
||||||
runSettings.diagnosticConfigId());
|
runSettings.diagnosticConfigId());
|
||||||
|
|
||||||
Utils::Environment env = projectBuildEnvironment(project);
|
Environment env = projectBuildEnvironment(project);
|
||||||
if (config.isClangTidyEnabled()) {
|
if (config.isClangTidyEnabled()) {
|
||||||
m_runnerCreators << [this, env, config]() {
|
m_runnerCreators << [this, env, config]() {
|
||||||
return createRunner<ClangTidyRunner>(config, env);
|
return createRunner<ClangTidyRunner>(config, env);
|
||||||
@@ -231,10 +234,10 @@ void DocumentClangToolRunner::run()
|
|||||||
runNext();
|
runNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<Utils::FilePath, QString> getClangIncludeDirAndVersion(ClangToolRunner *runner)
|
QPair<FilePath, QString> getClangIncludeDirAndVersion(ClangToolRunner *runner)
|
||||||
{
|
{
|
||||||
static QMap<Utils::FilePath, QPair<Utils::FilePath, QString>> cache;
|
static QMap<FilePath, QPair<FilePath, QString>> cache;
|
||||||
const Utils::FilePath tool = runner->executable();
|
const FilePath tool = runner->executable();
|
||||||
auto it = cache.find(tool);
|
auto it = cache.find(tool);
|
||||||
if (it == cache.end())
|
if (it == cache.end())
|
||||||
it = cache.insert(tool, getClangIncludeDirAndVersion(tool));
|
it = cache.insert(tool, getClangIncludeDirAndVersion(tool));
|
||||||
@@ -253,7 +256,7 @@ void DocumentClangToolRunner::runNext()
|
|||||||
runNext();
|
runNext();
|
||||||
} else {
|
} else {
|
||||||
AnalyzeUnit unit(m_fileInfo, clangIncludeDir, clangVersion);
|
AnalyzeUnit unit(m_fileInfo, clangIncludeDir, clangVersion);
|
||||||
QTC_ASSERT(Utils::FilePath::fromString(unit.file).exists(), runNext(); return;);
|
QTC_ASSERT(FilePath::fromString(unit.file).exists(), runNext(); return;);
|
||||||
m_currentRunner->setVFSOverlay(vfso().overlayFilePath().toString());
|
m_currentRunner->setVFSOverlay(vfso().overlayFilePath().toString());
|
||||||
if (!m_currentRunner->run(unit.file, unit.arguments))
|
if (!m_currentRunner->run(unit.file, unit.arguments))
|
||||||
runNext();
|
runNext();
|
||||||
@@ -271,10 +274,10 @@ static void updateLocation(Debugger::DiagnosticLocation &location)
|
|||||||
void DocumentClangToolRunner::onSuccess()
|
void DocumentClangToolRunner::onSuccess()
|
||||||
{
|
{
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
Utils::FilePath mappedPath = vfso().autoSavedFilePath(m_document);
|
FilePath mappedPath = vfso().autoSavedFilePath(m_document);
|
||||||
Diagnostics diagnostics = readExportedDiagnostics(
|
Diagnostics diagnostics = readExportedDiagnostics(
|
||||||
Utils::FilePath::fromString(m_currentRunner->outputFilePath()),
|
FilePath::fromString(m_currentRunner->outputFilePath()),
|
||||||
[&](const Utils::FilePath &path) { return path == mappedPath; },
|
[&](const FilePath &path) { return path == mappedPath; },
|
||||||
&errorMessage);
|
&errorMessage);
|
||||||
|
|
||||||
for (Diagnostic &diag : diagnostics) {
|
for (Diagnostic &diag : diagnostics) {
|
||||||
@@ -308,9 +311,9 @@ void DocumentClangToolRunner::onSuccess()
|
|||||||
TextEditor::RefactorMarker marker;
|
TextEditor::RefactorMarker marker;
|
||||||
marker.tooltip = diagnostic.description;
|
marker.tooltip = diagnostic.description;
|
||||||
QTextCursor cursor(doc->document());
|
QTextCursor cursor(doc->document());
|
||||||
cursor.setPosition(Utils::Text::positionInText(doc->document(),
|
cursor.setPosition(Text::positionInText(doc->document(),
|
||||||
diagnostic.location.line,
|
diagnostic.location.line,
|
||||||
diagnostic.location.column));
|
diagnostic.location.column));
|
||||||
cursor.movePosition(QTextCursor::EndOfLine);
|
cursor.movePosition(QTextCursor::EndOfLine);
|
||||||
marker.cursor = cursor;
|
marker.cursor = cursor;
|
||||||
marker.type = Constants::CLANG_TOOL_FIXIT_AVAILABLE_MARKER_ID;
|
marker.type = Constants::CLANG_TOOL_FIXIT_AVAILABLE_MARKER_ID;
|
||||||
@@ -365,7 +368,7 @@ bool DocumentClangToolRunner::isSuppressed(const Diagnostic &diagnostic) const
|
|||||||
auto equalsSuppressed = [this, &diagnostic](const SuppressedDiagnostic &suppressed) {
|
auto equalsSuppressed = [this, &diagnostic](const SuppressedDiagnostic &suppressed) {
|
||||||
if (suppressed.description != diagnostic.description)
|
if (suppressed.description != diagnostic.description)
|
||||||
return false;
|
return false;
|
||||||
Utils::FilePath filePath = suppressed.filePath;
|
FilePath filePath = suppressed.filePath;
|
||||||
if (filePath.toFileInfo().isRelative())
|
if (filePath.toFileInfo().isRelative())
|
||||||
filePath = m_lastProjectDirectory.pathAppended(filePath.toString());
|
filePath = m_lastProjectDirectory.pathAppended(filePath.toString());
|
||||||
return filePath == diagnostic.location.filePath;
|
return filePath == diagnostic.location.filePath;
|
||||||
@@ -373,7 +376,7 @@ bool DocumentClangToolRunner::isSuppressed(const Diagnostic &diagnostic) const
|
|||||||
return Utils::anyOf(m_suppressed, equalsSuppressed);
|
return Utils::anyOf(m_suppressed, equalsSuppressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CppTools::ClangDiagnosticConfig DocumentClangToolRunner::getDiagnosticConfig(ProjectExplorer::Project *project)
|
const ClangDiagnosticConfig DocumentClangToolRunner::getDiagnosticConfig(Project *project)
|
||||||
{
|
{
|
||||||
const auto projectSettings = ClangToolsProjectSettings::getSettings(project);
|
const auto projectSettings = ClangToolsProjectSettings::getSettings(project);
|
||||||
m_projectSettingsUpdate = connect(projectSettings.data(),
|
m_projectSettingsUpdate = connect(projectSettings.data(),
|
||||||
@@ -381,15 +384,15 @@ const CppTools::ClangDiagnosticConfig DocumentClangToolRunner::getDiagnosticConf
|
|||||||
this,
|
this,
|
||||||
&DocumentClangToolRunner::run);
|
&DocumentClangToolRunner::run);
|
||||||
|
|
||||||
const Utils::Id &id = projectSettings->useGlobalSettings()
|
const Id id = projectSettings->useGlobalSettings()
|
||||||
? ClangToolsSettings::instance()->runSettings().diagnosticConfigId()
|
? ClangToolsSettings::instance()->runSettings().diagnosticConfigId()
|
||||||
: projectSettings->runSettings().diagnosticConfigId();
|
: projectSettings->runSettings().diagnosticConfigId();
|
||||||
return diagnosticConfig(id);
|
return diagnosticConfig(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
ClangToolRunner *DocumentClangToolRunner::createRunner(const CppTools::ClangDiagnosticConfig &config,
|
ClangToolRunner *DocumentClangToolRunner::createRunner(const ClangDiagnosticConfig &config,
|
||||||
const Utils::Environment &env)
|
const Environment &env)
|
||||||
{
|
{
|
||||||
auto runner = new T(config, this);
|
auto runner = new T(config, this);
|
||||||
runner->init(m_temporaryDir.path(), env);
|
runner->init(m_temporaryDir.path(), env);
|
||||||
|
@@ -45,38 +45,39 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
static const char defineOption[] = "-D";
|
const char defineOption[] = "-D";
|
||||||
static const char undefineOption[] = "-U";
|
const char undefineOption[] = "-U";
|
||||||
|
|
||||||
static const char includeUserPathOption[] = "-I";
|
const char includeUserPathOption[] = "-I";
|
||||||
static const char includeUserPathOptionWindows[] = "/I";
|
const char includeUserPathOptionWindows[] = "/I";
|
||||||
static const char includeSystemPathOption[] = "-isystem";
|
const char includeSystemPathOption[] = "-isystem";
|
||||||
|
|
||||||
static const char includeFileOptionGcc[] = "-include";
|
const char includeFileOptionGcc[] = "-include";
|
||||||
static const char includeFileOptionCl[] = "/FI";
|
const char includeFileOptionCl[] = "/FI";
|
||||||
|
|
||||||
static QByteArray macroOption(const ProjectExplorer::Macro ¯o)
|
static QByteArray macroOption(const Macro ¯o)
|
||||||
{
|
{
|
||||||
switch (macro.type) {
|
switch (macro.type) {
|
||||||
case ProjectExplorer::MacroType::Define:
|
case MacroType::Define:
|
||||||
return defineOption;
|
return defineOption;
|
||||||
case ProjectExplorer::MacroType::Undefine:
|
case MacroType::Undefine:
|
||||||
return undefineOption;
|
return undefineOption;
|
||||||
default:
|
default:
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray toDefineOption(const ProjectExplorer::Macro ¯o)
|
static QByteArray toDefineOption(const Macro ¯o)
|
||||||
{
|
{
|
||||||
return macro.toKeyValue(macroOption(macro));
|
return macro.toKeyValue(macroOption(macro));
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString defineDirectiveToDefineOption(const ProjectExplorer::Macro ¯o)
|
static QString defineDirectiveToDefineOption(const Macro ¯o)
|
||||||
{
|
{
|
||||||
const QByteArray option = toDefineOption(macro);
|
const QByteArray option = toDefineOption(macro);
|
||||||
return QString::fromUtf8(option);
|
return QString::fromUtf8(option);
|
||||||
@@ -124,13 +125,11 @@ QStringList CompilerOptionsBuilder::build(ProjectFile::Kind fileKind,
|
|||||||
evaluateCompilerFlags();
|
evaluateCompilerFlags();
|
||||||
|
|
||||||
if (fileKind == ProjectFile::CHeader || fileKind == ProjectFile::CSource) {
|
if (fileKind == ProjectFile::CHeader || fileKind == ProjectFile::CSource) {
|
||||||
QTC_ASSERT(m_projectPart.languageVersion <= Utils::LanguageVersion::LatestC,
|
QTC_ASSERT(m_projectPart.languageVersion <= LanguageVersion::LatestC, return {});
|
||||||
return QStringList(););
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileKind == ProjectFile::CXXHeader || fileKind == ProjectFile::CXXSource) {
|
if (fileKind == ProjectFile::CXXHeader || fileKind == ProjectFile::CXXSource) {
|
||||||
QTC_ASSERT(m_projectPart.languageVersion > Utils::LanguageVersion::LatestC,
|
QTC_ASSERT(m_projectPart.languageVersion > LanguageVersion::LatestC, return {});
|
||||||
return QStringList(););
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addCompilerFlags();
|
addCompilerFlags();
|
||||||
@@ -278,7 +277,7 @@ void CompilerOptionsBuilder::addMsvcExceptions()
|
|||||||
{
|
{
|
||||||
if (!m_clStyle)
|
if (!m_clStyle)
|
||||||
return;
|
return;
|
||||||
if (Utils::anyOf(m_projectPart.toolChainMacros, [](const ProjectExplorer::Macro ¯o) {
|
if (Utils::anyOf(m_projectPart.toolChainMacros, [](const Macro ¯o) {
|
||||||
return macro.key == "_CPPUNWIND";
|
return macro.key == "_CPPUNWIND";
|
||||||
})) {
|
})) {
|
||||||
enableExceptions();
|
enableExceptions();
|
||||||
@@ -291,7 +290,7 @@ void CompilerOptionsBuilder::enableExceptions()
|
|||||||
// This is most likely due to incomplete exception support of clang.
|
// This is most likely due to incomplete exception support of clang.
|
||||||
// However, as we need exception support only in the frontend,
|
// However, as we need exception support only in the frontend,
|
||||||
// enabling them explicitly should be fine.
|
// enabling them explicitly should be fine.
|
||||||
if (m_projectPart.languageVersion > ::Utils::LanguageVersion::LatestC)
|
if (m_projectPart.languageVersion > LanguageVersion::LatestC)
|
||||||
add("-fcxx-exceptions");
|
add("-fcxx-exceptions");
|
||||||
add("-fexceptions");
|
add("-fexceptions");
|
||||||
}
|
}
|
||||||
@@ -347,9 +346,6 @@ void CompilerOptionsBuilder::addHeaderPathOptions()
|
|||||||
|
|
||||||
filter.process();
|
filter.process();
|
||||||
|
|
||||||
using ProjectExplorer::HeaderPath;
|
|
||||||
using ProjectExplorer::HeaderPathType;
|
|
||||||
|
|
||||||
for (const HeaderPath &headerPath : qAsConst(filter.userHeaderPaths))
|
for (const HeaderPath &headerPath : qAsConst(filter.userHeaderPaths))
|
||||||
addIncludeDirOptionForPath(headerPath);
|
addIncludeDirOptionForPath(headerPath);
|
||||||
for (const HeaderPath &headerPath : qAsConst(filter.systemHeaderPaths))
|
for (const HeaderPath &headerPath : qAsConst(filter.systemHeaderPaths))
|
||||||
@@ -410,11 +406,11 @@ void CompilerOptionsBuilder::addProjectMacros()
|
|||||||
addMacros(m_projectPart.projectMacros);
|
addMacros(m_projectPart.projectMacros);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addMacros(const ProjectExplorer::Macros ¯os)
|
void CompilerOptionsBuilder::addMacros(const Macros ¯os)
|
||||||
{
|
{
|
||||||
QStringList options;
|
QStringList options;
|
||||||
|
|
||||||
for (const ProjectExplorer::Macro ¯o : macros) {
|
for (const Macro ¯o : macros) {
|
||||||
if (excludeDefineDirective(macro))
|
if (excludeDefineDirective(macro))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -447,8 +443,7 @@ void CompilerOptionsBuilder::updateFileLanguage(ProjectFile::Kind fileKind)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool objcExt = m_projectPart.languageExtensions
|
const bool objcExt = m_projectPart.languageExtensions & LanguageExtension::ObjectiveC;
|
||||||
& Utils::LanguageExtension::ObjectiveC;
|
|
||||||
const QStringList options = createLanguageOptionGcc(fileKind, objcExt);
|
const QStringList options = createLanguageOptionGcc(fileKind, objcExt);
|
||||||
if (options.isEmpty())
|
if (options.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -463,9 +458,6 @@ void CompilerOptionsBuilder::updateFileLanguage(ProjectFile::Kind fileKind)
|
|||||||
|
|
||||||
void CompilerOptionsBuilder::addLanguageVersionAndExtensions()
|
void CompilerOptionsBuilder::addLanguageVersionAndExtensions()
|
||||||
{
|
{
|
||||||
using Utils::LanguageExtension;
|
|
||||||
using Utils::LanguageVersion;
|
|
||||||
|
|
||||||
if (m_compilerFlags.isLanguageVersionSpecified)
|
if (m_compilerFlags.isLanguageVersionSpecified)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -493,7 +485,7 @@ void CompilerOptionsBuilder::addLanguageVersionAndExtensions()
|
|||||||
// Continue in case no cl-style option could be chosen.
|
// Continue in case no cl-style option could be chosen.
|
||||||
}
|
}
|
||||||
|
|
||||||
const Utils::LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
const LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
||||||
const bool gnuExtensions = languageExtensions & LanguageExtension::Gnu;
|
const bool gnuExtensions = languageExtensions & LanguageExtension::Gnu;
|
||||||
|
|
||||||
switch (m_projectPart.languageVersion) {
|
switch (m_projectPart.languageVersion) {
|
||||||
@@ -542,9 +534,9 @@ static QByteArray toMsCompatibilityVersionFormat(const QByteArray &mscFullVer)
|
|||||||
+ mscFullVer.mid(2, 2);
|
+ mscFullVer.mid(2, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QByteArray msCompatibilityVersionFromDefines(const ProjectExplorer::Macros ¯os)
|
static QByteArray msCompatibilityVersionFromDefines(const Macros ¯os)
|
||||||
{
|
{
|
||||||
for (const ProjectExplorer::Macro ¯o : macros) {
|
for (const Macro ¯o : macros) {
|
||||||
if (macro.key == "_MSC_FULL_VER")
|
if (macro.key == "_MSC_FULL_VER")
|
||||||
return toMsCompatibilityVersionFormat(macro.value);
|
return toMsCompatibilityVersionFormat(macro.value);
|
||||||
}
|
}
|
||||||
@@ -652,18 +644,18 @@ void CompilerOptionsBuilder::addDefineFunctionMacrosMsvc()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerOptionsBuilder::addIncludeDirOptionForPath(const ProjectExplorer::HeaderPath &path)
|
void CompilerOptionsBuilder::addIncludeDirOptionForPath(const HeaderPath &path)
|
||||||
{
|
{
|
||||||
if (path.type == ProjectExplorer::HeaderPathType::Framework) {
|
if (path.type == HeaderPathType::Framework) {
|
||||||
QTC_ASSERT(!isClStyle(), return;);
|
QTC_ASSERT(!isClStyle(), return;);
|
||||||
add({"-F", QDir::toNativeSeparators(path.path)});
|
add({"-F", QDir::toNativeSeparators(path.path)});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool systemPath = false;
|
bool systemPath = false;
|
||||||
if (path.type == ProjectExplorer::HeaderPathType::BuiltIn) {
|
if (path.type == HeaderPathType::BuiltIn) {
|
||||||
systemPath = true;
|
systemPath = true;
|
||||||
} else if (path.type == ProjectExplorer::HeaderPathType::System) {
|
} else if (path.type == HeaderPathType::System) {
|
||||||
if (m_useSystemHeader == UseSystemHeader::Yes)
|
if (m_useSystemHeader == UseSystemHeader::Yes)
|
||||||
systemPath = true;
|
systemPath = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -682,7 +674,7 @@ void CompilerOptionsBuilder::addIncludeDirOptionForPath(const ProjectExplorer::H
|
|||||||
add({includeUserPathOption, QDir::toNativeSeparators(path.path)});
|
add({includeUserPathOption, QDir::toNativeSeparators(path.path)});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro ¯o) const
|
bool CompilerOptionsBuilder::excludeDefineDirective(const Macro ¯o) const
|
||||||
{
|
{
|
||||||
// Avoid setting __cplusplus & co as this might conflict with other command line flags.
|
// Avoid setting __cplusplus & co as this might conflict with other command line flags.
|
||||||
// Clang should set __cplusplus based on -std= and -fms-compatibility-version version.
|
// Clang should set __cplusplus based on -std= and -fms-compatibility-version version.
|
||||||
@@ -726,7 +718,7 @@ bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro
|
|||||||
|
|
||||||
QStringList CompilerOptionsBuilder::wrappedQtHeadersIncludePath() const
|
QStringList CompilerOptionsBuilder::wrappedQtHeadersIncludePath() const
|
||||||
{
|
{
|
||||||
if (m_projectPart.qtVersion == Utils::QtVersion::None)
|
if (m_projectPart.qtVersion == QtVersion::None)
|
||||||
return {};
|
return {};
|
||||||
return {"wrappedQtHeaders", "wrappedQtHeaders/QtCore"};
|
return {"wrappedQtHeaders", "wrappedQtHeaders/QtCore"};
|
||||||
}
|
}
|
||||||
@@ -782,7 +774,7 @@ void CompilerOptionsBuilder::evaluateCompilerFlags()
|
|||||||
qgetenv("QTC_CLANG_CMD_OPTIONS_BLACKLIST"))
|
qgetenv("QTC_CLANG_CMD_OPTIONS_BLACKLIST"))
|
||||||
.split(';', Qt::SkipEmptyParts);
|
.split(';', Qt::SkipEmptyParts);
|
||||||
|
|
||||||
const Utils::Id &toolChain = m_projectPart.toolchainType;
|
const Id toolChain = m_projectPart.toolchainType;
|
||||||
bool containsDriverMode = false;
|
bool containsDriverMode = false;
|
||||||
bool skipNext = false;
|
bool skipNext = false;
|
||||||
const QStringList allFlags = m_projectPart.compilerFlags + m_projectPart.extraCodeModelFlags;
|
const QStringList allFlags = m_projectPart.compilerFlags + m_projectPart.extraCodeModelFlags;
|
||||||
|
@@ -80,11 +80,11 @@ static FilePath fallbackClangdFilePath()
|
|||||||
return "clangd";
|
return "clangd";
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utils::Id clangDiagnosticConfigIdFromSettings(QSettings *s)
|
static Id clangDiagnosticConfigIdFromSettings(QSettings *s)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(s->group() == QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP), return Utils::Id());
|
QTC_ASSERT(s->group() == QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP), return Id());
|
||||||
|
|
||||||
return Utils::Id::fromSetting(
|
return Id::fromSetting(
|
||||||
s->value(clangDiagnosticConfigKey(), initialClangDiagnosticConfigId().toSetting()));
|
s->value(clangDiagnosticConfigKey(), initialClangDiagnosticConfigId().toSetting()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ static ClangDiagnosticConfigs removedBuiltinConfigs()
|
|||||||
return configs;
|
return configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ClangDiagnosticConfig convertToCustomConfig(const Utils::Id &id)
|
static ClangDiagnosticConfig convertToCustomConfig(const Id &id)
|
||||||
{
|
{
|
||||||
const ClangDiagnosticConfig config
|
const ClangDiagnosticConfig config
|
||||||
= Utils::findOrDefault(removedBuiltinConfigs(), [id](const ClangDiagnosticConfig &config) {
|
= Utils::findOrDefault(removedBuiltinConfigs(), [id](const ClangDiagnosticConfig &config) {
|
||||||
@@ -151,7 +151,7 @@ void CppCodeModelSettings::fromSettings(QSettings *s)
|
|||||||
|
|
||||||
// Qt Creator 4.11 removes some built-in configs.
|
// Qt Creator 4.11 removes some built-in configs.
|
||||||
bool write = false;
|
bool write = false;
|
||||||
const Utils::Id id = m_clangDiagnosticConfigId;
|
const Id id = m_clangDiagnosticConfigId;
|
||||||
if (id == "Builtin.Pedantic" || id == "Builtin.EverythingWithExceptions") {
|
if (id == "Builtin.Pedantic" || id == "Builtin.EverythingWithExceptions") {
|
||||||
// If one of them was used, continue to use it, but convert it to a custom config.
|
// If one of them was used, continue to use it, but convert it to a custom config.
|
||||||
const ClangDiagnosticConfig customConfig = convertToCustomConfig(id);
|
const ClangDiagnosticConfig customConfig = convertToCustomConfig(id);
|
||||||
@@ -192,7 +192,7 @@ void CppCodeModelSettings::toSettings(QSettings *s)
|
|||||||
{
|
{
|
||||||
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
s->beginGroup(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP));
|
||||||
const ClangDiagnosticConfigs previousConfigs = diagnosticConfigsFromSettings(s);
|
const ClangDiagnosticConfigs previousConfigs = diagnosticConfigsFromSettings(s);
|
||||||
const Utils::Id previousConfigId = clangDiagnosticConfigIdFromSettings(s);
|
const Id previousConfigId = clangDiagnosticConfigIdFromSettings(s);
|
||||||
|
|
||||||
diagnosticConfigsToSettings(s, m_clangCustomDiagnosticConfigs);
|
diagnosticConfigsToSettings(s, m_clangCustomDiagnosticConfigs);
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ void CppCodeModelSettings::toSettings(QSettings *s)
|
|||||||
|
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
|
|
||||||
QVector<Utils::Id> invalidated
|
QVector<Id> invalidated
|
||||||
= ClangDiagnosticConfigsModel::changedOrRemovedConfigs(previousConfigs,
|
= ClangDiagnosticConfigsModel::changedOrRemovedConfigs(previousConfigs,
|
||||||
m_clangCustomDiagnosticConfigs);
|
m_clangCustomDiagnosticConfigs);
|
||||||
|
|
||||||
@@ -218,19 +218,19 @@ void CppCodeModelSettings::toSettings(QSettings *s)
|
|||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Id CppCodeModelSettings::clangDiagnosticConfigId() const
|
Id CppCodeModelSettings::clangDiagnosticConfigId() const
|
||||||
{
|
{
|
||||||
if (!diagnosticConfigsModel().hasConfigWithId(m_clangDiagnosticConfigId))
|
if (!diagnosticConfigsModel().hasConfigWithId(m_clangDiagnosticConfigId))
|
||||||
return defaultClangDiagnosticConfigId();
|
return defaultClangDiagnosticConfigId();
|
||||||
return m_clangDiagnosticConfigId;
|
return m_clangDiagnosticConfigId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCodeModelSettings::setClangDiagnosticConfigId(const Utils::Id &configId)
|
void CppCodeModelSettings::setClangDiagnosticConfigId(const Id &configId)
|
||||||
{
|
{
|
||||||
m_clangDiagnosticConfigId = configId;
|
m_clangDiagnosticConfigId = configId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Id CppCodeModelSettings::defaultClangDiagnosticConfigId()
|
Id CppCodeModelSettings::defaultClangDiagnosticConfigId()
|
||||||
{
|
{
|
||||||
return initialClangDiagnosticConfigId();
|
return initialClangDiagnosticConfigId();
|
||||||
}
|
}
|
||||||
@@ -310,7 +310,7 @@ ClangdSettings &ClangdSettings::instance()
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangdSettings::setDefaultClangdPath(const Utils::FilePath &filePath)
|
void ClangdSettings::setDefaultClangdPath(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
g_defaultClangdFilePath = filePath;
|
g_defaultClangdFilePath = filePath;
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,8 @@ void ClangdSettings::saveSettings()
|
|||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
void ClangdSettings::setUseClangd(bool use) { instance().m_data.useClangd = use; }
|
void ClangdSettings::setUseClangd(bool use) { instance().m_data.useClangd = use; }
|
||||||
void ClangdSettings::setClangdFilePath(const Utils::FilePath &filePath)
|
|
||||||
|
void ClangdSettings::setClangdFilePath(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
instance().m_data.executableFilePath = filePath;
|
instance().m_data.executableFilePath = filePath;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user