summaryrefslogtreecommitdiff
path: root/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@qt.io>2017-07-03 11:12:00 +0200
committerTim Jenssen <tim.jenssen@qt.io>2017-07-03 09:27:05 +0000
commitdae4477cd367d115e2011cfedae6b1d5dbc22cb7 (patch)
tree5fa0ebf3db5cfe9f946c70e8c82f4bd09fca77db /src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
parent35ca318d187eb1356f36dce86946f12a530dfd6f (diff)
downloadqt-creator-dae4477cd367d115e2011cfedae6b1d5dbc22cb7.tar.gz
Clang: Make file ids unique
Clang file ids are only unique for one query. Because we query in parallel we have to manage our own unique ids. Change-Id: I67d57d8b1766cab75ad252a14e57bbf9dc5fdb79 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp')
-rw-r--r--src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
index 18b6288cae..e83f6a3c38 100644
--- a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
+++ b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
@@ -51,11 +51,14 @@
namespace ClangBackEnd {
-SourceRangeExtractor::SourceRangeExtractor(const clang::SourceManager &sourceManager,
- const clang::LangOptions &languageOptions,
- SourceRangesContainer &sourceRangesContainer)
+SourceRangeExtractor::SourceRangeExtractor(
+ const clang::SourceManager &sourceManager,
+ const clang::LangOptions &languageOptions,
+ ClangBackEnd::StringCache<Utils::PathString, std::mutex> &filePathCache,
+ SourceRangesContainer &sourceRangesContainer)
: sourceManager(sourceManager),
languageOptions(languageOptions),
+ filePathCache(filePathCache),
sourceRangesContainer(sourceRangesContainer)
{
}
@@ -123,19 +126,16 @@ const clang::SourceRange SourceRangeExtractor::extendSourceRangeToLastTokenEnd(c
return {sourceRange.getBegin(), endLocation};
}
-void SourceRangeExtractor::insertSourceRange(uint fileHash,
- Utils::SmallString &&directoryPath,
- Utils::SmallString &&fileName,
+void SourceRangeExtractor::insertSourceRange(uint fileId,
+ Utils::PathString &&filePath,
const clang::FullSourceLoc &startLocation,
uint startOffset,
const clang::FullSourceLoc &endLocation,
uint endOffset,
Utils::SmallString &&lineSnippet)
{
- sourceRangesContainer.insertFilePath(fileHash,
- std::move(directoryPath),
- std::move(fileName));
- sourceRangesContainer.insertSourceRange(fileHash,
+ sourceRangesContainer.insertFilePath(fileId, std::move(filePath));
+ sourceRangesContainer.insertSourceRange(fileId,
startLocation.getSpellingLineNumber(),
startLocation.getSpellingColumnNumber(),
startOffset,
@@ -145,6 +145,17 @@ void SourceRangeExtractor::insertSourceRange(uint fileHash,
std::move(lineSnippet));
}
+uint SourceRangeExtractor::findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const
+{
+ auto found = m_fileIdMapping.find(fileId.getHashValue());
+ if (found != m_fileIdMapping.end()) {
+ return found->second;
+ }
+
+ auto filePath = absolutePath(fileEntry->tryGetRealPathName());
+ return filePathCache.stringId(fromNativePath(filePath));
+}
+
void SourceRangeExtractor::addSourceRange(const clang::SourceRange &sourceRange)
{
auto extendedSourceRange = extendSourceRangeToLastTokenEnd(sourceRange);
@@ -158,15 +169,13 @@ void SourceRangeExtractor::addSourceRange(const clang::SourceRange &sourceRange)
const auto startOffset = startDecomposedLoction.second;
const auto endOffset = endDecomposedLoction.second;
const auto fileEntry = sourceManager.getFileEntryForID(fileId);
- auto filePath = absolutePath(fileEntry->getName());
- const auto fileName = llvm::sys::path::filename(filePath);
- llvm::sys::path::remove_filename(filePath);
+
Utils::SmallString lineSnippet = getExpandedText(startSourceLocation.getBufferData(),
startOffset,
endOffset);
- insertSourceRange(fileId.getHashValue(),
- fromNativePath(filePath),
- {fileName.data(), fileName.size()},
+
+ insertSourceRange(findFileId(fileId, fileEntry),
+ fromNativePath(fileEntry->tryGetRealPathName()),
startSourceLocation,
startOffset,
endSourceLocation,