Clang: Use reference instead of pointer in editor processor

...because the pointer can't be null.

Change-Id: I318f5d7ff2d2ac7de188718ec6281b083965dfd4
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-01-22 09:18:37 +01:00
parent 193e3de80a
commit b31978a2f7
2 changed files with 21 additions and 30 deletions

View File

@@ -405,7 +405,7 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPartInfo().projectPart; const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPartInfo().projectPart;
if (isProjectPartLoadedOrIsFallback(projectPart)) { if (isProjectPartLoadedOrIsFallback(projectPart)) {
registerTranslationUnitForEditor(projectPart.data()); registerTranslationUnitForEditor(*projectPart.data());
m_projectPart = projectPart; m_projectPart = projectPart;
m_isProjectFile = m_parser->projectPartInfo().hints m_isProjectFile = m_parser->projectPartInfo().hints
@@ -421,7 +421,8 @@ void ClangEditorDocumentProcessor::onParserFinished()
updateProjectPartAndTranslationUnitForEditor(); updateProjectPartAndTranslationUnitForEditor();
} }
void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart) void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(
CppTools::ProjectPart &projectPart)
{ {
// On registration we send the document content immediately as an unsaved // On registration we send the document content immediately as an unsaved
// file, because // file, because
@@ -433,7 +434,7 @@ void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::Pr
// like on Windows. // like on Windows.
if (m_projectPart) { if (m_projectPart) {
if (projectPart->id() == m_projectPart->id()) if (projectPart.id() == m_projectPart->id())
return; return;
} }
@@ -503,35 +504,26 @@ ClangBackEnd::FileContainer ClangEditorDocumentProcessor::simpleFileContainer(
Utf8String::fromByteArray(codecName)); Utf8String::fromByteArray(codecName));
} }
static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart *projectPart) static QStringList languageOptions(const QString &filePath, CppTools::ProjectPart &projectPart)
{ {
if (projectPart)
return *projectPart;
return *CppTools::CppModelManager::instance()->fallbackProjectPart().data();
}
static QStringList languageOptions(const QString &filePath, CppTools::ProjectPart *projectPart)
{
const auto theProjectPart = projectPartForLanguageOption(projectPart);
// Determine file kind with respect to ambiguous headers. // Determine file kind with respect to ambiguous headers.
CppTools::ProjectFile::Kind fileKind = CppTools::ProjectFile::classify(filePath); CppTools::ProjectFile::Kind fileKind = CppTools::ProjectFile::classify(filePath);
if (fileKind == CppTools::ProjectFile::AmbiguousHeader) { if (fileKind == CppTools::ProjectFile::AmbiguousHeader) {
fileKind = theProjectPart.languageVersion <= CppTools::ProjectPart::LatestCVersion fileKind = projectPart.languageVersion <= CppTools::ProjectPart::LatestCVersion
? CppTools::ProjectFile::CHeader ? CppTools::ProjectFile::CHeader
: CppTools::ProjectFile::CXXHeader; : CppTools::ProjectFile::CXXHeader;
} }
CppTools::CompilerOptionsBuilder builder(theProjectPart); CppTools::CompilerOptionsBuilder builder(projectPart);
builder.addLanguageOption(fileKind); builder.addLanguageOption(fileKind);
return builder.options(); return builder.options();
} }
static QStringList warningOptions(CppTools::ProjectPart *projectPart) static QStringList warningOptions(CppTools::ProjectPart &projectPart)
{ {
if (projectPart && projectPart->project) { if (projectPart.project) {
ClangProjectSettings projectSettings(projectPart->project); ClangProjectSettings projectSettings(projectPart.project);
if (!projectSettings.useGlobalConfig()) { if (!projectSettings.useGlobalConfig()) {
const Core::Id warningConfigId = projectSettings.warningConfigId(); const Core::Id warningConfigId = projectSettings.warningConfigId();
const CppTools::ClangDiagnosticConfigsModel configsModel( const CppTools::ClangDiagnosticConfigsModel configsModel(
@@ -581,13 +573,13 @@ static QStringList clazyCommandLine()
return result; return result;
} }
static QStringList commandLineOptions(CppTools::ProjectPart *projectPart) static QStringList commandLineOptions(CppTools::ProjectPart &projectPart)
{ {
QStringList result; QStringList result;
if (!projectPart || !projectPart->project) if (!projectPart.project)
result.append(ClangProjectSettings::globalCommandLineOptions()); result.append(ClangProjectSettings::globalCommandLineOptions());
else else
result.append(ClangProjectSettings{projectPart->project}.commandLineOptions()); result.append(ClangProjectSettings{projectPart.project}.commandLineOptions());
result.append(tidyCommandLine()); result.append(tidyCommandLine());
result.append(clazyCommandLine()); result.append(clazyCommandLine());
return result; return result;
@@ -595,24 +587,23 @@ static QStringList commandLineOptions(CppTools::ProjectPart *projectPart)
static QStringList precompiledHeaderOptions( static QStringList precompiledHeaderOptions(
const QString& filePath, const QString& filePath,
CppTools::ProjectPart *projectPart) CppTools::ProjectPart &projectPart)
{ {
using namespace CppTools; using namespace CppTools;
if (CppTools::getPchUsage() == CompilerOptionsBuilder::PchUsage::None) if (CppTools::getPchUsage() == CompilerOptionsBuilder::PchUsage::None)
return QStringList(); return QStringList();
if (projectPart->precompiledHeaders.contains(filePath)) if (projectPart.precompiledHeaders.contains(filePath))
return QStringList(); return QStringList();
const CppTools::ProjectPart theProjectPart = projectPartForLanguageOption(projectPart); CppTools::CompilerOptionsBuilder builder(projectPart);
CppTools::CompilerOptionsBuilder builder(theProjectPart);
builder.addPrecompiledHeaderOptions(CompilerOptionsBuilder::PchUsage::Use); builder.addPrecompiledHeaderOptions(CompilerOptionsBuilder::PchUsage::Use);
return builder.options(); return builder.options();
} }
static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart *projectPart) static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart &projectPart)
{ {
return languageOptions(filePath, projectPart) return languageOptions(filePath, projectPart)
+ warningOptions(projectPart) + warningOptions(projectPart)
@@ -622,12 +613,12 @@ static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart
ClangBackEnd::FileContainer ClangBackEnd::FileContainer
ClangEditorDocumentProcessor::fileContainerWithArgumentsAndDocumentContent( ClangEditorDocumentProcessor::fileContainerWithArgumentsAndDocumentContent(
CppTools::ProjectPart *projectPart) const CppTools::ProjectPart &projectPart) const
{ {
const QStringList theFileArguments = fileArguments(filePath(), projectPart); const QStringList theFileArguments = fileArguments(filePath(), projectPart);
return ClangBackEnd::FileContainer(filePath(), return ClangBackEnd::FileContainer(filePath(),
projectPart->id(), projectPart.id(),
Utf8StringVector(theFileArguments), Utf8StringVector(theFileArguments),
textDocument()->toPlainText(), textDocument()->toPlainText(),
true, true,

View File

@@ -104,14 +104,14 @@ public:
private: private:
void onParserFinished(); void onParserFinished();
void updateProjectPartAndTranslationUnitForEditor(); void updateProjectPartAndTranslationUnitForEditor();
void registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart); void registerTranslationUnitForEditor(CppTools::ProjectPart &projectPart);
void updateTranslationUnitIfProjectPartExists(); void updateTranslationUnitIfProjectPartExists();
void requestDocumentAnnotations(const QString &projectpartId); void requestDocumentAnnotations(const QString &projectpartId);
HeaderErrorDiagnosticWidgetCreator creatorForHeaderErrorDiagnosticWidget( HeaderErrorDiagnosticWidgetCreator creatorForHeaderErrorDiagnosticWidget(
const ClangBackEnd::DiagnosticContainer &firstHeaderErrorDiagnostic); const ClangBackEnd::DiagnosticContainer &firstHeaderErrorDiagnostic);
ClangBackEnd::FileContainer simpleFileContainer(const QByteArray &codecName = QByteArray()) const; ClangBackEnd::FileContainer simpleFileContainer(const QByteArray &codecName = QByteArray()) const;
ClangBackEnd::FileContainer fileContainerWithArgumentsAndDocumentContent( ClangBackEnd::FileContainer fileContainerWithArgumentsAndDocumentContent(
CppTools::ProjectPart *projectPart) const; CppTools::ProjectPart &projectPart) const;
ClangBackEnd::FileContainer fileContainerWithDocumentContent(const QString &projectpartId) const; ClangBackEnd::FileContainer fileContainerWithDocumentContent(const QString &projectpartId) const;
private: private: