diff options
author | Marco Bubke <marco.bubke@qt.io> | 2017-08-17 12:44:52 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2017-09-14 13:39:55 +0000 |
commit | 3adb71d45ebebd8c8fc2ec6beeb7a5ee67d64e4e (patch) | |
tree | 7bbe767ce3f6c39f4e19428dc67e5ddb6f6c233e /src/tools | |
parent | 8488ce627b82238c7737c24909d7f6164b2061dd (diff) | |
download | qt-creator-3adb71d45ebebd8c8fc2ec6beeb7a5ee67d64e4e.tar.gz |
Clang: Add Symbol Indexing
It is a first step and now a database is generated if you start QtCreator.
Some code is now shared with the PchManager which can be improved in the
future.
Change-Id: Ic267fe7960f6c455d91832859a673ce98f269aa2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/tools')
18 files changed, 288 insertions, 40 deletions
diff --git a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp index fca9a0c9fc..fcf6f12f1f 100644 --- a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp +++ b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp @@ -26,14 +26,19 @@ #include <QCommandLineParser> #include <QCoreApplication> #include <QLoggingCategory> +#include <QDir> #include <connectionserver.h> +#include <stringcache.h> #include <refactoringserver.h> #include <refactoringclientproxy.h> +#include <symbolindexing.h> +using ClangBackEnd::FilePathCache; using ClangBackEnd::RefactoringClientProxy; using ClangBackEnd::RefactoringServer; using ClangBackEnd::ConnectionServer; +using ClangBackEnd::SymbolIndexing; QString processArguments(QCoreApplication &application) { @@ -52,7 +57,7 @@ QString processArguments(QCoreApplication &application) } int main(int argc, char *argv[]) -{ +try { //QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false")); QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); @@ -64,13 +69,17 @@ int main(int argc, char *argv[]) const QString connection = processArguments(application); - RefactoringServer clangCodeModelServer; + FilePathCache<std::mutex> filePathCache; + SymbolIndexing symbolIndexing{filePathCache, Utils::PathString{QDir::tempPath() + "/symbol.db"}}; + RefactoringServer clangCodeModelServer{symbolIndexing, filePathCache}; ConnectionServer<RefactoringServer, RefactoringClientProxy> connectionServer(connection); connectionServer.start(); connectionServer.setServer(&clangCodeModelServer); return application.exec(); +} catch (const Sqlite::SqliteException &exception) { + exception.printWarning(); } diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri index 21748bb071..8ed0c6803c 100644 --- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri +++ b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri @@ -9,7 +9,9 @@ HEADERS += \ $$PWD/symbolscollectorinterface.h \ $$PWD/symbolstorageinterface.h \ $$PWD/symbolstorage.h \ - $$PWD/storagesqlitestatementfactory.h + $$PWD/storagesqlitestatementfactory.h \ + $$PWD/symbolindexing.h \ + $$PWD/symbolindexinginterface.h !isEmpty(LIBTOOLING_LIBS) { SOURCES += \ @@ -55,4 +57,5 @@ SOURCES += \ $$PWD/symbolindexer.cpp \ $$PWD/symbolentry.cpp \ $$PWD/sourcelocationentry.cpp \ - $$PWD/symbolstorage.cpp + $$PWD/symbolstorage.cpp \ + $$PWD/symbolindexing.cpp diff --git a/src/tools/clangrefactoringbackend/source/clangtool.h b/src/tools/clangrefactoringbackend/source/clangtool.h index 7957bb7044..0f436a0e37 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.h +++ b/src/tools/clangrefactoringbackend/source/clangtool.h @@ -110,4 +110,11 @@ private: std::vector<UnsavedFileContent> m_unsavedFileContents; }; +extern template +void ClangTool::addFiles<Utils::SmallStringVector>(const Utils::SmallStringVector &filePaths, + const Utils::SmallStringVector &arguments); +extern template +void ClangTool::addFiles<Utils::PathStringVector>(const Utils::PathStringVector &filePaths, + const Utils::SmallStringVector &arguments); + } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h index ceaf0ee85b..1ddd34b595 100644 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h +++ b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h @@ -35,12 +35,14 @@ #include <clang/Frontend/FrontendAction.h> +#include <mutex> + namespace ClangBackEnd { class CollectSymbolsAction { public: - CollectSymbolsAction(FilePathCache<> &filePathCache) + CollectSymbolsAction(FilePathCache<std::mutex> &filePathCache) : m_filePathCache(filePathCache) {} @@ -64,7 +66,7 @@ public: private: SymbolEntries m_symbolEntries; SourceLocationEntries m_sourceLocationEntries; - FilePathCache<> &m_filePathCache; + FilePathCache<std::mutex> &m_filePathCache; }; diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h b/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h index 837ede57da..fcedd6a6d0 100644 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h +++ b/src/tools/clangrefactoringbackend/source/collectsymbolsastvisitor.h @@ -50,7 +50,7 @@ class CollectSymbolsASTVisitor : public clang::RecursiveASTVisitor<CollectSymbol public: CollectSymbolsASTVisitor(SymbolEntries &symbolEntries, SourceLocationEntries &sourceLocationEntries, - FilePathCache<> &filePathCache, + FilePathCache<std::mutex> &filePathCache, const clang::SourceManager &sourceManager) : m_symbolEntries(symbolEntries), m_sourceLocationEntries(sourceLocationEntries), @@ -58,8 +58,16 @@ public: m_sourceManager(sourceManager) {} + bool shouldVisitTemplateInstantiations() const + { + return true; + } + bool VisitNamedDecl(const clang::NamedDecl *declaration) { + if (!declaration->getIdentifier()) + return true; + SymbolIndex globalId = toSymbolIndex(declaration->getCanonicalDecl()); auto sourceLocation = declaration->getLocation(); @@ -141,7 +149,7 @@ private: SymbolEntries &m_symbolEntries; std::unordered_map<uint, FilePathIndex> m_filePathIndices; SourceLocationEntries &m_sourceLocationEntries; - FilePathCache<> &m_filePathCache; + FilePathCache<std::mutex> &m_filePathCache; const clang::SourceManager &m_sourceManager; }; diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h b/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h index 035db37ebc..0eeb7a73f2 100644 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h +++ b/src/tools/clangrefactoringbackend/source/collectsymbolsconsumer.h @@ -40,13 +40,14 @@ class CollectSymbolsConsumer : public clang::ASTConsumer public: CollectSymbolsConsumer(SymbolEntries &symbolEntries, SourceLocationEntries &sourceLocationEntries, - FilePathCache<> &filePathCache) + FilePathCache<std::mutex> &filePathCache) : m_symbolEntries(symbolEntries), m_sourceLocationEntries(sourceLocationEntries), m_filePathCache(filePathCache) {} - void HandleTranslationUnit(clang::ASTContext &astContext) override { + void HandleTranslationUnit(clang::ASTContext &astContext) override + { CollectSymbolsASTVisitor visitor{m_symbolEntries, m_sourceLocationEntries, m_filePathCache, @@ -54,9 +55,20 @@ public: visitor.TraverseDecl(astContext.getTranslationUnitDecl()); } + bool shouldSkipFunctionBody(clang::Decl *declation) override + { + const clang::SourceManager &sourceManager = declation->getASTContext().getSourceManager(); + const clang::SourceLocation location = declation->getLocation(); + + if (sourceManager.isInSystemHeader(location)) + return true; + + return false; + } + private: SymbolEntries &m_symbolEntries; SourceLocationEntries &m_sourceLocationEntries; - FilePathCache<> &m_filePathCache; + FilePathCache<std::mutex> &m_filePathCache; }; } diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp index 043fa87711..84b588118e 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp @@ -27,6 +27,7 @@ #include "symbolfinder.h" #include "clangquery.h" +#include "symbolindexing.h" #include <refactoringclientinterface.h> #include <clangrefactoringmessages.h> @@ -38,7 +39,10 @@ namespace ClangBackEnd { -RefactoringServer::RefactoringServer() +RefactoringServer::RefactoringServer(SymbolIndexingInterface &symbolIndexing, + FilePathCache<std::mutex> &filePathCache) + : m_symbolIndexing(symbolIndexing), + m_filePathCache(filePathCache) { m_pollTimer.setInterval(100); @@ -88,7 +92,17 @@ void RefactoringServer::requestSourceRangesForQueryMessage(RequestSourceRangesFo { gatherSourceRangesForQueryMessages(message.takeSources(), message.takeUnsavedContent(), - message.takeQuery()); + message.takeQuery()); +} + +void RefactoringServer::updatePchProjectParts(UpdatePchProjectPartsMessage &&message) +{ + m_symbolIndexing.updateProjectParts(message.takeProjectsParts(), message.takeGeneratedFiles()); +} + +void RefactoringServer::removePchProjectParts(RemovePchProjectPartsMessage &&) +{ + } void RefactoringServer::cancel() diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.h b/src/tools/clangrefactoringbackend/source/refactoringserver.h index 33eaee2a0a..b11cf3fc21 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.h +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.h @@ -42,6 +42,7 @@ namespace ClangBackEnd { class SourceRangesForQueryMessage; +class SymbolIndexingInterface; namespace V2 { class FileContainer; @@ -52,12 +53,15 @@ class RefactoringServer : public RefactoringServerInterface, { using Future = std::future<SourceRangesForQueryMessage>; public: - RefactoringServer(); + RefactoringServer(SymbolIndexingInterface &symbolIndexing, + FilePathCache<std::mutex> &filePathCache); void end() override; void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) override; void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) override; void requestSourceRangesForQueryMessage(RequestSourceRangesForQueryMessage &&message) override; + void updatePchProjectParts(UpdatePchProjectPartsMessage &&message) override; + void removePchProjectParts(RemovePchProjectPartsMessage &&message) override; void cancel() override; bool isCancelingJobs() const; @@ -75,9 +79,10 @@ private: Utils::SmallString &&query); private: - FilePathCache<std::mutex> m_filePathCache; ClangQueryGatherer m_gatherer; QTimer m_pollTimer; + SymbolIndexingInterface &m_symbolIndexing; + FilePathCache<std::mutex> &m_filePathCache; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h index 22bd7cf5f5..8e1149ca3f 100644 --- a/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h +++ b/src/tools/clangrefactoringbackend/source/storagesqlitestatementfactory.h @@ -53,8 +53,9 @@ public: table.setUseIfNotExists(true); table.setName("symbols"); table.addColumn("symbolId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); - table.addColumn("usr", Sqlite::ColumnType::Text); + const Sqlite::SqliteColumn &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text); table.addColumn("symbolName", Sqlite::ColumnType::Text); + table.addIndex({usrColumn}); Sqlite::SqliteImmediateTransaction<DatabaseType> transaction(database); table.initialize(database); @@ -71,7 +72,8 @@ public: table.addColumn("symbolId", Sqlite::ColumnType::Integer); table.addColumn("line", Sqlite::ColumnType::Integer); table.addColumn("column", Sqlite::ColumnType::Integer); - table.addColumn("sourceId", Sqlite::ColumnType::Integer); + const Sqlite::SqliteColumn &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); + table.addIndex({sourceIdColumn}); Sqlite::SqliteImmediateTransaction<DatabaseType> transaction(database); table.initialize(database); @@ -101,9 +103,11 @@ public: table.setName("newSymbols"); table.setUseTemporaryTable(true); table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); - table.addColumn("symbolId", Sqlite::ColumnType::Integer); - table.addColumn("usr", Sqlite::ColumnType::Text); - table.addColumn("symbolName", Sqlite::ColumnType::Text); + const Sqlite::SqliteColumn &symbolIdColumn = table.addColumn("symbolId", Sqlite::ColumnType::Integer); + const Sqlite::SqliteColumn &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text); + const Sqlite::SqliteColumn &symbolNameColumn = table.addColumn("symbolName", Sqlite::ColumnType::Text); + table.addIndex({usrColumn, symbolNameColumn}); + table.addIndex({symbolIdColumn}); Sqlite::SqliteImmediateTransaction<DatabaseType> transaction(database); table.initialize(database); @@ -121,7 +125,8 @@ public: table.addColumn("symbolId", Sqlite::ColumnType::Integer); table.addColumn("line", Sqlite::ColumnType::Integer); table.addColumn("column", Sqlite::ColumnType::Integer); - table.addColumn("sourceId", Sqlite::ColumnType::Integer); + const Sqlite::SqliteColumn &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); + table.addIndex({sourceIdColumn}); Sqlite::SqliteImmediateTransaction<DatabaseType> transaction(database); table.initialize(database); @@ -142,39 +147,49 @@ public: database}; WriteStatement insertLocationsToNewLocationsStatement{ "INSERT INTO newLocations(temporarySymbolId, line, column, sourceId) VALUES(?,?,?,?)", - database}; + 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}; + database + }; WriteStatement addNewSymbolsToSymbolsStatement{ - "INSERT INTO symbols(usr, symbolname) " - "SELECT usr, symbolname FROM newsymbols WHERE NOT EXISTS " - "(SELECT usr FROM symbols WHERE usr == newsymbols.usr)", - database}; + "INSERT INTO symbols(usr, symbolName) " + "SELECT usr, symbolName FROM newSymbols WHERE NOT EXISTS " + "(SELECT usr FROM symbols WHERE symbols.usr == newSymbols.usr)", + database + }; WriteStatement insertSourcesStatement{ "INSERT INTO sources(sourceId, sourcePath) VALUES(?,?)", - database}; + database + }; WriteStatement syncNewSymbolsFromSymbolsStatement{ "UPDATE newSymbols SET symbolId = (SELECT symbolId FROM symbols WHERE newSymbols.usr = symbols.usr)", - database}; + database + }; WriteStatement syncSymbolsIntoNewLocationsStatement{ "UPDATE newLocations SET symbolId = (SELECT symbolId FROM newSymbols WHERE newSymbols.temporarySymbolId = newLocations.temporarySymbolId)", - database}; + database + }; WriteStatement deleteAllLocationsFromUpdatedFilesStatement{ "DELETE FROM locations WHERE sourceId IN (SELECT DISTINCT sourceId FROM newLocations)", - database}; + database + }; WriteStatement insertNewLocationsInLocationsStatement{ "INSERT INTO locations(symbolId, line, column, sourceId) SELECT symbolId, line, column, sourceId FROM newLocations", - database}; + database + }; WriteStatement deleteNewSymbolsTableStatement{ "DELETE FROM newSymbols", - database}; + database + }; WriteStatement deleteNewLocationsTableStatement{ "DELETE FROM newLocations", - database}; + database + }; }; } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 477c7c72f4..ed48d920a6 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp @@ -33,11 +33,14 @@ SymbolIndexer::SymbolIndexer(SymbolsCollectorInterface &symbolsCollector, Symbol { } -void SymbolIndexer::updateProjectParts(V2::ProjectPartContainers &&projectParts) +void SymbolIndexer::updateProjectParts(V2::ProjectPartContainers &&projectParts, + V2::FileContainers &&generatedFiles) { for (const V2::ProjectPartContainer &projectPart : projectParts) m_symbolsCollector.addFiles(projectPart.sourcePaths(), projectPart.arguments()); + m_symbolsCollector.addUnsavedFiles(generatedFiles); + m_symbolsCollector.collectSymbols(); m_symbolStorage.addSymbolsAndSourceLocations(m_symbolsCollector.symbols(), diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.h b/src/tools/clangrefactoringbackend/source/symbolindexer.h index 625fc21c98..283e761da5 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.h @@ -29,6 +29,7 @@ #include "symbolstorageinterface.h" #include <projectpartcontainerv2.h> +#include <filecontainerv2.h> namespace ClangBackEnd { @@ -38,7 +39,8 @@ public: SymbolIndexer(SymbolsCollectorInterface &symbolsCollector, SymbolStorageInterface &symbolStorage); - void updateProjectParts(V2::ProjectPartContainers &&projectParts); + void updateProjectParts(V2::ProjectPartContainers &&projectParts, + V2::FileContainers &&generatedFiles); private: SymbolsCollectorInterface &m_symbolsCollector; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.cpp b/src/tools/clangrefactoringbackend/source/symbolindexing.cpp new file mode 100644 index 0000000000..11e34e449f --- /dev/null +++ b/src/tools/clangrefactoringbackend/source/symbolindexing.cpp @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** 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 "symbolindexing.h" + +namespace ClangBackEnd { + +} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.h b/src/tools/clangrefactoringbackend/source/symbolindexing.h new file mode 100644 index 0000000000..2986f6e4ce --- /dev/null +++ b/src/tools/clangrefactoringbackend/source/symbolindexing.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include "symbolindexinginterface.h" + +#include "storagesqlitestatementfactory.h" +#include "symbolindexer.h" +#include "symbolscollector.h" +#include "symbolstorage.h" + +#include <stringcache.h> + +#include <sqlitedatabase.h> +#include <sqlitereadstatement.h> +#include <sqlitewritestatement.h> + +namespace ClangBackEnd { + +class SymbolIndexing final : public SymbolIndexingInterface +{ +public: + using StatementFactory = ClangBackEnd::StorageSqliteStatementFactory<Sqlite::SqliteDatabase, + Sqlite::SqliteReadStatement, + Sqlite::SqliteWriteStatement>; + using Storage = ClangBackEnd::SymbolStorage<StatementFactory>; + + SymbolIndexing(FilePathCache<std::mutex> &filePathCache, + Utils::PathString &&databaseFilePath) + : m_filePathCache(filePathCache), + m_database(std::move(databaseFilePath)) + + { + } + + SymbolIndexer &indexer() + { + return m_indexer; + } + + Sqlite::SqliteDatabase &database() + { + return m_database; + } + + void updateProjectParts(V2::ProjectPartContainers &&projectParts, + V2::FileContainers &&generatedFiles) + { + m_indexer.updateProjectParts(std::move(projectParts), std::move(generatedFiles)); + } + +private: + FilePathCache<std::mutex> &m_filePathCache; + Sqlite::SqliteDatabase m_database; + SymbolsCollector m_collector{m_filePathCache}; + StatementFactory m_statementFactory{m_database}; + Storage m_symbolStorage{m_statementFactory, m_filePathCache}; + SymbolIndexer m_indexer{m_collector, m_symbolStorage}; +}; + +} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h b/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h new file mode 100644 index 0000000000..8c331aadce --- /dev/null +++ b/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include <projectpartcontainerv2.h> +#include <filecontainerv2.h> + +namespace ClangBackEnd { + +class SymbolIndexingInterface +{ +public: + virtual void updateProjectParts(V2::ProjectPartContainers &&projectParts, + V2::FileContainers &&generatedFiles) = 0; +}; + +} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp index f83d71e1c1..c759232a04 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp @@ -27,7 +27,7 @@ namespace ClangBackEnd { -SymbolsCollector::SymbolsCollector(FilePathCache<> &filePathCache) +SymbolsCollector::SymbolsCollector(FilePathCache<std::mutex> &filePathCache) : m_collectSymbolsAction(filePathCache) { } @@ -37,6 +37,11 @@ void SymbolsCollector::addFiles(const Utils::PathStringVector &filePaths, const ClangTool::addFiles(filePaths, arguments); } +void SymbolsCollector::addUnsavedFiles(const V2::FileContainers &unsavedFiles) +{ + ClangTool::addUnsavedFiles(unsavedFiles); +} + void SymbolsCollector::collectSymbols() { auto tool = createTool(); diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.h b/src/tools/clangrefactoringbackend/source/symbolscollector.h index d0eb020158..6bbdfbcf9e 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.h +++ b/src/tools/clangrefactoringbackend/source/symbolscollector.h @@ -37,11 +37,13 @@ namespace ClangBackEnd { class SymbolsCollector : public ClangTool, public SymbolsCollectorInterface { public: - SymbolsCollector(FilePathCache<> &filePathCache); + SymbolsCollector(FilePathCache<std::mutex> &filePathCache); void addFiles(const Utils::PathStringVector &filePaths, const Utils::SmallStringVector &arguments) override; + void addUnsavedFiles(const V2::FileContainers &unsavedFiles) override; + void collectSymbols() override; const SymbolEntries &symbols() const override; diff --git a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h index a34705382e..fcb909bdc8 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h +++ b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h @@ -28,6 +28,8 @@ #include "symbolentry.h" #include "sourcelocationentry.h" +#include <filecontainerv2.h> + #include <utils/smallstringvector.h> #include <string> @@ -41,6 +43,8 @@ public: virtual void addFiles(const Utils::PathStringVector &filePaths, const Utils::SmallStringVector &arguments) = 0; + virtual void addUnsavedFiles(const V2::FileContainers &unsavedFiles) = 0; + virtual void collectSymbols() = 0; virtual const SymbolEntries &symbols() const = 0; diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index 12163b0f25..cbe2e570da 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -27,9 +27,12 @@ #include "symbolstorageinterface.h" +#include <sqliteexception.h> #include <sqlitetransaction.h> #include <stringcache.h> +#include <mutex> + namespace ClangBackEnd { template <typename StatementFactory> @@ -42,7 +45,7 @@ class SymbolStorage : public SymbolStorageInterface public: SymbolStorage(StatementFactory &statementFactory, - FilePathCache<> &filePathCache) + FilePathCache<std::mutex> &filePathCache) : m_statementFactory(statementFactory), m_filePathCache(filePathCache) { @@ -149,7 +152,7 @@ public: private: StatementFactory &m_statementFactory; - FilePathCache<> &m_filePathCache; + FilePathCache<std::mutex> &m_filePathCache; }; } // namespace ClangBackEnd |