aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2019-05-23 18:32:47 +0200
committerMarco Bubke <marco.bubke@qt.io>2019-06-17 10:49:49 +0000
commitee27ae2ef78692b29d26c466c519f4318526a7a4 (patch)
tree2ebb99780af3335260d33f2eaf6f1f9a49745a7f /src/tools
parentb36e9d0e95f53fdebcf63f79060c0ebff42d0bf2 (diff)
ClangRefactoring: Improve indexing
Fix some bugs in the indexing and use the new macro indexer from clang. Change-Id: I2ba1b28097a8751aea942071851a60d164c6f371 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp3
-rw-r--r--src/tools/clangpchmanagerbackend/source/builddependencycollector.h1
-rw-r--r--src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h18
-rw-r--r--src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h3
-rw-r--r--src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h16
-rw-r--r--src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h4
-rw-r--r--src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h4
-rw-r--r--src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h15
-rw-r--r--src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp1
-rw-r--r--src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h1
-rw-r--r--src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri2
-rw-r--r--src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h19
-rw-r--r--src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp19
-rw-r--r--src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h11
-rw-r--r--src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp3
-rw-r--r--src/tools/clangrefactoringbackend/source/collectsymbolsaction.h67
-rw-r--r--src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp59
-rw-r--r--src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h59
-rw-r--r--src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp102
-rw-r--r--src/tools/clangrefactoringbackend/source/indexdataconsumer.h29
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollector.cpp103
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollector.h8
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h3
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h43
24 files changed, 368 insertions, 225 deletions
diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp
index 2bd0b87af0..b2c6cf8f86 100644
--- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp
+++ b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp
@@ -129,8 +129,7 @@ void BuildDependencyCollector::collect()
auto action = std::make_unique<CollectBuildDependencyToolAction>(m_buildDependency,
m_filePathCache,
- m_excludedFilePaths,
- m_sourcesManager);
+ m_excludedFilePaths);
tool.run(action.get());
}
diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.h b/src/tools/clangpchmanagerbackend/source/builddependencycollector.h
index f8aaa8f07c..084024c821 100644
--- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.h
+++ b/src/tools/clangpchmanagerbackend/source/builddependencycollector.h
@@ -95,7 +95,6 @@ private:
BuildDependency m_buildDependency;
ClangBackEnd::FilePaths m_excludedFilePaths;
Utils::SmallStringVector m_directories;
- SourcesManager m_sourcesManager;
const FilePathCachingInterface &m_filePathCache;
const GeneratedFilesInterface &m_generatedFiles;
const Environment &m_environment;
diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h
index fa1a10e79c..3e98dc2483 100644
--- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h
+++ b/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h
@@ -40,15 +40,13 @@ class CollectBuildDependencyAction final : public clang::PreprocessOnlyAction
{
public:
CollectBuildDependencyAction(BuildDependency &buildDependency,
- const FilePathCachingInterface &filePathCache,
- std::vector<uint> &excludedIncludeUID,
- std::vector<uint> &alreadyIncludedFileUIDs,
- SourcesManager &sourcesManager)
- : m_buildDependency(buildDependency),
- m_filePathCache(filePathCache),
- m_excludedIncludeUID(excludedIncludeUID),
- m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs),
- m_sourcesManager(sourcesManager)
+ const FilePathCachingInterface &filePathCache,
+ std::vector<uint> &excludedIncludeUID,
+ std::vector<uint> &alreadyIncludedFileUIDs)
+ : m_buildDependency(buildDependency)
+ , m_filePathCache(filePathCache)
+ , m_excludedIncludeUID(excludedIncludeUID)
+ , m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs)
{
}
@@ -66,7 +64,6 @@ public:
m_excludedIncludeUID,
m_alreadyIncludedFileUIDs,
compilerInstance.getSourceManager(),
- m_sourcesManager,
compilerInstance.getPreprocessorPtr());
preprocessor.addPPCallbacks(
@@ -88,7 +85,6 @@ private:
const FilePathCachingInterface &m_filePathCache;
std::vector<uint> &m_excludedIncludeUID;
std::vector<uint> &m_alreadyIncludedFileUIDs;
- SourcesManager &m_sourcesManager;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h
index 9db095bd75..8583ff7a15 100644
--- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h
+++ b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h
@@ -54,12 +54,10 @@ public:
const std::vector<uint> &excludedIncludeUID,
std::vector<uint> &alreadyIncludedFileUIDs,
clang::SourceManager &sourceManager,
- SourcesManager &sourcesManager,
std::shared_ptr<clang::Preprocessor> preprocessor)
: CollectUsedMacrosAndSourcesPreprocessorCallbacksBase(buildDependency.usedMacros,
filePathCache,
sourceManager,
- sourcesManager,
preprocessor,
buildDependency.sourceDependencies,
buildDependency.sourceFiles,
@@ -189,7 +187,6 @@ public:
{
filterOutHeaderGuards();
mergeUsedMacros();
- m_sourcesManager.updateModifiedTimeStamps();
filterOutIncludesWithMissingIncludes();
}
diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h
index 4f28d0f7c8..471291ee90 100644
--- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h
+++ b/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h
@@ -38,13 +38,11 @@ class CollectBuildDependencyToolAction final : public clang::tooling::FrontendAc
{
public:
CollectBuildDependencyToolAction(BuildDependency &buildDependency,
- const FilePathCachingInterface &filePathCache,
- const ClangBackEnd::FilePaths &excludedIncludes,
- SourcesManager &sourcesManager)
- : m_buildDependency(buildDependency),
- m_filePathCache(filePathCache),
- m_excludedFilePaths(excludedIncludes),
- m_sourcesManager(sourcesManager)
+ const FilePathCachingInterface &filePathCache,
+ const ClangBackEnd::FilePaths &excludedIncludes)
+ : m_buildDependency(buildDependency)
+ , m_filePathCache(filePathCache)
+ , m_excludedFilePaths(excludedIncludes)
{}
@@ -67,8 +65,7 @@ public:
return new CollectBuildDependencyAction(m_buildDependency,
m_filePathCache,
m_excludedIncludeUIDs,
- m_alreadyIncludedFileUIDs,
- m_sourcesManager);
+ m_alreadyIncludedFileUIDs);
}
std::vector<uint> generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const
@@ -95,7 +92,6 @@ private:
BuildDependency &m_buildDependency;
const FilePathCachingInterface &m_filePathCache;
const ClangBackEnd::FilePaths &m_excludedFilePaths;
- SourcesManager &m_sourcesManager;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h b/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h
index b3f1cc0029..423d5f8876 100644
--- a/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h
+++ b/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h
@@ -39,13 +39,11 @@ class CollectUsedMacrosToolActionFactory final : public clang::tooling::Frontend
public:
CollectUsedMacrosToolActionFactory(UsedMacros &usedMacros,
FilePathCachingInterface &filePathCache,
- SourcesManager &sourcesManager,
SourceDependencies &sourceDependencies,
FilePathIds &sourceFiles,
FileStatuses &fileStatuses)
: m_usedMacros(usedMacros),
m_filePathCache(filePathCache),
- m_sourcesManager(sourcesManager),
m_sourceDependencies(sourceDependencies),
m_sourceFiles(sourceFiles),
m_fileStatuses(fileStatuses)
@@ -67,7 +65,6 @@ public:
{
return new CollectUsedMacrosAction(m_usedMacros,
m_filePathCache,
- m_sourcesManager,
m_sourceDependencies,
m_sourceFiles,
m_fileStatuses);
@@ -76,7 +73,6 @@ public:
private:
UsedMacros &m_usedMacros;
FilePathCachingInterface &m_filePathCache;
- SourcesManager &m_sourcesManager;
SourceDependencies &m_sourceDependencies;
FilePathIds &m_sourceFiles;
FileStatuses &m_fileStatuses;
diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h b/src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h
index 4134d41d41..8f50e5a230 100644
--- a/src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h
+++ b/src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h
@@ -41,13 +41,11 @@ class CollectUsedMacrosAction final : public clang::PreprocessOnlyAction
public:
CollectUsedMacrosAction(UsedMacros &usedMacros,
FilePathCachingInterface &filePathCache,
- SourcesManager &sourcesManager,
SourceDependencies &sourceDependencies,
FilePathIds &sourceFiles,
FileStatuses &fileStatuses)
: m_usedMacros(usedMacros),
m_filePathCache(filePathCache),
- m_sourcesManager(sourcesManager),
m_sourceDependencies(sourceDependencies),
m_sourceFiles(sourceFiles),
m_fileStatuses(fileStatuses)
@@ -65,7 +63,6 @@ public:
m_usedMacros,
m_filePathCache,
compilerInstance.getSourceManager(),
- m_sourcesManager,
compilerInstance.getPreprocessorPtr(),
m_sourceDependencies,
m_sourceFiles,
@@ -87,7 +84,6 @@ public:
private:
UsedMacros &m_usedMacros;
FilePathCachingInterface &m_filePathCache;
- SourcesManager &m_sourcesManager;
SourceDependencies &m_sourceDependencies;
FilePathIds &m_sourceFiles;
FileStatuses &m_fileStatuses;
diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h
index b8ea406df0..5dc630de18 100644
--- a/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h
+++ b/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h
@@ -54,17 +54,16 @@ public:
CollectUsedMacrosAndSourcesPreprocessorCallbacksBase(UsedMacros &usedMacros,
const FilePathCachingInterface &filePathCache,
const clang::SourceManager &sourceManager,
- SourcesManager &sourcesManager,
std::shared_ptr<clang::Preprocessor> preprocessor,
SourceDependencies &sourceDependencies,
FilePathIds &sourceFiles,
FileStatuses &fileStatuses)
- : SymbolsVisitorBase(filePathCache, &sourceManager, sourcesManager),
- m_usedMacros(usedMacros),
- m_preprocessor(preprocessor),
- m_sourceDependencies(sourceDependencies),
- m_sourceFiles(sourceFiles),
- m_fileStatuses(fileStatuses)
+ : SymbolsVisitorBase(filePathCache, &sourceManager, m_filePathIndices)
+ , m_usedMacros(usedMacros)
+ , m_preprocessor(preprocessor)
+ , m_sourceDependencies(sourceDependencies)
+ , m_sourceFiles(sourceFiles)
+ , m_fileStatuses(fileStatuses)
{}
void addSourceFile(const clang::FileEntry *fileEntry)
@@ -166,6 +165,7 @@ public:
private:
UsedMacros m_maybeUsedMacros;
+ FilePathIds m_filePathIndices;
UsedMacros &m_usedMacros;
std::shared_ptr<clang::Preprocessor> m_preprocessor;
SourceDependencies &m_sourceDependencies;
@@ -248,7 +248,6 @@ public:
{
filterOutHeaderGuards();
mergeUsedMacros();
- m_sourcesManager.updateModifiedTimeStamps();
}
private:
diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp b/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp
index b26b2b801c..770d46f5e1 100644
--- a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp
+++ b/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp
@@ -48,7 +48,6 @@ void UsedMacroAndSourcesCollector::collect()
auto action = std::make_unique<CollectUsedMacrosToolActionFactory>(
m_usedMacros,
m_filePathCache,
- m_sourcesManager,
m_sourceDependencies,
m_sourceFiles,
m_fileStatuses);
diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h b/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h
index a5b5749c12..9b72201fbb 100644
--- a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h
+++ b/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h
@@ -74,7 +74,6 @@ public:
private:
ClangTool m_clangTool;
- SourcesManager m_sourcesManager;
UsedMacros m_usedMacros;
FilePathCachingInterface &m_filePathCache;
FilePathIds m_sourceFiles;
diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri
index fcac51f226..e7e83da788 100644
--- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri
+++ b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri
@@ -2,6 +2,7 @@ INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/clangrefactoringbackend_global.h \
+ $$PWD/filestatuspreprocessorcallbacks.h \
$$PWD/sourcerangefilter.h \
$$PWD/symbolindexer.h \
$$PWD/symbolentry.h \
@@ -64,6 +65,7 @@ HEADERS += \
}
SOURCES += \
+ $$PWD/filestatuspreprocessorcallbacks.cpp \
$$PWD/sourcerangefilter.cpp \
$$PWD/symbolindexer.cpp \
$$PWD/filestatuscache.cpp
diff --git a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h
index 1d16b0f5e1..b0d59607e2 100644
--- a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h
+++ b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h
@@ -56,18 +56,16 @@ public:
SourceDependencies &sourceDependencies,
FilePathCachingInterface &filePathCache,
const clang::SourceManager &sourceManager,
- std::shared_ptr<clang::Preprocessor> &&preprocessor,
- SourcesManager &sourcesManager)
+ std::shared_ptr<clang::Preprocessor> &&preprocessor)
: CollectUsedMacrosAndSourcesPreprocessorCallbacksBase(usedMacros,
filePathCache,
sourceManager,
- sourcesManager,
std::move(preprocessor),
sourceDependencies,
sourceFiles,
- fileStatuses),
- m_symbolEntries(symbolEntries),
- m_sourceLocationEntries(sourceLocationEntries)
+ fileStatuses)
+ , m_symbolEntries(symbolEntries)
+ , m_sourceLocationEntries(sourceLocationEntries)
{
}
@@ -88,17 +86,15 @@ public:
}
void InclusionDirective(clang::SourceLocation hashLocation,
- const clang::Token &/*includeToken*/,
+ const clang::Token & /*includeToken*/,
llvm::StringRef /*fileName*/,
bool /*isAngled*/,
clang::CharSourceRange /*fileNameRange*/,
const clang::FileEntry *file,
llvm::StringRef /*searchPath*/,
llvm::StringRef /*relativePath*/,
- const clang::Module * /*imported*/
-#if LLVM_VERSION_MAJOR >= 7
- , clang::SrcMgr::CharacteristicKind /*fileType*/
-#endif
+ const clang::Module * /*imported*/,
+ clang::SrcMgr::CharacteristicKind /*fileType*/
) override
{
if (!m_skipInclude && file)
@@ -174,7 +170,6 @@ public:
{
filterOutHeaderGuards();
mergeUsedMacros();
- m_sourcesManager.updateModifiedTimeStamps();
}
static const clang::MacroInfo *firstMacroInfo(const clang::MacroDirective *macroDirective)
diff --git a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp b/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp
index d96fb05026..d360b727c4 100644
--- a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp
+++ b/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp
@@ -34,16 +34,15 @@ namespace ClangBackEnd {
bool CollectMacrosSourceFileCallbacks::handleBeginSource(clang::CompilerInstance &compilerInstance)
{
auto callbacks = std::make_unique<CollectMacrosPreprocessorCallbacks>(
- m_symbolEntries,
- m_sourceLocationEntries,
- m_sourceFiles,
- m_usedMacros,
- m_fileStatuses,
- m_sourceDependencies,
- m_filePathCache,
- compilerInstance.getSourceManager(),
- compilerInstance.getPreprocessorPtr(),
- m_sourcesManager);
+ m_symbolEntries,
+ m_sourceLocationEntries,
+ m_sourceFiles,
+ m_usedMacros,
+ m_fileStatuses,
+ m_sourceDependencies,
+ m_filePathCache,
+ compilerInstance.getSourceManager(),
+ compilerInstance.getPreprocessorPtr());
compilerInstance.getPreprocessorPtr()->addPPCallbacks(std::move(callbacks));
diff --git a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h b/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h
index 2392238106..16ba5a4f53 100644
--- a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h
+++ b/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h
@@ -44,12 +44,10 @@ class CollectMacrosSourceFileCallbacks : public clang::tooling::SourceFileCallba
public:
CollectMacrosSourceFileCallbacks(SymbolEntries &symbolEntries,
SourceLocationEntries &sourceLocationEntries,
- FilePathCachingInterface &filePathCache,
- SourcesManager &sourcesManager)
- : m_symbolEntries(symbolEntries),
- m_sourceLocationEntries(sourceLocationEntries),
- m_filePathCache(filePathCache),
- m_sourcesManager(sourcesManager)
+ FilePathCachingInterface &filePathCache)
+ : m_symbolEntries(symbolEntries)
+ , m_sourceLocationEntries(sourceLocationEntries)
+ , m_filePathCache(filePathCache)
{
}
@@ -96,7 +94,6 @@ private:
SymbolEntries &m_symbolEntries;
SourceLocationEntries &m_sourceLocationEntries;
FilePathCachingInterface &m_filePathCache;
- SourcesManager &m_sourcesManager;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp
index 91c0dd28d8..301f50beae 100644
--- a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp
+++ b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp
@@ -33,8 +33,7 @@ std::unique_ptr<clang::ASTConsumer> CollectSymbolsAction::newASTConsumer(
clang::CompilerInstance &compilerInstance,
llvm::StringRef inFile)
{
- m_indexDataConsumer->setSourceManager(&compilerInstance.getSourceManager());
- return m_action.CreateASTConsumer(compilerInstance, inFile);
+ return clang::WrapperFrontendAction::CreateASTConsumer(compilerInstance, inFile);
}
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h
index 2074a25a6e..a38f1c4f87 100644
--- a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h
+++ b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h
@@ -26,8 +26,8 @@
#pragma once
#include "clangrefactoringbackend_global.h"
-#include "sourcelocationentry.h"
#include "indexdataconsumer.h"
+#include "sourcelocationentry.h"
#include "symbolentry.h"
#include <utils/smallstring.h>
@@ -37,53 +37,68 @@
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/FrontendAction.h>
#include <clang/Index/IndexingAction.h>
+#include <clang/Lex/PreprocessorOptions.h>
#include <mutex>
namespace ClangBackEnd {
-class CollectSymbolsAction
+class CollectSymbolsAction : public clang::WrapperFrontendAction
{
public:
CollectSymbolsAction(std::shared_ptr<IndexDataConsumer> indexDataConsumer)
- : m_action(indexDataConsumer, createIndexingOptions()),
- m_indexDataConsumer(indexDataConsumer.get())
+ : clang::WrapperFrontendAction(
+ clang::index::createIndexingAction(indexDataConsumer, createIndexingOptions(), nullptr))
+ , m_indexDataConsumer(indexDataConsumer)
{}
std::unique_ptr<clang::ASTConsumer> newASTConsumer(clang::CompilerInstance &compilerInstance,
llvm::StringRef inFile);
-private:
- class WrappedIndexAction final : public clang::WrapperFrontendAction
- {
- public:
- WrappedIndexAction(std::shared_ptr<clang::index::IndexDataConsumer> indexDataConsumer,
- clang::index::IndexingOptions indexingOptions)
- : clang::WrapperFrontendAction(
- clang::index::createIndexingAction(indexDataConsumer, indexingOptions, nullptr))
- {}
-
- std::unique_ptr<clang::ASTConsumer>
- CreateASTConsumer(clang::CompilerInstance &compilerInstance,
- llvm::StringRef inFile) override
- {
- return WrapperFrontendAction::CreateASTConsumer(compilerInstance, inFile);
- }
- };
-
- static
- clang::index::IndexingOptions createIndexingOptions()
+
+ static clang::index::IndexingOptions createIndexingOptions()
{
clang::index::IndexingOptions options;
options.SystemSymbolFilter = clang::index::IndexingOptions::SystemSymbolFilterKind::None;
options.IndexFunctionLocals = true;
+ options.IndexMacrosInPreprocessor = true;
return options;
}
+ bool BeginInvocation(clang::CompilerInstance &compilerInstance) override
+ {
+ m_indexDataConsumer->setSourceManager(&compilerInstance.getSourceManager());
+ compilerInstance.getPreprocessorOpts().AllowPCHWithCompilerErrors = true;
+ compilerInstance.getDiagnosticOpts().ErrorLimit = 1;
+
+ return clang::WrapperFrontendAction::BeginInvocation(compilerInstance);
+ }
+
+ bool BeginSourceFileAction(clang::CompilerInstance &compilerInstance) override
+ {
+ compilerInstance.getPreprocessor().SetSuppressIncludeNotFoundError(true);
+
+ return clang::WrapperFrontendAction::BeginSourceFileAction(compilerInstance);
+ }
+
+ void EndSourceFileAction() override { clang::WrapperFrontendAction::EndSourceFileAction(); }
+
+ bool PrepareToExecuteAction(clang::CompilerInstance &instance) override
+ {
+ return clang::WrapperFrontendAction::PrepareToExecuteAction(instance);
+ }
+
+ void ExecuteAction() override { clang::WrapperFrontendAction::ExecuteAction(); }
+
+ std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &compilerInstance,
+ llvm::StringRef inFile) override
+ {
+ return WrapperFrontendAction::CreateASTConsumer(compilerInstance, inFile);
+ }
+
private:
- WrappedIndexAction m_action;
- IndexDataConsumer *m_indexDataConsumer;
+ std::shared_ptr<IndexDataConsumer> m_indexDataConsumer;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp b/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp
new file mode 100644
index 0000000000..28efe39f9b
--- /dev/null
+++ b/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "filestatuspreprocessorcallbacks.h"
+
+namespace ClangBackEnd {
+
+void FileStatusPreprocessorCallbacks::FileChanged(clang::SourceLocation sourceLocation,
+ clang::PPCallbacks::FileChangeReason reason,
+ clang::SrcMgr::CharacteristicKind,
+ clang::FileID)
+{
+ if (reason == clang::PPCallbacks::EnterFile) {
+ const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(
+ m_sourceManager->getFileID(sourceLocation));
+ if (fileEntry)
+ addFileStatus(fileEntry);
+ }
+}
+
+void FileStatusPreprocessorCallbacks::addFileStatus(const clang::FileEntry *fileEntry)
+{
+ auto id = filePathId(fileEntry);
+
+ auto found = std::lower_bound(m_fileStatuses.begin(),
+ m_fileStatuses.end(),
+ id,
+ [](const auto &first, const auto &second) {
+ return first.filePathId < second;
+ });
+
+ if (found == m_fileStatuses.end() || found->filePathId != id) {
+ m_fileStatuses.emplace(found, id, fileEntry->getSize(), fileEntry->getModificationTime());
+ }
+}
+
+} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h
new file mode 100644
index 0000000000..ad7bc4f4d6
--- /dev/null
+++ b/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "filestatus.h"
+#include "symbolsvisitorbase.h"
+
+#include <filepathid.h>
+
+#include <clang/Lex/PPCallbacks.h>
+
+namespace ClangBackEnd {
+
+class FileStatusPreprocessorCallbacks final : public clang::PPCallbacks, public SymbolsVisitorBase
+{
+public:
+ FileStatusPreprocessorCallbacks(FileStatuses &fileStatuses,
+ const FilePathCachingInterface &filePathCache,
+ const clang::SourceManager *sourceManager,
+ FilePathIds &filePathIndices)
+ : SymbolsVisitorBase(filePathCache, sourceManager, filePathIndices)
+ , m_fileStatuses(fileStatuses)
+ {}
+
+ void FileChanged(clang::SourceLocation sourceLocation,
+ clang::PPCallbacks::FileChangeReason reason,
+ clang::SrcMgr::CharacteristicKind,
+ clang::FileID) override;
+
+ void addFileStatus(const clang::FileEntry *fileEntry);
+
+private:
+ FileStatuses &m_fileStatuses;
+};
+
+} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp
index f44b3134a2..1fa6043461 100644
--- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp
+++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp
@@ -24,11 +24,13 @@
****************************************************************************/
#include "indexdataconsumer.h"
+#include "collectsymbolsaction.h"
+#include "filestatuspreprocessorcallbacks.h"
+#include <clang/AST/DeclVisitor.h>
#include <clang/Basic/SourceLocation.h>
#include <clang/Index/IndexSymbol.h>
-#include <clang/AST/Decl.h>
-#include <clang/AST/DeclVisitor.h>
+#include <clang/Index/IndexingAction.h>
#include <llvm/ADT/ArrayRef.h>
@@ -115,33 +117,41 @@ bool isReference(clang::index::SymbolRoleSet symbolRoles)
return symbolRoles & (uint(SymbolRole::Reference) | uint(SymbolRole::Call));
}
-}
+} // namespace
bool IndexDataConsumer::skipSymbol(clang::FileID fileId, clang::index::SymbolRoleSet symbolRoles)
{
- bool alreadyParsed = isAlreadyParsed(fileId);
- bool isParsedDeclaration = alreadyParsed && isDeclaration(symbolRoles);
- bool isParsedReference = alreadyParsed && !dependentFilesAreModified() && isReference(symbolRoles);
+ return isAlreadyParsed(fileId, m_symbolSourcesManager)
+ && !m_symbolSourcesManager.dependentFilesModified();
+}
+
+bool IndexDataConsumer::isAlreadyParsed(clang::FileID fileId, SourcesManager &sourcesManager)
+{
+ const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(fileId);
+ if (!fileEntry)
+ return false;
+ return sourcesManager.alreadyParsed(filePathId(fileEntry), fileEntry->getModificationTime());
+}
- return isParsedDeclaration || isParsedReference;
+void IndexDataConsumer::setPreprocessor(std::shared_ptr<clang::Preprocessor> preprocessor)
+{
+ preprocessor->addPPCallbacks(std::make_unique<FileStatusPreprocessorCallbacks>(
+ m_fileStatuses, m_filePathCache, m_sourceManager, m_filePathIndices));
}
-bool IndexDataConsumer::handleDeclOccurence(
- const clang::Decl *declaration,
- clang::index::SymbolRoleSet symbolRoles,
- llvm::ArrayRef<clang::index::SymbolRelation> /*symbolRelations*/,
- clang::SourceLocation sourceLocation,
- IndexDataConsumer::ASTNodeInfo /*astNodeInfo*/)
+bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration,
+ clang::index::SymbolRoleSet symbolRoles,
+ llvm::ArrayRef<clang::index::SymbolRelation> /*symbolRelations*/,
+ clang::SourceLocation sourceLocation,
+ IndexDataConsumer::ASTNodeInfo /*astNodeInfo*/)
{
const auto *namedDeclaration = clang::dyn_cast<clang::NamedDecl>(declaration);
if (namedDeclaration) {
if (!namedDeclaration->getIdentifier())
return true;
- if (skipSymbol(m_sourceManager->getFileID(sourceLocation), symbolRoles)) {
- namedDeclaration->getDeclName().dump();
+ if (skipSymbol(m_sourceManager->getFileID(sourceLocation), symbolRoles))
return true;
- }
SymbolIndex globalId = toSymbolIndex(declaration->getCanonicalDecl());
@@ -168,4 +178,64 @@ bool IndexDataConsumer::handleDeclOccurence(
return true;
}
+namespace {
+
+SourceLocationKind macroSymbolType(clang::index::SymbolRoleSet roles)
+{
+ if (roles & static_cast<clang::index::SymbolRoleSet>(clang::index::SymbolRole::Definition))
+ return SourceLocationKind::MacroDefinition;
+
+ if (roles & static_cast<clang::index::SymbolRoleSet>(clang::index::SymbolRole::Undefinition))
+ return SourceLocationKind::MacroUndefinition;
+
+ if (roles & static_cast<clang::index::SymbolRoleSet>(clang::index::SymbolRole::Reference))
+ return SourceLocationKind::MacroUsage;
+
+ return SourceLocationKind::None;
+}
+
+} // namespace
+
+bool IndexDataConsumer::handleMacroOccurence(const clang::IdentifierInfo *identifierInfo,
+ const clang::MacroInfo *macroInfo,
+ clang::index::SymbolRoleSet roles,
+ clang::SourceLocation sourceLocation)
+{
+ if (macroInfo && sourceLocation.isFileID()
+ && !isAlreadyParsed(m_sourceManager->getFileID(sourceLocation), m_macroSourcesManager)
+ && !isInSystemHeader(sourceLocation)) {
+ FilePathId fileId = filePathId(sourceLocation);
+ if (fileId.isValid()) {
+ auto macroName = identifierInfo->getName();
+ SymbolIndex globalId = toSymbolIndex(macroInfo);
+
+ auto found = m_symbolEntries.find(globalId);
+ if (found == m_symbolEntries.end()) {
+ Utils::optional<Utils::PathString> usr = generateUSR(macroName, sourceLocation);
+ if (usr) {
+ m_symbolEntries.emplace(std::piecewise_construct,
+ std::forward_as_tuple(globalId),
+ std::forward_as_tuple(std::move(*usr),
+ macroName,
+ SymbolKind::Macro));
+ }
+ }
+
+ m_sourceLocationEntries.emplace_back(globalId,
+ fileId,
+ lineColum(sourceLocation),
+ macroSymbolType(roles));
+ }
+ }
+
+ return true;
+}
+
+void IndexDataConsumer::finish()
+{
+ m_macroSourcesManager.updateModifiedTimeStamps();
+ m_symbolSourcesManager.updateModifiedTimeStamps();
+ m_filePathIndices.clear();
+}
+
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h b/src/tools/clangrefactoringbackend/source/indexdataconsumer.h
index 6db595391c..730ca12b23 100644
--- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h
+++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.h
@@ -26,6 +26,7 @@
#pragma once
#include "clangrefactoringbackend_global.h"
+#include "filestatus.h"
#include "sourcelocationentry.h"
#include "symbolentry.h"
#include "symbolsvisitorbase.h"
@@ -42,28 +43,48 @@ class IndexDataConsumer : public clang::index::IndexDataConsumer,
public:
IndexDataConsumer(SymbolEntries &symbolEntries,
SourceLocationEntries &sourceLocationEntries,
+ FileStatuses &fileStatuses,
FilePathCachingInterface &filePathCache,
- SourcesManager &sourcesManager)
- : SymbolsVisitorBase(filePathCache, nullptr, sourcesManager),
- m_symbolEntries(symbolEntries),
- m_sourceLocationEntries(sourceLocationEntries)
+ SourcesManager &symbolSourcesManager,
+ SourcesManager &macroSourcesManager)
+ : SymbolsVisitorBase(filePathCache, nullptr, m_filePathIndices)
+ , m_symbolEntries(symbolEntries)
+ , m_sourceLocationEntries(sourceLocationEntries)
+ , m_fileStatuses(fileStatuses)
+ , m_symbolSourcesManager(symbolSourcesManager)
+ , m_macroSourcesManager(macroSourcesManager)
+
{}
IndexDataConsumer(const IndexDataConsumer &) = delete;
IndexDataConsumer &operator=(const IndexDataConsumer &) = delete;
+ void setPreprocessor(std::shared_ptr<clang::Preprocessor> preprocessor) override;
+
bool handleDeclOccurence(const clang::Decl *declaration,
clang::index::SymbolRoleSet symbolRoles,
llvm::ArrayRef<clang::index::SymbolRelation> symbolRelations,
clang::SourceLocation sourceLocation,
ASTNodeInfo astNodeInfo) override;
+ bool handleMacroOccurence(const clang::IdentifierInfo *identifierInfo,
+ const clang::MacroInfo *macroInfo,
+ clang::index::SymbolRoleSet roles,
+ clang::SourceLocation sourceLocation) override;
+
+ void finish() override;
+
private:
bool skipSymbol(clang::FileID fileId, clang::index::SymbolRoleSet symbolRoles);
+ bool isAlreadyParsed(clang::FileID fileId, SourcesManager &sourcesManager);
private:
+ FilePathIds m_filePathIndices;
SymbolEntries &m_symbolEntries;
SourceLocationEntries &m_sourceLocationEntries;
+ FileStatuses &m_fileStatuses;
+ SourcesManager &m_symbolSourcesManager;
+ SourcesManager &m_macroSourcesManager;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp
index b4bafcc8ad..071837ac52 100644
--- a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp
+++ b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp
@@ -32,10 +32,14 @@
namespace ClangBackEnd {
SymbolsCollector::SymbolsCollector(Sqlite::Database &database)
- : m_filePathCache(database),
- m_indexDataConsumer(std::make_shared<IndexDataConsumer>(m_symbolEntries, m_sourceLocationEntries, m_filePathCache, m_sourcesManager)),
- m_collectSymbolsAction(m_indexDataConsumer),
- m_collectMacrosSourceFileCallbacks(m_symbolEntries, m_sourceLocationEntries, m_filePathCache, m_sourcesManager)
+ : m_filePathCache(database)
+ , m_indexDataConsumer(std::make_shared<IndexDataConsumer>(m_symbolEntries,
+ m_sourceLocationEntries,
+ m_fileStatuses,
+ m_filePathCache,
+ m_symbolSourcesManager,
+ m_macroSourcesManager))
+ , m_collectSymbolsAction(m_indexDataConsumer)
{
}
@@ -43,7 +47,6 @@ void SymbolsCollector::addFiles(const FilePathIds &filePathIds,
const Utils::SmallStringVector &arguments)
{
m_clangTool.addFiles(m_filePathCache.filePaths(filePathIds), arguments);
- m_collectMacrosSourceFileCallbacks.addSourceFiles(filePathIds);
}
void SymbolsCollector::setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments)
@@ -58,90 +61,73 @@ void SymbolsCollector::setUnsavedFiles(const V2::FileContainers &unsavedFiles)
void SymbolsCollector::clear()
{
- m_indexDataConsumer->clear();
- m_collectMacrosSourceFileCallbacks.clear();
m_symbolEntries.clear();
m_sourceLocationEntries.clear();
+ m_fileStatuses.clear();
m_clangTool = ClangTool();
}
-template <typename Factory>
-std::unique_ptr<clang::tooling::FrontendActionFactory>
-newFrontendActionFactory(Factory *consumerFactory,
- clang::tooling::SourceFileCallbacks *sourceFileCallbacks)
+std::unique_ptr<clang::tooling::FrontendActionFactory> newFrontendActionFactory(CollectSymbolsAction *action)
{
class FrontendActionFactoryAdapter : public clang::tooling::FrontendActionFactory
{
public:
- explicit FrontendActionFactoryAdapter(Factory *consumerFactory,
- clang::tooling::SourceFileCallbacks *sourceFileCallbacks)
- : m_consumerFactory(consumerFactory),
- m_sourceFileCallbacks(sourceFileCallbacks)
+ explicit FrontendActionFactoryAdapter(CollectSymbolsAction *consumerFactory)
+ : m_action(consumerFactory)
{}
- clang::FrontendAction *create() override {
- return new ConsumerFactoryAdaptor(m_consumerFactory, m_sourceFileCallbacks);
- }
+ clang::FrontendAction *create() override { return new AdaptorAction(m_action); }
private:
- class ConsumerFactoryAdaptor : public clang::ASTFrontendAction {
+ class AdaptorAction : public clang::ASTFrontendAction
+ {
public:
- ConsumerFactoryAdaptor(Factory *consumerFactory,
- clang::tooling::SourceFileCallbacks *sourceFileCallbacks)
- : m_consumerFactory(consumerFactory),
- m_sourceFileCallbacks(sourceFileCallbacks)
+ AdaptorAction(CollectSymbolsAction *action)
+ : m_action(action)
{}
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &instance,
llvm::StringRef inFile) override
{
- return m_consumerFactory->newASTConsumer(instance, inFile);
+ return m_action->newASTConsumer(instance, inFile);
}
- protected:
- bool BeginInvocation(clang::CompilerInstance &compilerInstance) override
+ bool BeginInvocation(clang::CompilerInstance &instance) override
{
- compilerInstance.getPreprocessorOpts().AllowPCHWithCompilerErrors = true;
-
- return clang::ASTFrontendAction::BeginInvocation(compilerInstance);
+ return m_action->BeginInvocation(instance);
}
-
- bool BeginSourceFileAction(clang::CompilerInstance &compilerInstance) override
+ bool BeginSourceFileAction(clang::CompilerInstance &instance) override
{
- compilerInstance.getPreprocessor().SetSuppressIncludeNotFoundError(true);
-
- if (!clang::ASTFrontendAction::BeginSourceFileAction(compilerInstance))
- return false;
- if (m_sourceFileCallbacks)
- return m_sourceFileCallbacks->handleBeginSource(compilerInstance);
- return true;
+ return m_action->BeginSourceFileAction(instance);
}
- void EndSourceFileAction() override
+ bool PrepareToExecuteAction(clang::CompilerInstance &instance) override
{
- if (m_sourceFileCallbacks)
- m_sourceFileCallbacks->handleEndSource();
- clang::ASTFrontendAction::EndSourceFileAction();
+ return m_action->PrepareToExecuteAction(instance);
}
+ void ExecuteAction() override { m_action->ExecuteAction(); }
+ void EndSourceFileAction() override { m_action->EndSourceFileAction(); }
+
+ bool hasPCHSupport() const override { return m_action->hasPCHSupport(); }
+ bool hasASTFileSupport() const override { return m_action->hasASTFileSupport(); }
+ bool hasIRSupport() const override { return false; }
+ bool hasCodeCompletionSupport() const override { return false; }
private:
- Factory *m_consumerFactory;
- clang::tooling::SourceFileCallbacks *m_sourceFileCallbacks;
+ CollectSymbolsAction *m_action;
};
- Factory *m_consumerFactory;
- clang::tooling::SourceFileCallbacks *m_sourceFileCallbacks;
+ CollectSymbolsAction *m_action;
};
- return std::unique_ptr<clang::tooling::FrontendActionFactory>(
- new FrontendActionFactoryAdapter(consumerFactory, sourceFileCallbacks));
+ return std::unique_ptr<clang::tooling::FrontendActionFactory>(
+ new FrontendActionFactoryAdapter(action));
}
bool SymbolsCollector::collectSymbols()
{
auto tool = m_clangTool.createTool();
- auto actionFactory = ClangBackEnd::newFrontendActionFactory(&m_collectSymbolsAction,
- &m_collectMacrosSourceFileCallbacks);
+ auto actionFactory = ClangBackEnd::newFrontendActionFactory(&m_collectSymbolsAction);
return tool.run(actionFactory.get()) != 1;
}
@@ -160,24 +146,9 @@ const SourceLocationEntries &SymbolsCollector::sourceLocations() const
return m_sourceLocationEntries;
}
-const FilePathIds &SymbolsCollector::sourceFiles() const
-{
- return m_collectMacrosSourceFileCallbacks.sourceFiles();
-}
-
-const UsedMacros &SymbolsCollector::usedMacros() const
-{
- return m_collectMacrosSourceFileCallbacks.usedMacros();
-}
-
const FileStatuses &SymbolsCollector::fileStatuses() const
{
- return m_collectMacrosSourceFileCallbacks.fileStatuses();
-}
-
-const SourceDependencies &SymbolsCollector::sourceDependencies() const
-{
- return m_collectMacrosSourceFileCallbacks.sourceDependencies();
+ return m_fileStatuses;
}
bool SymbolsCollector::isUsed() const
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.h b/src/tools/clangrefactoringbackend/source/symbolscollector.h
index b37647e969..cc7ca4396c 100644
--- a/src/tools/clangrefactoringbackend/source/symbolscollector.h
+++ b/src/tools/clangrefactoringbackend/source/symbolscollector.h
@@ -58,10 +58,7 @@ public:
const SymbolEntries &symbols() const override;
const SourceLocationEntries &sourceLocations() const override;
- const FilePathIds &sourceFiles() const override;
- const UsedMacros &usedMacros() const override;
const FileStatuses &fileStatuses() const override;
- const SourceDependencies &sourceDependencies() const override;
bool isUsed() const override;
void setIsUsed(bool isUsed) override;
@@ -71,10 +68,11 @@ private:
ClangTool m_clangTool;
SymbolEntries m_symbolEntries;
SourceLocationEntries m_sourceLocationEntries;
+ FileStatuses m_fileStatuses;
std::shared_ptr<IndexDataConsumer> m_indexDataConsumer;
CollectSymbolsAction m_collectSymbolsAction;
- CollectMacrosSourceFileCallbacks m_collectMacrosSourceFileCallbacks;
- SourcesManager m_sourcesManager;
+ SourcesManager m_symbolSourcesManager;
+ SourcesManager m_macroSourcesManager;
bool m_isUsed = false;
};
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h
index 94b3142371..07b5de223c 100644
--- a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h
+++ b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h
@@ -48,10 +48,7 @@ public:
virtual const SymbolEntries &symbols() const = 0;
virtual const SourceLocationEntries &sourceLocations() const = 0;
- virtual const FilePathIds &sourceFiles() const = 0;
- virtual const UsedMacros &usedMacros() const = 0;
virtual const FileStatuses &fileStatuses() const = 0;
- virtual const SourceDependencies &sourceDependencies() const = 0;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h b/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h
index ff2142f40e..7b63cb223e 100644
--- a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h
+++ b/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h
@@ -46,10 +46,10 @@ class SymbolsVisitorBase
public:
SymbolsVisitorBase(const FilePathCachingInterface &filePathCache,
const clang::SourceManager *sourceManager,
- SourcesManager &sourcesManager)
- : m_filePathCache(filePathCache),
- m_sourceManager(sourceManager),
- m_sourcesManager(sourcesManager)
+ FilePathIds &filePathIndices)
+ : m_filePathCache(filePathCache)
+ , m_sourceManager(sourceManager)
+ , m_filePathIndices(filePathIndices)
{}
FilePathId filePathId(clang::SourceLocation sourceLocation)
@@ -60,25 +60,6 @@ public:
return filePathId(fileEntry);
}
- bool dependentFilesAreModified()
- {
- return m_sourcesManager.dependentFilesModified();
- }
-
- bool isAlreadyParsed(clang::FileID fileId)
- {
- const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(fileId);
- if (!fileEntry)
- return false;
- return m_sourcesManager.alreadyParsed(filePathId(fileEntry),
- fileEntry->getModificationTime());
- }
-
- bool alreadyParsed(clang::SourceLocation sourceLocation)
- {
- return isAlreadyParsed(m_sourceManager->getFileID(sourceLocation));
- }
-
FilePathId filePathId(const clang::FileEntry *fileEntry)
{
if (fileEntry) {
@@ -156,22 +137,26 @@ public:
return isSystem(m_sourceManager->getSLocEntry(fileId).getFile().getFileCharacteristic());
}
+ bool isInSystemHeader(clang::SourceLocation sourceLocation) const
+ {
+ return m_sourceManager->isInSystemHeader(sourceLocation);
+ }
+
static
bool isSystem(clang::SrcMgr::CharacteristicKind kind)
{
return clang::SrcMgr::isSystem(kind);
}
- void clear()
- {
- m_filePathIndices.clear();
- }
+ const FilePathCachingInterface &filePathCache() const { return m_filePathCache; }
+ const clang::SourceManager *sourceManager() const { return m_sourceManager; }
protected:
- std::vector<FilePathId> m_filePathIndices;
const FilePathCachingInterface &m_filePathCache;
const clang::SourceManager *m_sourceManager = nullptr;
- SourcesManager &m_sourcesManager;
+
+private:
+ FilePathIds &m_filePathIndices;
};
} // namespace ClangBackend