Clang: Don't reparse if the macros haven't changed

We have to extend that to include paths too, which will be happen in a
follow up patch.

Change-Id: I7f8ac663ae8588e647fc6a6b5d689a629a28ef65
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-02-07 16:18:16 +01:00
parent b5c3d5a40d
commit 0172631b48
13 changed files with 140 additions and 21 deletions

View File

@@ -18,6 +18,7 @@ HEADERS += \
$$PWD/usedmacro.h \
$$PWD/sourcedependency.h \
$$PWD/filestatus.h \
$$PWD/projectpartartefactexception.h \
$$PWD/projectpartartefact.h
!isEmpty(LIBTOOLING_LIBS) {

View File

@@ -221,6 +221,9 @@ public:
"SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)",
database
};
ReadStatement getProjectPartCompilerArgumentsAndCompilerMacrosByProjectPartName{
"SELECT compilerArguments, compilerMacros, projectPartId FROM projectParts WHERE projectPartName = ?",
database
};
};
} // namespace ClangBackEnd

View File

@@ -52,31 +52,32 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
{
m_symbolsCollector.clear();
m_symbolsCollector.addFiles(projectPart.sourcePathIds(), projectPart.arguments());
if (compilerMacrosAreDifferent(projectPart)) {
m_symbolsCollector.addFiles(projectPart.sourcePathIds(), projectPart.arguments());
m_symbolsCollector.addUnsavedFiles(generatedFiles);
m_symbolsCollector.addUnsavedFiles(generatedFiles);
m_symbolsCollector.collectSymbols();
m_symbolsCollector.collectSymbols();
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
m_symbolStorage.addSymbolsAndSourceLocations(m_symbolsCollector.symbols(),
m_symbolsCollector.sourceLocations());
m_symbolStorage.addSymbolsAndSourceLocations(m_symbolsCollector.symbols(),
m_symbolsCollector.sourceLocations());
m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId(),
projectPart.arguments(),
projectPart.compilerMacros());
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
m_symbolsCollector.sourceFiles());
m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId(),
projectPart.arguments(),
projectPart.compilerMacros());
m_symbolStorage.updateProjectPartSources(projectPart.projectPartId(),
m_symbolsCollector.sourceFiles());
m_symbolStorage.insertOrUpdateUsedMacros(m_symbolsCollector.usedMacros());
m_symbolStorage.insertOrUpdateUsedMacros(m_symbolsCollector.usedMacros());
m_symbolStorage.insertFileStatuses(m_symbolsCollector.fileStatuses());
m_symbolStorage.insertFileStatuses(m_symbolsCollector.fileStatuses());
m_symbolStorage.insertOrUpdateSourceDependencies(m_symbolsCollector.sourceDependencies());
transaction.commit();
m_symbolStorage.insertOrUpdateSourceDependencies(m_symbolsCollector.sourceDependencies());
transaction.commit();
}
}
void SymbolIndexer::pathsWithIdsChanged(const Utils::SmallStringVector &)
@@ -120,4 +121,15 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId)
}
}
bool SymbolIndexer::compilerMacrosAreDifferent(const V2::ProjectPartContainer &projectPart) const
{
const Utils::optional<ProjectPartArtefact> optionalArtefact = m_symbolStorage.fetchProjectPartArtefact(
projectPart.projectPartId());
if (optionalArtefact)
return projectPart.compilerMacros() != optionalArtefact.value().compilerMacros;
return true;
}
} // namespace ClangBackEnd

View File

@@ -52,6 +52,8 @@ public:
void pathsChanged(const FilePathIds &filePathIds) override;
void updateChangedPath(FilePathId filePath);
bool compilerMacrosAreDifferent(const V2::ProjectPartContainer &projectPart) const;
private:
SymbolsCollectorInterface &m_symbolsCollector;
SymbolStorageInterface &m_symbolStorage;

View File

@@ -91,6 +91,13 @@ public:
return statement.template value<ProjectPartArtefact, 3>(sourceId.filePathId);
}
Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const override
{
ReadStatement &statement = m_statementFactory.getProjectPartCompilerArgumentsAndCompilerMacrosByProjectPartName;
return statement.template value<ProjectPartArtefact, 3>(projectPartName);
}
void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override
{
WriteStatement &insertStatement = m_statementFactory.insertIntoNewUsedMacrosStatement;

View File

@@ -60,6 +60,7 @@ public:
virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0;
virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0;
virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const = 0;
virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const = 0;
};
} // namespace ClangBackEnd