summaryrefslogtreecommitdiff
path: root/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2017-09-21 11:43:59 +0200
committerTim Jenssen <tim.jenssen@qt.io>2017-10-05 17:36:37 +0000
commitd2e15e5f1efa1ef160a2d4f40ab61180477d1f14 (patch)
treeb35eeec94b895a48e9c7ce6ea00c245935d1ea38 /src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
parent0be824000262882023b2b48b5eab0786f3db379b (diff)
downloadqt-creator-d2e15e5f1efa1ef160a2d4f40ab61180477d1f14.tar.gz
Clang: Add file cache
The database is using file path integer ids to handle file paths because otherwise we would save many redundant data. This patch is improving it further with the introduction of a database based file path cache. The entries are now divided in a directory path and file name. This is quite handy for directory based file watching. Change-Id: I03f2e388e43f3d521d6bf8e39dfb95eb2309dc73 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.cpp29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
index 399a7353f3..d275cfe4e2 100644
--- a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
+++ b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp
@@ -28,14 +28,7 @@
#include "sourcelocationsutils.h"
#include <sourcerangescontainer.h>
-
-#if defined(__GNUC__)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wunused-parameter"
-#elif defined(_MSC_VER)
-# pragma warning(push)
-# pragma warning( disable : 4100 )
-#endif
+#include <filepathcachinginterface.h>
#include <clang/Basic/SourceManager.h>
#include <clang/Lex/Lexer.h>
@@ -43,18 +36,12 @@
#include <llvm/Support/FileUtilities.h>
#include <llvm/ADT/SmallVector.h>
-#if defined(__GNUC__)
-# pragma GCC diagnostic pop
-#elif defined(_MSC_VER)
-# pragma warning(pop)
-#endif
-
namespace ClangBackEnd {
SourceRangeExtractor::SourceRangeExtractor(
const clang::SourceManager &sourceManager,
const clang::LangOptions &languageOptions,
- ClangBackEnd::FilePathCache<std::mutex> &filePathCache,
+ FilePathCachingInterface &filePathCache,
SourceRangesContainer &sourceRangesContainer)
: sourceManager(sourceManager),
languageOptions(languageOptions),
@@ -127,16 +114,14 @@ const clang::SourceRange SourceRangeExtractor::extendSourceRangeToLastTokenEnd(c
return {sourceRange.getBegin(), endLocation};
}
-void SourceRangeExtractor::insertSourceRange(uint fileId,
- Utils::PathString &&filePath,
+void SourceRangeExtractor::insertSourceRange(FilePathId filePathId,
const clang::FullSourceLoc &startLocation,
uint startOffset,
const clang::FullSourceLoc &endLocation,
uint endOffset,
Utils::SmallString &&lineSnippet)
{
- sourceRangesContainer.insertFilePath(fileId, std::move(filePath));
- sourceRangesContainer.insertSourceRange(fileId,
+ sourceRangesContainer.insertSourceRange(filePathId,
startLocation.getSpellingLineNumber(),
startLocation.getSpellingColumnNumber(),
startOffset,
@@ -146,7 +131,7 @@ void SourceRangeExtractor::insertSourceRange(uint fileId,
std::move(lineSnippet));
}
-FilePathIndex SourceRangeExtractor::findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const
+FilePathId SourceRangeExtractor::findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const
{
auto found = m_fileIdMapping.find(fileId.getHashValue());
if (found != m_fileIdMapping.end()) {
@@ -154,7 +139,7 @@ FilePathIndex SourceRangeExtractor::findFileId(clang::FileID fileId, const clang
}
auto filePath = absolutePath(fileEntry->getName());
- return filePathCache.stringId(fromNativePath(filePath));
+ return filePathCache.filePathId(fromNativePath(filePath));
}
void SourceRangeExtractor::addSourceRange(const clang::SourceRange &sourceRange)
@@ -176,13 +161,11 @@ void SourceRangeExtractor::addSourceRange(const clang::SourceRange &sourceRange)
endOffset);
insertSourceRange(findFileId(fileId, fileEntry),
- fromNativePath(absolutePath(fileEntry->getName())),
startSourceLocation,
startOffset,
endSourceLocation,
endOffset,
std::move(lineSnippet));
-
}
}