forked from qt-creator/qt-creator
Clang: Improve generated files handling
Generated files are referenced by the system collector directly to set the unsaved files. Change-Id: I24be3ee544b7824b8b0e518eafd409f32bd002ab Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -76,5 +76,4 @@ SOURCES += \
|
||||
$$PWD/projectpartartefact.cpp \
|
||||
$$PWD/filestatuscache.cpp \
|
||||
$$PWD/symbolindexertaskqueue.cpp \
|
||||
$$PWD/symbolindexertaskscheduler.cpp \
|
||||
$$PWD/symbolscollectormanager.cpp
|
||||
$$PWD/symbolindexertaskscheduler.cpp
|
||||
|
||||
@@ -40,9 +40,11 @@
|
||||
namespace ClangBackEnd {
|
||||
|
||||
RefactoringServer::RefactoringServer(SymbolIndexingInterface &symbolIndexing,
|
||||
FilePathCachingInterface &filePathCache)
|
||||
FilePathCachingInterface &filePathCache,
|
||||
GeneratedFiles &generatedFiles)
|
||||
: m_symbolIndexing(symbolIndexing),
|
||||
m_filePathCache(filePathCache)
|
||||
m_filePathCache(filePathCache),
|
||||
m_generatedFiles(generatedFiles)
|
||||
{
|
||||
m_pollTimer.setInterval(100);
|
||||
|
||||
@@ -97,8 +99,7 @@ void RefactoringServer::requestSourceRangesForQueryMessage(RequestSourceRangesFo
|
||||
|
||||
void RefactoringServer::updateProjectParts(UpdateProjectPartsMessage &&message)
|
||||
{
|
||||
m_symbolIndexing.updateProjectParts(message.takeProjectsParts(),
|
||||
m_generatedFiles.fileContainers());
|
||||
m_symbolIndexing.updateProjectParts(message.takeProjectsParts());
|
||||
}
|
||||
|
||||
void RefactoringServer::updateGeneratedFiles(UpdateGeneratedFilesMessage &&message)
|
||||
|
||||
@@ -56,7 +56,8 @@ class RefactoringServer : public RefactoringServerInterface,
|
||||
using Future = std::future<SourceRangesForQueryMessage>;
|
||||
public:
|
||||
RefactoringServer(SymbolIndexingInterface &symbolIndexing,
|
||||
FilePathCachingInterface &filePathCache);
|
||||
FilePathCachingInterface &filePathCache,
|
||||
GeneratedFiles &generatedFiles);
|
||||
|
||||
void end() override;
|
||||
void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) override;
|
||||
@@ -85,10 +86,10 @@ private:
|
||||
|
||||
private:
|
||||
ClangQueryGatherer m_gatherer;
|
||||
GeneratedFiles m_generatedFiles;
|
||||
QTimer m_pollTimer;
|
||||
SymbolIndexingInterface &m_symbolIndexing;
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
GeneratedFiles &m_generatedFiles;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -25,11 +25,37 @@
|
||||
|
||||
#include "symbolindexer.h"
|
||||
|
||||
#include <symbolscollector.h>
|
||||
#include <symbolscollectorinterface.h>
|
||||
#include <symbolindexertaskqueue.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer(Utils::SmallStringView name)
|
||||
: name(name)
|
||||
{}
|
||||
|
||||
void commit()
|
||||
{
|
||||
auto end = steady_clock::now();
|
||||
auto time_difference = duration_cast<milliseconds>(end - begin);
|
||||
begin = end;
|
||||
std::cerr << name << " " << timePoint++ << ": " << time_difference.count() << "\n";
|
||||
}
|
||||
|
||||
private:
|
||||
Utils::SmallString name;
|
||||
time_point<steady_clock> begin{steady_clock::now()};
|
||||
int timePoint = 1;
|
||||
};
|
||||
|
||||
SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue,
|
||||
SymbolStorageInterface &symbolStorage,
|
||||
ClangPathWatcherInterface &pathWatcher,
|
||||
@@ -46,14 +72,13 @@ SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQ
|
||||
pathWatcher.setNotifier(this);
|
||||
}
|
||||
|
||||
void SymbolIndexer::updateProjectParts(V2::ProjectPartContainers &&projectParts, const V2::FileContainers &generatedFiles)
|
||||
void SymbolIndexer::updateProjectParts(V2::ProjectPartContainers &&projectParts)
|
||||
{
|
||||
for (V2::ProjectPartContainer &projectPart : projectParts)
|
||||
updateProjectPart(std::move(projectPart), generatedFiles);
|
||||
updateProjectPart(std::move(projectPart));
|
||||
}
|
||||
|
||||
void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
const V2::FileContainers &generatedFiles)
|
||||
void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart)
|
||||
{
|
||||
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
|
||||
const auto optionalArtefact = m_symbolStorage.fetchProjectPartArtefact(projectPart.projectPartId);
|
||||
@@ -67,7 +92,6 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
projectPartId = optionalArtefact->projectPartId;
|
||||
|
||||
FilePathIds sourcePathIds = updatableFilePathIds(projectPart, optionalArtefact);
|
||||
|
||||
if (sourcePathIds.empty())
|
||||
return;
|
||||
|
||||
@@ -75,15 +99,14 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
|
||||
std::vector<SymbolIndexerTask> symbolIndexerTask;
|
||||
symbolIndexerTask.reserve(projectPart.sourcePathIds.size());
|
||||
|
||||
for (FilePathId sourcePathId : projectPart.sourcePathIds) {
|
||||
auto indexing = [projectPart, arguments, generatedFiles, sourcePathId]
|
||||
auto indexing = [projectPartId = projectPart.projectPartId, arguments, sourcePathId]
|
||||
(SymbolsCollectorInterface &symbolsCollector,
|
||||
SymbolStorageInterface &symbolStorage,
|
||||
Sqlite::TransactionInterface &transactionInterface) {
|
||||
symbolsCollector.addFile(sourcePathId, arguments);
|
||||
auto id = Utils::SmallString::number(sourcePathId.filePathId);
|
||||
|
||||
symbolsCollector.addUnsavedFiles(generatedFiles);
|
||||
symbolsCollector.setFile(sourcePathId, arguments);
|
||||
|
||||
symbolsCollector.collectSymbols();
|
||||
|
||||
@@ -92,7 +115,7 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
|
||||
symbolsCollector.sourceLocations());
|
||||
|
||||
symbolStorage.updateProjectPartSources(projectPart.projectPartId,
|
||||
symbolStorage.updateProjectPartSources(projectPartId,
|
||||
symbolsCollector.sourceFiles());
|
||||
|
||||
symbolStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros());
|
||||
@@ -147,7 +170,7 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
|
||||
(SymbolsCollectorInterface &symbolsCollector,
|
||||
SymbolStorageInterface &symbolStorage,
|
||||
Sqlite::TransactionInterface &transactionInterface) {
|
||||
symbolsCollector.addFile(filePathId, arguments);
|
||||
symbolsCollector.setFile(filePathId, arguments);
|
||||
|
||||
symbolsCollector.collectSymbols();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ClangBackEnd {
|
||||
|
||||
class SymbolsCollectorInterface;
|
||||
|
||||
class SymbolIndexer : public ClangPathWatcherNotifier
|
||||
class SymbolIndexer final : public ClangPathWatcherNotifier
|
||||
{
|
||||
public:
|
||||
SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue,
|
||||
@@ -47,10 +47,8 @@ public:
|
||||
FileStatusCache &fileStatusCache,
|
||||
Sqlite::TransactionInterface &transactionInterface);
|
||||
|
||||
void updateProjectParts(V2::ProjectPartContainers &&projectParts,
|
||||
const V2::FileContainers &generatedFiles);
|
||||
void updateProjectPart(V2::ProjectPartContainer &&projectPart,
|
||||
const V2::FileContainers &generatedFiles);
|
||||
void updateProjectParts(V2::ProjectPartContainers &&projectParts);
|
||||
void updateProjectPart(V2::ProjectPartContainer &&projectPart);
|
||||
|
||||
void pathsWithIdsChanged(const Utils::SmallStringVector &ids) override;
|
||||
void pathsChanged(const FilePathIds &filePathIds) override;
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
void SymbolIndexing::updateProjectParts(V2::ProjectPartContainers &&projectParts,
|
||||
const V2::FileContainers &generatedFiles)
|
||||
void SymbolIndexing::updateProjectParts(V2::ProjectPartContainers &&projectParts)
|
||||
{
|
||||
m_indexer.updateProjectParts(std::move(projectParts), generatedFiles);
|
||||
m_indexer.updateProjectParts(std::move(projectParts));
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -55,10 +55,11 @@ public:
|
||||
using Storage = ClangBackEnd::SymbolStorage<StatementFactory>;
|
||||
|
||||
SymbolIndexing(Sqlite::Database &database,
|
||||
FilePathCachingInterface &filePathCache)
|
||||
FilePathCachingInterface &filePathCache,
|
||||
const GeneratedFiles &generatedFiles)
|
||||
: m_filePathCache(filePathCache),
|
||||
m_statementFactory(database),
|
||||
m_collectorManger(database),
|
||||
m_collectorManger(database, generatedFiles),
|
||||
m_indexerScheduler(m_collectorManger, m_symbolStorage, database, m_indexerQueue, std::thread::hardware_concurrency())
|
||||
{
|
||||
}
|
||||
@@ -82,8 +83,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void updateProjectParts(V2::ProjectPartContainers &&projectParts,
|
||||
const V2::FileContainers &generatedFiles) override;
|
||||
void updateProjectParts(V2::ProjectPartContainers &&projectParts) override;
|
||||
|
||||
private:
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
|
||||
@@ -37,8 +37,7 @@ public:
|
||||
SymbolIndexingInterface(const SymbolIndexingInterface&) = delete;
|
||||
SymbolIndexingInterface &operator=(const SymbolIndexingInterface&) = delete;
|
||||
|
||||
virtual void updateProjectParts(V2::ProjectPartContainers &&projectParts,
|
||||
const V2::FileContainers &generatedFiles) = 0;
|
||||
virtual void updateProjectParts(V2::ProjectPartContainers &&projectParts) = 0;
|
||||
|
||||
protected:
|
||||
~SymbolIndexingInterface() = default;
|
||||
|
||||
@@ -44,12 +44,12 @@ void SymbolsCollector::addFiles(const FilePathIds &filePathIds,
|
||||
m_collectMacrosSourceFileCallbacks.addSourceFiles(filePathIds);
|
||||
}
|
||||
|
||||
void SymbolsCollector::addFile(FilePathId filePathId, const Utils::SmallStringVector &arguments)
|
||||
void SymbolsCollector::setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments)
|
||||
{
|
||||
addFiles({filePathId}, arguments);
|
||||
}
|
||||
|
||||
void SymbolsCollector::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
|
||||
void SymbolsCollector::setUnsavedFiles(const V2::FileContainers &unsavedFiles)
|
||||
{
|
||||
m_clangTool.addUnsavedFiles(unsavedFiles);
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ public:
|
||||
|
||||
void addFiles(const FilePathIds &filePathIds,
|
||||
const Utils::SmallStringVector &arguments);
|
||||
void addFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) override;
|
||||
void setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) override;
|
||||
|
||||
void addUnsavedFiles(const V2::FileContainers &unsavedFiles) override;
|
||||
void setUnsavedFiles(const V2::FileContainers &unsavedFiles) override;
|
||||
|
||||
void clear() override;
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ public:
|
||||
SymbolsCollectorInterface(const SymbolsCollectorInterface &) = delete;
|
||||
SymbolsCollectorInterface &operator=(const SymbolsCollectorInterface &) = delete;
|
||||
|
||||
virtual void addFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) = 0;
|
||||
virtual void setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) = 0;
|
||||
|
||||
virtual void addUnsavedFiles(const V2::FileContainers &unsavedFiles) = 0;
|
||||
virtual void setUnsavedFiles(const V2::FileContainers &unsavedFiles) = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
|
||||
|
||||
@@ -1,35 +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 "symbolscollectormanager.h"
|
||||
|
||||
#include "symbolscollector.h"
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "symbolscollectormanagerinterface.h"
|
||||
#include "symbolscollectorinterface.h"
|
||||
#include "generatedfiles.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -36,13 +37,16 @@ class Database;
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class GeneratedFiles;
|
||||
class SymbolsCollector;
|
||||
template<typename SymbolsCollector>
|
||||
class SymbolsCollectorManager final : public SymbolsCollectorManagerInterface
|
||||
{
|
||||
public:
|
||||
SymbolsCollectorManager(Sqlite::Database &database)
|
||||
: m_database(database)
|
||||
SymbolsCollectorManager(Sqlite::Database &database,
|
||||
const GeneratedFiles &generatedFiles)
|
||||
: m_database(database),
|
||||
m_generatedFiles(generatedFiles)
|
||||
{}
|
||||
|
||||
SymbolsCollector &unusedSymbolsCollector() override
|
||||
@@ -56,11 +60,11 @@ public:
|
||||
auto freeCollectors = std::distance(split, m_collectors.end());
|
||||
|
||||
if (freeCollectors > 0)
|
||||
return usedCollector(*split->get());
|
||||
return initializedCollector(*split->get());
|
||||
|
||||
m_collectors.emplace_back(std::make_unique<SymbolsCollector>(m_database));
|
||||
|
||||
return usedCollector(*m_collectors.back().get());
|
||||
return initializedCollector(*m_collectors.back().get());
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<SymbolsCollector>> &collectors() const
|
||||
@@ -69,15 +73,17 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
SymbolsCollector &usedCollector(SymbolsCollector &collector)
|
||||
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
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filecontainerv2.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
Reference in New Issue
Block a user