diff options
author | Marco Bubke <marco.bubke@qt.io> | 2017-09-21 11:43:59 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2017-10-05 17:36:37 +0000 |
commit | d2e15e5f1efa1ef160a2d4f40ab61180477d1f14 (patch) | |
tree | b35eeec94b895a48e9c7ce6ea00c245935d1ea38 /src/tools | |
parent | 0be824000262882023b2b48b5eab0786f3db379b (diff) | |
download | qt-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')
44 files changed, 337 insertions, 522 deletions
diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp index 5622179272..d17fbd2bd9 100644 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp +++ b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp @@ -31,7 +31,9 @@ #include <pchmanagerserver.h> #include <pchmanagerclientproxy.h> #include <projectparts.h> -#include <stringcache.h> +#include <filepathcaching.h> +#include <refactoringdatabaseinitializer.h> +#include <sqlitedatabase.h> #include <QCommandLineParser> #include <QCoreApplication> @@ -103,15 +105,16 @@ int main(int argc, char *argv[]) const QString connection = processArguments(application); - FilePathCache<> filePathCache; + Sqlite::Database database{Utils::PathString{QDir::tempPath() + "/symbol.db"}}; + ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database}; + ClangBackEnd::FilePathCaching filePathCache{database}; ClangPathWatcher<QFileSystemWatcher, QTimer> includeWatcher(filePathCache); ApplicationEnvironment environment; PchGenerator<QProcess> pchGenerator(environment); PchCreator pchCreator(environment, filePathCache); pchCreator.setGenerator(&pchGenerator); ProjectParts projectParts; - PchManagerServer clangPchManagerServer(filePathCache, - includeWatcher, + PchManagerServer clangPchManagerServer(includeWatcher, pchCreator, projectParts); includeWatcher.setNotifier(&clangPchManagerServer); diff --git a/src/tools/clangpchmanagerbackend/source/clangpathwatcher.cpp b/src/tools/clangpchmanagerbackend/source/clangpathwatcher.cpp deleted file mode 100644 index 1647fa7943..0000000000 --- a/src/tools/clangpchmanagerbackend/source/clangpathwatcher.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 "clangpathwatcher.h" - -#include <utils/smallstringio.h> - -namespace ClangBackEnd { - -std::ostream &operator<<(std::ostream &out, const WatcherEntry &entry) -{ - out << "(" - << entry.id << ", " - << entry.path - << ")"; - - return out; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/clangpathwatcher.h b/src/tools/clangpchmanagerbackend/source/clangpathwatcher.h index 85ad8bbd63..e37668d7a7 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpathwatcher.h +++ b/src/tools/clangpchmanagerbackend/source/clangpathwatcher.h @@ -28,7 +28,9 @@ #include "clangpathwatcherinterface.h" #include "clangpathwatchernotifier.h" #include "changedfilepathcompressor.h" -#include "stringcache.h" + +#include <filepathcachinginterface.h> +#include <stringcache.h> #include <QTimer> @@ -37,34 +39,34 @@ namespace ClangBackEnd { class WatcherEntry { public: - FilePathIndex id; - FilePathIndex path; + int id; + FilePathId pathId; friend bool operator==(const WatcherEntry &first, const WatcherEntry &second) { - return first.id == second.id && first.path == second.path; + return first.id == second.id && first.pathId == second.pathId; } friend bool operator<(const WatcherEntry &first, const WatcherEntry &second) { - return std::tie(first.path, first.id) < std::tie(second.path, second.id); + return std::tie(first.pathId, first.id) < std::tie(second.pathId, second.id); } - friend bool operator<(const WatcherEntry &entry, FilePathIndex path) + friend bool operator<(const WatcherEntry &entry, FilePathId pathId) { - return entry.path < path; + return entry.pathId < pathId; } - friend bool operator<(FilePathIndex path, const WatcherEntry &entry) + friend bool operator<(FilePathId pathId, const WatcherEntry &entry) { - return path < entry.path; + return pathId < entry.pathId; } }; using WatcherEntries = std::vector<WatcherEntry>; using IdCache = StringCache<Utils::SmallString, - FilePathIndex, + int, NonLockingMutex, decltype(&Utils::compare), Utils::compare>; @@ -74,7 +76,7 @@ template <typename FileSystemWatcher, class ClangPathWatcher : public ClangPathWatcherInterface { public: - ClangPathWatcher(FilePathCache<> &pathCache, + ClangPathWatcher(FilePathCachingInterface &pathCache, ClangPathWatcherNotifier *notifier=nullptr) : m_pathCache(pathCache), m_notifier(notifier) @@ -136,9 +138,9 @@ unittest_public: return ids; } - std::vector<FilePathIndex> convertToIdNumbers(const Utils::SmallStringVector &ids) + std::vector<int> convertToIdNumbers(const Utils::SmallStringVector &ids) { - std::vector<FilePathIndex> idNumbers = m_idCache.stringIds(ids); + std::vector<int> idNumbers = m_idCache.stringIds(ids); std::sort(idNumbers.begin(), idNumbers.end()); @@ -148,33 +150,33 @@ unittest_public: std::size_t sizeOfIdPaths(const std::vector<IdPaths> &idPaths) { auto sumSize = [] (std::size_t size, const IdPaths &idPath) { - return size + idPath.paths.size(); + return size + idPath.filePathIds.size(); }; return std::accumulate(idPaths.begin(), idPaths.end(), std::size_t(0), sumSize); } - std::pair<WatcherEntries,std::vector<FilePathIndex>> + std::pair<WatcherEntries, std::vector<int>> convertIdPathsToWatcherEntriesAndIds(const std::vector<IdPaths> &idPaths) { WatcherEntries entries; entries.reserve(sizeOfIdPaths(idPaths)); - std::vector<FilePathIndex> ids; + std::vector<int> ids; ids.reserve(ids.size()); auto outputIterator = std::back_inserter(entries); for (const IdPaths &idPath : idPaths) { - FilePathIndex id = m_idCache.stringId(idPath.id); + int id = m_idCache.stringId(idPath.id); ids.push_back(id); - outputIterator = std::transform(idPath.paths.begin(), - idPath.paths.end(), + outputIterator = std::transform(idPath.filePathIds.begin(), + idPath.filePathIds.end(), outputIterator, - [&] (uint path) { return WatcherEntry{id, path}; }); + [&] (FilePathId pathId) { return WatcherEntry{id, pathId}; }); } std::sort(entries.begin(), entries.end()); @@ -196,7 +198,7 @@ unittest_public: } void removeUnusedEntries(const WatcherEntries &entries, - const std::vector<FilePathIndex> &ids) + const std::vector<int> &ids) { auto oldEntries = notAnymoreWatchedEntriesWithIds(entries, ids); @@ -222,7 +224,9 @@ unittest_public: std::transform(watcherEntries.begin(), watcherEntries.end(), std::back_inserter(paths), - [&] (const WatcherEntry &entry) { return QString(m_pathCache.string(entry.path)); }); + [&] (const WatcherEntry &entry) { + return QString(m_pathCache.filePath(entry.pathId).path()); + }); return paths; } @@ -252,7 +256,7 @@ unittest_public: WatcherEntries notWatchedPaths(const WatcherEntries &entries) const { auto compare = [] (const WatcherEntry &first, const WatcherEntry &second) { - return first.path < second.path; + return first.pathId < second.pathId; }; return notWatchedEntries(entries, compare); @@ -278,7 +282,7 @@ unittest_public: WatcherEntries notAnymoreWatchedEntriesWithIds( const WatcherEntries &newEntries, - const std::vector<FilePathIndex> &ids) const + const std::vector<int> &ids) const { auto oldEntries = notAnymoreWatchedEntries(newEntries, std::less<WatcherEntry>()); @@ -313,7 +317,7 @@ unittest_public: WatcherEntries uniqueEntries; auto compare = [] (const WatcherEntry &first, const WatcherEntry &second) { - return first.path == second.path; + return first.pathId == second.pathId; }; std::unique_copy(pathEntries.begin(), @@ -334,7 +338,7 @@ unittest_public: return m_watchedEntries; } - WatcherEntries removeIdsFromWatchedEntries(const std::vector<FilePathIndex> &ids) + WatcherEntries removeIdsFromWatchedEntries(const std::vector<int> &ids) { auto keep = [&] (const WatcherEntry &entry) { @@ -374,11 +378,11 @@ unittest_public: WatcherEntries watchedEntriesForPaths(Utils::PathStringVector &&filePaths) { - std::vector<FilePathIndex> pathIds = m_pathCache.stringIds(filePaths); + FilePathIds pathIds = m_pathCache.filePathIds(filePaths); WatcherEntries foundEntries; - for (uint pathId : pathIds) { + for (FilePathId pathId : pathIds) { auto range = std::equal_range(m_watchedEntries.begin(), m_watchedEntries.end(), pathId); foundEntries.insert(foundEntries.end(), range.first, range.second); } @@ -420,7 +424,7 @@ unittest_public: } } - FilePathCache<> &pathCache() + FilePathCachingInterface &pathCache() { return m_pathCache; } @@ -435,10 +439,8 @@ private: WatcherEntries m_watchedEntries; ChangedFilePathCompressor<Timer> m_changedFilePathCompressor; FileSystemWatcher m_fileSystemWatcher; - FilePathCache<> &m_pathCache; + FilePathCachingInterface &m_pathCache; ClangPathWatcherNotifier *m_notifier; }; -std::ostream &operator<<(std::ostream &out, const WatcherEntry &entry); - } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri index 926280a5fa..686d9a5d18 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri @@ -2,9 +2,7 @@ INCLUDEPATH += $$PWD SOURCES += \ $$PWD/pchmanagerserver.cpp \ - $$PWD/clangpathwatcher.cpp \ $$PWD/projectparts.cpp \ - $$PWD/idpaths.cpp \ $$PWD/pchcreatorinterface.cpp \ $$PWD/clangpathwatcherinterface.cpp \ $$PWD/projectpartsinterface.cpp \ diff --git a/src/tools/clangpchmanagerbackend/source/collectincludesaction.h b/src/tools/clangpchmanagerbackend/source/collectincludesaction.h index 339d491848..c61dfecb61 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludesaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludesaction.h @@ -25,10 +25,11 @@ #pragma once -#include "stringcache.h" - #include <collectincludespreprocessorcallbacks.h> +#include <filepathcachingfwd.h> +#include <filepathid.h> + #include <clang/Frontend/FrontendActions.h> #include <clang/Frontend/CompilerInstance.h> #include <clang/Lex/Preprocessor.h> @@ -38,10 +39,10 @@ namespace ClangBackEnd { class CollectIncludesAction final : public clang::PreprocessOnlyAction { public: - CollectIncludesAction(FilePathIndices &includeIds, - FilePathCache<> &filePathCache, - FilePathIndices &excludedIncludeUID, - FilePathIndices &alreadyIncludedFileUIDs) + CollectIncludesAction(FilePathIds &includeIds, + FilePathCachingInterface &filePathCache, + std::vector<uint> &excludedIncludeUID, + std::vector<uint> &alreadyIncludedFileUIDs) : m_includeIds(includeIds), m_filePathCache(filePathCache), m_excludedIncludeUID(excludedIncludeUID), @@ -78,10 +79,10 @@ public: } private: - FilePathIndices &m_includeIds; - FilePathCache<> &m_filePathCache; - FilePathIndices &m_excludedIncludeUID; - FilePathIndices &m_alreadyIncludedFileUIDs; + FilePathIds &m_includeIds; + FilePathCachingInterface &m_filePathCache; + std::vector<uint> &m_excludedIncludeUID; + std::vector<uint> &m_alreadyIncludedFileUIDs; }; } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h index a57d72adfc..dff1dc39ce 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h @@ -25,7 +25,10 @@ #pragma once -#include "stringcache.h" +#include <filepathcachinginterface.h> +#include <filepathid.h> + +#include <utils/smallstringvector.h> #include <clang/Basic/SourceManager.h> #include <clang/Lex/MacroInfo.h> @@ -33,8 +36,6 @@ #include <clang/Lex/PPCallbacks.h> #include <clang/Lex/Preprocessor.h> -#include <utils/smallstringvector.h> - #include <QFile> #include <QDir> #include <QTemporaryDir> @@ -47,10 +48,10 @@ class CollectIncludesPreprocessorCallbacks final : public clang::PPCallbacks { public: CollectIncludesPreprocessorCallbacks(clang::HeaderSearch &headerSearch, - std::vector<FilePathIndex> &includeIds, - FilePathCache<> &filePathCache, - const std::vector<FilePathIndex> &excludedIncludeUID, - std::vector<FilePathIndex> &alreadyIncludedFileUIDs) + FilePathIds &includeIds, + FilePathCachingInterface &filePathCache, + const std::vector<uint> &excludedIncludeUID, + std::vector<uint> &alreadyIncludedFileUIDs) : m_headerSearch(headerSearch), m_includeIds(includeIds), m_filePathCache(filePathCache), @@ -78,7 +79,7 @@ public: m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, fileUID); Utils::PathString filePath = filePathFromFile(file); if (!filePath.isEmpty()) { - FilePathIndex includeId = m_filePathCache.stringId(filePath); + FilePathId includeId = m_filePathCache.filePathId(filePath); m_includeIds.emplace_back(includeId); } } @@ -132,7 +133,7 @@ public: uid); } - std::pair<bool, std::vector<FilePathIndex>::iterator> isNotAlreadyIncluded(FilePathIndex uid) const + std::pair<bool, std::vector<uint>::iterator> isNotAlreadyIncluded(uint uid) const { auto range = std::equal_range(m_alreadyIncludedFileUIDs.begin(), m_alreadyIncludedFileUIDs.end(), @@ -174,10 +175,10 @@ public: private: clang::HeaderSearch &m_headerSearch; - std::vector<FilePathIndex> &m_includeIds; - FilePathCache<> &m_filePathCache; - const std::vector<FilePathIndex> &m_excludedIncludeUID; - std::vector<FilePathIndex> &m_alreadyIncludedFileUIDs; + FilePathIds &m_includeIds; + FilePathCachingInterface &m_filePathCache; + const std::vector<uint> &m_excludedIncludeUID; + std::vector<uint> &m_alreadyIncludedFileUIDs; bool m_skipInclude = false; }; diff --git a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h index 42b8a62cea..969a8ddb8b 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h @@ -25,10 +25,11 @@ #pragma once -#include "stringcache.h" - #include "collectincludesaction.h" +#include <filepathcachingfwd.h> +#include <filepathid.h> + #include <clang/Tooling/Tooling.h> namespace ClangBackEnd { @@ -36,8 +37,8 @@ namespace ClangBackEnd { class CollectIncludesToolAction final : public clang::tooling::FrontendActionFactory { public: - CollectIncludesToolAction(std::vector<FilePathIndex> &includeIds, - FilePathCache<> &filePathCache, + CollectIncludesToolAction(FilePathIds &includeIds, + FilePathCachingInterface &filePathCache, const Utils::PathStringVector &excludedIncludes) : m_includeIds(includeIds), m_filePathCache(filePathCache), @@ -72,9 +73,9 @@ public: m_alreadyIncludedFileUIDs); } - std::vector<FilePathIndex> generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const + std::vector<uint> generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const { - std::vector<FilePathIndex> fileUIDs; + std::vector<uint> fileUIDs; fileUIDs.reserve(m_excludedIncludes.size()); for (const Utils::PathString &filePath : m_excludedIncludes) { @@ -90,10 +91,10 @@ public: } private: - std::vector<FilePathIndex> m_alreadyIncludedFileUIDs; - std::vector<FilePathIndex> m_excludedIncludeUIDs; - std::vector<FilePathIndex> &m_includeIds; - FilePathCache<> &m_filePathCache; + std::vector<uint> m_alreadyIncludedFileUIDs; + std::vector<uint> m_excludedIncludeUIDs; + FilePathIds &m_includeIds; + FilePathCachingInterface &m_filePathCache; const Utils::PathStringVector &m_excludedIncludes; }; diff --git a/src/tools/clangpchmanagerbackend/source/idpaths.cpp b/src/tools/clangpchmanagerbackend/source/idpaths.cpp deleted file mode 100644 index f1dba02e4e..0000000000 --- a/src/tools/clangpchmanagerbackend/source/idpaths.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 "idpaths.h" - -#include <utils/smallstringio.h> - -namespace ClangBackEnd { - -std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths) -{ - out << "(" - << idPaths.id << ", " - << idPaths.paths << ")"; - - return out; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/idpaths.h b/src/tools/clangpchmanagerbackend/source/idpaths.h index a407e24530..3b24ba7538 100644 --- a/src/tools/clangpchmanagerbackend/source/idpaths.h +++ b/src/tools/clangpchmanagerbackend/source/idpaths.h @@ -27,9 +27,7 @@ #include <utils/smallstring.h> -#include <iosfwd> - -#include <stringcachefwd.h> +#include <filepathid.h> namespace ClangBackEnd { @@ -37,14 +35,12 @@ class IdPaths { public: Utils::SmallString id; - std::vector<FilePathIndex> paths; + FilePathIds filePathIds; friend bool operator==(const IdPaths &first, const IdPaths &second) { - return first.id == second.id && first.paths == second.paths; + return first.id == second.id && first.filePathIds == second.filePathIds; } }; -std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths); - } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.cpp b/src/tools/clangpchmanagerbackend/source/includecollector.cpp index 421123b3a7..6ac142e22b 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.cpp +++ b/src/tools/clangpchmanagerbackend/source/includecollector.cpp @@ -33,7 +33,7 @@ namespace ClangBackEnd { -IncludeCollector::IncludeCollector(FilePathCache<> &filePathCache) +IncludeCollector::IncludeCollector(FilePathCachingInterface &filePathCache) : m_filePathCache(filePathCache) { } @@ -69,7 +69,7 @@ void IncludeCollector::setExcludedIncludes(Utils::PathStringVector &&excludedInc #endif } -std::vector<FilePathIndex> IncludeCollector::takeIncludeIds() +FilePathIds IncludeCollector::takeIncludeIds() { std::sort(m_includeIds.begin(), m_includeIds.end()); diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.h b/src/tools/clangpchmanagerbackend/source/includecollector.h index 73f9b948af..52e6e560db 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.h +++ b/src/tools/clangpchmanagerbackend/source/includecollector.h @@ -25,28 +25,28 @@ #pragma once -#include "stringcache.h" - #include <clangtool.h> +#include <filepathcachingfwd.h> + namespace ClangBackEnd { class IncludeCollector : public ClangTool { public: - IncludeCollector(FilePathCache<> &filePathCache); + IncludeCollector(FilePathCachingInterface &filePathCache); void collectIncludes(); void setExcludedIncludes(Utils::PathStringVector &&excludedIncludes); - std::vector<FilePathIndex> takeIncludeIds(); + FilePathIds takeIncludeIds(); private: Utils::PathStringVector m_excludedIncludes; - std::vector<FilePathIndex> m_includeIds; + FilePathIds m_includeIds; Utils::SmallStringVector m_directories; - FilePathCache<> &m_filePathCache; + FilePathCachingInterface &m_filePathCache; }; } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index fd6da58012..645e266db0 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -29,6 +29,7 @@ #include "includecollector.h" #include "pchnotcreatederror.h" +#include <filepathcachinginterface.h> #include <projectpartpch.h> #include <QCryptographicHash> @@ -37,7 +38,7 @@ namespace ClangBackEnd { -PchCreator::PchCreator(Environment &environment, FilePathCache<> &filePathCache) +PchCreator::PchCreator(Environment &environment, FilePathCachingInterface &filePathCache) : m_environment(environment), m_filePathCache(filePathCache) { @@ -45,7 +46,7 @@ PchCreator::PchCreator(Environment &environment, FilePathCache<> &filePathCache) PchCreator::PchCreator(V2::ProjectPartContainers &&projectsParts, Environment &environment, - FilePathCache<> &filePathCache, + FilePathCachingInterface &filePathCache, PchGeneratorInterface *pchGenerator, V2::FileContainers &&generatedFiles) : m_projectParts(std::move(projectsParts)), @@ -239,7 +240,7 @@ Utils::SmallStringVector PchCreator::generateGlobalClangCompilerArguments() cons return compilerArguments; } -std::vector<FilePathIndex> PchCreator::generateGlobalPchIncludeIds() const +FilePathIds PchCreator::generateGlobalPchIncludeIds() const { IncludeCollector collector(m_filePathCache); @@ -256,7 +257,7 @@ std::vector<FilePathIndex> PchCreator::generateGlobalPchIncludeIds() const namespace { -std::size_t contentSize(const std::vector<Utils::PathString> &includes) +std::size_t contentSize(const FilePaths &includes) { auto countIncludeSize = [] (std::size_t size, const Utils::PathString &include) { return size + include.size(); @@ -266,20 +267,16 @@ std::size_t contentSize(const std::vector<Utils::PathString> &includes) } } -Utils::SmallString PchCreator::generatePchIncludeFileContent( - const std::vector<FilePathIndex> &includeIds) const +Utils::SmallString PchCreator::generatePchIncludeFileContent(const FilePathIds &includeIds) const { Utils::SmallString fileContent; const std::size_t lineTemplateSize = 12; - auto includes = m_filePathCache.strings(includeIds); + auto includes = m_filePathCache.filePaths(includeIds); fileContent.reserve(includes.size() * lineTemplateSize + contentSize(includes)); - for (const Utils::PathString &include : includes) { - fileContent += "#include \""; - fileContent += include; - fileContent += "\"\n"; - } + for (const Utils::PathString &include : includes) + fileContent += {"#include \"", include, "\"\n"}; return fileContent; } @@ -461,7 +458,7 @@ Utils::PathStringVector PchCreator::generateProjectPartHeaderAndSourcePaths( return includeAndSources; } -std::vector<FilePathIndex> PchCreator::generateProjectPartPchIncludes( +FilePathIds PchCreator::generateProjectPartPchIncludes( const V2::ProjectPartContainer &projectPart) const { Utils::SmallString jointedFileContent = generateProjectPartHeaderAndSourcesContent(projectPart); diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index 5548ec7acd..26e591302f 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -28,9 +28,9 @@ #include "pchcreatorinterface.h" #include "pchgeneratorinterface.h" -#include "stringcache.h" #include "idpaths.h" +#include <filepathcachingfwd.h> #include <projectpartpch.h> #include <projectpartcontainerv2.h> @@ -48,10 +48,10 @@ class PchCreator final : public PchCreatorInterface { public: PchCreator(Environment &environment, - FilePathCache<> &filePathCache); + FilePathCachingInterface &filePathCache); PchCreator(V2::ProjectPartContainers &&projectsParts, Environment &environment, - FilePathCache<> &filePathCache, + FilePathCachingInterface &filePathCache, PchGeneratorInterface *pchGenerator, V2::FileContainers &&generatedFiles); @@ -70,9 +70,9 @@ unittest_public: Utils::SmallStringVector generateGlobalPchCompilerArguments() const; Utils::SmallStringVector generateGlobalClangCompilerArguments() const; - std::vector<FilePathIndex> generateGlobalPchIncludeIds() const; + FilePathIds generateGlobalPchIncludeIds() const; - Utils::SmallString generatePchIncludeFileContent(const std::vector<FilePathIndex> &includeIds) const; + Utils::SmallString generatePchIncludeFileContent(const FilePathIds &includeIds) const; Utils::SmallString generateGlobalPchHeaderFileContent() const; std::unique_ptr<QFile> generateGlobalPchHeaderFile(); void generatePch(Utils::SmallStringVector &&commandLineArguments, @@ -97,7 +97,7 @@ unittest_public: const V2::ProjectPartContainer &projectPart); static Utils::PathStringVector generateProjectPartHeaderAndSourcePaths( const V2::ProjectPartContainer &projectPart); - std::vector<FilePathIndex> generateProjectPartPchIncludes( + FilePathIds generateProjectPartPchIncludes( const V2::ProjectPartContainer &projectPart) const; Utils::SmallString generateProjectPathPchHeaderFilePath( const V2::ProjectPartContainer &projectPart) const; @@ -127,7 +127,7 @@ private: std::vector<ProjectPartPch> m_projectPartPchs; std::vector<IdPaths> m_projectsIncludeIds; Environment &m_environment; - FilePathCache<> &m_filePathCache; + FilePathCachingInterface &m_filePathCache; PchGeneratorInterface *m_pchGenerator = nullptr; }; diff --git a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp index 03261ae164..8abcda8d65 100644 --- a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp @@ -36,12 +36,10 @@ namespace ClangBackEnd { -PchManagerServer::PchManagerServer(FilePathCache<> &filePathCache, - ClangPathWatcherInterface &fileSystemWatcher, +PchManagerServer::PchManagerServer(ClangPathWatcherInterface &fileSystemWatcher, PchCreatorInterface &pchCreator, ProjectPartsInterface &projectParts) - : m_filePathCache(filePathCache), - m_fileSystemWatcher(fileSystemWatcher), + : m_fileSystemWatcher(fileSystemWatcher), m_pchCreator(pchCreator), m_projectParts(projectParts) { diff --git a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h index 7be9c75966..bac2dcd00f 100644 --- a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h +++ b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h @@ -31,7 +31,6 @@ #include "pchgeneratornotifierinterface.h" #include "pchmanagerserverinterface.h" #include "projectpartsinterface.h" -#include "stringcache.h" #include <ipcclientprovider.h> @@ -46,8 +45,7 @@ class PchManagerServer : public PchManagerServerInterface, { public: - PchManagerServer(FilePathCache<> &filePathCache, - ClangPathWatcherInterface &fileSystemWatcher, + PchManagerServer(ClangPathWatcherInterface &fileSystemWatcher, PchCreatorInterface &pchCreator, ProjectPartsInterface &projectParts); @@ -60,7 +58,6 @@ public: void taskFinished(TaskFinishStatus status, const ProjectPartPch &projectPartPch) override; private: - FilePathCache<> &m_filePathCache; ClangPathWatcherInterface &m_fileSystemWatcher; PchCreatorInterface &m_pchCreator; ProjectPartsInterface &m_projectParts; diff --git a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp index 8c5fe3f751..7c628fa376 100644 --- a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp +++ b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp @@ -29,14 +29,15 @@ #include <QDir> #include <connectionserver.h> -#include <stringcache.h> +#include <filepathcaching.h> #include <refactoringserver.h> #include <refactoringclientproxy.h> #include <symbolindexing.h> -using ClangBackEnd::FilePathCache; +using ClangBackEnd::FilePathCaching; using ClangBackEnd::RefactoringClientProxy; using ClangBackEnd::RefactoringServer; +using ClangBackEnd::RefactoringDatabaseInitializer; using ClangBackEnd::ConnectionServer; using ClangBackEnd::SymbolIndexing; @@ -69,8 +70,10 @@ try { const QString connection = processArguments(application); - FilePathCache<std::mutex> filePathCache; - SymbolIndexing symbolIndexing{filePathCache, Utils::PathString{QDir::tempPath() + "/symbol.db"}}; + Sqlite::Database database{Utils::PathString{QDir::tempPath() + "/symbol.db"}}; + RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database}; + FilePathCaching filePathCache{database}; + SymbolIndexing symbolIndexing{database, filePathCache}; RefactoringServer clangCodeModelServer{symbolIndexing, filePathCache}; ConnectionServer<RefactoringServer, RefactoringClientProxy> connectionServer(connection); connectionServer.start(); diff --git a/src/tools/clangrefactoringbackend/source/clangquery.cpp b/src/tools/clangrefactoringbackend/source/clangquery.cpp index 620a7ebaab..fc9dd868c0 100644 --- a/src/tools/clangrefactoringbackend/source/clangquery.cpp +++ b/src/tools/clangrefactoringbackend/source/clangquery.cpp @@ -54,16 +54,16 @@ struct CollectBoundNodes : MatchFinder::MatchCallback { } }; -ClangQuery::ClangQuery(FilePathCache<std::mutex> &filePathCache, +ClangQuery::ClangQuery(FilePathCachingInterface &filePathCache, Utils::SmallString &&query) - : query(std::move(query)), - filePathCache(filePathCache) + : m_query(std::move(query)), + m_filePathCache(filePathCache) { } void ClangQuery::setQuery(Utils::SmallString &&query) { - this->query = std::move(query); + this->m_query = std::move(query); } void ClangQuery::findLocations() @@ -78,7 +78,7 @@ void ClangQuery::findLocations() std::make_move_iterator(asts.end()), [&] (std::unique_ptr<clang::ASTUnit> &&ast) { Diagnostics diagnostics; - auto optionalMatcher = Parser::parseMatcherExpression({query.data(), query.size()}, + auto optionalMatcher = Parser::parseMatcherExpression({m_query.data(), m_query.size()}, nullptr, &diagnostics); parseDiagnostics(diagnostics); @@ -89,19 +89,19 @@ void ClangQuery::findLocations() SourceRangesContainer ClangQuery::takeSourceRanges() { - return std::move(sourceRangesContainer); + return std::move(m_sourceRangesContainer); } DynamicASTMatcherDiagnosticContainers ClangQuery::takeDiagnosticContainers() { - return std::move(diagnosticContainers_); + return std::move(m_diagnosticContainers_); } namespace { V2::SourceRangeContainer convertToContainer(const clang::ast_matchers::dynamic::SourceRange sourceRange) { - return V2::SourceRangeContainer(0, + return V2::SourceRangeContainer({1, 0}, sourceRange.Start.Line, sourceRange.Start.Column, 0, @@ -159,8 +159,8 @@ void ClangQuery::parseDiagnostics(const clang::ast_matchers::dynamic::Diagnostic auto errors = diagnostics.errors(); for (const auto &errorContent : errors) { - diagnosticContainers_.emplace_back(); - DynamicASTMatcherDiagnosticContainer &diagnosticContainer = diagnosticContainers_.back(); + m_diagnosticContainers_.emplace_back(); + DynamicASTMatcherDiagnosticContainer &diagnosticContainer = m_diagnosticContainers_.back(); for (const auto &message : errorContent.Messages) { diagnosticContainer.insertMessage(convertToContainer(message.Range), @@ -216,8 +216,8 @@ void ClangQuery::matchLocation( SourceRangeExtractor extractor(ast->getSourceManager(), ast->getLangOpts(), - filePathCache, - sourceRangesContainer); + m_filePathCache, + m_sourceRangesContainer); extractor.addSourceRanges(sourceRanges); } diff --git a/src/tools/clangrefactoringbackend/source/clangquery.h b/src/tools/clangrefactoringbackend/source/clangquery.h index 7d99766008..daccd8335e 100644 --- a/src/tools/clangrefactoringbackend/source/clangquery.h +++ b/src/tools/clangrefactoringbackend/source/clangquery.h @@ -30,7 +30,7 @@ #include <sourcerangescontainer.h> #include <dynamicastmatcherdiagnosticcontainer.h> -#include <stringcache.h> +#include <filepathcachingfwd.h> namespace clang { namespace ast_matchers { @@ -51,9 +51,9 @@ namespace ClangBackEnd { class ClangQuery : public ClangTool { public: - ClangQuery(FilePathCache<std::mutex> &filePathCache, Utils::SmallString &&query={}); + ClangQuery(FilePathCachingInterface &m_filePathCache, Utils::SmallString &&m_query={}); - void setQuery(Utils::SmallString &&query); + void setQuery(Utils::SmallString &&m_query); void findLocations(); @@ -66,10 +66,10 @@ private: std::unique_ptr<clang::ASTUnit> ast); private: - SourceRangesContainer sourceRangesContainer; - Utils::SmallString query; - std::vector<DynamicASTMatcherDiagnosticContainer> diagnosticContainers_; - FilePathCache<std::mutex> &filePathCache; + SourceRangesContainer m_sourceRangesContainer; + Utils::SmallString m_query; + std::vector<DynamicASTMatcherDiagnosticContainer> m_diagnosticContainers_; + ClangBackEnd::FilePathCachingInterface &m_filePathCache; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp b/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp index 692065a9e7..0ac42d6ef1 100644 --- a/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp +++ b/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp @@ -29,7 +29,7 @@ namespace ClangBackEnd { -ClangQueryGatherer::ClangQueryGatherer(FilePathCache<std::mutex> *filePathCache, +ClangQueryGatherer::ClangQueryGatherer(FilePathCachingInterface *filePathCache, std::vector<V2::FileContainer> &&sources, std::vector<V2::FileContainer> &&unsaved, Utils::SmallString &&query) @@ -43,7 +43,7 @@ ClangQueryGatherer::ClangQueryGatherer(FilePathCache<std::mutex> *filePathCache, SourceRangesForQueryMessage ClangQueryGatherer::createSourceRangesForSource( - FilePathCache<std::mutex> *filePathCache, + FilePathCachingInterface *filePathCache, V2::FileContainer &&source, const std::vector<V2::FileContainer> &unsaved, Utils::SmallString &&query) diff --git a/src/tools/clangrefactoringbackend/source/clangquerygatherer.h b/src/tools/clangrefactoringbackend/source/clangquerygatherer.h index c1fd6341fa..f0e0e181f2 100644 --- a/src/tools/clangrefactoringbackend/source/clangquerygatherer.h +++ b/src/tools/clangrefactoringbackend/source/clangquerygatherer.h @@ -29,7 +29,7 @@ #include <sourcerangesforquerymessage.h> #include <filecontainerv2.h> -#include <stringcache.h> +#include <filepathcachingfwd.h> #include <future> @@ -41,13 +41,13 @@ public: using Future = std::future<SourceRangesForQueryMessage>; ClangQueryGatherer() = default; - ClangQueryGatherer(FilePathCache<std::mutex> *filePathCache, + ClangQueryGatherer(FilePathCachingInterface *filePathCache, std::vector<V2::FileContainer> &&sources, std::vector<V2::FileContainer> &&unsaved, Utils::SmallString &&query); static SourceRangesForQueryMessage createSourceRangesForSource( - FilePathCache<std::mutex> *filePathCache, + FilePathCachingInterface *filePathCache, V2::FileContainer &&source, const std::vector<V2::FileContainer> &unsaved, Utils::SmallString &&query); @@ -69,7 +69,7 @@ protected: std::vector<Future> finishedFutures(); private: - FilePathCache<std::mutex> *m_filePathCache = nullptr; + FilePathCachingInterface *m_filePathCache = nullptr; SourceRangeFilter m_sourceRangeFilter; std::vector<V2::FileContainer> m_sources; std::vector<V2::FileContainer> m_unsaved; diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri index 50041e596a..e95981a4a3 100644 --- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri +++ b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri @@ -57,5 +57,4 @@ HEADERS += \ SOURCES += \ $$PWD/sourcerangefilter.cpp \ $$PWD/symbolindexer.cpp \ - $$PWD/symbolentry.cpp \ - $$PWD/sourcelocationentry.cpp + $$PWD/symbolentry.cpp diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h index 1ddd34b595..2c8a93e940 100644 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h +++ b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h @@ -31,7 +31,7 @@ #include <utils/smallstring.h> -#include <stringcachefwd.h> +#include <filepathcachingfwd.h> #include <clang/Frontend/FrontendAction.h> @@ -42,7 +42,7 @@ namespace ClangBackEnd { class CollectSymbolsAction { public: - CollectSymbolsAction(FilePathCache<std::mutex> &filePathCache) + CollectSymbolsAction(FilePathCachingInterface &filePathCache) : m_filePathCache(filePathCache) {} @@ -66,7 +66,7 @@ public: private: SymbolEntries m_symbolEntries; SourceLocationEntries m_sourceLocationEntries; - FilePathCache<std::mutex> &m_filePathCache; + FilePathCachingInterface &m_filePathCache; }; diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h b/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h index fcedd6a6d0..f93f44a1cb 100644 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h +++ b/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h @@ -28,7 +28,7 @@ #include "symbolentry.h" #include "sourcelocationentry.h" -#include <stringcache.h> +#include <filepathcachinginterface.h> #include <clang/AST/AST.h> #include <clang/AST/ASTContext.h> @@ -50,7 +50,7 @@ class CollectSymbolsASTVisitor : public clang::RecursiveASTVisitor<CollectSymbol public: CollectSymbolsASTVisitor(SymbolEntries &symbolEntries, SourceLocationEntries &sourceLocationEntries, - FilePathCache<std::mutex> &filePathCache, + FilePathCachingInterface &filePathCache, const clang::SourceManager &sourceManager) : m_symbolEntries(symbolEntries), m_sourceLocationEntries(sourceLocationEntries), @@ -100,7 +100,7 @@ public: return true; } - FilePathIndex filePathId(clang::SourceLocation sourceLocation) + FilePathId filePathId(clang::SourceLocation sourceLocation) { uint clangFileId = m_sourceManager.getFileID(sourceLocation).getHashValue(); @@ -111,11 +111,11 @@ public: auto filePath = m_sourceManager.getFilename(sourceLocation); - FilePathIndex index = m_filePathCache.stringId(toStringView(filePath)); + FilePathId filePathId = m_filePathCache.filePathId(toStringView(filePath)); - m_filePathIndices.emplace(clangFileId, index); + m_filePathIndices.emplace(clangFileId, filePathId); - return index; + return filePathId; } LineColumn lineColum(clang::SourceLocation sourceLocation) @@ -147,9 +147,9 @@ public: private: SymbolEntries &m_symbolEntries; - std::unordered_map<uint, FilePathIndex> m_filePathIndices; + std::unordered_map<uint, FilePathId> m_filePathIndices; SourceLocationEntries &m_sourceLocationEntries; - FilePathCache<std::mutex> &m_filePathCache; + FilePathCachingInterface &m_filePathCache; const clang::SourceManager &m_sourceManager; }; diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h b/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h index 0eeb7a73f2..55822ab091 100644 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h +++ b/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h @@ -31,7 +31,7 @@ #include <clang/AST/ASTConsumer.h> #include <clang/AST/ASTContext.h> -#include <stringcachefwd.h> +#include <filepathcachingfwd.h> namespace ClangBackEnd { @@ -40,7 +40,7 @@ class CollectSymbolsConsumer : public clang::ASTConsumer public: CollectSymbolsConsumer(SymbolEntries &symbolEntries, SourceLocationEntries &sourceLocationEntries, - FilePathCache<std::mutex> &filePathCache) + FilePathCachingInterface &filePathCache) : m_symbolEntries(symbolEntries), m_sourceLocationEntries(sourceLocationEntries), m_filePathCache(filePathCache) @@ -69,6 +69,6 @@ public: private: SymbolEntries &m_symbolEntries; SourceLocationEntries &m_sourceLocationEntries; - FilePathCache<std::mutex> &m_filePathCache; + FilePathCachingInterface &m_filePathCache; }; } diff --git a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp b/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp index cc6e8e609a..3dd43976a0 100644 --- a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp +++ b/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp @@ -48,9 +48,12 @@ namespace ClangBackEnd { -LocationSourceFileCallbacks::LocationSourceFileCallbacks(uint line, uint column) - : line(line), - column(column) +LocationSourceFileCallbacks::LocationSourceFileCallbacks(uint line, + uint column, + FilePathCachingInterface &filePathCache) + : m_filePathCache(filePathCache), + m_line(line), + m_column(column) { } @@ -58,30 +61,31 @@ bool LocationSourceFileCallbacks::handleBeginSource(clang::CompilerInstance &com { auto &preprocessor = compilerInstance.getPreprocessor(); - macroPreprocessorCallbacks = new MacroPreprocessorCallbacks(sourceLocationsContainer, - symbolName, - preprocessor, - line, - column); + m_macroPreprocessorCallbacks = new MacroPreprocessorCallbacks(m_sourceLocationsContainer, + m_symbolName, + preprocessor, + m_filePathCache, + m_line, + m_column); - preprocessor.addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(macroPreprocessorCallbacks)); + preprocessor.addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(m_macroPreprocessorCallbacks)); return true; } SourceLocationsContainer LocationSourceFileCallbacks::takeSourceLocations() { - return std::move(sourceLocationsContainer); + return std::move(m_sourceLocationsContainer); } Utils::SmallString LocationSourceFileCallbacks::takeSymbolName() { - return std::move(symbolName); + return std::move(m_symbolName); } bool LocationSourceFileCallbacks::hasSourceLocations() const { - return sourceLocationsContainer.hasContent(); + return m_sourceLocationsContainer.hasContent(); } diff --git a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h b/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h index cb9560ae7d..5b7fe2af4a 100644 --- a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h +++ b/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h @@ -25,6 +25,7 @@ #pragma once +#include <filepathcachingfwd.h> #include <sourcelocationscontainer.h> #include <clang/Tooling/Tooling.h> @@ -45,7 +46,7 @@ class SourceLocationsContainer; class LocationSourceFileCallbacks : public clang::tooling::SourceFileCallbacks { public: - LocationSourceFileCallbacks(uint line, uint column); + LocationSourceFileCallbacks(uint line, uint column, FilePathCachingInterface &filePathCache); bool handleBeginSource(clang::CompilerInstance &compilerInstance, llvm::StringRef fileName) override; @@ -56,11 +57,12 @@ public: bool hasSourceLocations() const; private: - SourceLocationsContainer sourceLocationsContainer; - Utils::SmallString symbolName; - MacroPreprocessorCallbacks *macroPreprocessorCallbacks; - uint line; - uint column; + SourceLocationsContainer m_sourceLocationsContainer; + Utils::SmallString m_symbolName; + MacroPreprocessorCallbacks *m_macroPreprocessorCallbacks; + FilePathCachingInterface &m_filePathCache; + uint m_line; + uint m_column; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp b/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp index c0015f867d..2d46efed28 100644 --- a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp +++ b/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp @@ -30,13 +30,15 @@ namespace ClangBackEnd { MacroPreprocessorCallbacks::MacroPreprocessorCallbacks(SourceLocationsContainer &sourceLocationsContainer, Utils::SmallString &symbolName, clang::Preprocessor &preprocessor, + FilePathCachingInterface &filePathCache, uint line, uint column) - : sourceLocationsContainer(sourceLocationsContainer), - symbolName(symbolName), - preprocessor(preprocessor), - line(line), - column(column) + : m_sourceLocationsContainer(sourceLocationsContainer), + m_symbolName(symbolName), + m_preprocessor(preprocessor), + m_filePathCache(filePathCache), + m_line(line), + m_column(column) { } diff --git a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h index 6c6010b2bb..f94d993ef2 100644 --- a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h +++ b/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h @@ -27,27 +27,14 @@ #include "sourcelocationsutils.h" +#include <filepathcachingfwd.h> #include <sourcelocationscontainer.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 <clang/Basic/SourceManager.h> #include <clang/Lex/PPCallbacks.h> #include <clang/Lex/Preprocessor.h> #include <clang/Lex/MacroInfo.h> -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#elif defined(_MSC_VER) -# pragma warning(pop) -#endif - #include <QDebug> namespace ClangBackEnd { @@ -67,18 +54,19 @@ struct MacroDirectiveToken class MacroPreprocessorCallbacks : public clang::PPCallbacks { public: - MacroPreprocessorCallbacks(SourceLocationsContainer &sourceLocationsContainer, - Utils::SmallString &symbolName, - clang::Preprocessor &preprocessor, - uint line, - uint column); + MacroPreprocessorCallbacks(SourceLocationsContainer &m_sourceLocationsContainer, + Utils::SmallString &m_symbolName, + clang::Preprocessor &m_preprocessor, + FilePathCachingInterface &filePathCache, + uint m_line, + uint m_column); void FileChanged(clang::SourceLocation location, FileChangeReason reason, clang::SrcMgr::CharacteristicKind /*fileType*/, clang::FileID /*previousFileIdentifier*/) final { - if (!isMainFileEntered) { + if (!m_isMainFileEntered) { updateLocations(); updateIsMainFileEntered(location, reason); } @@ -88,9 +76,9 @@ public: { if (isInMainFile(token)) { if (includesCursorPosition(token)) { - sourceLocations.push_back(token.getLocation()); - cursorMacroDirective = macroDirective; - symbolName = Utils::SmallString(token.getIdentifierInfo()->getNameStart(), + m_sourceLocations.push_back(token.getLocation()); + m_cursorMacroDirective = macroDirective; + m_symbolName = Utils::SmallString(token.getIdentifierInfo()->getNameStart(), token.getIdentifierInfo()->getLength()); } } @@ -103,59 +91,60 @@ public: { if (includesCursorPosition(token)) { appendSourceLocations(token, macroDefinition); - cursorMacroDirective = macroDefinition.getLocalDirective(); - symbolName = Utils::SmallString(token.getIdentifierInfo()->getNameStart(), + m_cursorMacroDirective = macroDefinition.getLocalDirective(); + m_symbolName = Utils::SmallString(token.getIdentifierInfo()->getNameStart(), token.getIdentifierInfo()->getLength()); } else if (isCurrentTokenExpansion(macroDefinition)) { - sourceLocations.push_back(token.getLocation()); + m_sourceLocations.push_back(token.getLocation()); } else if (isBeforeCursorSourceLocation()) { - preCursorMacroDirectiveTokens.emplace_back(macroDefinition.getLocalDirective(), token); + m_preCursorMacroDirectiveTokens.emplace_back(macroDefinition.getLocalDirective(), token); } } void EndOfMainFile() final { - appendSourceLocationsToSourceLocationsContainer(sourceLocationsContainer, - sourceLocations, - sourceManager()); + appendSourceLocationsToSourceLocationsContainer(m_sourceLocationsContainer, + m_sourceLocations, + sourceManager(), + m_filePathCache); } private: void appendSourceLocations(const clang::Token &token, const clang::MacroDefinition ¯oDefinition) { - sourceLocations.push_back(macroDefinition.getLocalDirective()->getLocation()); - for (const auto ¯oDirectiveToken : preCursorMacroDirectiveTokens) { + m_sourceLocations.push_back(macroDefinition.getLocalDirective()->getLocation()); + for (const auto ¯oDirectiveToken : m_preCursorMacroDirectiveTokens) { if (macroDirectiveToken.macroDirective == macroDefinition.getLocalDirective()) - sourceLocations.push_back(macroDirectiveToken.token.getLocation()); + m_sourceLocations.push_back(macroDirectiveToken.token.getLocation()); } - sourceLocations.push_back(token.getLocation()); + m_sourceLocations.push_back(token.getLocation()); } void updateLocations() { - if (mainFileSourceLocation.isInvalid()) { - mainFileSourceLocation = sourceManager().getLocForStartOfFile(sourceManager().getMainFileID()); - cursorSourceLocation = sourceManager().translateLineCol(sourceManager().getMainFileID(), - line, - column); + if (m_mainFileSourceLocation.isInvalid()) { + m_mainFileSourceLocation = sourceManager().getLocForStartOfFile(sourceManager().getMainFileID()); + m_cursorSourceLocation = sourceManager().translateLineCol(sourceManager().getMainFileID(), + m_line, + m_column); } } void updateIsMainFileEntered(clang::SourceLocation location, FileChangeReason reason) { - if (location == mainFileSourceLocation && reason == PPCallbacks::EnterFile) - isMainFileEntered = true; + if (location == m_mainFileSourceLocation && reason == PPCallbacks::EnterFile) + m_isMainFileEntered = true; } const clang::SourceManager &sourceManager() const { - return preprocessor.getSourceManager(); + return m_preprocessor.getSourceManager(); } bool isInMainFile(const clang::Token &token) { - return isMainFileEntered && sourceManager().isWrittenInMainFile(token.getLocation()); + return m_isMainFileEntered && sourceManager().isWrittenInMainFile(token.getLocation()); } bool includesCursorPosition(const clang::Token &token) @@ -163,35 +152,36 @@ private: auto start = token.getLocation(); auto end = token.getEndLoc(); - return cursorSourceLocation == start - || cursorSourceLocation == end - || (sourceManager().isBeforeInTranslationUnit(start, cursorSourceLocation) && - sourceManager().isBeforeInTranslationUnit(cursorSourceLocation, end)); + return m_cursorSourceLocation == start + || m_cursorSourceLocation == end + || (sourceManager().isBeforeInTranslationUnit(start, m_cursorSourceLocation) && + sourceManager().isBeforeInTranslationUnit(m_cursorSourceLocation, end)); } bool isCurrentTokenExpansion(const clang::MacroDefinition ¯oDefinition) { - return cursorMacroDirective - && cursorMacroDirective == macroDefinition.getLocalDirective(); + return m_cursorMacroDirective + && m_cursorMacroDirective == macroDefinition.getLocalDirective(); } bool isBeforeCursorSourceLocation() const { - return !cursorMacroDirective; + return !m_cursorMacroDirective; } private: - std::vector<clang::SourceLocation> sourceLocations; - std::vector<MacroDirectiveToken> preCursorMacroDirectiveTokens; - SourceLocationsContainer &sourceLocationsContainer; - Utils::SmallString &symbolName; - clang::Preprocessor &preprocessor; - const clang::MacroDirective *cursorMacroDirective = nullptr; - clang::SourceLocation mainFileSourceLocation; - clang::SourceLocation cursorSourceLocation; - uint line; - uint column; - bool isMainFileEntered = false; + std::vector<clang::SourceLocation> m_sourceLocations; + std::vector<MacroDirectiveToken> m_preCursorMacroDirectiveTokens; + SourceLocationsContainer &m_sourceLocationsContainer; + Utils::SmallString &m_symbolName; + clang::Preprocessor &m_preprocessor; + const clang::MacroDirective *m_cursorMacroDirective = nullptr; + clang::SourceLocation m_mainFileSourceLocation; + clang::SourceLocation m_cursorSourceLocation; + FilePathCachingInterface &m_filePathCache; + uint m_line; + uint m_column; + bool m_isMainFileEntered = false; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp index 84b588118e..da16f5bdc4 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp @@ -40,7 +40,7 @@ namespace ClangBackEnd { RefactoringServer::RefactoringServer(SymbolIndexingInterface &symbolIndexing, - FilePathCache<std::mutex> &filePathCache) + FilePathCachingInterface &filePathCache) : m_symbolIndexing(symbolIndexing), m_filePathCache(filePathCache) { @@ -58,7 +58,7 @@ void RefactoringServer::end() void RefactoringServer::requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) { - SymbolFinder symbolFinder(message.line(), message.column()); + SymbolFinder symbolFinder(message.line(), message.column(), m_filePathCache); symbolFinder.addFile(std::string(message.filePath().directory()), std::string(message.filePath().name()), diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.h b/src/tools/clangrefactoringbackend/source/refactoringserver.h index b11cf3fc21..e0a1f23ce9 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.h +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.h @@ -29,12 +29,13 @@ #include <refactoringserverinterface.h> -#include <QTimer> #include <ipcclientprovider.h> -#include <stringcache.h> +#include <filepathcachinginterface.h> #include <utils/smallstring.h> +#include <QTimer> + #include <future> #include <mutex> #include <vector> @@ -54,7 +55,7 @@ class RefactoringServer : public RefactoringServerInterface, using Future = std::future<SourceRangesForQueryMessage>; public: RefactoringServer(SymbolIndexingInterface &symbolIndexing, - FilePathCache<std::mutex> &filePathCache); + FilePathCachingInterface &filePathCache); void end() override; void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) override; @@ -82,7 +83,7 @@ private: ClangQueryGatherer m_gatherer; QTimer m_pollTimer; SymbolIndexingInterface &m_symbolIndexing; - FilePathCache<std::mutex> &m_filePathCache; + FilePathCachingInterface &m_filePathCache; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationentry.cpp b/src/tools/clangrefactoringbackend/source/sourcelocationentry.cpp deleted file mode 100644 index 9cea242fa8..0000000000 --- a/src/tools/clangrefactoringbackend/source/sourcelocationentry.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 "sourcelocationentry.h" - -#include <utils/smallstringio.h> - -namespace ClangBackEnd { - -std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry) -{ - out << "(" - << entry.fileId << ", " - << entry.line << ", " - << entry.column << ")"; - - return out; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h b/src/tools/clangrefactoringbackend/source/sourcelocationentry.h index dbe7012388..1a7d89efcf 100644 --- a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h +++ b/src/tools/clangrefactoringbackend/source/sourcelocationentry.h @@ -25,11 +25,10 @@ #pragma once -#include <stringcachefwd.h> +#include <filepathid.h> #include <limits> #include <vector> -#include <iosfwd> using uint = unsigned int; @@ -59,18 +58,18 @@ class SourceLocationEntry { public: SourceLocationEntry(SymbolIndex symbolId, - FilePathIndex fileId, + FilePathId filePathId, LineColumn lineColumn, SymbolType symbolType) : symbolId(symbolId), - fileId(fileId), + filePathId(filePathId), line(lineColumn.line), column(lineColumn.column), symbolType(symbolType) {} SymbolIndex symbolId = 0; - FilePathIndex fileId = std::numeric_limits<uint>::max(); + FilePathId filePathId; uint line = 0; uint column = 0; SymbolType symbolType; @@ -78,7 +77,7 @@ public: friend bool operator==(const SourceLocationEntry &first, const SourceLocationEntry &second) { return first.symbolId == second.symbolId - && first.fileId == second.fileId + && first.filePathId == second.filePathId && first.line == second.line && first.column == second.column && first.symbolType == second.symbolType; @@ -87,6 +86,4 @@ public: using SourceLocationEntries = std::vector<SourceLocationEntry>; -std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry); - } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h b/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h index 82dfcf2b40..c7d11da517 100644 --- a/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h +++ b/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h @@ -25,28 +25,15 @@ #pragma once +#include <filepathcachinginterface.h> #include <sourcelocationscontainer.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 <clang/Basic/SourceManager.h> #include <clang/Lex/Lexer.h> #include <llvm/Support/FileSystem.h> #include <llvm/Support/FileUtilities.h> -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#elif defined(_MSC_VER) -# pragma warning(pop) -#endif - #include <iterator> #include <cctype> @@ -79,7 +66,8 @@ inline void appendSourceLocationsToSourceLocationsContainer( ClangBackEnd::SourceLocationsContainer &sourceLocationsContainer, const std::vector<clang::SourceLocation> &sourceLocations, - const clang::SourceManager &sourceManager) + const clang::SourceManager &sourceManager, + FilePathCachingInterface &filePathCache) { sourceLocationsContainer.reserve(sourceLocations.size()); @@ -89,10 +77,9 @@ void appendSourceLocationsToSourceLocationsContainer( const auto fileId = decomposedLoction.first; const auto offset = decomposedLoction.second; const auto fileEntry = sourceManager.getFileEntryForID(fileId); + auto filePath = fromNativePath(absolutePath(fileEntry->getName())); - sourceLocationsContainer.insertFilePath(fileId.getHashValue(), - fromNativePath(absolutePath(fileEntry->getName()))); - sourceLocationsContainer.insertSourceLocation(fileId.getHashValue(), + sourceLocationsContainer.insertSourceLocation(filePathCache.filePathId(filePath), fullSourceLocation.getSpellingLineNumber(), fullSourceLocation.getSpellingColumnNumber(), offset); 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)); - } } diff --git a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h index 3064642974..85c277265d 100644 --- a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h +++ b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h @@ -25,9 +25,10 @@ #pragma once -#include <stringcache.h> +#include <filepathcachingfwd.h> #include <filepath.h> +#include <filepathid.h> #include <utils/smallstringfwd.h> @@ -59,7 +60,7 @@ class SourceRangeExtractor public: SourceRangeExtractor(const clang::SourceManager &sourceManager, const clang::LangOptions &languageOptions, - ClangBackEnd::FilePathCache<std::mutex> &filePathCache, + FilePathCachingInterface &filePathCache, SourceRangesContainer &sourceRangesContainer); void addSourceRange(const clang::SourceRange &sourceRange); @@ -74,21 +75,20 @@ public: const clang::SourceRange extendSourceRangeToLastTokenEnd(const clang::SourceRange sourceRange); private: - void insertSourceRange(uint fileId, - Utils::PathString &&filePath, + void insertSourceRange(FilePathId filePathId, const clang::FullSourceLoc &startLocation, uint startOffset, const clang::FullSourceLoc &endLocation, uint endOffset, Utils::SmallString &&lineSnippet); - FilePathIndex findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const; + FilePathId findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const; private: - mutable std::unordered_map<uint, uint> m_fileIdMapping; + mutable std::unordered_map<uint, FilePathId> m_fileIdMapping; const clang::SourceManager &sourceManager; const clang::LangOptions &languageOptions; - ClangBackEnd::FilePathCache<std::mutex> &filePathCache; + FilePathCachingInterface &filePathCache; SourceRangesContainer &sourceRangesContainer; }; diff --git a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h index c144c7a9c5..5a103fd233 100644 --- a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h +++ b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h @@ -25,8 +25,6 @@ #pragma once -#include <createtablesqlstatementbuilder.h> - #include <sqlitetransaction.h> #include <sqlitetable.h> @@ -96,9 +94,6 @@ public: "INSERT INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)", database }; -// WriteStatement syncNewLocationsToLocationsStatement{ -// "INSERT INTO locations(symbolId, line, column, sourceId) SELECT symbolId, line, column, sourceId FROM newLocations", -// database}; ReadStatement selectNewSourceIdsStatement{ "SELECT DISTINCT sourceId FROM newLocations WHERE NOT EXISTS (SELECT sourceId FROM sources WHERE newLocations.sourceId == sources.sourceId)", database @@ -109,10 +104,6 @@ public: "(SELECT usr FROM symbols WHERE symbols.usr == newSymbols.usr)", database }; - WriteStatement insertSourcesStatement{ - "INSERT INTO sources(sourceId, sourcePath) VALUES(?,?)", - database - }; WriteStatement syncNewSymbolsFromSymbolsStatement{ "UPDATE newSymbols SET symbolId = (SELECT symbolId FROM symbols WHERE newSymbols.usr = symbols.usr)", database diff --git a/src/tools/clangrefactoringbackend/source/symbolfinder.cpp b/src/tools/clangrefactoringbackend/source/symbolfinder.cpp index 02f727b614..8f002f10a1 100644 --- a/src/tools/clangrefactoringbackend/source/symbolfinder.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolfinder.cpp @@ -30,9 +30,10 @@ namespace ClangBackEnd { -SymbolFinder::SymbolFinder(uint line, uint column) - : usrFindingAction(line, column), - sourceFileCallbacks(line, column) +SymbolFinder::SymbolFinder(uint line, uint column, FilePathCachingInterface &filePathCache) + : m_usrFindingAction(line, column), + m_symbolLocationFinderAction(filePathCache), + m_sourceFileCallbacks(line, column, filePathCache) { } @@ -40,39 +41,39 @@ void SymbolFinder::findSymbol() { clang::tooling::ClangTool tool = createTool(); - tool.run(clang::tooling::newFrontendActionFactory(&usrFindingAction, &sourceFileCallbacks).get()); + tool.run(clang::tooling::newFrontendActionFactory(&m_usrFindingAction, &m_sourceFileCallbacks).get()); - if (sourceFileCallbacks.hasSourceLocations()) { - sourceLocations_ = sourceFileCallbacks.takeSourceLocations(); - symbolName = sourceFileCallbacks.takeSymbolName(); + if (m_sourceFileCallbacks.hasSourceLocations()) { + m_sourceLocations_ = m_sourceFileCallbacks.takeSourceLocations(); + m_symbolName = m_sourceFileCallbacks.takeSymbolName(); } else { - symbolLocationFinderAction.setUnifiedSymbolResolutions(usrFindingAction.takeUnifiedSymbolResolutions()); + m_symbolLocationFinderAction.setUnifiedSymbolResolutions(m_usrFindingAction.takeUnifiedSymbolResolutions()); - tool.run(clang::tooling::newFrontendActionFactory(&symbolLocationFinderAction).get()); + tool.run(clang::tooling::newFrontendActionFactory(&m_symbolLocationFinderAction).get()); - sourceLocations_ = symbolLocationFinderAction.takeSourceLocations(); - symbolName = usrFindingAction.takeSymbolName(); + m_sourceLocations_ = m_symbolLocationFinderAction.takeSourceLocations(); + m_symbolName = m_usrFindingAction.takeSymbolName(); } } Utils::SmallString SymbolFinder::takeSymbolName() { - return std::move(symbolName); + return std::move(m_symbolName); } const std::vector<USRName> &SymbolFinder::unifiedSymbolResolutions() { - return symbolLocationFinderAction.unifiedSymbolResolutions(); + return m_symbolLocationFinderAction.unifiedSymbolResolutions(); } const SourceLocationsContainer &SymbolFinder::sourceLocations() const { - return sourceLocations_; + return m_sourceLocations_; } SourceLocationsContainer SymbolFinder::takeSourceLocations() { - return std::move(sourceLocations_); + return std::move(m_sourceLocations_); } } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolfinder.h b/src/tools/clangrefactoringbackend/source/symbolfinder.h index a76639aa26..a3c9659032 100644 --- a/src/tools/clangrefactoringbackend/source/symbolfinder.h +++ b/src/tools/clangrefactoringbackend/source/symbolfinder.h @@ -30,6 +30,7 @@ #include "symbollocationfinderaction.h" #include "locationsourcefilecallbacks.h" +#include <filepathcachingfwd.h> #include <sourcelocationscontainer.h> namespace ClangBackEnd { @@ -37,7 +38,7 @@ namespace ClangBackEnd { class SymbolFinder : public ClangTool { public: - SymbolFinder(uint line, uint column); + SymbolFinder(uint line, uint column, FilePathCachingInterface &filePathCache); void findSymbol(); @@ -47,12 +48,11 @@ public: SourceLocationsContainer takeSourceLocations(); private: - Utils::SmallString symbolName; - USRFindingAction usrFindingAction; - SymbolLocationFinderAction symbolLocationFinderAction; - LocationSourceFileCallbacks sourceFileCallbacks; - - ClangBackEnd::SourceLocationsContainer sourceLocations_; + Utils::SmallString m_symbolName; + USRFindingAction m_usrFindingAction; + SymbolLocationFinderAction m_symbolLocationFinderAction; + LocationSourceFileCallbacks m_sourceFileCallbacks; + ClangBackEnd::SourceLocationsContainer m_sourceLocations_; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.h b/src/tools/clangrefactoringbackend/source/symbolindexing.h index 4dd173e1bf..24957eb7bf 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexing.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexing.h @@ -33,7 +33,7 @@ #include "symbolstorage.h" #include <refactoringdatabaseinitializer.h> -#include <stringcache.h> +#include <filepathcachingfwd.h> #include <sqlitedatabase.h> #include <sqlitereadstatement.h> @@ -48,13 +48,11 @@ public: Sqlite::ReadStatement, Sqlite::WriteStatement>; using Storage = ClangBackEnd::SymbolStorage<StatementFactory>; - using DatabaseInitializer = RefactoringDatabaseInitializer<Sqlite::Database>; - SymbolIndexing(FilePathCache<std::mutex> &filePathCache, - Utils::PathString &&databaseFilePath) + SymbolIndexing(Sqlite::Database &database, + FilePathCachingInterface &filePathCache) : m_filePathCache(filePathCache), - m_database(std::move(databaseFilePath)), - m_databaseInitializer(m_database) + m_statementFactory(database) { } @@ -63,11 +61,6 @@ public: return m_indexer; } - Sqlite::Database &database() - { - return m_database; - } - void updateProjectParts(V2::ProjectPartContainers &&projectParts, V2::FileContainers &&generatedFiles) { @@ -75,11 +68,9 @@ public: } private: - FilePathCache<std::mutex> &m_filePathCache; - Sqlite::Database m_database; - DatabaseInitializer m_databaseInitializer; + FilePathCachingInterface &m_filePathCache; SymbolsCollector m_collector{m_filePathCache}; - StatementFactory m_statementFactory{m_database}; + StatementFactory m_statementFactory; Storage m_symbolStorage{m_statementFactory, m_filePathCache}; SymbolIndexer m_indexer{m_collector, m_symbolStorage}; }; diff --git a/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.cpp b/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.cpp index 2b07e893f5..f8782b405b 100644 --- a/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.cpp +++ b/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.cpp @@ -28,6 +28,8 @@ #include "sourcelocationsutils.h" #include "findlocationsofusrs.h" +#include <filepathcachingfwd.h> + #include <clang/AST/ASTConsumer.h> #include <clang/AST/ASTContext.h> @@ -38,8 +40,10 @@ namespace ClangBackEnd { class FindingSymbolsASTConsumer : public clang::ASTConsumer { public: - FindingSymbolsASTConsumer(std::vector<USRName> &unifiedSymbolResolutions) - : m_unifiedSymbolResolutions(unifiedSymbolResolutions) + FindingSymbolsASTConsumer(std::vector<USRName> &unifiedSymbolResolutions, + FilePathCachingInterface &filePathCache) + : m_unifiedSymbolResolutions(unifiedSymbolResolutions), + m_filePathCache(filePathCache) { } @@ -65,7 +69,10 @@ public: void updateSourceLocations(const std::vector<clang::SourceLocation> &sourceLocations, const clang::SourceManager &sourceManager) { - appendSourceLocationsToSourceLocationsContainer(*m_sourceLocationsContainer, sourceLocations, sourceManager); + appendSourceLocationsToSourceLocationsContainer(*m_sourceLocationsContainer, + sourceLocations, + sourceManager, + m_filePathCache); } void setSourceLocations(ClangBackEnd::SourceLocationsContainer *sourceLocations) @@ -76,11 +83,13 @@ public: private: ClangBackEnd::SourceLocationsContainer *m_sourceLocationsContainer = nullptr; std::vector<USRName> &m_unifiedSymbolResolutions; + FilePathCachingInterface &m_filePathCache; }; std::unique_ptr<clang::ASTConsumer> SymbolLocationFinderAction::newASTConsumer() { - auto consumer = std::unique_ptr<FindingSymbolsASTConsumer>(new FindingSymbolsASTConsumer(m_unifiedSymbolResolutions_)); + auto consumer = std::make_unique<FindingSymbolsASTConsumer>(m_unifiedSymbolResolutions_, + m_filePathCache); consumer->setSourceLocations(&m_sourceLocations); diff --git a/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.h b/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.h index ae601d8219..e3f4c4a2f3 100644 --- a/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.h +++ b/src/tools/clangrefactoringbackend/source/symbollocationfinderaction.h @@ -27,6 +27,7 @@ #include "clangrefactoringbackend_global.h" +#include <filepathcachingfwd.h> #include <sourcelocationscontainer.h> #include <clang/Tooling/Refactoring.h> @@ -40,27 +41,31 @@ namespace ClangBackEnd { class SymbolLocationFinderAction { public: + SymbolLocationFinderAction(FilePathCachingInterface &filePathCache) + : m_filePathCache(filePathCache) + {} - std::unique_ptr<clang::ASTConsumer> newASTConsumer(); + std::unique_ptr<clang::ASTConsumer> newASTConsumer(); - SourceLocationsContainer takeSourceLocations() - { - return std::move(m_sourceLocations); - } + SourceLocationsContainer takeSourceLocations() + { + return std::move(m_sourceLocations); + } - void setUnifiedSymbolResolutions(std::vector<USRName> &&unifiedSymbolResolutions) - { - m_unifiedSymbolResolutions_ = std::move(unifiedSymbolResolutions); - } + void setUnifiedSymbolResolutions(std::vector<USRName> &&unifiedSymbolResolutions) + { + m_unifiedSymbolResolutions_ = std::move(unifiedSymbolResolutions); + } - const std::vector<USRName> &unifiedSymbolResolutions() const - { - return m_unifiedSymbolResolutions_; - } + const std::vector<USRName> &unifiedSymbolResolutions() const + { + return m_unifiedSymbolResolutions_; + } private: - ClangBackEnd::SourceLocationsContainer m_sourceLocations; - std::vector<USRName> m_unifiedSymbolResolutions_; + ClangBackEnd::SourceLocationsContainer m_sourceLocations; + std::vector<USRName> m_unifiedSymbolResolutions_; + FilePathCachingInterface &m_filePathCache; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp index c759232a04..a6e8b21727 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp @@ -27,7 +27,7 @@ namespace ClangBackEnd { -SymbolsCollector::SymbolsCollector(FilePathCache<std::mutex> &filePathCache) +SymbolsCollector::SymbolsCollector(FilePathCachingInterface &filePathCache) : m_collectSymbolsAction(filePathCache) { } diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.h b/src/tools/clangrefactoringbackend/source/symbolscollector.h index 6bbdfbcf9e..279de0dadb 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.h +++ b/src/tools/clangrefactoringbackend/source/symbolscollector.h @@ -30,14 +30,15 @@ #include "collectsymbolsaction.h" #include "symbolscollectorinterface.h" #include "symbolentry.h" -#include "stringcache.h" + +#include <filepathcachingfwd.h> namespace ClangBackEnd { class SymbolsCollector : public ClangTool, public SymbolsCollectorInterface { public: - SymbolsCollector(FilePathCache<std::mutex> &filePathCache); + SymbolsCollector(FilePathCachingInterface &filePathCache); void addFiles(const Utils::PathStringVector &filePaths, const Utils::SmallStringVector &arguments) override; diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index 835f7dec92..b1fdb75d11 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -29,9 +29,7 @@ #include <sqliteexception.h> #include <sqlitetransaction.h> -#include <stringcache.h> - -#include <mutex> +#include <filepathcachingfwd.h> namespace ClangBackEnd { @@ -45,7 +43,7 @@ class SymbolStorage : public SymbolStorageInterface public: SymbolStorage(StatementFactory &statementFactory, - FilePathCache<std::mutex> &filePathCache) + FilePathCachingInterface &filePathCache) : m_statementFactory(statementFactory), m_filePathCache(filePathCache) { @@ -61,7 +59,6 @@ public: addNewSymbolsToSymbols(); syncNewSymbolsFromSymbols(); syncSymbolsIntoNewLocations(); - insertNewSources(); deleteAllLocationsFromUpdatedFiles(); insertNewLocationsInLocations(); deleteNewSymbolsTable(); @@ -89,7 +86,7 @@ public: statement.write(locationsEntry.symbolId, locationsEntry.line, locationsEntry.column, - locationsEntry.fileId); + locationsEntry.filePathId.fileNameId); } } @@ -118,23 +115,6 @@ public: m_statementFactory.insertNewLocationsInLocationsStatement.execute(); } - FilePathIndices selectNewSourceIds() const - { - ReadStatement &statement = m_statementFactory.selectNewSourceIdsStatement; - - return statement.template values<FilePathIndex>(16); - } - - void insertNewSources() - { - WriteStatement &statement = m_statementFactory.insertSourcesStatement; - - FilePathIndices newSourceIds = selectNewSourceIds(); - - for (FilePathIndex sourceId : newSourceIds) - statement.write(sourceId, m_filePathCache.string(sourceId)); - } - void deleteNewSymbolsTable() { m_statementFactory.deleteNewSymbolsTableStatement.execute(); @@ -152,7 +132,7 @@ public: private: StatementFactory &m_statementFactory; - FilePathCache<std::mutex> &m_filePathCache; + FilePathCachingInterface &m_filePathCache; }; } // namespace ClangBackEnd |