From 1e703a690136786b4e6ee7ca0c6a950682110fba Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 24 Jul 2019 16:44:24 +0200 Subject: [PATCH] ClangRefactoring: Remove file status collection It is not needed anymore. If we need it again we can reintroduce it. Change-Id: If8897ddb404daaf52b249ddd3763deb685c35fe5 Reviewed-by: Tim Jenssen --- .../source/clangrefactoringbackend-source.pri | 2 - .../filestatuspreprocessorcallbacks.cpp | 59 ------------------- .../source/filestatuspreprocessorcallbacks.h | 59 ------------------- .../source/indexdataconsumer.cpp | 7 --- .../source/indexdataconsumer.h | 5 -- .../source/symbolscollector.cpp | 7 --- .../source/symbolscollector.h | 2 - .../source/symbolscollectorinterface.h | 1 - tests/unit/unittest/mocksymbolscollector.h | 3 - tests/unit/unittest/symbolindexer-test.cpp | 3 - tests/unit/unittest/symbolscollector-test.cpp | 33 ----------- 11 files changed, 181 deletions(-) delete mode 100644 src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri index ce809e9efbd..407621b4be6 100644 --- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri +++ b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri @@ -32,7 +32,6 @@ SOURCES += \ $$PWD/collectsymbolsaction.cpp \ $$PWD/collectmacrossourcefilecallbacks.cpp \ $$PWD/symbolscollector.cpp \ - $$PWD/filestatuspreprocessorcallbacks.cpp \ $$PWD/clangquerygatherer.cpp \ $$PWD/symbolindexing.cpp \ $$PWD/indexdataconsumer.cpp @@ -51,7 +50,6 @@ HEADERS += \ $$PWD/symbolscollector.h \ $$PWD/symbolsvisitorbase.h \ $$PWD/indexdataconsumer.h \ - $$PWD/filestatuspreprocessorcallbacks.h \ $$PWD/clangquerygatherer.h } diff --git a/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp b/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp deleted file mode 100644 index 28efe39f9bb..00000000000 --- a/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 "filestatuspreprocessorcallbacks.h" - -namespace ClangBackEnd { - -void FileStatusPreprocessorCallbacks::FileChanged(clang::SourceLocation sourceLocation, - clang::PPCallbacks::FileChangeReason reason, - clang::SrcMgr::CharacteristicKind, - clang::FileID) -{ - if (reason == clang::PPCallbacks::EnterFile) { - const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID( - m_sourceManager->getFileID(sourceLocation)); - if (fileEntry) - addFileStatus(fileEntry); - } -} - -void FileStatusPreprocessorCallbacks::addFileStatus(const clang::FileEntry *fileEntry) -{ - auto id = filePathId(fileEntry); - - auto found = std::lower_bound(m_fileStatuses.begin(), - m_fileStatuses.end(), - id, - [](const auto &first, const auto &second) { - return first.filePathId < second; - }); - - if (found == m_fileStatuses.end() || found->filePathId != id) { - m_fileStatuses.emplace(found, id, fileEntry->getSize(), fileEntry->getModificationTime()); - } -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h deleted file mode 100644 index ad7bc4f4d60..00000000000 --- a/src/tools/clangrefactoringbackend/source/filestatuspreprocessorcallbacks.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 "filestatus.h" -#include "symbolsvisitorbase.h" - -#include - -#include - -namespace ClangBackEnd { - -class FileStatusPreprocessorCallbacks final : public clang::PPCallbacks, public SymbolsVisitorBase -{ -public: - FileStatusPreprocessorCallbacks(FileStatuses &fileStatuses, - const FilePathCachingInterface &filePathCache, - const clang::SourceManager *sourceManager, - FilePathIds &filePathIndices) - : SymbolsVisitorBase(filePathCache, sourceManager, filePathIndices) - , m_fileStatuses(fileStatuses) - {} - - void FileChanged(clang::SourceLocation sourceLocation, - clang::PPCallbacks::FileChangeReason reason, - clang::SrcMgr::CharacteristicKind, - clang::FileID) override; - - void addFileStatus(const clang::FileEntry *fileEntry); - -private: - FileStatuses &m_fileStatuses; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp index 8d67d710865..68f2f771561 100644 --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp +++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp @@ -25,7 +25,6 @@ #include "indexdataconsumer.h" #include "collectsymbolsaction.h" -#include "filestatuspreprocessorcallbacks.h" #include #include @@ -119,12 +118,6 @@ bool IndexDataConsumer::isAlreadyParsed(clang::FileID fileId, SourcesManager &so return sourcesManager.alreadyParsed(filePathId(fileEntry), fileEntry->getModificationTime()); } -void IndexDataConsumer::setPreprocessor(std::shared_ptr preprocessor) -{ - preprocessor->addPPCallbacks(std::make_unique( - m_fileStatuses, m_filePathCache, m_sourceManager, m_filePathIndices)); -} - bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration, clang::index::SymbolRoleSet symbolRoles, llvm::ArrayRef /*symbolRelations*/, diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h b/src/tools/clangrefactoringbackend/source/indexdataconsumer.h index 83208682281..c80e066b6c1 100644 --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h +++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.h @@ -43,14 +43,12 @@ class IndexDataConsumer : public clang::index::IndexDataConsumer, public: IndexDataConsumer(SymbolEntries &symbolEntries, SourceLocationEntries &sourceLocationEntries, - FileStatuses &fileStatuses, FilePathCachingInterface &filePathCache, SourcesManager &symbolSourcesManager, SourcesManager ¯oSourcesManager) : SymbolsVisitorBase(filePathCache, nullptr, m_filePathIndices) , m_symbolEntries(symbolEntries) , m_sourceLocationEntries(sourceLocationEntries) - , m_fileStatuses(fileStatuses) , m_symbolSourcesManager(symbolSourcesManager) , m_macroSourcesManager(macroSourcesManager) @@ -59,8 +57,6 @@ public: IndexDataConsumer(const IndexDataConsumer &) = delete; IndexDataConsumer &operator=(const IndexDataConsumer &) = delete; - void setPreprocessor(std::shared_ptr preprocessor) override; - bool handleDeclOccurence(const clang::Decl *declaration, clang::index::SymbolRoleSet symbolRoles, llvm::ArrayRef symbolRelations, @@ -82,7 +78,6 @@ private: FilePathIds m_filePathIndices; SymbolEntries &m_symbolEntries; SourceLocationEntries &m_sourceLocationEntries; - FileStatuses &m_fileStatuses; SourcesManager &m_symbolSourcesManager; SourcesManager &m_macroSourcesManager; }; diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp index ab5a00fc6b0..ac93ae360d9 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp @@ -35,7 +35,6 @@ SymbolsCollector::SymbolsCollector(Sqlite::Database &database) : m_filePathCache(database) , m_indexDataConsumer(std::make_shared(m_symbolEntries, m_sourceLocationEntries, - m_fileStatuses, m_filePathCache, m_symbolSourcesManager, m_macroSourcesManager)) @@ -63,7 +62,6 @@ void SymbolsCollector::clear() { m_symbolEntries.clear(); m_sourceLocationEntries.clear(); - m_fileStatuses.clear(); m_clangTool = ClangTool(); } @@ -150,11 +148,6 @@ const SourceLocationEntries &SymbolsCollector::sourceLocations() const return m_sourceLocationEntries; } -const FileStatuses &SymbolsCollector::fileStatuses() const -{ - return m_fileStatuses; -} - bool SymbolsCollector::isUsed() const { return m_isUsed; diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.h b/src/tools/clangrefactoringbackend/source/symbolscollector.h index e1034713726..1ad0c9e29c2 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.h +++ b/src/tools/clangrefactoringbackend/source/symbolscollector.h @@ -58,7 +58,6 @@ public: const SymbolEntries &symbols() const override; const SourceLocationEntries &sourceLocations() const override; - const FileStatuses &fileStatuses() const override; bool isUsed() const override; void setIsUsed(bool isUsed) override; @@ -70,7 +69,6 @@ private: ClangTool m_clangTool; SymbolEntries m_symbolEntries; SourceLocationEntries m_sourceLocationEntries; - FileStatuses m_fileStatuses; std::shared_ptr m_indexDataConsumer; CollectSymbolsAction m_collectSymbolsAction; SourcesManager m_symbolSourcesManager; diff --git a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h index 07b5de223ce..d90d4db5286 100644 --- a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h +++ b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h @@ -48,7 +48,6 @@ public: virtual const SymbolEntries &symbols() const = 0; virtual const SourceLocationEntries &sourceLocations() const = 0; - virtual const FileStatuses &fileStatuses() const = 0; }; } // namespace ClangBackEnd diff --git a/tests/unit/unittest/mocksymbolscollector.h b/tests/unit/unittest/mocksymbolscollector.h index 34cd71b17d4..7c62e54e17f 100644 --- a/tests/unit/unittest/mocksymbolscollector.h +++ b/tests/unit/unittest/mocksymbolscollector.h @@ -74,9 +74,6 @@ public: MOCK_CONST_METHOD0(usedMacros, const ClangBackEnd::UsedMacros &()); - MOCK_CONST_METHOD0(fileStatuses, - const ClangBackEnd::FileStatuses &()); - MOCK_CONST_METHOD0(sourceDependencies, const ClangBackEnd::SourceDependencies &()); diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index 87d5ba3710b..127921ca985 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -111,7 +111,6 @@ protected: ON_CALL(mockCollector, sourceLocations()).WillByDefault(ReturnRef(sourceLocations)); ON_CALL(mockCollector, sourceFiles()).WillByDefault(ReturnRef(sourceFileIds)); ON_CALL(mockCollector, usedMacros()).WillByDefault(ReturnRef(usedMacros)); - ON_CALL(mockCollector, fileStatuses()).WillByDefault(ReturnRef(fileStatus)); ON_CALL(mockCollector, sourceDependencies()).WillByDefault(ReturnRef(sourceDependencies)); ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) .WillByDefault(Return(artefact)); @@ -871,7 +870,6 @@ TEST_F(SymbolIndexer, UpdateProjectPartsFetchIncludedIndexingTimeStamps) InSequence s; EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockCollector, fileStatuses()).WillRepeatedly(ReturnRef(fileStatuses1)); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateIndexingTimeStampsWithoutTransaction(_, _)); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)); @@ -887,7 +885,6 @@ TEST_F(SymbolIndexer, UpdateProjectPartsIsBusyInStoringData) EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()) .WillOnce(Throw(Sqlite::StatementIsBusy{""})); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockCollector, fileStatuses()).WillRepeatedly(ReturnRef(fileStatuses1)); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateIndexingTimeStampsWithoutTransaction(_, _)); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)); diff --git a/tests/unit/unittest/symbolscollector-test.cpp b/tests/unit/unittest/symbolscollector-test.cpp index a766b70fa40..fca9ec88d0b 100644 --- a/tests/unit/unittest/symbolscollector-test.cpp +++ b/tests/unit/unittest/symbolscollector-test.cpp @@ -295,16 +295,6 @@ TEST_F(SymbolsCollector, ClearSourceLocations) ASSERT_THAT(collector.sourceLocations(), IsEmpty()); } -TEST_F(SymbolsCollector, ClearFileStatus) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - collector.collectSymbols(); - - collector.clear(); - - ASSERT_THAT(collector.fileStatuses(), IsEmpty()); -} - TEST_F(SymbolsCollector, DontCollectSymbolsAfterFilesAreCleared) { collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); @@ -315,16 +305,6 @@ TEST_F(SymbolsCollector, DontCollectSymbolsAfterFilesAreCleared) ASSERT_THAT(collector.symbols(), IsEmpty()); } -TEST_F(SymbolsCollector, DontCollectFileStatusAfterFilesAreCleared) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.clear(); - collector.collectSymbols(); - - ASSERT_THAT(collector.fileStatuses(), IsEmpty()); -} - TEST_F(SymbolsCollector, CollectMacroDefinitionSourceLocation) { auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); @@ -457,19 +437,6 @@ TEST_F(SymbolsCollector, DISABLED_CollectMacroCompilerArgumentSymbols) Contains(AllOf(HasSymbolName("COMPILER_ARGUMENT"), HasSymbolKind(SymbolKind::Macro)))); } -TEST_F(SymbolsCollector, CollectFileStatuses) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"); - collector.setFile(fileId, {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.fileStatuses(), - ElementsAre(fileStatus(TESTDATA_DIR "/symbolscollector/main.cpp"), - fileStatus(TESTDATA_DIR "/symbolscollector/header1.h"), - fileStatus(TESTDATA_DIR "/symbolscollector/header2.h"))); -} - TEST_F(SymbolsCollector, IsClassSymbol) { collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"});