summaryrefslogtreecommitdiff
path: root/src/tools/clangrefactoringbackend/source
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clangrefactoringbackend/source')
-rw-r--r--src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri8
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexer.cpp46
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexertask.h5
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.cpp71
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h46
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h9
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.cpp146
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.h91
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexertaskschedulerinterface.h60
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexing.h34
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollector.cpp4
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollector.h2
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h17
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollectormanager.h89
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolscollectormanagerinterface.h49
15 files changed, 101 insertions, 576 deletions
diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri
index d15e0f625d..26fa44aa68 100644
--- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri
+++ b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri
@@ -24,11 +24,7 @@ HEADERS += \
$$PWD/indexdataconsumer.h \
$$PWD/sourcesmanager.h \
$$PWD/symbolindexertaskqueue.h \
- $$PWD/symbolindexertaskscheduler.h \
- $$PWD/symbolscollectormanagerinterface.h \
$$PWD/symbolindexertaskqueueinterface.h \
- $$PWD/symbolindexertaskschedulerinterface.h \
- $$PWD/symbolscollectormanager.h \
$$PWD/symbolindexertask.h
!isEmpty(LIBTOOLING_LIBS) {
@@ -74,6 +70,4 @@ SOURCES += \
$$PWD/sourcerangefilter.cpp \
$$PWD/symbolindexer.cpp \
$$PWD/projectpartartefact.cpp \
- $$PWD/filestatuscache.cpp \
- $$PWD/symbolindexertaskqueue.cpp \
- $$PWD/symbolindexertaskscheduler.cpp
+ $$PWD/filestatuscache.cpp
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp
index 5c9f0cbccc..272e89fa89 100644
--- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp
+++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp
@@ -101,27 +101,25 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart)
std::vector<SymbolIndexerTask> symbolIndexerTask;
symbolIndexerTask.reserve(projectPart.sourcePathIds.size());
for (FilePathId sourcePathId : projectPart.sourcePathIds) {
- auto indexing = [projectPartId, arguments, sourcePathId]
- (SymbolsCollectorInterface &symbolsCollector,
- SymbolStorageInterface &symbolStorage,
- Sqlite::TransactionInterface &transactionInterface) {
+ auto indexing = [projectPartId, arguments, sourcePathId, this]
+ (SymbolsCollectorInterface &symbolsCollector) {
symbolsCollector.setFile(sourcePathId, arguments);
symbolsCollector.collectSymbols();
- Sqlite::ImmediateTransaction transaction{transactionInterface};
+ Sqlite::ImmediateTransaction transaction{m_transactionInterface};
- symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
- symbolsCollector.sourceLocations());
+ m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
+ symbolsCollector.sourceLocations());
- symbolStorage.updateProjectPartSources(projectPartId,
- symbolsCollector.sourceFiles());
+ m_symbolStorage.updateProjectPartSources(projectPartId,
+ symbolsCollector.sourceFiles());
- symbolStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
+ m_symbolStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
- symbolStorage.insertFileStatuses(symbolsCollector.fileStatuses());
+ m_symbolStorage.insertFileStatuses(symbolsCollector.fileStatuses());
- symbolStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
+ m_symbolStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
transaction.commit();
};
@@ -130,7 +128,7 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart)
}
m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask));
- m_symbolIndexerTaskQueue.processTasks();
+ m_symbolIndexerTaskQueue.processEntries();
}
void SymbolIndexer::pathsWithIdsChanged(const Utils::SmallStringVector &)
@@ -146,7 +144,7 @@ void SymbolIndexer::pathsChanged(const FilePathIds &filePathIds)
updateChangedPath(filePathId, symbolIndexerTask);
m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask));
- m_symbolIndexerTaskQueue.processTasks();
+ m_symbolIndexerTaskQueue.processEntries();
}
void SymbolIndexer::updateChangedPath(FilePathId filePathId,
@@ -169,26 +167,24 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
const Utils::SmallStringVector arguments = compilerArguments(artefact.compilerArguments,
optionalProjectPartPch);
- auto indexing = [projectPartId=artefact.projectPartId, arguments, filePathId]
- (SymbolsCollectorInterface &symbolsCollector,
- SymbolStorageInterface &symbolStorage,
- Sqlite::TransactionInterface &transactionInterface) {
+ auto indexing = [projectPartId=artefact.projectPartId, arguments, filePathId, this]
+ (SymbolsCollectorInterface &symbolsCollector) {
symbolsCollector.setFile(filePathId, arguments);
symbolsCollector.collectSymbols();
- Sqlite::ImmediateTransaction transaction{transactionInterface};
+ Sqlite::ImmediateTransaction transaction{m_transactionInterface};
- symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
- symbolsCollector.sourceLocations());
+ m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
+ symbolsCollector.sourceLocations());
- symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles());
+ m_symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles());
- symbolStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
+ m_symbolStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
- symbolStorage.insertFileStatuses(symbolsCollector.fileStatuses());
+ m_symbolStorage.insertFileStatuses(symbolsCollector.fileStatuses());
- symbolStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
+ m_symbolStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies());
transaction.commit();
};
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertask.h b/src/tools/clangrefactoringbackend/source/symbolindexertask.h
index 3b18681e07..de3303815d 100644
--- a/src/tools/clangrefactoringbackend/source/symbolindexertask.h
+++ b/src/tools/clangrefactoringbackend/source/symbolindexertask.h
@@ -35,16 +35,13 @@ class TransactionInterface;
namespace ClangBackEnd {
-class SymbolIndexerTaskSchedulerInterface;
class SymbolsCollectorInterface;
class SymbolStorageInterface;
class SymbolIndexerTask
{
public:
- using Callable = std::function<void(SymbolsCollectorInterface &symbolsCollector,
- SymbolStorageInterface &symbolStorage,
- Sqlite::TransactionInterface &transaction)>;
+ using Callable = std::function<void(SymbolsCollectorInterface &symbolsCollector)>;
SymbolIndexerTask(FilePathId filePathId,
int projectPartId,
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.cpp b/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.cpp
deleted file mode 100644
index bb891467a6..0000000000
--- a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 "symbolindexertaskqueue.h"
-
-#include <symbolindexertaskschedulerinterface.h>
-
-#include <utils/algorithm.h>
-
-namespace ClangBackEnd {
-
-void SymbolIndexerTaskQueue::addOrUpdateTasks(std::vector<SymbolIndexerTask> &&tasks)
-{
- auto merge = [] (SymbolIndexerTask &&first, SymbolIndexerTask &&second) {
- first.callable = std::move(second.callable);
-
- return std::move(first);
- };
-
- m_tasks = Utils::setUnionMerge<std::vector<SymbolIndexerTask>>(tasks, m_tasks, merge);
-}
-
-void SymbolIndexerTaskQueue::removeTasks(const std::vector<int> &projectPartIds)
-{
- auto shouldBeRemoved = [&] (const SymbolIndexerTask& task) {
- return std::binary_search(projectPartIds.begin(), projectPartIds.end(), task.projectPartId);
- };
-
- auto newEnd = std::remove_if(m_tasks.begin(), m_tasks.end(), shouldBeRemoved);
-
- m_tasks.erase(newEnd, m_tasks.end());
-}
-
-const std::vector<SymbolIndexerTask> &SymbolIndexerTaskQueue::tasks() const
-{
- return m_tasks;
-}
-
-void SymbolIndexerTaskQueue::processTasks()
-{
- int taskCount = m_symbolIndexerScheduler.freeSlots();
-
- auto newEnd = std::prev(m_tasks.end(), std::min<int>(taskCount, int(m_tasks.size())));
- m_symbolIndexerScheduler.addTasks({std::make_move_iterator(newEnd),
- std::make_move_iterator(m_tasks.end())});
- m_tasks.erase(newEnd, m_tasks.end());
-}
-
-} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h b/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h
index 6a627e8865..3dc54998d0 100644
--- a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h
+++ b/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h
@@ -29,7 +29,9 @@
#include "symbolindexertask.h"
#include <filepathid.h>
+#include <taskschedulerinterface.h>
+#include <utils/algorithm.h>
#include <utils/smallstringvector.h>
#include <functional>
@@ -41,29 +43,59 @@ class TransactionInterface;
namespace ClangBackEnd {
-class SymbolIndexerTaskSchedulerInterface;
class SymbolsCollectorInterface;
class SymbolStorageInterface;
class SymbolIndexerTaskQueue final : public SymbolIndexerTaskQueueInterface
{
public:
- SymbolIndexerTaskQueue(SymbolIndexerTaskSchedulerInterface &symbolIndexerTaskScheduler)
+ using Task = SymbolIndexerTask::Callable;
+
+ SymbolIndexerTaskQueue(TaskSchedulerInterface<Task> &symbolIndexerTaskScheduler)
: m_symbolIndexerScheduler(symbolIndexerTaskScheduler)
{}
- void addOrUpdateTasks(std::vector<SymbolIndexerTask> &&tasks);
- void removeTasks(const std::vector<int> &projectPartIds);
+ void addOrUpdateTasks(std::vector<SymbolIndexerTask> &&tasks)
+ {
+ auto merge = [] (SymbolIndexerTask &&first, SymbolIndexerTask &&second) {
+ first.callable = std::move(second.callable);
+
+ return std::move(first);
+ };
+
+ m_tasks = Utils::setUnionMerge<std::vector<SymbolIndexerTask>>(tasks, m_tasks, merge);
+ }
+ void removeTasks(const std::vector<int> &projectPartIds)
+ {
+ auto shouldBeRemoved = [&] (const SymbolIndexerTask& task) {
+ return std::binary_search(projectPartIds.begin(), projectPartIds.end(), task.projectPartId);
+ };
+
+ auto newEnd = std::remove_if(m_tasks.begin(), m_tasks.end(), shouldBeRemoved);
+
+ m_tasks.erase(newEnd, m_tasks.end());
+ }
+
+ const std::vector<SymbolIndexerTask> &tasks() const
+ {
+ return m_tasks;
+ }
- const std::vector<SymbolIndexerTask> &tasks() const;
+ void processEntries()
+ {
+ uint taskCount = m_symbolIndexerScheduler.freeSlots();
- void processTasks();
+ auto newEnd = std::prev(m_tasks.end(), std::min<int>(int(taskCount), int(m_tasks.size())));
+ m_symbolIndexerScheduler.addTasks({std::make_move_iterator(newEnd),
+ std::make_move_iterator(m_tasks.end())});
+ m_tasks.erase(newEnd, m_tasks.end());
+ }
void syncTasks();
private:
std::vector<Utils::SmallString> m_projectPartIds;
std::vector<SymbolIndexerTask> m_tasks;
- SymbolIndexerTaskSchedulerInterface &m_symbolIndexerScheduler;
+ TaskSchedulerInterface<Task> &m_symbolIndexerScheduler;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h b/src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h
index 9e96a79e6c..dfcc78bd23 100644
--- a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h
+++ b/src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h
@@ -25,24 +25,21 @@
#pragma once
+#include <queueinterface.h>
+
#include <utils/smallstringvector.h>
namespace ClangBackEnd {
class SymbolIndexerTask;
-class SymbolIndexerTaskQueueInterface
+class SymbolIndexerTaskQueueInterface : public QueueInterface
{
public:
- SymbolIndexerTaskQueueInterface() = default;
- SymbolIndexerTaskQueueInterface(const SymbolIndexerTaskQueueInterface &) = delete;
- SymbolIndexerTaskQueueInterface &operator=(const SymbolIndexerTaskQueueInterface &) = delete;
-
virtual void addOrUpdateTasks(std::vector<SymbolIndexerTask> &&tasks) = 0
/* [[expects: std::is_sorted(tasks)]] */;
virtual void removeTasks(const std::vector<int> &projectPartIds) = 0
/* [[expects: std::is_sorted(projectPartIds)]] */;
- virtual void processTasks() = 0;
protected:
~SymbolIndexerTaskQueueInterface() = default;
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.cpp b/src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.cpp
deleted file mode 100644
index e9f5cbe285..0000000000
--- a/src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 "symbolindexertaskscheduler.h"
-
-#include <symbolindexertaskqueueinterface.h>
-#include <symbolscollectormanagerinterface.h>
-#include <symbolscollectorinterface.h>
-
-#include <QAbstractEventDispatcher>
-#include <QCoreApplication>
-#include <QMetaObject>
-#include <QThread>
-
-#include <algorithm>
-#include <thread>
-
-namespace ClangBackEnd {
-namespace {
-#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
-template <typename CallableType>
-class CallableEvent : public QEvent {
-public:
- using Callable = std::decay_t<CallableType>;
- CallableEvent(Callable &&callable)
- : QEvent(QEvent::None),
- callable(std::move(callable))
- {}
- CallableEvent(const Callable &callable)
- : QEvent(QEvent::None),
- callable(callable)
- {}
-
- ~CallableEvent()
- {
- callable();
- }
-public:
- Callable callable;
-};
-
-template <typename Callable>
-void executeInLoop(Callable &&callable, QObject *object = QCoreApplication::instance()) {
- if (QThread *thread = qobject_cast<QThread*>(object))
- object = QAbstractEventDispatcher::instance(thread);
-
- QCoreApplication::postEvent(object,
- new CallableEvent<Callable>(std::forward<Callable>(callable)),
- Qt::HighEventPriority);
-}
-#else
-template <typename Callable>
-void executeInLoop(Callable &&callable, QObject *object = QCoreApplication::instance()) {
- if (QThread *thread = qobject_cast<QThread*>(object))
- object = QAbstractEventDispatcher::instance(thread);
-
- QMetaObject::invokeMethod(object, std::forward<Callable>(callable));
-}
-#endif
-}
-
-void SymbolIndexerTaskScheduler::addTasks(std::vector<Task> &&tasks)
-{
- for (auto &task : tasks) {
- auto callWrapper = [&, task=std::move(task)] (
- std::reference_wrapper<SymbolsCollectorInterface> symbolsCollector)
- -> SymbolsCollectorInterface& {
- task(symbolsCollector.get(), m_symbolStorage, m_transactionInterface);
- executeInLoop([&] {
- m_symbolIndexerTaskQueue.processTasks();
- });
-
- return symbolsCollector;
- };
- m_futures.emplace_back(std::async(m_launchPolicy,
- std::move(callWrapper),
- std::ref(m_symbolsCollectorManager.unusedSymbolsCollector())));
- }
-}
-
-const std::vector<SymbolIndexerTaskScheduler::Future> &SymbolIndexerTaskScheduler::futures() const
-{
- return m_futures;
-}
-
-uint SymbolIndexerTaskScheduler::freeSlots()
-{
- removeFinishedFutures();
-
- if (m_isDisabled)
- return 0;
-
- return uint(std::max(int(m_hardware_concurrency) - int(m_futures.size()), 0));
-}
-
-void SymbolIndexerTaskScheduler::syncTasks()
-{
- for (auto &future : m_futures)
- future.wait();
-}
-
-void SymbolIndexerTaskScheduler::disable()
-{
- m_isDisabled = true;
-}
-
-void SymbolIndexerTaskScheduler::removeFinishedFutures()
-{
- auto notReady = [] (Future &future) {
- return future.wait_for(std::chrono::duration<int>::zero()) != std::future_status::ready;
- };
-
- auto split = std::partition(m_futures.begin(), m_futures.end(), notReady);
-
- std::for_each(split, m_futures.end(), [] (Future &future) {
- SymbolsCollectorInterface &symbolCollector = future.get();
- symbolCollector.setIsUsed(false);
- symbolCollector.clear();
- });
-
- m_futures.erase(split, m_futures.end());
-}
-
-} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.h b/src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.h
deleted file mode 100644
index 6182376dab..0000000000
--- a/src/tools/clangrefactoringbackend/source/symbolindexertaskscheduler.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 "symbolindexertaskschedulerinterface.h"
-#include "symbolindexertask.h"
-
-#include <functional>
-#include <future>
-#include <vector>
-
-namespace Sqlite {
-class TransactionInterface;
-};
-
-namespace ClangBackEnd {
-
-class FilePathCachingInterface;
-class SymbolsCollectorInterface;
-class SymbolsCollectorManagerInterface;
-class SymbolIndexerTaskQueueInterface;
-class SymbolStorageInterface;
-
-class SymbolIndexerTaskScheduler final : public SymbolIndexerTaskSchedulerInterface
-{
-public:
- using Task = SymbolIndexerTask::Callable;
- using Future = std::future<SymbolsCollectorInterface&>;
-
- SymbolIndexerTaskScheduler(SymbolsCollectorManagerInterface &symbolsCollectorManager,
- SymbolStorageInterface &symbolStorage,
- Sqlite::TransactionInterface &transactionInterface,
- SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue,
- uint hardware_concurrency,
- std::launch launchPolicy = std::launch::async)
- : m_symbolsCollectorManager(symbolsCollectorManager),
- m_symbolStorage(symbolStorage),
- m_transactionInterface(transactionInterface),
- m_symbolIndexerTaskQueue(symbolIndexerTaskQueue),
- m_hardware_concurrency(hardware_concurrency),
- m_launchPolicy(launchPolicy)
- {}
-
- void addTasks(std::vector<Task> &&tasks);
-
- const std::vector<Future> &futures() const;
-
- uint freeSlots();
-
- void syncTasks();
-
- void disable();
-
-private:
- void removeFinishedFutures();
-
-private:
- std::vector<Future> m_futures;
- SymbolsCollectorManagerInterface &m_symbolsCollectorManager;
- SymbolStorageInterface &m_symbolStorage;
- Sqlite::TransactionInterface &m_transactionInterface;
- SymbolIndexerTaskQueueInterface &m_symbolIndexerTaskQueue;
- uint m_hardware_concurrency;
- std::launch m_launchPolicy;
- bool m_isDisabled = false;
-};
-
-} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskschedulerinterface.h b/src/tools/clangrefactoringbackend/source/symbolindexertaskschedulerinterface.h
deleted file mode 100644
index c71454df3d..0000000000
--- a/src/tools/clangrefactoringbackend/source/symbolindexertaskschedulerinterface.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 <functional>
-#include <vector>
-
-namespace Sqlite {
-class TransactionInterface;
-}
-
-namespace ClangBackEnd {
-
-class SymbolsCollectorInterface;
-class SymbolStorageInterface;
-
-using uint = unsigned int;
-
-class SymbolIndexerTaskSchedulerInterface
-{
-public:
- using Task = std::function<void(SymbolsCollectorInterface &symbolsCollector,
- SymbolStorageInterface &symbolStorage,
- Sqlite::TransactionInterface &transaction)>;
-
- SymbolIndexerTaskSchedulerInterface() = default;
- SymbolIndexerTaskSchedulerInterface(const SymbolIndexerTaskSchedulerInterface &) = delete;
- SymbolIndexerTaskSchedulerInterface &operator=(const SymbolIndexerTaskSchedulerInterface &) = delete;
-
- virtual void addTasks(std::vector<Task> &&tasks) = 0;
- virtual uint freeSlots() = 0;
-
-protected:
- ~SymbolIndexerTaskSchedulerInterface() = default;
-};
-
-} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.h b/src/tools/clangrefactoringbackend/source/symbolindexing.h
index 8f7821bddb..918edb626a 100644
--- a/src/tools/clangrefactoringbackend/source/symbolindexing.h
+++ b/src/tools/clangrefactoringbackend/source/symbolindexing.h
@@ -30,9 +30,9 @@
#include "storagesqlitestatementfactory.h"
#include "symbolindexer.h"
#include "symbolscollector.h"
-#include "symbolscollectormanager.h"
+#include "processormanager.h"
#include "symbolindexertaskqueue.h"
-#include "symbolindexertaskscheduler.h"
+#include "taskscheduler.h"
#include "symbolstorage.h"
#include <refactoringdatabaseinitializer.h>
@@ -48,19 +48,40 @@
namespace ClangBackEnd {
+class SymbolsCollectorManager;
+
+class SymbolsCollectorManager final : public ClangBackEnd::ProcessorManager<SymbolsCollector>
+{
+public:
+ using Processor = SymbolsCollector;
+ SymbolsCollectorManager(const ClangBackEnd::GeneratedFiles &generatedFiles,
+ Sqlite::Database &database)
+ : ProcessorManager(generatedFiles),
+ m_database(database)
+ {}
+
+protected:
+ std::unique_ptr<SymbolsCollector> createProcessor() const
+ {
+ return std::make_unique<SymbolsCollector>(m_database);
+ }
+
+private:
+ Sqlite::Database &m_database;
+};
+
class SymbolIndexing final : public SymbolIndexingInterface
{
public:
using StatementFactory = ClangBackEnd::StorageSqliteStatementFactory<Sqlite::Database>;
using Storage = ClangBackEnd::SymbolStorage<StatementFactory>;
-
SymbolIndexing(Sqlite::Database &database,
FilePathCachingInterface &filePathCache,
const GeneratedFiles &generatedFiles)
: m_filePathCache(filePathCache),
m_statementFactory(database),
- m_collectorManger(database, generatedFiles),
- m_indexerScheduler(m_collectorManger, m_symbolStorage, database, m_indexerQueue, std::thread::hardware_concurrency())
+ m_collectorManger(generatedFiles, database),
+ m_indexerScheduler(m_collectorManger, m_indexerQueue, std::thread::hardware_concurrency())
{
}
@@ -86,12 +107,13 @@ public:
void updateProjectParts(V2::ProjectPartContainers &&projectParts) override;
private:
+ using SymbolIndexerTaskScheduler = TaskScheduler<SymbolsCollectorManager, SymbolIndexerTask::Callable>;
FilePathCachingInterface &m_filePathCache;
StatementFactory m_statementFactory;
Storage m_symbolStorage{m_statementFactory};
ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache};
FileStatusCache m_fileStatusCache{m_filePathCache};
- SymbolsCollectorManager<SymbolsCollector> m_collectorManger;
+ SymbolsCollectorManager m_collectorManger;
SymbolIndexerTaskScheduler m_indexerScheduler;
SymbolIndexerTaskQueue m_indexerQueue{m_indexerScheduler};
SymbolIndexer m_indexer{m_indexerQueue,
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp
index 53e0bbba6e..afa01de2e9 100644
--- a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp
+++ b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp
@@ -129,6 +129,10 @@ void SymbolsCollector::collectSymbols()
&m_collectMacrosSourceFileCallbacks).get());
}
+void SymbolsCollector::doInMainThreadAfterFinished()
+{
+}
+
const SymbolEntries &SymbolsCollector::symbols() const
{
return m_symbolEntries;
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.h b/src/tools/clangrefactoringbackend/source/symbolscollector.h
index 70213555d6..beb610d190 100644
--- a/src/tools/clangrefactoringbackend/source/symbolscollector.h
+++ b/src/tools/clangrefactoringbackend/source/symbolscollector.h
@@ -54,6 +54,8 @@ public:
void collectSymbols() override;
+ void doInMainThreadAfterFinished() override;
+
const SymbolEntries &symbols() const override;
const SourceLocationEntries &sourceLocations() const override;
const FilePathIds &sourceFiles() const override;
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h
index 540866630f..0b7e00509d 100644
--- a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h
+++ b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h
@@ -31,7 +31,7 @@
#include "sourcelocationentry.h"
#include "usedmacro.h"
-#include <filecontainerv2.h>
+#include <processorinterface.h>
#include <utils/smallstringvector.h>
@@ -40,20 +40,10 @@
namespace ClangBackEnd {
-class SymbolsCollectorInterface
+class SymbolsCollectorInterface : public ProcessorInterface
{
public:
- SymbolsCollectorInterface() = default;
- virtual ~SymbolsCollectorInterface() = default;
- SymbolsCollectorInterface(const SymbolsCollectorInterface &) = delete;
- SymbolsCollectorInterface &operator=(const SymbolsCollectorInterface &) = delete;
-
virtual void setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) = 0;
-
- virtual void setUnsavedFiles(const V2::FileContainers &unsavedFiles) = 0;
-
- virtual void clear() = 0;
-
virtual void collectSymbols() = 0;
virtual const SymbolEntries &symbols() const = 0;
@@ -62,9 +52,6 @@ public:
virtual const UsedMacros &usedMacros() const = 0;
virtual const FileStatuses &fileStatuses() const = 0;
virtual const SourceDependencies &sourceDependencies() const = 0;
-
- virtual bool isUsed() const = 0;
- virtual void setIsUsed(bool isUsed) = 0;
};
} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollectormanager.h b/src/tools/clangrefactoringbackend/source/symbolscollectormanager.h
deleted file mode 100644
index d5a020904f..0000000000
--- a/src/tools/clangrefactoringbackend/source/symbolscollectormanager.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 "symbolscollectormanagerinterface.h"
-#include "symbolscollectorinterface.h"
-#include "generatedfiles.h"
-
-#include <memory>
-
-namespace Sqlite {
-class Database;
-}
-
-namespace ClangBackEnd {
-
-class GeneratedFiles;
-class SymbolsCollector;
-template<typename SymbolsCollector>
-class SymbolsCollectorManager final : public SymbolsCollectorManagerInterface
-{
-public:
- SymbolsCollectorManager(Sqlite::Database &database,
- const GeneratedFiles &generatedFiles)
- : m_database(database),
- m_generatedFiles(generatedFiles)
- {}
-
- SymbolsCollector &unusedSymbolsCollector() override
- {
- auto split = std::partition(m_collectors.begin(),
- m_collectors.end(),
- [] (const auto &collector) {
- return collector->isUsed();
- });
-
- auto freeCollectors = std::distance(split, m_collectors.end());
-
- if (freeCollectors > 0)
- return initializedCollector(*split->get());
-
- m_collectors.emplace_back(std::make_unique<SymbolsCollector>(m_database));
-
- return initializedCollector(*m_collectors.back().get());
- }
-
- const std::vector<std::unique_ptr<SymbolsCollector>> &collectors() const
- {
- return m_collectors;
- }
-
-private:
- SymbolsCollector &initializedCollector(SymbolsCollector &collector)
- {
- collector.setIsUsed(true);
- collector.setUnsavedFiles(m_generatedFiles.fileContainers());
- return collector;
- }
-
-private:
- std::vector<std::unique_ptr<SymbolsCollector>> m_collectors;
- Sqlite::Database &m_database;
- const GeneratedFiles &m_generatedFiles;
-};
-
-} // namespace ClangBackEnd
diff --git a/src/tools/clangrefactoringbackend/source/symbolscollectormanagerinterface.h b/src/tools/clangrefactoringbackend/source/symbolscollectormanagerinterface.h
deleted file mode 100644
index b0cb3a0332..0000000000
--- a/src/tools/clangrefactoringbackend/source/symbolscollectormanagerinterface.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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 <filecontainerv2.h>
-
-#include <vector>
-
-namespace ClangBackEnd {
-
-class SymbolsCollectorInterface;
-
-class SymbolsCollectorManagerInterface
-{
-public:
- SymbolsCollectorManagerInterface() = default;
- SymbolsCollectorManagerInterface(const SymbolsCollectorManagerInterface &) = delete;
- SymbolsCollectorManagerInterface &operator=(const SymbolsCollectorManagerInterface &) = delete;
-
- virtual SymbolsCollectorInterface &unusedSymbolsCollector() = 0;
-
-protected:
- ~SymbolsCollectorManagerInterface() = default;
-};
-
-} // namespace ClangBackEnd