From 9edfdacd724d2faf6b58d9201e461a4344214b7a Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Thu, 4 Oct 2018 21:21:31 +0200 Subject: [PATCH] data: Removed separate comment_location table * added LocationType LOCATION_COMMENT * store comment locations within source_locations --- src/lib/CMakeLists.txt | 1 - .../component/controller/CodeController.cpp | 4 +- src/lib/data/access/StorageAccess.h | 2 - src/lib/data/access/StorageAccessProxy.cpp | 82 +++++----- src/lib/data/access/StorageAccessProxy.h | 2 - ...InterprocessIntermediateStorageManager.cpp | 2 - .../SharedIntermediateStorage.cpp | 23 --- .../shared_types/SharedIntermediateStorage.h | 4 - .../shared_types/SharedStorageTypes.h | 2 - src/lib/data/location/LocationType.cpp | 2 + src/lib/data/location/LocationType.h | 7 +- src/lib/data/parser/ParserClientImpl.cpp | 10 +- src/lib/data/storage/IntermediateStorage.cpp | 17 -- src/lib/data/storage/IntermediateStorage.h | 18 +-- src/lib/data/storage/PersistentStorage.cpp | 38 ----- src/lib/data/storage/PersistentStorage.h | 5 - src/lib/data/storage/Storage.cpp | 32 ---- src/lib/data/storage/Storage.h | 3 - .../storage/sqlite/SqliteIndexStorage.cpp | 145 +++--------------- .../data/storage/sqlite/SqliteIndexStorage.h | 8 - .../storage/type/StorageCommentLocation.h | 75 --------- src/lib_gui/qt/element/QtCodeField.cpp | 2 +- src/lib_gui/qt/element/QtCodeNavigator.cpp | 2 +- src/lib_java/data/parser/java/JavaParser.h | 2 +- 24 files changed, 80 insertions(+), 408 deletions(-) delete mode 100644 src/lib/data/storage/type/StorageCommentLocation.h diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index a2e8509b..885dc970 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -237,7 +237,6 @@ add_files( data/storage/type/StorageBookmark.h data/storage/type/StorageBookmarkedEdge.h data/storage/type/StorageBookmarkedNode.h - data/storage/type/StorageCommentLocation.h data/storage/type/StorageComponentAccess.h data/storage/type/StorageEdge.h data/storage/type/StorageError.h diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index ab1c5539..8db7a7e0 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -630,7 +630,9 @@ std::vector CodeController::getSnippetsForFile( ); std::vector atomicRanges; - m_storageAccess->getCommentLocationsInFile(activeSourceLocations->getFilePath())->forEachStartSourceLocation( + std::shared_ptr commentLocations = + m_storageAccess->getSourceLocationsOfTypeInFile(activeSourceLocations->getFilePath(), LOCATION_COMMENT); + commentLocations->forEachStartSourceLocation( [&](SourceLocation* location) { atomicRanges.push_back(SnippetMerger::Range( diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 8908301e..1990fa65 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -73,8 +73,6 @@ public: virtual std::shared_ptr getSourceLocationsOfTypeInFile( const FilePath& filePath, LocationType type) const = 0; - virtual std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const = 0; - virtual std::shared_ptr getFileContent(const FilePath& filePath) const = 0; virtual FileInfo getFileInfoForFileId(Id id) const = 0; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index 8521fd61..7bf91b18 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -16,58 +16,57 @@ void StorageAccessProxy::setSubject(std::weak_ptr subject) #define UNWRAP(...) __VA_ARGS__ -#define DEF_GETTER_0(_METHOD_NAME_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ - UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_() const \ - { \ - if (std::shared_ptr subject = m_subject.lock()) \ - { \ - return subject->_METHOD_NAME_(); \ - } \ - return _DEFAULT_VALUE_; \ +#define DEF_GETTER_0(_METHOD_NAME_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_() const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(); \ + } \ + return _DEFAULT_VALUE_; \ } -#define DEF_GETTER_1(_METHOD_NAME_, _PATAMETER_1_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ - UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1) const \ - { \ - if (std::shared_ptr subject = m_subject.lock()) \ - { \ - return subject->_METHOD_NAME_(p1); \ - } \ - return _DEFAULT_VALUE_; \ +#define DEF_GETTER_1(_METHOD_NAME_, _PARAM_1_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1); \ + } \ + return _DEFAULT_VALUE_; \ } -#define DEF_GETTER_2(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ - UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2) const \ - { \ - if (std::shared_ptr subject = m_subject.lock()) \ - { \ - return subject->_METHOD_NAME_(p1, p2); \ - } \ - return _DEFAULT_VALUE_; \ +#define DEF_GETTER_2(_METHOD_NAME_, _PARAM_1_TYPE_, _PARAM_2_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1, _PARAM_2_TYPE_ p2) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1, p2); \ + } \ + return _DEFAULT_VALUE_; \ } -#define DEF_GETTER_3(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _PATAMETER_3_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ - UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2, _PATAMETER_3_TYPE_ p3) const \ - { \ - if (std::shared_ptr subject = m_subject.lock()) \ - { \ - return subject->_METHOD_NAME_(p1, p2, p3); \ - } \ - return _DEFAULT_VALUE_; \ +#define DEF_GETTER_3(_METHOD_NAME_, _PARAM_1_TYPE_, _PARAM_2_TYPE_, _PARAM_3_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1, _PARAM_2_TYPE_ p2, _PARAM_3_TYPE_ p3) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1, p2, p3); \ + } \ + return _DEFAULT_VALUE_; \ } -#define DEF_GETTER_4(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _PATAMETER_3_TYPE_, _PATAMETER_4_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ - UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2, _PATAMETER_3_TYPE_ p3, _PATAMETER_4_TYPE_ p4) const \ - { \ - if (std::shared_ptr subject = m_subject.lock()) \ - { \ - return subject->_METHOD_NAME_(p1, p2, p3, p4); \ - } \ - return _DEFAULT_VALUE_; \ +#define DEF_GETTER_4(_METHOD_NAME_, _PARAM_1_TYPE_, _PARAM_2_TYPE_, _PARAM_3_TYPE_, _PARAM_4_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PARAM_1_TYPE_ p1, _PARAM_2_TYPE_ p2, _PARAM_3_TYPE_ p3, _PARAM_4_TYPE_ p4) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1, p2, p3, p4); \ + } \ + return _DEFAULT_VALUE_; \ } - DEF_GETTER_1(getNodeIdForFileNode, const FilePath&, Id, 0) DEF_GETTER_1(getNodeIdForNameHierarchy, const NameHierarchy&, Id, 0) DEF_GETTER_1(getNodeIdsForNameHierarchies, const std::vector, std::vector, {}) @@ -94,7 +93,6 @@ DEF_GETTER_1(getSourceLocationsForLocationIds, const std::vector&, std::shar DEF_GETTER_1(getSourceLocationsForFile, const FilePath&, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) DEF_GETTER_3(getSourceLocationsForLinesInFile, const FilePath&, size_t, size_t, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) DEF_GETTER_2(getSourceLocationsOfTypeInFile, const FilePath&, LocationType, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) -DEF_GETTER_1(getCommentLocationsInFile, const FilePath&, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) DEF_GETTER_1(getFileContent, const FilePath&, std::shared_ptr, nullptr) DEF_GETTER_1(getFileInfoForFileId, Id, FileInfo, FileInfo()) DEF_GETTER_1(getFileInfoForFilePath, const FilePath&, FileInfo, FileInfo()) diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 3883948d..2115c740 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -54,8 +54,6 @@ public: std::shared_ptr getSourceLocationsOfTypeInFile( const FilePath& filePath, LocationType type) const override; - std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const override; - std::shared_ptr getFileContent(const FilePath& filePath) const override; FileInfo getFileInfoForFileId(Id id) const override; diff --git a/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp b/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp index 46d0f2e4..3ab7d98a 100644 --- a/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp +++ b/src/lib/data/indexer/interprocess/InterprocessIntermediateStorageManager.cpp @@ -65,7 +65,6 @@ void InterprocessIntermediateStorageManager::pushIntermediateStorage( storage.setStorageSourceLocations(intermediateStorage->getStorageSourceLocations()); storage.setStorageOccurrences(intermediateStorage->getStorageOccurrences()); storage.setStorageComponentAccesses(intermediateStorage->getComponentAccesses()); - storage.setStorageCommentLocations(intermediateStorage->getCommentLocations()); storage.setStorageErrors(intermediateStorage->getErrors()); storage.setNextId(intermediateStorage->getNextId()); @@ -96,7 +95,6 @@ std::shared_ptr InterprocessIntermediateStorageManager::pop storage->setStorageSourceLocations(sharedIntermediateStorage.getStorageSourceLocations()); storage->setStorageOccurrences(sharedIntermediateStorage.getStorageOccurrences()); storage->setComponentAccesses(sharedIntermediateStorage.getStorageComponentAccesses()); - storage->setCommentLocations(sharedIntermediateStorage.getStorageCommentLocations()); storage->setErrors(sharedIntermediateStorage.getStorageErrors()); storage->setNextId(sharedIntermediateStorage.getNextId()); diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp index cca76694..49cddc3e 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp +++ b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp @@ -5,7 +5,6 @@ SharedIntermediateStorage::SharedIntermediateStorage(SharedMemory::Allocator* al , m_storageSymbols(allocator) , m_storageOccurrences(allocator) , m_storageComponentAccesses(allocator) - , m_storageCommentLocations(allocator) , m_storageNodes(allocator) , m_storageEdges(allocator) , m_storageLocalSymbols(allocator) @@ -200,28 +199,6 @@ void SharedIntermediateStorage::setStorageComponentAccesses(const std::set SharedIntermediateStorage::getStorageCommentLocations() const -{ - std::set result; - - for (unsigned int i = 0; i < m_storageCommentLocations.size(); i++) - { - result.emplace(fromShared(m_storageCommentLocations[i])); - } - - return result; -} - -void SharedIntermediateStorage::setStorageCommentLocations(const std::set& commentLocations) -{ - m_storageCommentLocations.clear(); - - for (const StorageCommentLocationData commentLocation : commentLocations) - { - m_storageCommentLocations.push_back(toShared(commentLocation, m_allocator)); - } -} - std::vector SharedIntermediateStorage::getStorageErrors() const { std::vector result; diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h index d473b7a6..7b5196a0 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h +++ b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h @@ -37,9 +37,6 @@ public: std::set getStorageComponentAccesses() const; void setStorageComponentAccesses(const std::set& storageComponentAccesses); - std::set getStorageCommentLocations() const; - void setStorageCommentLocations(const std::set& commentLocations); - std::vector getStorageErrors() const; void setStorageErrors(const std::vector& errors); @@ -51,7 +48,6 @@ private: SharedMemory::Vector m_storageSymbols; SharedMemory::Vector m_storageOccurrences; SharedMemory::Vector m_storageComponentAccesses; - SharedMemory::Vector m_storageCommentLocations; SharedMemory::Vector m_storageNodes; SharedMemory::Vector m_storageEdges; SharedMemory::Vector m_storageLocalSymbols; diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h b/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h index 378449d5..a570f562 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h +++ b/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h @@ -1,7 +1,6 @@ #ifndef SHARED_STORAGE_TYPES_H #define SHARED_STORAGE_TYPES_H -#include "StorageCommentLocation.h" #include "StorageComponentAccess.h" #include "StorageEdge.h" #include "StorageError.h" @@ -37,7 +36,6 @@ CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageSymbol, SharedStorageSymbol ) CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageSourceLocation, SharedStorageSourceLocation ) CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageOccurrence, SharedStorageOccurrence ) CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageComponentAccess, SharedStorageComponentAccess) -CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageCommentLocationData, SharedStorageCommentLocationData) struct SharedStorageNode diff --git a/src/lib/data/location/LocationType.cpp b/src/lib/data/location/LocationType.cpp index d2a907e0..0701fefb 100644 --- a/src/lib/data/location/LocationType.cpp +++ b/src/lib/data/location/LocationType.cpp @@ -19,6 +19,8 @@ LocationType intToLocationType(int value) return LOCATION_LOCAL_SYMBOL; case LOCATION_SIGNATURE: return LOCATION_SIGNATURE; + case LOCATION_COMMENT: + return LOCATION_COMMENT; case LOCATION_ERROR: return LOCATION_ERROR; case LOCATION_FULLTEXT_SEARCH: diff --git a/src/lib/data/location/LocationType.h b/src/lib/data/location/LocationType.h index 2ec5f14f..cf879805 100644 --- a/src/lib/data/location/LocationType.h +++ b/src/lib/data/location/LocationType.h @@ -8,9 +8,10 @@ enum LocationType LOCATION_QUALIFIER = 2, LOCATION_LOCAL_SYMBOL = 3, LOCATION_SIGNATURE = 4, - LOCATION_ERROR = 5, - LOCATION_FULLTEXT_SEARCH = 6, - LOCATION_SCREEN_SEARCH = 7 + LOCATION_COMMENT = 5, + LOCATION_ERROR = 6, + LOCATION_FULLTEXT_SEARCH = 7, + LOCATION_SCREEN_SEARCH = 8 }; int locationTypeToInt(LocationType type); diff --git a/src/lib/data/parser/ParserClientImpl.cpp b/src/lib/data/parser/ParserClientImpl.cpp index fa6ec1a6..85e8ba7d 100644 --- a/src/lib/data/parser/ParserClientImpl.cpp +++ b/src/lib/data/parser/ParserClientImpl.cpp @@ -89,12 +89,18 @@ void ParserClientImpl::recordFile(const FilePath& filePath, bool indexed) void ParserClientImpl::recordComment(const ParseLocation& location) { - m_storage->addCommentLocation(StorageCommentLocationData( + if (!location.isValid()) + { + return; + } + + m_storage->addSourceLocation(StorageSourceLocationData( addFileName(location.filePath), location.startLineNumber, location.startColumnNumber, location.endLineNumber, - location.endColumnNumber + location.endColumnNumber, + locationTypeToInt(LOCATION_COMMENT) )); } diff --git a/src/lib/data/storage/IntermediateStorage.cpp b/src/lib/data/storage/IntermediateStorage.cpp index 38166596..6f7eab93 100644 --- a/src/lib/data/storage/IntermediateStorage.cpp +++ b/src/lib/data/storage/IntermediateStorage.cpp @@ -24,7 +24,6 @@ void IntermediateStorage::clear() m_sourceLocations.clear(); m_occurrences.clear(); m_componentAccesses.clear(); - m_commentLocations.clear(); m_errorsIndex.clear(); m_errors.clear(); @@ -63,7 +62,6 @@ size_t IntermediateStorage::getByteSize(size_t stringSize) const } byteSize += sizeof(StorageEdge) * getStorageEdges().size(); - byteSize += sizeof(StorageCommentLocationData) * getCommentLocations().size(); byteSize += sizeof(StorageComponentAccess) * getComponentAccesses().size(); byteSize += sizeof(StorageOccurrence) * getStorageOccurrences().size(); byteSize += sizeof(StorageSymbol) * getStorageSymbols().size(); @@ -259,11 +257,6 @@ void IntermediateStorage::addComponentAccesses(const std::vector& IntermediateStorage::getComponentAccesse return m_componentAccesses; } -const std::set& IntermediateStorage::getCommentLocations() const -{ - return m_commentLocations; -} - const std::vector& IntermediateStorage::getErrors() const { return m_errors; @@ -381,11 +369,6 @@ void IntermediateStorage::setComponentAccesses(std::set m_componentAccesses = std::move(componentAccesses); } -void IntermediateStorage::setCommentLocations(std::set commentLocations) -{ - m_commentLocations = std::move(commentLocations); -} - void IntermediateStorage::setErrors(std::vector errors) { m_errors = std::move(errors); diff --git a/src/lib/data/storage/IntermediateStorage.h b/src/lib/data/storage/IntermediateStorage.h index bb033708..a6852cd8 100644 --- a/src/lib/data/storage/IntermediateStorage.h +++ b/src/lib/data/storage/IntermediateStorage.h @@ -5,19 +5,10 @@ #include #include -#include "StorageCommentLocation.h" -#include "StorageComponentAccess.h" -#include "StorageEdge.h" -#include "StorageError.h" -#include "StorageFile.h" -#include "StorageLocalSymbol.h" -#include "StorageNode.h" -#include "StorageOccurrence.h" -#include "StorageSourceLocation.h" -#include "StorageSymbol.h" #include "Storage.h" -class IntermediateStorage: public Storage +class IntermediateStorage + : public Storage { public: IntermediateStorage(); @@ -45,7 +36,6 @@ public: void addOccurrences(const std::vector& occurrences) override; void addComponentAccess(const StorageComponentAccess& componentAccess) override; void addComponentAccesses(const std::vector& componentAccesses) override; - void addCommentLocation(const StorageCommentLocationData& commentLocationData) override; void addError(const StorageErrorData& errorData) override; const std::vector& getStorageNodes() const override; @@ -56,7 +46,6 @@ public: const std::set& getStorageSourceLocations() const override; const std::set& getStorageOccurrences() const override; const std::set& getComponentAccesses() const override; - const std::set& getCommentLocations() const override; const std::vector& getErrors() const override; void setStorageNodes(std::vector storageNodes); @@ -67,7 +56,6 @@ public: void setStorageSourceLocations(std::set storageSourceLocations); void setStorageOccurrences(std::set storageOccurrences); void setComponentAccesses(std::set componentAccesses); - void setCommentLocations(std::set commentLocations); void setErrors(std::vector errors); Id getNextId() const; @@ -95,8 +83,6 @@ private: std::set m_componentAccesses; - std::set m_commentLocations; - std::set m_errorsIndex; // this is used to prevent duplicates (unique) std::vector m_errors; diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index 33cdc0fd..140f2c41 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -138,11 +138,6 @@ void PersistentStorage::addComponentAccesses(const std::vector& PersistentStorage::getComponentAccesses( return m_storageData.accesses = utility::toSet(m_sqliteIndexStorage.getAll()); } -const std::set& PersistentStorage::getCommentLocations() const -{ - std::set comments; - for (const StorageCommentLocation& comment : m_sqliteIndexStorage.getAll()) - { - comments.emplace(comment); - } - return m_storageData.comments = comments; -} - const std::vector& PersistentStorage::getErrors() const { std::vector errors; @@ -1449,29 +1434,6 @@ std::shared_ptr PersistentStorage::getSourceLocationsOfTypeI return m_sqliteIndexStorage.getSourceLocationsOfTypeInFile(filePath, type); } -std::shared_ptr PersistentStorage::getCommentLocationsInFile(const FilePath& filePath) const -{ - TRACE(); - - const std::shared_ptr file = std::make_shared(filePath, false, false, false); - - const std::vector storageLocations = m_sqliteIndexStorage.getCommentLocationsInFile(filePath); - for (size_t i = 0; i < storageLocations.size(); i++) - { - file->addSourceLocation( - LOCATION_TOKEN, - storageLocations[i].id, - std::vector(), // comment token location has no element. - storageLocations[i].startLine, - storageLocations[i].startCol, - storageLocations[i].endLine, - storageLocations[i].endCol - ); - } - - return file; -} - std::shared_ptr PersistentStorage::getFileContent(const FilePath& filePath) const { TRACE(); diff --git a/src/lib/data/storage/PersistentStorage.h b/src/lib/data/storage/PersistentStorage.h index 055e7734..3849d369 100644 --- a/src/lib/data/storage/PersistentStorage.h +++ b/src/lib/data/storage/PersistentStorage.h @@ -34,7 +34,6 @@ public: void addOccurrences(const std::vector& occurrences) override; void addComponentAccess(const StorageComponentAccess& componentAccess) override; void addComponentAccesses(const std::vector& componentAccesses) override; - void addCommentLocation(const StorageCommentLocationData& data) override; void addError(const StorageErrorData& data) override; const std::vector& getStorageNodes() const override; @@ -45,7 +44,6 @@ public: const std::set& getStorageSourceLocations() const override; const std::set& getStorageOccurrences() const override; const std::set& getComponentAccesses() const override; - const std::set& getCommentLocations() const override; const std::vector& getErrors() const override; void startInjection() override; @@ -122,8 +120,6 @@ public: std::shared_ptr getSourceLocationsOfTypeInFile( const FilePath& filePath, LocationType type) const override; - std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const override; - std::shared_ptr getFileContent(const FilePath& filePath) const override; bool hasContentForFile(const FilePath& filePath) const; @@ -168,7 +164,6 @@ private: std::set locations; std::set occurrences; std::set accesses; - std::set comments; std::vector errors; } m_storageData; diff --git a/src/lib/data/storage/Storage.cpp b/src/lib/data/storage/Storage.cpp index 32c15dcf..40c2894f 100644 --- a/src/lib/data/storage/Storage.cpp +++ b/src/lib/data/storage/Storage.cpp @@ -1,18 +1,6 @@ #include "Storage.h" -#include - #include "logging.h" -#include "StorageCommentLocation.h" -#include "StorageComponentAccess.h" -#include "StorageEdge.h" -#include "StorageError.h" -#include "StorageFile.h" -#include "StorageLocalSymbol.h" -#include "StorageNode.h" -#include "StorageOccurrence.h" -#include "StorageSourceLocation.h" -#include "StorageSymbol.h" #include "tracing.h" Storage::Storage() @@ -261,26 +249,6 @@ void Storage::inject(Storage* injected) addComponentAccesses(accesses); } - { - // TRACE("inject comments"); - - for (const StorageCommentLocationData& location : injected->getCommentLocations()) - { - auto it = injectedIdToOwnElementId.find(location.fileNodeId); - if (it != injectedIdToOwnElementId.end()) - { - const Id ownFileNodeId = it->second; - addCommentLocation(StorageCommentLocationData( - ownFileNodeId, - location.startLine, - location.startCol, - location.endLine, - location.endCol - )); - } - } - } - finishInjection(); } diff --git a/src/lib/data/storage/Storage.h b/src/lib/data/storage/Storage.h index ba6afe41..cdbaf391 100644 --- a/src/lib/data/storage/Storage.h +++ b/src/lib/data/storage/Storage.h @@ -6,7 +6,6 @@ #include #include -#include "StorageCommentLocation.h" #include "StorageComponentAccess.h" #include "StorageEdge.h" #include "StorageError.h" @@ -39,7 +38,6 @@ public: virtual void addOccurrences(const std::vector& occurrences) = 0; virtual void addComponentAccess(const StorageComponentAccess& componentAccess) = 0; virtual void addComponentAccesses(const std::vector& componentAccesses) = 0; - virtual void addCommentLocation(const StorageCommentLocationData& data) = 0; virtual void addError(const StorageErrorData& data) = 0; virtual const std::vector& getStorageNodes() const = 0; @@ -50,7 +48,6 @@ public: virtual const std::set& getStorageSourceLocations() const = 0; virtual const std::set& getStorageOccurrences() const = 0; virtual const std::set& getComponentAccesses() const = 0; - virtual const std::set& getCommentLocations() const = 0; virtual const std::vector& getErrors() const = 0; void inject(Storage* injected); diff --git a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp index 8cc6451e..12187991 100644 --- a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp +++ b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp @@ -11,7 +11,7 @@ #include "SourceLocationCollection.h" #include "SourceLocationFile.h" -const size_t SqliteIndexStorage::s_storageVersion = 19; +const size_t SqliteIndexStorage::s_storageVersion = 20; namespace { @@ -410,42 +410,6 @@ bool SqliteIndexStorage::addComponentAccesses(const std::vector 0) - { - id = checkQuery.getIntField(0, 0); - } - m_checkCommentLocationExistsStmt.reset(); - } - - if (id == 0) - { - m_insertCommentLocationStmt.bind(1, int(data.fileNodeId)); - m_insertCommentLocationStmt.bind(2, int(data.startLine)); - m_insertCommentLocationStmt.bind(3, int(data.startCol)); - m_insertCommentLocationStmt.bind(4, int(data.endLine)); - m_insertCommentLocationStmt.bind(5, int(data.endCol)); - - const bool success = executeStatement(m_insertCommentLocationStmt); - if (success) - { - id = m_database.lastRowId(); - } - } - - return StorageCommentLocation(id, data); -} - StorageError SqliteIndexStorage::addError(const StorageErrorData& data) { const std::wstring sanitizedMessage = utility::replace(data.message, L"'", L"''"); @@ -874,13 +838,14 @@ std::shared_ptr SqliteIndexStorage::getSourceLocationsForFil ret->setIsComplete(file.complete); ret->setIsIndexed(file.indexed); + std::vector sourceLocations = + doGetAll("WHERE file_node_id == " + std::to_string(file.id) + " " + query); + std::vector sourceLocationIds; - std::unordered_map sourceLocationIdToData; - for (const StorageSourceLocation& storageLocation: - doGetAll("WHERE file_node_id == " + std::to_string(file.id) + " " + query)) + sourceLocationIds.reserve(sourceLocations.size()); + for (const StorageSourceLocation& storageLocation : sourceLocations) { sourceLocationIds.push_back(storageLocation.id); - sourceLocationIdToData[storageLocation.id] = storageLocation; } std::map> sourceLocationIdToElementIds; @@ -889,21 +854,19 @@ std::shared_ptr SqliteIndexStorage::getSourceLocationsForFil sourceLocationIdToElementIds[occurrence.sourceLocationId].push_back(occurrence.elementId); } - for (const std::pair>& p : sourceLocationIdToElementIds) + for (const StorageSourceLocation& location : sourceLocations) { - auto it = sourceLocationIdToData.find(p.first); - if (it != sourceLocationIdToData.end()) - { - ret->addSourceLocation( - intToLocationType(it->second.type), - it->second.id, - p.second, - it->second.startLine, - it->second.startCol, - it->second.endLine, - it->second.endCol - ); - } + auto it = sourceLocationIdToElementIds.find(location.id); + + ret->addSourceLocation( + intToLocationType(location.type), + location.id, + it != sourceLocationIdToElementIds.end() ? it->second : std::vector(), + location.startLine, + location.startCol, + location.endLine, + location.endCol + ); } return ret; @@ -999,12 +962,6 @@ std::vector SqliteIndexStorage::getComponentAccessesByNo return doGetAll("WHERE node_id IN (" + utility::join(utility::toStrings(nodeIds), ',') + ")"); } -std::vector SqliteIndexStorage::getCommentLocationsInFile(const FilePath& filePath) const -{ - Id fileNodeId = getFileByPath(filePath.wstr()).id; - return doGetAll("WHERE file_node_id == " + std::to_string(fileNodeId)); -} - int SqliteIndexStorage::getNodeCount() const { return executeStatementScalar("SELECT COUNT(*) FROM node;", 0); @@ -1063,15 +1020,6 @@ std::vector> SqliteIndexStorage::getIndices( STORAGE_MODE_READ, SqliteDatabaseIndex("source_location_file_node_id_type_index", "source_location(file_node_id, type)") )); - indices.push_back(std::make_pair( - STORAGE_MODE_WRITE, - SqliteDatabaseIndex("comment_location_all_data_index", - "comment_location(file_node_id, start_line, start_column, end_line, end_column)") - )); - indices.push_back(std::make_pair( - STORAGE_MODE_CLEAR, - SqliteDatabaseIndex("comment_location_file_node_id_index", "comment_location(file_node_id)") - )); indices.push_back(std::make_pair( STORAGE_MODE_WRITE, SqliteDatabaseIndex("error_all_data_index", "error(message, fatal, file_path, line_number, column_number)") @@ -1096,7 +1044,6 @@ void SqliteIndexStorage::clearTables() try { m_database.execDML("DROP TABLE IF EXISTS main.error;"); - m_database.execDML("DROP TABLE IF EXISTS main.comment_location;"); m_database.execDML("DROP TABLE IF EXISTS main.component_access;"); m_database.execDML("DROP TABLE IF EXISTS main.occurrence;"); m_database.execDML("DROP TABLE IF EXISTS main.source_location;"); @@ -1213,18 +1160,6 @@ void SqliteIndexStorage::setupTables() "FOREIGN KEY(node_id) REFERENCES node(id) ON DELETE CASCADE);" ); - m_database.execDML( - "CREATE TABLE IF NOT EXISTS comment_location(" - "id INTEGER NOT NULL, " - "file_node_id INTEGER, " - "start_line INTEGER, " - "start_column INTEGER, " - "end_line INTEGER, " - "end_column INTEGER, " - "PRIMARY KEY(id), " - "FOREIGN KEY(file_node_id) REFERENCES node(id) ON DELETE CASCADE);" - ); - m_database.execDML( "CREATE TABLE IF NOT EXISTS error(" "id INTEGER NOT NULL, " @@ -1337,19 +1272,6 @@ void SqliteIndexStorage::setupPrecompiledStatements() m_insertFileContentStmt = m_database.compileStatement( "INSERT INTO filecontent(id, content) VALUES(?, ?);" ); - m_checkCommentLocationExistsStmt = m_database.compileStatement( - "SELECT id FROM comment_location WHERE " - "file_node_id = ? AND " - "start_line == ? AND " - "start_column == ? AND " - "end_line == ? AND " - "end_column == ? " - "LIMIT 1;" - ); - m_insertCommentLocationStmt = m_database.compileStatement( - "INSERT INTO comment_location(id, file_node_id, start_line, start_column, end_line, end_column) " - "VALUES(NULL, ?, ?, ?, ?, ?);" - ); m_checkErrorExistsStmt = m_database.compileStatement( "SELECT id FROM error WHERE " "message = ? AND " @@ -1574,37 +1496,6 @@ std::vector SqliteIndexStorage::doGetAll -std::vector SqliteIndexStorage::doGetAll(const std::string& query) const -{ - CppSQLite3Query q = executeQuery( - "SELECT id, file_node_id, start_line, start_column, end_line, end_column FROM comment_location " + query + ";" - ); - - std::vector commentLocations; - - while (!q.eof()) - { - const Id id = q.getIntField(0, 0); - const Id fileNodeId = q.getIntField(1, 0); - const int startLineNumber = q.getIntField(2, -1); - const int startColNumber = q.getIntField(3, -1); - const int endLineNumber = q.getIntField(4, -1); - const int endColNumber = q.getIntField(5, -1); - - if (id != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && - endColNumber != -1) - { - commentLocations.emplace_back( - id, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber - ); - } - - q.nextRow(); - } - return commentLocations; -} - template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const { diff --git a/src/lib/data/storage/sqlite/SqliteIndexStorage.h b/src/lib/data/storage/sqlite/SqliteIndexStorage.h index c9007081..28c1d4d2 100644 --- a/src/lib/data/storage/sqlite/SqliteIndexStorage.h +++ b/src/lib/data/storage/sqlite/SqliteIndexStorage.h @@ -8,7 +8,6 @@ #include "LocationType.h" #include "SqliteDatabaseIndex.h" #include "SqliteStorage.h" -#include "StorageCommentLocation.h" #include "StorageComponentAccess.h" #include "StorageEdge.h" #include "StorageError.h" @@ -64,7 +63,6 @@ public: bool addOccurrences(const std::vector& occurrences); bool addComponentAccess(const StorageComponentAccess& componentAccess); bool addComponentAccesses(const std::vector& componentAccesses); - StorageCommentLocation addCommentLocation(const StorageCommentLocationData& data); StorageError addError(const StorageErrorData& data); void removeElement(Id id); @@ -122,8 +120,6 @@ public: StorageComponentAccess getComponentAccessByNodeId(Id memberEdgeId) const; std::vector getComponentAccessesByNodeIds(const std::vector& memberEdgeIds) const; - std::vector getCommentLocationsInFile(const FilePath& filePath) const; - template std::vector getAll() const { @@ -306,8 +302,6 @@ private: CppSQLite3Statement m_insertElementStmt; CppSQLite3Statement m_insertFileStmt; CppSQLite3Statement m_insertFileContentStmt; - CppSQLite3Statement m_checkCommentLocationExistsStmt; - CppSQLite3Statement m_insertCommentLocationStmt; CppSQLite3Statement m_checkErrorExistsStmt; CppSQLite3Statement m_insertErrorStmt; }; @@ -332,8 +326,6 @@ std::vector SqliteIndexStorage::doGetAll(c template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; template <> -std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; -template <> std::vector SqliteIndexStorage::doGetAll(const std::string& query) const; #endif // SQLITE_INDEX_STORAGE_H diff --git a/src/lib/data/storage/type/StorageCommentLocation.h b/src/lib/data/storage/type/StorageCommentLocation.h deleted file mode 100644 index f2cd657a..00000000 --- a/src/lib/data/storage/type/StorageCommentLocation.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef STORAGE_COMMENT_LOCATION_H -#define STORAGE_COMMENT_LOCATION_H - -#include "types.h" - -struct StorageCommentLocationData -{ - StorageCommentLocationData() - : fileNodeId(0) - , startLine(-1) - , startCol(-1) - , endLine(-1) - , endCol(-1) - {} - - StorageCommentLocationData(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) - : fileNodeId(fileNodeId) - , startLine(startLine) - , startCol(startCol) - , endLine(endLine) - , endCol(endCol) - {} - - bool operator<(const StorageCommentLocationData& other) const - { - if (fileNodeId != other.fileNodeId) - { - return fileNodeId < other.fileNodeId; - } - else if (startLine != other.startLine) - { - return startLine < other.startLine; - } - else if (startCol != other.startCol) - { - return startCol < other.startCol; - } - else if (endLine != other.endLine) - { - return endLine < other.endLine; - } - else - { - return endCol < other.endCol; - } - } - - Id fileNodeId; - uint startLine; - uint startCol; - uint endLine; - uint endCol; -}; - -struct StorageCommentLocation: public StorageCommentLocationData -{ - StorageCommentLocation() - : StorageCommentLocationData() - , id(0) - {} - - StorageCommentLocation(Id id, const StorageCommentLocationData& data) - : StorageCommentLocationData(data) - , id(id) - {} - - StorageCommentLocation(Id id, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) - : StorageCommentLocationData(fileNodeId, startLine, startCol, endLine, endCol) - , id(id) - {} - - Id id; -}; - -#endif // STORAGE_COMMENT_LOCATION_H diff --git a/src/lib_gui/qt/element/QtCodeField.cpp b/src/lib_gui/qt/element/QtCodeField.cpp index e5ad77ed..5364ecaa 100644 --- a/src/lib_gui/qt/element/QtCodeField.cpp +++ b/src/lib_gui/qt/element/QtCodeField.cpp @@ -352,7 +352,7 @@ void QtCodeField::createAnnotations(std::shared_ptr location locationFile->forEachSourceLocation( [&](const SourceLocation* location) { - if (location->getType() == LOCATION_SIGNATURE) + if (location->getType() == LOCATION_SIGNATURE || location->getType() == LOCATION_COMMENT) { return; } diff --git a/src/lib_gui/qt/element/QtCodeNavigator.cpp b/src/lib_gui/qt/element/QtCodeNavigator.cpp index 7a037662..5b1a396b 100644 --- a/src/lib_gui/qt/element/QtCodeNavigator.cpp +++ b/src/lib_gui/qt/element/QtCodeNavigator.cpp @@ -224,7 +224,7 @@ void QtCodeNavigator::addFile(std::shared_ptr locationFile, locationFile->forEachStartSourceLocation( [&](SourceLocation* location) { - if (location->isScopeLocation() || location->getType() == LOCATION_SIGNATURE) + if (location->isScopeLocation() || location->getType() == LOCATION_SIGNATURE || location->getType() == LOCATION_COMMENT) { return; } diff --git a/src/lib_java/data/parser/java/JavaParser.h b/src/lib_java/data/parser/java/JavaParser.h index 5c930b1a..06f7ddf7 100644 --- a/src/lib_java/data/parser/java/JavaParser.h +++ b/src/lib_java/data/parser/java/JavaParser.h @@ -229,9 +229,9 @@ private: std::shared_ptr m_javaEnvironment; - const int m_id; FilePath m_currentFilePath; std::shared_ptr m_indexerStateInfo; + const int m_id; }; #endif // JAVA_PARSER_H