Clang: Clear SymbolCollector before updating new project parts

Change-Id: I82e9bb4f66a7597bb911fbc97d6022ff3fdb0b35
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2017-12-13 12:04:19 +01:00
parent 3c43e5d7ec
commit ab60cfd3a4
11 changed files with 100 additions and 14 deletions

View File

@@ -56,6 +56,11 @@ public:
});
}
void clearSourceFiles()
{
m_sourceFiles.clear();
}
private:
FilePathIds m_sourceFiles;
FilePathCachingInterface &m_filePathCache;

View File

@@ -63,6 +63,12 @@ public:
return m_sourceLocationEntries;
}
void clear()
{
m_symbolEntries.clear();
m_sourceLocationEntries.clear();
}
private:
SymbolEntries m_symbolEntries;
SourceLocationEntries m_sourceLocationEntries;

View File

@@ -46,8 +46,8 @@ RefactoringCompilationDatabase::getCompileCommands(llvm::StringRef filePath) con
{
std::vector<clang::tooling::CompileCommand> foundCommands;
std::copy_if(compileCommands.begin(),
compileCommands.end(),
std::copy_if(m_compileCommands.begin(),
m_compileCommands.end(),
std::back_inserter(foundCommands),
[&] (const clang::tooling::CompileCommand &compileCommand) {
return filePath == concatFilePath(compileCommand);
@@ -60,10 +60,10 @@ std::vector<std::string>
RefactoringCompilationDatabase::getAllFiles() const
{
std::vector<std::string> filePaths;
filePaths.reserve(compileCommands.size());
filePaths.reserve(m_compileCommands.size());
std::transform(compileCommands.begin(),
compileCommands.end(),
std::transform(m_compileCommands.begin(),
m_compileCommands.end(),
std::back_inserter(filePaths),
[&] (const clang::tooling::CompileCommand &compileCommand) {
return concatFilePath(compileCommand);
@@ -75,7 +75,7 @@ RefactoringCompilationDatabase::getAllFiles() const
std::vector<clang::tooling::CompileCommand>
RefactoringCompilationDatabase::getAllCompileCommands() const
{
return compileCommands;
return m_compileCommands;
}
void RefactoringCompilationDatabase::addFile(const std::string &directory,
@@ -83,7 +83,7 @@ void RefactoringCompilationDatabase::addFile(const std::string &directory,
const std::vector<std::string> &commandLine)
{
compileCommands.emplace_back(directory, fileName, commandLine, llvm::StringRef());
m_compileCommands.emplace_back(directory, fileName, commandLine, llvm::StringRef());
}
} // namespace ClangBackEnd

View File

@@ -58,7 +58,7 @@ public:
const std::vector<std::string> &commandLine);
private:
std::vector<clang::tooling::CompileCommand> compileCommands;
std::vector<clang::tooling::CompileCommand> m_compileCommands;
};
} // namespace ClangBackEnd

View File

@@ -39,6 +39,8 @@ SymbolIndexer::SymbolIndexer(SymbolsCollectorInterface &symbolsCollector,
void SymbolIndexer::updateProjectParts(V2::ProjectPartContainers &&projectParts,
V2::FileContainers &&generatedFiles)
{
m_symbolsCollector.clear();
for (const V2::ProjectPartContainer &projectPart : projectParts)
m_symbolsCollector.addFiles(projectPart.sourcePaths(), projectPart.arguments());

View File

@@ -35,18 +35,26 @@ SymbolsCollector::SymbolsCollector(FilePathCachingInterface &filePathCache)
void SymbolsCollector::addFiles(const Utils::PathStringVector &filePaths, const Utils::SmallStringVector &arguments)
{
ClangTool::addFiles(filePaths, arguments);
m_clangTool.addFiles(filePaths, arguments);
m_collectMacrosSourceFileCallbacks.addSourceFiles(filePaths);
}
void SymbolsCollector::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
{
ClangTool::addUnsavedFiles(unsavedFiles);
m_clangTool.addUnsavedFiles(unsavedFiles);
}
void SymbolsCollector::clear()
{
m_collectMacrosSourceFileCallbacks.clearSourceFiles();
m_collectSymbolsAction.clear();
m_clangTool = ClangTool();
}
void SymbolsCollector::collectSymbols()
{
auto tool = createTool();
auto tool = m_clangTool.createTool();
tool.run(clang::tooling::newFrontendActionFactory(&m_collectSymbolsAction,
&m_collectMacrosSourceFileCallbacks).get());

View File

@@ -35,7 +35,7 @@
namespace ClangBackEnd {
class SymbolsCollector : public ClangTool, public SymbolsCollectorInterface
class SymbolsCollector : public SymbolsCollectorInterface
{
public:
SymbolsCollector(FilePathCachingInterface &filePathCache);
@@ -45,6 +45,8 @@ public:
void addUnsavedFiles(const V2::FileContainers &unsavedFiles) override;
void clear() override;
void collectSymbols() override;
const SymbolEntries &symbols() const override;
@@ -52,6 +54,7 @@ public:
const FilePathIds &sourceFiles() const override;
private:
ClangTool m_clangTool;
CollectSymbolsAction m_collectSymbolsAction;
CollectMacrosSourceFileCallbacks m_collectMacrosSourceFileCallbacks;
};

View File

@@ -45,6 +45,8 @@ public:
virtual void addUnsavedFiles(const V2::FileContainers &unsavedFiles) = 0;
virtual void clear() = 0;
virtual void collectSymbols() = 0;
virtual const SymbolEntries &symbols() const = 0;