diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 174b4b54..39532963 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -229,6 +229,21 @@ add_files( data/storage/sqlite/SqliteStorage.cpp data/storage/sqlite/SqliteStorage.h + data/storage/type/StorageBookmarkCategory.h + 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 + data/storage/type/StorageFile.h + data/storage/type/StorageLocalSymbol.h + data/storage/type/StorageNode.h + data/storage/type/StorageOccurrence.h + data/storage/type/StorageSourceLocation.h + data/storage/type/StorageSymbol.h + data/storage/IntermediateStorage.cpp data/storage/IntermediateStorage.h data/storage/PersistentStorage.cpp @@ -239,7 +254,6 @@ add_files( data/storage/StorageCache.h data/storage/StorageProvider.cpp data/storage/StorageProvider.h - data/storage/StorageTypes.h data/storage/StorageStats.h data/tooltip/TooltipInfo.h diff --git a/src/lib/component/controller/BookmarkController.cpp b/src/lib/component/controller/BookmarkController.cpp index d9f4207e..8bcca107 100644 --- a/src/lib/component/controller/BookmarkController.cpp +++ b/src/lib/component/controller/BookmarkController.cpp @@ -6,6 +6,7 @@ #include "data/bookmark/Bookmark.h" #include "data/bookmark/EdgeBookmark.h" #include "data/bookmark/NodeBookmark.h" +#include "data/storage/type/StorageEdge.h" #include "utility/messaging/type/MessageActivateEdge.h" #include "utility/messaging/type/MessageActivateNodes.h" diff --git a/src/lib/data/ErrorFilter.h b/src/lib/data/ErrorFilter.h index da018012..69b6faf5 100644 --- a/src/lib/data/ErrorFilter.h +++ b/src/lib/data/ErrorFilter.h @@ -2,7 +2,6 @@ #define ERROR_FILTER_H #include "data/ErrorInfo.h" -#include "data/storage/StorageTypes.h" struct ErrorFilter { diff --git a/src/lib/data/ErrorInfo.h b/src/lib/data/ErrorInfo.h index 1c4ec165..3101710f 100644 --- a/src/lib/data/ErrorInfo.h +++ b/src/lib/data/ErrorInfo.h @@ -1,7 +1,7 @@ #ifndef ERROR_INFO_H #define ERROR_INFO_H -#include "data/storage/StorageTypes.h" +#include "data/storage/type/StorageError.h" typedef StorageError ErrorInfo; diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 88a9a312..6e4f2c57 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -12,6 +12,7 @@ #include "data/bookmark/NodeBookmark.h" #include "data/graph/Node.h" #include "data/search/SearchMatch.h" +#include "data/storage/type/StorageEdge.h" #include "data/ErrorCountInfo.h" #include "data/ErrorFilter.h" #include "data/ErrorInfo.h" diff --git a/src/lib/data/indexer/TaskBuildIndex.cpp b/src/lib/data/indexer/TaskBuildIndex.cpp index a3b3fef6..89b7e556 100644 --- a/src/lib/data/indexer/TaskBuildIndex.cpp +++ b/src/lib/data/indexer/TaskBuildIndex.cpp @@ -141,9 +141,11 @@ void TaskBuildIndex::doExit(std::shared_ptr blackboard) std::shared_ptr is = std::make_shared(); for (const FilePath& path : crashedFiles) { - is->addError("The translation unit threw an exception during indexing. Please check if the source file " + is->addError(StorageErrorData( + "The translation unit threw an exception during indexing. Please check if the source file " "conforms to the specified language standard and all necessary options are defined within your project " - "setup.", "", path, 1, 1, true, true); + "setup.", "", path, 1, 1, true, true + )); LOG_INFO_STREAM(<< "crashed translation unit: " << path.str()); } m_storageProvider->insert(is); diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp index 15bc1d8f..4207b210 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp +++ b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.cpp @@ -174,9 +174,9 @@ void SharedIntermediateStorage::setStorageOccurrences(const std::vector SharedIntermediateStorage::getStorageComponentAccesses() const +std::vector SharedIntermediateStorage::getStorageComponentAccesses() const { - std::vector result; + std::vector result; for (unsigned int i = 0; i < m_storageComponentAccesses.size(); i++) { @@ -186,7 +186,7 @@ std::vector SharedIntermediateStorage::getStorageCompone return result; } -void SharedIntermediateStorage::setStorageComponentAccesses(const std::vector& storageComponentAccesses) +void SharedIntermediateStorage::setStorageComponentAccesses(const std::vector& storageComponentAccesses) { m_storageComponentAccesses.clear(); @@ -196,9 +196,9 @@ void SharedIntermediateStorage::setStorageComponentAccesses(const std::vector SharedIntermediateStorage::getStorageCommentLocations() const +std::vector SharedIntermediateStorage::getStorageCommentLocations() const { - std::vector result; + std::vector result; for (unsigned int i = 0; i < m_storageCommentLocations.size(); i++) { @@ -208,7 +208,7 @@ std::vector SharedIntermediateStorage::getStorageComment return result; } -void SharedIntermediateStorage::setStorageCommentLocations(const std::vector& commentLocations) +void SharedIntermediateStorage::setStorageCommentLocations(const std::vector& commentLocations) { m_storageCommentLocations.clear(); @@ -218,9 +218,9 @@ void SharedIntermediateStorage::setStorageCommentLocations(const std::vector SharedIntermediateStorage::getStorageErrors() const +std::vector SharedIntermediateStorage::getStorageErrors() const { - std::vector result; + std::vector result; for (unsigned int i = 0; i < m_storageErrors.size(); i++) { @@ -230,7 +230,7 @@ std::vector SharedIntermediateStorage::getStorageErrors() const return result; } -void SharedIntermediateStorage::setStorageErrors(const std::vector& errors) +void SharedIntermediateStorage::setStorageErrors(const std::vector& errors) { m_storageErrors.clear(); diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h index cd4703ae..757b40e2 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h +++ b/src/lib/data/indexer/interprocess/shared_types/SharedIntermediateStorage.h @@ -1,7 +1,6 @@ #ifndef SHARED_INTERMEDIATE_STORAGE_H #define SHARED_INTERMEDIATE_STORAGE_H -#include "data/storage/StorageTypes.h" #include "data/indexer/interprocess/shared_types/SharedStorageTypes.h" #include "utility/interprocess/SharedMemory.h" @@ -32,14 +31,14 @@ public: std::vector getStorageOccurrences() const; void setStorageOccurrences(const std::vector& storageOccurences); - std::vector getStorageComponentAccesses() const; - void setStorageComponentAccesses(const std::vector& storageComponentAccesses); + std::vector getStorageComponentAccesses() const; + void setStorageComponentAccesses(const std::vector& storageComponentAccesses); - std::vector getStorageCommentLocations() const; - void setStorageCommentLocations(const std::vector& commentLocations); + std::vector getStorageCommentLocations() const; + void setStorageCommentLocations(const std::vector& commentLocations); - std::vector getStorageErrors() const; - void setStorageErrors(const std::vector& errors); + std::vector getStorageErrors() const; + void setStorageErrors(const std::vector& errors); Id getNextId() const; void setNextId(const Id nextId); @@ -48,13 +47,13 @@ private: SharedMemory::Vector m_storageFiles; SharedMemory::Vector m_storageSymbols; SharedMemory::Vector m_storageOccurrences; - SharedMemory::Vector m_storageComponentAccesses; - SharedMemory::Vector m_storageCommentLocations; + SharedMemory::Vector m_storageComponentAccesses; + SharedMemory::Vector m_storageCommentLocations; SharedMemory::Vector m_storageNodes; SharedMemory::Vector m_storageEdges; SharedMemory::Vector m_storageLocalSymbols; SharedMemory::Vector m_storageSourceLocations; - SharedMemory::Vector m_storageErrors; + SharedMemory::Vector m_storageErrors; SharedMemory::Allocator* m_allocator; diff --git a/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h b/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h index b78f8316..abe48218 100644 --- a/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h +++ b/src/lib/data/indexer/interprocess/shared_types/SharedStorageTypes.h @@ -1,6 +1,16 @@ #ifndef SHARED_STORAGE_TYPES_H #define SHARED_STORAGE_TYPES_H +#include "data/storage/type/StorageCommentLocation.h" +#include "data/storage/type/StorageComponentAccess.h" +#include "data/storage/type/StorageEdge.h" +#include "data/storage/type/StorageError.h" +#include "data/storage/type/StorageFile.h" +#include "data/storage/type/StorageLocalSymbol.h" +#include "data/storage/type/StorageNode.h" +#include "data/storage/type/StorageOccurrence.h" +#include "data/storage/type/StorageSourceLocation.h" +#include "data/storage/type/StorageSymbol.h" #include "utility/types.h" #include "utility/interprocess/SharedMemory.h" @@ -25,8 +35,8 @@ CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageEdge, SharedStorageEdge ) 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( StorageCommentLocation, SharedStorageCommentLocation ) +CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageComponentAccessData, SharedStorageComponentAccessData) +CONVERT_STORAGE_TYPE_TO_SHARED_TYPE( StorageCommentLocationData, SharedStorageCommentLocationData) struct SharedStorageNode @@ -103,10 +113,9 @@ inline StorageLocalSymbol fromShared(const SharedStorageLocalSymbol& symbol) } -struct SharedStorageError +struct SharedStorageErrorData { - SharedStorageError( - Id id, + SharedStorageErrorData( const std::string& message, const std::string& commandline, const std::string& filePath, @@ -116,8 +125,7 @@ struct SharedStorageError bool indexed, SharedMemory::Allocator* allocator ) - : id(id) - , message(message.c_str(), allocator) + : message(message.c_str(), allocator) , commandline(commandline.c_str(), allocator) , filePath(filePath.c_str(), allocator) , lineNumber(lineNumber) @@ -126,7 +134,6 @@ struct SharedStorageError , indexed(indexed) {} - Id id; SharedMemory::String message; SharedMemory::String commandline; @@ -138,17 +145,17 @@ struct SharedStorageError bool indexed; }; -inline SharedStorageError toShared(const StorageError& error, SharedMemory::Allocator* allocator) +inline SharedStorageErrorData toShared(const StorageErrorData& error, SharedMemory::Allocator* allocator) { - return SharedStorageError( - error.id, error.message, error.commandline, error.filePath.str(), + return SharedStorageErrorData( + error.message, error.commandline, error.filePath.str(), error.lineNumber, error.columnNumber, error.fatal, error.indexed, allocator); } -inline StorageError fromShared(const SharedStorageError& error) +inline StorageErrorData fromShared(const SharedStorageErrorData& error) { - return StorageError( - error.id, error.message.c_str(), error.commandline.c_str(), FilePath(error.filePath.c_str()), + return StorageErrorData( + error.message.c_str(), error.commandline.c_str(), FilePath(error.filePath.c_str()), error.lineNumber, error.columnNumber, error.fatal, error.indexed); } diff --git a/src/lib/data/parser/ParserClientImpl.cpp b/src/lib/data/parser/ParserClientImpl.cpp index 9887a614..7b87c914 100644 --- a/src/lib/data/parser/ParserClientImpl.cpp +++ b/src/lib/data/parser/ParserClientImpl.cpp @@ -222,7 +222,7 @@ Id ParserClientImpl::addNode(Node::NodeType nodeType, NameHierarchy nameHierarch return 0; } - return m_storage->addNode(Node::typeToInt(nodeType), NameHierarchy::serialize(nameHierarchy)); + return m_storage->addNode(StorageNodeData(Node::typeToInt(nodeType), NameHierarchy::serialize(nameHierarchy))); } void ParserClientImpl::addFile(Id id, const FilePath& filePath, const std::string& modificationTime) @@ -232,7 +232,7 @@ void ParserClientImpl::addFile(Id id, const FilePath& filePath, const std::strin return; } - m_storage->addFile(id, filePath.str(), modificationTime, true); + m_storage->addFile(StorageFile(id, filePath.str(), modificationTime, true)); } void ParserClientImpl::addSymbol(Id id, DefinitionKind definitionKind) @@ -244,7 +244,7 @@ void ParserClientImpl::addSymbol(Id id, DefinitionKind definitionKind) if (definitionKind != DEFINITION_NONE) { - m_storage->addSymbol(id, definitionKindToInt(definitionKind)); + m_storage->addSymbol(StorageSymbol(id, definitionKindToInt(definitionKind))); } } @@ -260,7 +260,7 @@ Id ParserClientImpl::addEdge(int type, Id sourceId, Id targetId) return 0; } - return m_storage->addEdge(type, sourceId, targetId); + return m_storage->addEdge(StorageEdgeData(type, sourceId, targetId)); } Id ParserClientImpl::addLocalSymbol(const std::string& name) @@ -291,19 +291,19 @@ void ParserClientImpl::addSourceLocation(Id elementId, const ParseLocation& loca return; } - Id sourceLocationId = m_storage->addSourceLocation( + Id sourceLocationId = m_storage->addSourceLocation(StorageSourceLocationData( addNodeHierarchy(NameHierarchy(location.filePath.str(), NAME_DELIMITER_FILE), Node::NODE_FILE), location.startLineNumber, location.startColumnNumber, location.endLineNumber, location.endColumnNumber, type - ); + )); - m_storage->addOccurrence( + m_storage->addOccurrence(StorageOccurrence( elementId, sourceLocationId - ); + )); } void ParserClientImpl::addComponentAccess(Id nodeId , int type) @@ -313,7 +313,7 @@ void ParserClientImpl::addComponentAccess(Id nodeId , int type) return; } - m_storage->addComponentAccess(nodeId, type); + m_storage->addComponentAccess(StorageComponentAccessData(nodeId, type)); } void ParserClientImpl::addCommentLocation(const ParseLocation& location) @@ -323,13 +323,13 @@ void ParserClientImpl::addCommentLocation(const ParseLocation& location) return; } - m_storage->addCommentLocation( + m_storage->addCommentLocation(StorageCommentLocationData( addNodeHierarchy(NameHierarchy(location.filePath.str(), NAME_DELIMITER_FILE), Node::NODE_FILE), location.startLineNumber, location.startColumnNumber, location.endLineNumber, location.endColumnNumber - ); + )); } void ParserClientImpl::addError( @@ -340,6 +340,7 @@ void ParserClientImpl::addError( return; } - m_storage->addError( - message, commandline, location.filePath, location.startLineNumber, location.startColumnNumber, fatal, indexed); + m_storage->addError(StorageErrorData( + message, commandline, location.filePath, location.startLineNumber, location.startColumnNumber, fatal, indexed + )); } diff --git a/src/lib/data/storage/IntermediateStorage.cpp b/src/lib/data/storage/IntermediateStorage.cpp index 34d9e6c7..4e521f0f 100644 --- a/src/lib/data/storage/IntermediateStorage.cpp +++ b/src/lib/data/storage/IntermediateStorage.cpp @@ -39,9 +39,9 @@ size_t IntermediateStorage::getByteSize(size_t stringSize) const byteSize += stringSize + storageFile.modificationTime.size(); } - for (const StorageError& storageError: getErrors()) + for (const StorageErrorData& storageError: getErrors()) { - byteSize += sizeof(StorageError); + byteSize += sizeof(StorageErrorData); byteSize += stringSize + storageError.filePath.str().size(); byteSize += stringSize + storageError.message.size(); byteSize += stringSize + storageError.commandline.size(); @@ -60,8 +60,8 @@ size_t IntermediateStorage::getByteSize(size_t stringSize) const } byteSize += sizeof(StorageEdge) * getStorageEdges().size(); - byteSize += sizeof(StorageCommentLocation) * getCommentLocations().size(); - byteSize += sizeof(StorageComponentAccess) * getComponentAccesses().size(); + byteSize += sizeof(StorageCommentLocationData) * getCommentLocations().size(); + byteSize += sizeof(StorageComponentAccessData) * getComponentAccesses().size(); byteSize += sizeof(StorageOccurrence) * getStorageOccurrences().size(); byteSize += sizeof(StorageSymbol) * getStorageSymbols().size(); byteSize += sizeof(StorageSourceLocation) * getStorageSourceLocations().size(); @@ -85,7 +85,7 @@ void IntermediateStorage::setAllFilesIncomplete() void IntermediateStorage::setFilesWithErrorsIncomplete() { std::set errorFileNames; - for (const StorageError& error : m_errors) + for (const StorageErrorData& error : m_errors) { errorFileNames.insert(error.filePath.str()); } @@ -99,34 +99,35 @@ void IntermediateStorage::setFilesWithErrorsIncomplete() } } -Id IntermediateStorage::addNode(int type, const std::string& serializedName) +Id IntermediateStorage::addNode(const StorageNodeData& nodeData) { - StorageNode node(0, type, serializedName); - const std::string serialized = serialize(node); + const std::string serialized = serialize(nodeData); std::unordered_map::iterator it = m_nodesIndex.find(serialized); if (it != m_nodesIndex.end()) { StorageNode& storedNode = m_nodes[it->second]; - if (storedNode.type < type) + if (storedNode.type < nodeData.type) { - storedNode.type = type; + storedNode.type = nodeData.type; } return storedNode.id; } - const Id id = m_nextId++; - node.id = id; + const StorageNode node(m_nextId++, nodeData); m_nodes.push_back(node); m_nodesIndex.emplace(serialized, m_nodes.size() - 1); - return id; + return node.id; } -void IntermediateStorage::addFile(const Id id, const std::string& filePath, const std::string& modificationTime, bool complete) +void IntermediateStorage::addSymbol(const StorageSymbol& symbol) { - const StorageFile file(id, filePath, modificationTime, complete); - const std::string serialized = serialize(file); + m_symbols.push_back(symbol); +} +void IntermediateStorage::addFile(const StorageFile& file) +{ + const std::string serialized = serialize(file); if (m_serializedFiles.find(serialized) == m_serializedFiles.end()) { m_files.push_back(file); @@ -135,74 +136,53 @@ void IntermediateStorage::addFile(const Id id, const std::string& filePath, cons } } -void IntermediateStorage::addSymbol(const Id id, int definitionKind) +Id IntermediateStorage::addEdge(const StorageEdgeData& edgeData) { - m_symbols.push_back(StorageSymbol(id, definitionKind)); -} -Id IntermediateStorage::addEdge(int type, Id sourceId, Id targetId) -{ - StorageEdge edge = StorageEdge(0, type, sourceId, targetId); - - const std::string serialized = serialize(edge); + const std::string serialized = serialize(edgeData); std::unordered_map::const_iterator it = m_edgesIndex.find(serialized); if (it != m_edgesIndex.end()) { return m_edges[it->second].id; } - const Id id = m_nextId++; - edge.id = id; + const StorageEdge edge = StorageEdge(m_nextId++, edgeData); m_edges.push_back(edge); m_edgesIndex.emplace(serialized, m_edges.size() - 1); - return id; + return edge.id; } -Id IntermediateStorage::addLocalSymbol(const std::string& name) +Id IntermediateStorage::addLocalSymbol(const StorageLocalSymbolData& localSymbolData) { - StorageLocalSymbol localSymbol = StorageLocalSymbol(0, name); - const std::string serialized = serialize(localSymbol); + const std::string serialized = serialize(localSymbolData); std::unordered_map::const_iterator it = m_localSymbols.find(serialized); if (it != m_localSymbols.end()) { return it->second.id; } - const Id id = m_nextId++; - localSymbol.id = id; + const StorageLocalSymbol localSymbol = StorageLocalSymbol(m_nextId++, localSymbolData); m_localSymbols[serialized] = localSymbol; - return id; + return localSymbol.id; } -Id IntermediateStorage::addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) +Id IntermediateStorage::addSourceLocation(const StorageSourceLocationData& sourceLocationData) { - StorageSourceLocation sourceLocation = StorageSourceLocation( - 0, - fileNodeId, - startLine, - startCol, - endLine, - endCol, - type - ); - - const std::string serialized = serialize(sourceLocation); + const std::string serialized = serialize(sourceLocationData); std::unordered_map::const_iterator it = m_sourceLocations.find(serialized); if (it != m_sourceLocations.end()) { return it->second.id; } - const Id id = m_nextId++; - sourceLocation.id = id; + const StorageSourceLocation sourceLocation = StorageSourceLocation(m_nextId++, sourceLocationData); m_sourceLocations[serialized] = sourceLocation; - return id; + return sourceLocation.id; } -void IntermediateStorage::addOccurrence(Id elementId, Id sourceLocationId) +void IntermediateStorage::addOccurrence(const StorageOccurrence& occurrence) { - const StorageOccurrence occurrence(elementId, sourceLocationId); const std::string serialized = serialize(occurrence); if (m_serializedOccurrences.find(serialized) == m_serializedOccurrences.end()) @@ -212,57 +192,35 @@ void IntermediateStorage::addOccurrence(Id elementId, Id sourceLocationId) } } -void IntermediateStorage::addComponentAccess(Id nodeId, int type) +void IntermediateStorage::addComponentAccess(const StorageComponentAccessData& componentAccessData) { - const StorageComponentAccess componentAccess(0, nodeId, type); - const std::string serialized = serialize(componentAccess); + const std::string serialized = serialize(componentAccessData); if (m_serializedComponentAccesses.find(serialized) == m_serializedComponentAccesses.end()) { - m_componentAccesses.push_back(componentAccess); + m_componentAccesses.push_back(componentAccessData); m_serializedComponentAccesses.insert(serialized); } } -void IntermediateStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) +void IntermediateStorage::addCommentLocation(const StorageCommentLocationData& commentLocationData) { - const StorageCommentLocation commentLocation( - 0, - fileNodeId, - startLine, - startCol, - endLine, - endCol - ); - const std::string serialized = serialize(commentLocation); + const std::string serialized = serialize(commentLocationData); if (m_serializedCommentLocations.find(serialized) == m_serializedCommentLocations.end()) { - m_commentLocations.push_back(commentLocation); + m_commentLocations.push_back(commentLocationData); m_serializedCommentLocations.insert(serialized); - } } -void IntermediateStorage::addError( - const std::string& message, const std::string& commandline, const FilePath& filePath, - uint startLine, uint startCol, bool fatal, bool indexed) +void IntermediateStorage::addError(const StorageErrorData& errorData) { - const StorageError error( - 0, - message, - commandline, - filePath, - startLine, - startCol, - fatal, - indexed - ); - const std::string serialized = serialize(error); + const std::string serialized = serialize(errorData); if (m_serializedErrors.find(serialized) == m_serializedErrors.end()) { - m_errors.push_back(error); + m_errors.push_back(errorData); m_serializedErrors.insert(serialized); } } @@ -325,25 +283,25 @@ void IntermediateStorage::forEachOccurrence(std::function callback) const +void IntermediateStorage::forEachComponentAccess(std::function callback) const { - for (std::vector::const_iterator it = m_componentAccesses.begin(); it != m_componentAccesses.end(); it++) + for (std::vector::const_iterator it = m_componentAccesses.begin(); it != m_componentAccesses.end(); it++) { callback(*it); } } -void IntermediateStorage::forEachCommentLocation(std::function callback) const +void IntermediateStorage::forEachCommentLocation(std::function callback) const { - for (std::vector::const_iterator it = m_commentLocations.begin(); it != m_commentLocations.end(); it++) + for (std::vector::const_iterator it = m_commentLocations.begin(); it != m_commentLocations.end(); it++) { callback(*it); } } -void IntermediateStorage::forEachError(std::function callback) const +void IntermediateStorage::forEachError(std::function callback) const { - for (std::vector::const_iterator it = m_errors.begin(); it != m_errors.end(); it++) + for (std::vector::const_iterator it = m_errors.begin(); it != m_errors.end(); it++) { callback(*it); } @@ -396,17 +354,17 @@ std::vector IntermediateStorage::getStorageOccurrences() cons return m_occurrences; } -std::vector IntermediateStorage::getComponentAccesses() const +std::vector IntermediateStorage::getComponentAccesses() const { return m_componentAccesses; } -std::vector IntermediateStorage::getCommentLocations() const +std::vector IntermediateStorage::getCommentLocations() const { return m_commentLocations; } -std::vector IntermediateStorage::getErrors() const +std::vector IntermediateStorage::getErrors() const { return m_errors; } @@ -466,17 +424,17 @@ void IntermediateStorage::setStorageOccurrences(const std::vector& componentAccesses) +void IntermediateStorage::setComponentAccesses(const std::vector& componentAccesses) { m_componentAccesses = componentAccesses; } -void IntermediateStorage::setCommentLocations(const std::vector& commentLocations) +void IntermediateStorage::setCommentLocations(const std::vector& commentLocations) { m_commentLocations = commentLocations; } -void IntermediateStorage::setErrors(const std::vector& errors) +void IntermediateStorage::setErrors(const std::vector& errors) { m_errors = errors; } @@ -491,9 +449,9 @@ void IntermediateStorage::setNextId(const Id nextId) m_nextId = nextId; } -std::string IntermediateStorage::serialize(const StorageNode& node) const +std::string IntermediateStorage::serialize(const StorageNodeData& nodeData) const { - return node.serializedName; + return nodeData.serializedName; } std::string IntermediateStorage::serialize(const StorageFile& file) const @@ -501,29 +459,29 @@ std::string IntermediateStorage::serialize(const StorageFile& file) const return file.filePath; } -std::string IntermediateStorage::serialize(const StorageEdge& edge) const +std::string IntermediateStorage::serialize(const StorageEdgeData& edgeData) const { return ( - std::to_string(edge.type) + ";" + - std::to_string(edge.sourceNodeId) + ";" + - std::to_string(edge.targetNodeId) + std::to_string(edgeData.type) + ";" + + std::to_string(edgeData.sourceNodeId) + ";" + + std::to_string(edgeData.targetNodeId) ); } -std::string IntermediateStorage::serialize(const StorageLocalSymbol& localSymbol) const +std::string IntermediateStorage::serialize(const StorageLocalSymbolData& localSymbolData) const { - return localSymbol.name; + return localSymbolData.name; } -std::string IntermediateStorage::serialize(const StorageSourceLocation& sourceLocation) const +std::string IntermediateStorage::serialize(const StorageSourceLocationData& sourceLocationData) const { return ( - std::to_string(sourceLocation.fileNodeId) + ";" + - std::to_string(sourceLocation.startLine) + ";" + - std::to_string(sourceLocation.startCol) + ";" + - std::to_string(sourceLocation.endLine) + ";" + - std::to_string(sourceLocation.endCol) + ";" + - std::to_string(sourceLocation.type) + std::to_string(sourceLocationData.fileNodeId) + ";" + + std::to_string(sourceLocationData.startLine) + ";" + + std::to_string(sourceLocationData.startCol) + ";" + + std::to_string(sourceLocationData.endLine) + ";" + + std::to_string(sourceLocationData.endCol) + ";" + + std::to_string(sourceLocationData.type) ); } @@ -533,31 +491,31 @@ std::string IntermediateStorage::serialize(const StorageOccurrence& occurrence) } -std::string IntermediateStorage::serialize(const StorageComponentAccess& componentAccess) const +std::string IntermediateStorage::serialize(const StorageComponentAccessData& componentAccessData) const { - return std::to_string(componentAccess.nodeId); + return std::to_string(componentAccessData.nodeId); } -std::string IntermediateStorage::serialize(const StorageCommentLocation& commentLocation) const +std::string IntermediateStorage::serialize(const StorageCommentLocationData& commentLocationData) const { return ( - std::to_string(commentLocation.fileNodeId) + ";" + - std::to_string(commentLocation.startLine) + ";" + - std::to_string(commentLocation.startCol) + ";" + - std::to_string(commentLocation.endLine) + ";" + - std::to_string(commentLocation.endCol) + std::to_string(commentLocationData.fileNodeId) + ";" + + std::to_string(commentLocationData.startLine) + ";" + + std::to_string(commentLocationData.startCol) + ";" + + std::to_string(commentLocationData.endLine) + ";" + + std::to_string(commentLocationData.endCol) ); } -std::string IntermediateStorage::serialize(const StorageError& error) const +std::string IntermediateStorage::serialize(const StorageErrorData& errorData) const { return ( - error.message + ";" + - std::to_string(error.fatal) + ";" + - error.filePath.str() + ";" + - std::to_string(error.lineNumber) + ";" + - std::to_string(error.columnNumber) + errorData.message + ";" + + std::to_string(errorData.fatal) + ";" + + errorData.filePath.str() + ";" + + std::to_string(errorData.lineNumber) + ";" + + std::to_string(errorData.columnNumber) ); } diff --git a/src/lib/data/storage/IntermediateStorage.h b/src/lib/data/storage/IntermediateStorage.h index c25483dc..b79ee635 100644 --- a/src/lib/data/storage/IntermediateStorage.h +++ b/src/lib/data/storage/IntermediateStorage.h @@ -6,7 +6,16 @@ #include #include -#include "data/storage/StorageTypes.h" +#include "data/storage/type/StorageCommentLocation.h" +#include "data/storage/type/StorageComponentAccess.h" +#include "data/storage/type/StorageEdge.h" +#include "data/storage/type/StorageError.h" +#include "data/storage/type/StorageFile.h" +#include "data/storage/type/StorageLocalSymbol.h" +#include "data/storage/type/StorageNode.h" +#include "data/storage/type/StorageOccurrence.h" +#include "data/storage/type/StorageSourceLocation.h" +#include "data/storage/type/StorageSymbol.h" #include "data/storage/Storage.h" class IntermediateStorage: public Storage @@ -23,28 +32,27 @@ public: void setAllFilesIncomplete(); void setFilesWithErrorsIncomplete(); - virtual Id addNode(int type, const std::string& serializedName); - virtual void addFile(const Id id, const std::string& filePath, const std::string& modificationTime, bool complete); - virtual void addSymbol(const Id id, int definitionKind); - virtual Id addEdge(int type, Id sourceId, Id targetId); - virtual Id addLocalSymbol(const std::string& name); - virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type); - virtual void addOccurrence(Id elementId, Id sourceLocationId); - virtual void addComponentAccess(Id nodeId , int type); - virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol); - virtual void addError(const std::string& message, const std::string& commandline, const FilePath& filePath, - uint startLine, uint startCol, bool fatal, bool indexed); + virtual Id addNode(const StorageNodeData& nodeData) override; + virtual void addSymbol(const StorageSymbol& symbol) override; + virtual void addFile(const StorageFile& file) override; + virtual Id addEdge(const StorageEdgeData& edgeData) override; + virtual Id addLocalSymbol(const StorageLocalSymbolData& localSymbolData) override; + virtual Id addSourceLocation(const StorageSourceLocationData& sourceLocationData) override; + virtual void addOccurrence(const StorageOccurrence& occurrence) override; + virtual void addComponentAccess(const StorageComponentAccessData& componentAccessData) override; + virtual void addCommentLocation(const StorageCommentLocationData& commentLocationData) override; + virtual void addError(const StorageErrorData& errorData) override; - virtual void forEachNode(std::function callback) const; - virtual void forEachFile(std::function callback) const; - virtual void forEachSymbol(std::function callback) const; - virtual void forEachEdge(std::function callback) const; - virtual void forEachLocalSymbol(std::function callback) const; - virtual void forEachSourceLocation(std::function callback) const; - virtual void forEachOccurrence(std::function callback) const; - virtual void forEachComponentAccess(std::function callback) const; - virtual void forEachCommentLocation(std::function callback) const; - virtual void forEachError(std::function callback) const; + virtual void forEachNode(std::function callback) const override; + virtual void forEachFile(std::function callback) const override; + virtual void forEachSymbol(std::function callback) const override; + virtual void forEachEdge(std::function callback) const override; + virtual void forEachLocalSymbol(std::function callback) const override; + virtual void forEachSourceLocation(std::function callback) const override; + virtual void forEachOccurrence(std::function callback) const override; + virtual void forEachComponentAccess(std::function callback) const override; + virtual void forEachCommentLocation(std::function callback) const override; + virtual void forEachError(std::function callback) const override; // for conversion to and from 'SharedIntermediateStorage' @@ -56,9 +64,9 @@ public: std::vector getStorageLocalSymbols() const; std::vector getStorageSourceLocations() const; std::vector getStorageOccurrences() const; - std::vector getComponentAccesses() const; - std::vector getCommentLocations() const; - std::vector getErrors() const; + std::vector getComponentAccesses() const; + std::vector getCommentLocations() const; + std::vector getErrors() const; void setStorageNodes(const std::vector& storageNodes); void setStorageFiles(const std::vector& storageFiles); @@ -67,23 +75,23 @@ public: void setStorageLocalSymbols(const std::vector& storageLocalSymbols); void setStorageSourceLocations(const std::vector& storageSourceLocations); void setStorageOccurrences(const std::vector& storageOccurrences); - void setComponentAccesses(const std::vector& componentAccesses); - void setCommentLocations(const std::vector& commentLocations); - void setErrors(const std::vector& errors); + void setComponentAccesses(const std::vector& componentAccesses); + void setCommentLocations(const std::vector& commentLocations); + void setErrors(const std::vector& errors); Id getNextId() const; void setNextId(const Id nextId); private: - std::string serialize(const StorageNode& node) const; + std::string serialize(const StorageNodeData& nodeData) const; std::string serialize(const StorageFile& file) const; - std::string serialize(const StorageEdge& edge) const; - std::string serialize(const StorageLocalSymbol& localSymbol) const; - std::string serialize(const StorageSourceLocation& sourceLocation) const; + std::string serialize(const StorageEdgeData& edgeData) const; + std::string serialize(const StorageLocalSymbolData& localSymbolData) const; + std::string serialize(const StorageSourceLocationData& sourceLocationData) const; std::string serialize(const StorageOccurrence& occurrence) const; - std::string serialize(const StorageComponentAccess& componentAccess) const; - std::string serialize(const StorageCommentLocation& commentLocation) const; - std::string serialize(const StorageError& error) const; + std::string serialize(const StorageComponentAccessData& componentAccessData) const; + std::string serialize(const StorageCommentLocationData& commentLocationData) const; + std::string serialize(const StorageErrorData& errorData) const; std::unordered_map m_nodesIndex; std::vector m_nodes; @@ -104,13 +112,13 @@ private: std::vector m_occurrences; std::unordered_set m_serializedComponentAccesses; // this is used to prevent duplicates (unique) - std::vector m_componentAccesses; + std::vector m_componentAccesses; std::unordered_set m_serializedCommentLocations; // this is used to prevent duplicates (unique) - std::vector m_commentLocations; + std::vector m_commentLocations; std::unordered_set m_serializedErrors; // this is used to prevent duplicates (unique) - std::vector m_errors; + std::vector m_errors; Id m_nextId; }; diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index e7fd91d9..68b0cdf3 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -62,114 +62,90 @@ PersistentStorage::~PersistentStorage() { } -Id PersistentStorage::addNode(int type, const std::string& serializedName) +Id PersistentStorage::addNode(const StorageNodeData& data) { - const StorageNode storedNode = m_sqliteIndexStorage.getNodeBySerializedName(serializedName); - Id id = storedNode.id; + const StorageNode storedNode = m_sqliteIndexStorage.getNodeBySerializedName(data.serializedName); - if (id == 0) + if (storedNode.id == 0) { - id = m_sqliteIndexStorage.addNode(type, serializedName); - } - else - { - if (storedNode.type < type) - { - m_sqliteIndexStorage.setNodeType(type, id); - } + return m_sqliteIndexStorage.addNode(data).id; } - return id; + if (storedNode.type < data.type) + { + m_sqliteIndexStorage.setNodeType(data.type, storedNode.id); + return storedNode.id; + } + + return storedNode.id; } -void PersistentStorage::addFile(const Id id, const std::string& filePath, const std::string& modificationTime, bool complete) +void PersistentStorage::addSymbol(const StorageSymbol& data) { - StorageFile file = m_sqliteIndexStorage.getFirstById(id); - if (file.id == 0) + if (m_sqliteIndexStorage.getFirstById(data.id).id == 0) { - m_sqliteIndexStorage.addFile(id, filePath, modificationTime, complete); - } - else if (!file.complete && complete) - { - m_sqliteIndexStorage.setFileComplete(complete, id); + m_sqliteIndexStorage.addSymbol(data); } } -void PersistentStorage::addSymbol(const Id id, int definitionKind) +void PersistentStorage::addFile(const StorageFile& data) { - if (m_sqliteIndexStorage.getFirstById(id).id == 0) + StorageFile storedFile = m_sqliteIndexStorage.getFirstById(data.id); + + if (storedFile.id == 0) { - m_sqliteIndexStorage.addSymbol(id, definitionKind); + m_sqliteIndexStorage.addFile(data); + } + + if (!storedFile.complete && data.complete) + { + m_sqliteIndexStorage.setFileComplete(data.complete, storedFile.id); } } -Id PersistentStorage::addEdge(int type, Id sourceId, Id targetId) +Id PersistentStorage::addEdge(const StorageEdgeData& data) { - Id edgeId = m_sqliteIndexStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id; - if (edgeId == 0) + StorageEdge storedEdge = m_sqliteIndexStorage.getEdgeBySourceTargetType(data.sourceNodeId, data.targetNodeId, data.type); + if (storedEdge.id == 0) { - edgeId = m_sqliteIndexStorage.addEdge(type, sourceId, targetId); + return m_sqliteIndexStorage.addEdge(data).id; } - return edgeId; + return storedEdge.id; } -Id PersistentStorage::addLocalSymbol(const std::string& name) +Id PersistentStorage::addLocalSymbol(const StorageLocalSymbolData& data) { - Id localSymbolId = m_sqliteIndexStorage.getLocalSymbolByName(name).id; - if (localSymbolId == 0) + StorageLocalSymbol storedLocalSymbol = m_sqliteIndexStorage.getLocalSymbolByName(data.name); + if (storedLocalSymbol.id == 0) { - localSymbolId = m_sqliteIndexStorage.addLocalSymbol(name); + return m_sqliteIndexStorage.addLocalSymbol(data).id; } - return localSymbolId; + return storedLocalSymbol.id; } -Id PersistentStorage::addSourceLocation( - Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) +Id PersistentStorage::addSourceLocation(const StorageSourceLocationData& data) { - return m_sqliteIndexStorage.addSourceLocation( - fileNodeId, - startLine, - startCol, - endLine, - endCol, - type - ); + return m_sqliteIndexStorage.addSourceLocation(data).id; } -void PersistentStorage::addOccurrence(Id elementId, Id sourceLocationId) +void PersistentStorage::addOccurrence(const StorageOccurrence& data) { - m_sqliteIndexStorage.addOccurrence(elementId, sourceLocationId); + m_sqliteIndexStorage.addOccurrence(data); } -void PersistentStorage::addComponentAccess(Id nodeId , int type) +void PersistentStorage::addComponentAccess(const StorageComponentAccessData& data) { - m_sqliteIndexStorage.addComponentAccess(nodeId, type); + m_sqliteIndexStorage.addComponentAccess(data); } -void PersistentStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) +void PersistentStorage::addCommentLocation(const StorageCommentLocationData& data) { - m_sqliteIndexStorage.addCommentLocation( - fileNodeId, - startLine, - startCol, - endLine, - endCol - ); + m_sqliteIndexStorage.addCommentLocation(data); } -void PersistentStorage::addError( - const std::string& message, const std::string& commandline, const FilePath& filePath, - uint startLine, uint startCol, bool fatal, bool indexed) +void PersistentStorage::addError(const StorageErrorData& data) { - m_sqliteIndexStorage.addError( - message, - commandline, - filePath, - startLine, - startCol, - fatal, - indexed - ); + m_sqliteIndexStorage.addError(data); } void PersistentStorage::forEachNode(std::function callback) const @@ -228,7 +204,7 @@ void PersistentStorage::forEachOccurrence(std::function callback) const +void PersistentStorage::forEachComponentAccess(std::function callback) const { for (StorageComponentAccess& componentAccess: m_sqliteIndexStorage.getAll()) { @@ -236,7 +212,7 @@ void PersistentStorage::forEachComponentAccess(std::function callback) const +void PersistentStorage::forEachCommentLocation(std::function callback) const { for (StorageCommentLocation& commentLocation: m_sqliteIndexStorage.getAll()) { @@ -244,7 +220,7 @@ void PersistentStorage::forEachCommentLocation(std::function callback) const +void PersistentStorage::forEachError(std::function callback) const { for (StorageError& error: m_sqliteIndexStorage.getAll()) { @@ -1527,12 +1503,13 @@ std::shared_ptr PersistentStorage::getErrorSourceLocat Id PersistentStorage::addNodeBookmark(const NodeBookmark& bookmark) { const Id categoryId = addBookmarkCategory(bookmark.getCategory().getName()); - const Id id = m_sqliteBookmarkStorage.addBookmark( - bookmark.getName(), bookmark.getComment(), bookmark.getTimeStamp().toString(), categoryId); + const Id id = m_sqliteBookmarkStorage.addBookmark(StorageBookmarkData( + bookmark.getName(), bookmark.getComment(), bookmark.getTimeStamp().toString(), categoryId + )).id; for (const Id& nodeId: bookmark.getNodeIds()) { - m_sqliteBookmarkStorage.addBookmarkedNode(id, m_sqliteIndexStorage.getNodeById(nodeId).serializedName); + m_sqliteBookmarkStorage.addBookmarkedNode(StorageBookmarkedNodeData(id, m_sqliteIndexStorage.getNodeById(nodeId).serializedName)); } return id; @@ -1541,21 +1518,22 @@ Id PersistentStorage::addNodeBookmark(const NodeBookmark& bookmark) Id PersistentStorage::addEdgeBookmark(const EdgeBookmark& bookmark) { const Id categoryId = addBookmarkCategory(bookmark.getCategory().getName()); - const Id id = m_sqliteBookmarkStorage.addBookmark( - bookmark.getName(), bookmark.getComment(), bookmark.getTimeStamp().toString(), categoryId); + const Id id = m_sqliteBookmarkStorage.addBookmark(StorageBookmarkData( + bookmark.getName(), bookmark.getComment(), bookmark.getTimeStamp().toString(), categoryId + )).id; for (const Id& edgeId: bookmark.getEdgeIds()) { const StorageEdge storageEdge = m_sqliteIndexStorage.getEdgeById(edgeId); bool sourceNodeActive = storageEdge.sourceNodeId == bookmark.getActiveNodeId(); - m_sqliteBookmarkStorage.addBookmarkedEdge( + m_sqliteBookmarkStorage.addBookmarkedEdge(StorageBookmarkedEdgeData( id, // todo: optimization for multiple edges in same bookmark: use a local cache here m_sqliteIndexStorage.getNodeById(storageEdge.sourceNodeId).serializedName, m_sqliteIndexStorage.getNodeById(storageEdge.targetNodeId).serializedName, storageEdge.type, sourceNodeActive - ); + )); } return id; } @@ -1570,7 +1548,7 @@ Id PersistentStorage::addBookmarkCategory(const std::string& name) Id id = m_sqliteBookmarkStorage.getBookmarkCategoryByName(name).id; if (id == 0) { - id = m_sqliteBookmarkStorage.addBookmarkCategory(name); + id = m_sqliteBookmarkStorage.addBookmarkCategory(StorageBookmarkCategoryData(name)).id; } return id; } diff --git a/src/lib/data/storage/PersistentStorage.h b/src/lib/data/storage/PersistentStorage.h index 25cab317..e35ffc63 100644 --- a/src/lib/data/storage/PersistentStorage.h +++ b/src/lib/data/storage/PersistentStorage.h @@ -20,28 +20,27 @@ public: PersistentStorage(const FilePath& dbPath, const FilePath& bookmarkPath); virtual ~PersistentStorage(); - virtual Id addNode(int type, const std::string& serializedName); - virtual void addFile(const Id id, const std::string& filePath, const std::string& modificationTime, bool complete); - virtual void addSymbol(const Id id, int definitionKind); - virtual Id addEdge(int type, Id sourceId, Id targetId); - virtual Id addLocalSymbol(const std::string& name); - virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type); - virtual void addOccurrence(Id elementId, Id sourceLocationId); - virtual void addComponentAccess(Id nodeId , int type); - virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol); - virtual void addError(const std::string& message, const std::string& commandline, const FilePath& filePath, - uint startLine, uint startCol, bool fatal, bool indexed); + virtual Id addNode(const StorageNodeData& data) override; + virtual void addSymbol(const StorageSymbol& data) override; + virtual void addFile(const StorageFile& data) override; + virtual Id addEdge(const StorageEdgeData& data) override; + virtual Id addLocalSymbol(const StorageLocalSymbolData& data) override; + virtual Id addSourceLocation(const StorageSourceLocationData& data) override; + virtual void addOccurrence(const StorageOccurrence& data) override; + virtual void addComponentAccess(const StorageComponentAccessData& data) override; + virtual void addCommentLocation(const StorageCommentLocationData& data) override; + virtual void addError(const StorageErrorData& data) override; - virtual void forEachNode(std::function callback) const; - virtual void forEachFile(std::function callback) const; - virtual void forEachSymbol(std::function callback) const; - virtual void forEachEdge(std::function callback) const; - virtual void forEachLocalSymbol(std::function callback) const; - virtual void forEachSourceLocation(std::function callback) const; - virtual void forEachOccurrence(std::function callback) const; - virtual void forEachComponentAccess(std::function callback) const; - virtual void forEachCommentLocation(std::function callback) const; - virtual void forEachError(std::function callback) const; + virtual void forEachNode(std::function callback) const override; + virtual void forEachFile(std::function callback) const override; + virtual void forEachSymbol(std::function callback) const override; + virtual void forEachEdge(std::function callback) const override; + virtual void forEachLocalSymbol(std::function callback) const override; + virtual void forEachSourceLocation(std::function callback) const override; + virtual void forEachOccurrence(std::function callback) const override; + virtual void forEachComponentAccess(std::function callback) const override; + virtual void forEachCommentLocation(std::function callback) const override; + virtual void forEachError(std::function callback) const override; virtual void startInjection(); virtual void finishInjection(); diff --git a/src/lib/data/storage/Storage.cpp b/src/lib/data/storage/Storage.cpp index 21b93212..ede1fae1 100644 --- a/src/lib/data/storage/Storage.cpp +++ b/src/lib/data/storage/Storage.cpp @@ -2,7 +2,16 @@ #include -#include "data/storage/StorageTypes.h" +#include "data/storage/type/StorageCommentLocation.h" +#include "data/storage/type/StorageComponentAccess.h" +#include "data/storage/type/StorageEdge.h" +#include "data/storage/type/StorageError.h" +#include "data/storage/type/StorageFile.h" +#include "data/storage/type/StorageLocalSymbol.h" +#include "data/storage/type/StorageNode.h" +#include "data/storage/type/StorageOccurrence.h" +#include "data/storage/type/StorageSourceLocation.h" +#include "data/storage/type/StorageSymbol.h" #include "utility/tracing.h" Storage::Storage() @@ -25,7 +34,7 @@ void Storage::inject(Storage* injected) injected->forEachNode( [&](const StorageNode& injectedData) { - const Id ownId = addNode(injectedData.type, injectedData.serializedName); + const Id ownId = addNode(injectedData); if (ownId != 0) { injectedIdToOwnId[injectedData.id] = ownId; @@ -38,13 +47,11 @@ void Storage::inject(Storage* injected) { std::unordered_map::const_iterator it; it = injectedIdToOwnId.find(injectedData.id); - if (it == injectedIdToOwnId.end()) + if (it != injectedIdToOwnId.end()) { - return; + const Id ownId = it->second; + addFile(StorageFile(ownId, injectedData.filePath, injectedData.modificationTime, injectedData.complete)); } - const Id ownId = it->second; - - addFile(ownId, injectedData.filePath, injectedData.modificationTime, injectedData.complete); } ); @@ -53,13 +60,11 @@ void Storage::inject(Storage* injected) { std::unordered_map::const_iterator it; it = injectedIdToOwnId.find(injectedData.id); - if (it == injectedIdToOwnId.end()) + if (it != injectedIdToOwnId.end()) { - return; + const Id ownId = it->second; + addSymbol(StorageSymbol(ownId, injectedData.definitionKind)); } - const Id ownId = it->second; - - addSymbol(ownId, injectedData.definitionKind); } ); @@ -81,7 +86,7 @@ void Storage::inject(Storage* injected) } const Id ownTargetId = it->second; - const Id ownId = addEdge(injectedData.type, ownSourceId, ownTargetId); + const Id ownId = addEdge(StorageEdgeData(injectedData.type, ownSourceId, ownTargetId)); if (ownId != 0) { @@ -93,7 +98,7 @@ void Storage::inject(Storage* injected) injected->forEachLocalSymbol( [&](const StorageLocalSymbol& injectedData) { - const Id ownId = addLocalSymbol(injectedData.name); + const Id ownId = addLocalSymbol(injectedData); if (ownId != 0) { injectedIdToOwnId[injectedData.id] = ownId; @@ -106,23 +111,22 @@ void Storage::inject(Storage* injected) { std::unordered_map::const_iterator it; it = injectedIdToOwnId.find(injectedData.fileNodeId); - if (it == injectedIdToOwnId.end()) + if (it != injectedIdToOwnId.end()) { - return; - } - const Id ownFileNodeId = it->second; + const Id ownFileNodeId = it->second; - const Id ownId = addSourceLocation( - ownFileNodeId, - injectedData.startLine, - injectedData.startCol, - injectedData.endLine, - injectedData.endCol, - injectedData.type - ); - if (ownId != 0) - { - injectedIdToOwnId[injectedData.id] = ownId; + const Id ownId = addSourceLocation(StorageSourceLocationData( + ownFileNodeId, + injectedData.startLine, + injectedData.startCol, + injectedData.endLine, + injectedData.endCol, + injectedData.type + )); + if (ownId != 0) + { + injectedIdToOwnId[injectedData.id] = ownId; + } } } ); @@ -145,12 +149,12 @@ void Storage::inject(Storage* injected) } const Id ownSourceLocationId = it->second; - addOccurrence(ownElementId, ownSourceLocationId); + addOccurrence(StorageOccurrence(ownElementId, ownSourceLocationId)); } ); injected->forEachComponentAccess( - [&](const StorageComponentAccess& injectedData) + [&](const StorageComponentAccessData& injectedData) { std::unordered_map::const_iterator it; it = injectedIdToOwnId.find(injectedData.nodeId); @@ -160,12 +164,12 @@ void Storage::inject(Storage* injected) } const Id ownNodeId = it->second; - addComponentAccess(ownNodeId, injectedData.type); + addComponentAccess(StorageComponentAccessData(ownNodeId, injectedData.type)); } ); injected->forEachCommentLocation( - [&](const StorageCommentLocation& injectedData) + [&](const StorageCommentLocationData& injectedData) { std::unordered_map::const_iterator it; it = injectedIdToOwnId.find(injectedData.fileNodeId); @@ -175,28 +179,20 @@ void Storage::inject(Storage* injected) } const Id ownFileNodeId = it->second; - addCommentLocation( + addCommentLocation(StorageCommentLocationData( ownFileNodeId, injectedData.startLine, injectedData.startCol, injectedData.endLine, injectedData.endCol - ); + )); } ); injected->forEachError( - [&](const StorageError& injectedData) + [&](const StorageErrorData& injectedData) { - addError( - injectedData.message, - injectedData.commandline, - injectedData.filePath, - injectedData.lineNumber, - injectedData.columnNumber, - injectedData.fatal, - injectedData.indexed - ); + addError(injectedData); } ); diff --git a/src/lib/data/storage/Storage.h b/src/lib/data/storage/Storage.h index b2421611..f1ab5e8c 100644 --- a/src/lib/data/storage/Storage.h +++ b/src/lib/data/storage/Storage.h @@ -5,7 +5,16 @@ #include #include -#include "data/storage/StorageTypes.h" +#include "data/storage/type/StorageCommentLocation.h" +#include "data/storage/type/StorageComponentAccess.h" +#include "data/storage/type/StorageEdge.h" +#include "data/storage/type/StorageError.h" +#include "data/storage/type/StorageFile.h" +#include "data/storage/type/StorageLocalSymbol.h" +#include "data/storage/type/StorageNode.h" +#include "data/storage/type/StorageOccurrence.h" +#include "data/storage/type/StorageSourceLocation.h" +#include "data/storage/type/StorageSymbol.h" #include "utility/types.h" class Storage @@ -14,17 +23,16 @@ public: Storage(); virtual ~Storage(); - virtual Id addNode(int type, const std::string& serializedName) = 0; - virtual void addFile(const Id id, const std::string& filePath, const std::string& modificationTime, bool complete) = 0; - virtual void addSymbol(const Id id, int definitionKind) = 0; - virtual Id addEdge(int type, Id sourceId, Id targetId) = 0; - virtual Id addLocalSymbol(const std::string& name) = 0; - virtual Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) = 0; - virtual void addOccurrence(Id elementId, Id sourceLocationId) = 0; - virtual void addComponentAccess(Id nodeId , int type) = 0; - virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) = 0; - virtual void addError(const std::string& message, const std::string& commandline, const FilePath& filePath, - uint startLine, uint startCol, bool fatal, bool indexed) = 0; + virtual Id addNode(const StorageNodeData& data) = 0; + virtual void addSymbol(const StorageSymbol& data) = 0; + virtual void addFile(const StorageFile& data) = 0; + virtual Id addEdge(const StorageEdgeData& data) = 0; + virtual Id addLocalSymbol(const StorageLocalSymbolData& data) = 0; + virtual Id addSourceLocation(const StorageSourceLocationData& data) = 0; + virtual void addOccurrence(const StorageOccurrence& data) = 0; + virtual void addComponentAccess(const StorageComponentAccessData& data) = 0; + virtual void addCommentLocation(const StorageCommentLocationData& data) = 0; + virtual void addError(const StorageErrorData& data) = 0; virtual void forEachNode(std::function callback) const = 0; virtual void forEachFile(std::function callback) const = 0; @@ -33,9 +41,9 @@ public: virtual void forEachLocalSymbol(std::function callback) const = 0; virtual void forEachSourceLocation(std::function callback) const = 0; virtual void forEachOccurrence(std::function callback) const = 0; - virtual void forEachComponentAccess(std::function callback) const = 0; - virtual void forEachCommentLocation(std::function callback) const = 0; - virtual void forEachError(std::function callback) const = 0; + virtual void forEachComponentAccess(std::function callback) const = 0; + virtual void forEachCommentLocation(std::function callback) const = 0; + virtual void forEachError(std::function callback) const = 0; void inject(Storage* injected); diff --git a/src/lib/data/storage/StorageTypes.h b/src/lib/data/storage/StorageTypes.h deleted file mode 100644 index 881d3bfe..00000000 --- a/src/lib/data/storage/StorageTypes.h +++ /dev/null @@ -1,352 +0,0 @@ -#ifndef STORAGE_TYPES_H -#define STORAGE_TYPES_H - -#include - -#include "utility/file/FilePath.h" -#include "utility/types.h" - -#include "data/DefinitionKind.h" - -struct StorageEdge -{ - StorageEdge() - : id(0) - , type(0) - , sourceNodeId(0) - , targetNodeId(0) - {} - - StorageEdge(Id id, int type, Id sourceNodeId, Id targetNodeId) - : id(id) - , type(type) - , sourceNodeId(sourceNodeId) - , targetNodeId(targetNodeId) - {} - - Id id; - int type; - Id sourceNodeId; - Id targetNodeId; -}; - -struct StorageNode -{ - StorageNode() - : id(0) - , type(0) - , serializedName("") - {} - - StorageNode(Id id, int type, const std::string& serializedName) - : id(id) - , type(type) - , serializedName(serializedName) - {} - - Id id; - int type; - std::string serializedName; -}; - -struct StorageSymbol -{ - StorageSymbol() - : id(0) - , definitionKind(definitionKindToInt(DEFINITION_NONE)) - {} - - StorageSymbol(Id id, int definitionKind) - : id(id) - , definitionKind(definitionKind) - {} - - Id id; - int definitionKind; -}; - -struct StorageFile -{ - StorageFile() - : id(0) - , filePath("") - , modificationTime("") - , complete(true) - {} - - StorageFile(Id id, const std::string& filePath, const std::string& modificationTime, bool complete) - : id(id) - , filePath(filePath) - , modificationTime(modificationTime) - , complete(complete) - {} - - Id id; - std::string filePath; - std::string modificationTime; - bool complete; -}; - -struct StorageLocalSymbol -{ - StorageLocalSymbol() - : id(0) - , name("") - {} - - StorageLocalSymbol(Id id, const std::string& name) - : id(id) - , name(name) - {} - - Id id; - std::string name; -}; - -struct StorageSourceLocation -{ - StorageSourceLocation() - : id(0) - , fileNodeId(0) - , startLine(-1) - , startCol(-1) - , endLine(-1) - , endCol(-1) - , type(0) - {} - - StorageSourceLocation(Id id, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) - : id(id) - , fileNodeId(fileNodeId) - , startLine(startLine) - , startCol(startCol) - , endLine(endLine) - , endCol(endCol) - , type(type) - {} - - Id id; - Id fileNodeId; - uint startLine; - uint startCol; - uint endLine; - uint endCol; - int type; -}; - -struct StorageOccurrence -{ - StorageOccurrence() - : elementId(0) - , sourceLocationId(0) - {} - - StorageOccurrence(Id elementId, Id sourceLocationId) - : elementId(elementId) - , sourceLocationId(sourceLocationId) - {} - - Id elementId; - Id sourceLocationId; -}; - -struct StorageComponentAccess -{ - StorageComponentAccess() - : id(0) - , nodeId(0) - , type(0) - {} - - StorageComponentAccess(Id id, Id nodeId, int type) - : id(id) - , nodeId(nodeId) - , type(type) - {} - - Id id; - Id nodeId; - int type; -}; - -struct StorageCommentLocation -{ - StorageCommentLocation() - : id(0) - , fileNodeId(0) - , startLine(-1) - , startCol(-1) - , endLine(-1) - , endCol(-1) - {} - - StorageCommentLocation(Id id, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) - : id(id) - , fileNodeId(fileNodeId) - , startLine(startLine) - , startCol(startCol) - , endLine(endLine) - , endCol(endCol) - {} - - Id id; - Id fileNodeId; - uint startLine; - uint startCol; - uint endLine; - uint endCol; -}; - -struct StorageError -{ - StorageError() - : id(0) - , message("") - , lineNumber(-1) - , columnNumber(-1) - , fatal(0) - , indexed(0) - {} - - StorageError( - Id id, - const std::string& message, - const std::string& commandline, - const FilePath& filePath, - uint lineNumber, - uint columnNumber, - bool fatal, - bool indexed - ) - : id(id) - , message(message) - , commandline(commandline) - , filePath(filePath) - , lineNumber(lineNumber) - , columnNumber(columnNumber) - , fatal(fatal) - , indexed(indexed) - {} - - Id id; - std::string message; - std::string commandline; - - FilePath filePath; - uint lineNumber; - uint columnNumber; - - bool fatal; - bool indexed; -}; - - -struct StorageBookmarkCategory -{ - StorageBookmarkCategory() - : id(0) - , name("") - {} - - StorageBookmarkCategory( - Id id, - const std::string& name - ) - : id(id) - , name(name) - {} - - Id id; - std::string name; -}; - -struct StorageBookmark -{ - StorageBookmark() - : id(0) - , name("") - , comment("") - , timestamp("") - , categoryId(0) - {} - - StorageBookmark( - Id id, - const std::string& name, - const std::string& comment, - const std::string& timestamp, - const Id categoryId - ) - : id(id) - , name(name) - , comment(comment) - , timestamp(timestamp) - , categoryId(categoryId) - {} - - Id id; - std::string name; - std::string comment; - std::string timestamp; - Id categoryId; -}; - -struct StorageBookmarkedNode -{ - StorageBookmarkedNode() - : id(0) - , bookmarkId(0) - , serializedNodeName("") - {} - - StorageBookmarkedNode( - Id id, - Id bookmarkId, - const std::string& serializedNodeName - ) - : id(id) - , bookmarkId(bookmarkId) - , serializedNodeName(serializedNodeName) - {} - - Id id; - Id bookmarkId; - std::string serializedNodeName; -}; - -struct StorageBookmarkedEdge -{ - StorageBookmarkedEdge() - : id(0) - , bookmarkId(0) - , serializedSourceNodeName("") - , serializedTargetNodeName("") - , edgeType(0) - , sourceNodeActive(false) - {} - - StorageBookmarkedEdge( - Id id, - Id bookmarkId, - const std::string& serializedSourceNodeName, - const std::string& serializedTargetNodeName, - int edgeType, - bool sourceNodeActive - ) - : id(id) - , bookmarkId(bookmarkId) - , serializedSourceNodeName(serializedSourceNodeName) - , serializedTargetNodeName(serializedTargetNodeName) - , edgeType(edgeType) - , sourceNodeActive(sourceNodeActive) - {} - - Id id; - Id bookmarkId; - std::string serializedSourceNodeName; - std::string serializedTargetNodeName; - int edgeType; - bool sourceNodeActive; -}; - -#endif // STORAGE_TYPES_H diff --git a/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp b/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp index 899a9c46..b5adf77b 100644 --- a/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp +++ b/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp @@ -45,70 +45,67 @@ void SqliteBookmarkStorage::migrateIfNecessary() migrator.migrate(this, SqliteBookmarkStorage::s_storageVersion); } -Id SqliteBookmarkStorage::addBookmarkCategory(const std::string& name) +StorageBookmarkCategory SqliteBookmarkStorage::addBookmarkCategory(const StorageBookmarkCategoryData& data) { std::string statement = "INSERT INTO bookmark_category(id, name) " "VALUES (NULL, ?);"; CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str()); - stmt.bind(1, name.c_str()); + stmt.bind(1, data.name.c_str()); executeStatement(stmt); - const Id id = m_database.lastRowId(); - - return id; + return StorageBookmarkCategory(m_database.lastRowId(), data); } -Id SqliteBookmarkStorage::addBookmark(const std::string& name, const std::string& comment, const std::string& timestamp, const Id categoryId) +StorageBookmark SqliteBookmarkStorage::addBookmark(const StorageBookmarkData& data) { std::string statement = "INSERT INTO bookmark(id, name, comment, timestamp, category_id) " - "VALUES (NULL, ?, ?, ?, " + std::to_string(categoryId) + ");"; + "VALUES (NULL, ?, ?, ?, " + std::to_string(data.categoryId) + ");"; try { CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str()); - stmt.bind(1, name.c_str()); - stmt.bind(2, comment.c_str()); - stmt.bind(3, timestamp.c_str()); + stmt.bind(1, data.name.c_str()); + stmt.bind(2, data.comment.c_str()); + stmt.bind(3, data.timestamp.c_str()); executeStatement(stmt); - const Id id = m_database.lastRowId(); - return id; + return StorageBookmark(m_database.lastRowId(), data); } catch (CppSQLite3Exception e) { LOG_ERROR(std::to_string(e.errorCode()) + ": " + e.errorMessage()); } - return 0; + return StorageBookmark(); } -Id SqliteBookmarkStorage::addBookmarkedNode(const Id bookmarkId, const std::string& nodeName) +StorageBookmarkedNode SqliteBookmarkStorage::addBookmarkedNode(const StorageBookmarkedNodeData& data) { - executeStatement("INSERT INTO bookmarked_element(id, bookmark_id) VALUES(NULL, " + std::to_string(bookmarkId) + ");"); + executeStatement("INSERT INTO bookmarked_element(id, bookmark_id) VALUES(NULL, " + std::to_string(data.bookmarkId) + ");"); Id id = m_database.lastRowId(); std::string statement = "INSERT INTO bookmarked_node(id, serialized_node_name) " "VALUES (" + std::to_string(id) + ", ?);"; CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str()); - stmt.bind(1, nodeName.c_str()); + stmt.bind(1, data.serializedNodeName.c_str()); executeStatement(stmt); - return id; + return StorageBookmarkedNode(id, data); } -Id SqliteBookmarkStorage::addBookmarkedEdge(const Id bookmarkId, const std::string& sourceNodeName, const std::string& targetNodeName, const int edgeType, const bool sourceNodeActive) +StorageBookmarkedEdge SqliteBookmarkStorage::addBookmarkedEdge(const StorageBookmarkedEdgeData data) { - executeStatement("INSERT INTO bookmarked_element(id, bookmark_id) VALUES(NULL, " + std::to_string(bookmarkId) + ");"); + executeStatement("INSERT INTO bookmarked_element(id, bookmark_id) VALUES(NULL, " + std::to_string(data.bookmarkId) + ");"); Id id = m_database.lastRowId(); std::string statement = "INSERT INTO bookmarked_edge(id, serialized_source_node_name, serialized_target_node_name, edge_type, source_node_active) " - "VALUES (" + std::to_string(id) + ", ?, ?, " + std::to_string(edgeType) + ", " + std::to_string(sourceNodeActive) + ");"; + "VALUES (" + std::to_string(id) + ", ?, ?, " + std::to_string(data.edgeType) + ", " + std::to_string(data.sourceNodeActive) + ");"; CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str()); - stmt.bind(1, sourceNodeName.c_str()); - stmt.bind(2, targetNodeName.c_str()); + stmt.bind(1, data.serializedSourceNodeName.c_str()); + stmt.bind(2, data.serializedTargetNodeName.c_str()); executeStatement(stmt); - return id; + return StorageBookmarkedEdge(id, data); } std::vector SqliteBookmarkStorage::getAllBookmarks() const diff --git a/src/lib/data/storage/sqlite/SqliteBookmarkStorage.h b/src/lib/data/storage/sqlite/SqliteBookmarkStorage.h index e9f28239..da896fb5 100644 --- a/src/lib/data/storage/sqlite/SqliteBookmarkStorage.h +++ b/src/lib/data/storage/sqlite/SqliteBookmarkStorage.h @@ -2,7 +2,10 @@ #define SQLITE_BOOKMARK_STORAGE_H #include "data/storage/sqlite/SqliteStorage.h" -#include "data/storage/StorageTypes.h" +#include "data/storage/type/StorageBookmark.h" +#include "data/storage/type/StorageBookmarkCategory.h" +#include "data/storage/type/StorageBookmarkedNode.h" +#include "data/storage/type/StorageBookmarkedEdge.h" #include "utility/types.h" class SqliteBookmarkStorage @@ -16,10 +19,10 @@ public: void migrateIfNecessary(); - Id addBookmarkCategory(const std::string& name); - Id addBookmark(const std::string& name, const std::string& comment, const std::string& timestamp, const Id categoryId); - Id addBookmarkedNode(const Id bookmarkId, const std::string& nodeName); - Id addBookmarkedEdge(const Id bookmarkId, const std::string& sourceNodeName, const std::string& targetNodeName, const int edgeType, const bool sourceNodeActive); + StorageBookmarkCategory addBookmarkCategory(const StorageBookmarkCategoryData& data); + StorageBookmark addBookmark(const StorageBookmarkData& data); + StorageBookmarkedNode addBookmarkedNode(const StorageBookmarkedNodeData& data); + StorageBookmarkedEdge addBookmarkedEdge(const StorageBookmarkedEdgeData data); void removeBookmarkCategory(Id id); void removeBookmark(const Id id); diff --git a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp index 68095384..da907554 100644 --- a/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp +++ b/src/lib/data/storage/sqlite/SqliteIndexStorage.cpp @@ -31,26 +31,7 @@ void SqliteIndexStorage::setProjectSettingsText(std::string text) insertOrUpdateMetaValue("project_settings", text); } -Id SqliteIndexStorage::addEdge(int type, Id sourceNodeId, Id targetNodeId) -{ - Id id = 0; - { - executeStatement(m_insertElementStmt); - id = m_database.lastRowId(); - m_insertElementStmt.reset(); - } - { - m_insertEdgeStmt.bind(1, int(id)); - m_insertEdgeStmt.bind(2, type); - m_insertEdgeStmt.bind(3, int(sourceNodeId)); - m_insertEdgeStmt.bind(4, int(targetNodeId)); - executeStatement(m_insertEdgeStmt); - m_insertEdgeStmt.reset(); - } - return id; -} - -Id SqliteIndexStorage::addNode(const int type, const std::string& serializedName) +StorageNode SqliteIndexStorage::addNode(const StorageNodeData& data) { Id id = 0; { @@ -60,38 +41,38 @@ Id SqliteIndexStorage::addNode(const int type, const std::string& serializedName } { m_inserNodeStmt.bind(1, int(id)); - m_inserNodeStmt.bind(2, type); - m_inserNodeStmt.bind(3, serializedName.c_str()); + m_inserNodeStmt.bind(2, data.type); + m_inserNodeStmt.bind(3, data.serializedName.c_str()); executeStatement(m_inserNodeStmt); m_inserNodeStmt.reset(); } - return id; + return StorageNode(id, data); } -void SqliteIndexStorage::addSymbol(const int id, const int definitionKind) +void SqliteIndexStorage::addSymbol(const StorageSymbol& data) { - m_insertSymbolStmt.bind(1, id); - m_insertSymbolStmt.bind(2, definitionKind); + m_insertSymbolStmt.bind(1, int(data.id)); + m_insertSymbolStmt.bind(2, data.definitionKind); executeStatement(m_insertSymbolStmt); m_insertSymbolStmt.reset(); } -void SqliteIndexStorage::addFile(const int id, const std::string& filePath, const std::string& modificationTime, bool complete) +void SqliteIndexStorage::addFile(const StorageFile& data) { - if (getFileByPath(filePath).id != 0) + if (getFileByPath(data.filePath).id != 0) { return; } - std::shared_ptr content = TextAccess::createFromFile(FilePath(filePath)); + std::shared_ptr content = TextAccess::createFromFile(FilePath(data.filePath)); const int lineCount = content->getLineCount(); bool success = false; { - m_insertFileStmt.bind(1, id); - m_insertFileStmt.bind(2, filePath.c_str()); - m_insertFileStmt.bind(3, modificationTime.c_str()); - m_insertFileStmt.bind(4, complete); + m_insertFileStmt.bind(1, int(data.id)); + m_insertFileStmt.bind(2, data.filePath.c_str()); + m_insertFileStmt.bind(3, data.modificationTime.c_str()); + m_insertFileStmt.bind(4, data.complete); m_insertFileStmt.bind(5, lineCount); success = executeStatement(m_insertFileStmt); m_insertFileStmt.reset(); @@ -99,14 +80,33 @@ void SqliteIndexStorage::addFile(const int id, const std::string& filePath, cons if (success) { - m_insertFileContentStmt.bind(1, id); + m_insertFileContentStmt.bind(1, int(data.id)); m_insertFileContentStmt.bind(2, content->getText().c_str()); executeStatement(m_insertFileContentStmt); m_insertFileContentStmt.reset(); } } -Id SqliteIndexStorage::addLocalSymbol(const std::string& name) +StorageEdge SqliteIndexStorage::addEdge(const StorageEdgeData& data) +{ + Id id = 0; + { + executeStatement(m_insertElementStmt); + id = m_database.lastRowId(); + m_insertElementStmt.reset(); + } + { + m_insertEdgeStmt.bind(1, int(id)); + m_insertEdgeStmt.bind(2, data.type); + m_insertEdgeStmt.bind(3, int(data.sourceNodeId)); + m_insertEdgeStmt.bind(4, int(data.targetNodeId)); + executeStatement(m_insertEdgeStmt); + m_insertEdgeStmt.reset(); + } + return StorageEdge(id, data); +} + +StorageLocalSymbol SqliteIndexStorage::addLocalSymbol(const StorageLocalSymbolData& data) { Id id = 0; { @@ -116,24 +116,23 @@ Id SqliteIndexStorage::addLocalSymbol(const std::string& name) } { m_inserLocalSymbolStmt.bind(1, int(id)); - m_inserLocalSymbolStmt.bind(2, name.c_str()); + m_inserLocalSymbolStmt.bind(2, data.name.c_str()); executeStatement(m_inserLocalSymbolStmt); m_inserLocalSymbolStmt.reset(); } - return id; + return StorageLocalSymbol(id, data); } -Id SqliteIndexStorage::addSourceLocation( - Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) +StorageSourceLocation SqliteIndexStorage::addSourceLocation(const StorageSourceLocationData& data) { Id id = 0; { - m_checkSourceLocationExistsStmt.bind(1, int(fileNodeId)); - m_checkSourceLocationExistsStmt.bind(2, int(startLine)); - m_checkSourceLocationExistsStmt.bind(3, int(startCol)); - m_checkSourceLocationExistsStmt.bind(4, int(endLine)); - m_checkSourceLocationExistsStmt.bind(5, int(endCol)); - m_checkSourceLocationExistsStmt.bind(6, type); + m_checkSourceLocationExistsStmt.bind(1, int(data.fileNodeId)); + m_checkSourceLocationExistsStmt.bind(2, int(data.startLine)); + m_checkSourceLocationExistsStmt.bind(3, int(data.startCol)); + m_checkSourceLocationExistsStmt.bind(4, int(data.endLine)); + m_checkSourceLocationExistsStmt.bind(5, int(data.endCol)); + m_checkSourceLocationExistsStmt.bind(6, data.type); CppSQLite3Query checkQuery = executeQuery(m_checkSourceLocationExistsStmt); if (!checkQuery.eof() && checkQuery.numFields() > 0) @@ -146,12 +145,12 @@ Id SqliteIndexStorage::addSourceLocation( if (id == 0) { - m_insertSourceLocationStmt.bind(1, int(fileNodeId)); - m_insertSourceLocationStmt.bind(2, int(startLine)); - m_insertSourceLocationStmt.bind(3, int(startCol)); - m_insertSourceLocationStmt.bind(4, int(endLine)); - m_insertSourceLocationStmt.bind(5, int(endCol)); - m_insertSourceLocationStmt.bind(6, type); + m_insertSourceLocationStmt.bind(1, int(data.fileNodeId)); + m_insertSourceLocationStmt.bind(2, int(data.startLine)); + m_insertSourceLocationStmt.bind(3, int(data.startCol)); + m_insertSourceLocationStmt.bind(4, int(data.endLine)); + m_insertSourceLocationStmt.bind(5, int(data.endCol)); + m_insertSourceLocationStmt.bind(6, data.type); const bool success = executeStatement(m_insertSourceLocationStmt); if (success) @@ -162,14 +161,14 @@ Id SqliteIndexStorage::addSourceLocation( m_insertSourceLocationStmt.reset(); } - return id; + return StorageSourceLocation(id, data); } -bool SqliteIndexStorage::addOccurrence(Id elementId, Id sourceLocationId) +bool SqliteIndexStorage::addOccurrence(const StorageOccurrence& data) { { - m_checkOccurrenceExistsStmt.bind(1, int(elementId)); - m_checkOccurrenceExistsStmt.bind(2, int(sourceLocationId)); + m_checkOccurrenceExistsStmt.bind(1, int(data.elementId)); + m_checkOccurrenceExistsStmt.bind(2, int(data.sourceLocationId)); const int checkResult = executeStatementScalar(m_checkOccurrenceExistsStmt, 0); m_checkOccurrenceExistsStmt.reset(); @@ -179,22 +178,22 @@ bool SqliteIndexStorage::addOccurrence(Id elementId, Id sourceLocationId) } } { - m_insertOccurrenceStmt.bind(1, int(elementId)); - m_insertOccurrenceStmt.bind(2, int(sourceLocationId)); + m_insertOccurrenceStmt.bind(1, int(data.elementId)); + m_insertOccurrenceStmt.bind(2, int(data.sourceLocationId)); executeStatement(m_insertOccurrenceStmt); m_insertOccurrenceStmt.reset(); } return true; } -Id SqliteIndexStorage::addComponentAccess(Id nodeId, int type) +StorageComponentAccess SqliteIndexStorage::addComponentAccess(const StorageComponentAccessData& data) { - Id id = getComponentAccessByNodeId(nodeId).id; + Id id = getComponentAccessByNodeId(data.nodeId).id; if (id == 0) { - m_insertComponentAccessStmt.bind(1, int(nodeId)); - m_insertComponentAccessStmt.bind(2, type); + m_insertComponentAccessStmt.bind(1, int(data.nodeId)); + m_insertComponentAccessStmt.bind(2, data.type); const bool success = executeStatement(m_insertComponentAccessStmt); if (success) @@ -205,18 +204,18 @@ Id SqliteIndexStorage::addComponentAccess(Id nodeId, int type) m_insertComponentAccessStmt.reset(); } - return id; + return StorageComponentAccess(id, data); } -Id SqliteIndexStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) +StorageCommentLocation SqliteIndexStorage::addCommentLocation(const StorageCommentLocationData& data) { Id id = 0; { - m_checkCommentLocationExistsStmt.bind(1, int(fileNodeId)); - m_checkCommentLocationExistsStmt.bind(2, int(startLine)); - m_checkCommentLocationExistsStmt.bind(3, int(startCol)); - m_checkCommentLocationExistsStmt.bind(4, int(endLine)); - m_checkCommentLocationExistsStmt.bind(5, int(endCol)); + m_checkCommentLocationExistsStmt.bind(1, int(data.fileNodeId)); + m_checkCommentLocationExistsStmt.bind(2, int(data.startLine)); + m_checkCommentLocationExistsStmt.bind(3, int(data.startCol)); + m_checkCommentLocationExistsStmt.bind(4, int(data.endLine)); + m_checkCommentLocationExistsStmt.bind(5, int(data.endCol)); CppSQLite3Query checkQuery = executeQuery(m_checkCommentLocationExistsStmt); if (!checkQuery.eof() && checkQuery.numFields() > 0) @@ -229,11 +228,11 @@ Id SqliteIndexStorage::addCommentLocation(Id fileNodeId, uint startLine, uint st if (id == 0) { - m_insertCommentLocationStmt.bind(1, int(fileNodeId)); - m_insertCommentLocationStmt.bind(2, int(startLine)); - m_insertCommentLocationStmt.bind(3, int(startCol)); - m_insertCommentLocationStmt.bind(4, int(endLine)); - m_insertCommentLocationStmt.bind(5, int(endCol)); + 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) @@ -244,21 +243,20 @@ Id SqliteIndexStorage::addCommentLocation(Id fileNodeId, uint startLine, uint st m_insertCommentLocationStmt.reset(); } - return id; + return StorageCommentLocation(id, data); } -Id SqliteIndexStorage::addError(const std::string& message, const std::string& commandline, const FilePath& filePath, - uint lineNumber, uint columnNumber, bool fatal, bool indexed) +StorageError SqliteIndexStorage::addError(const StorageErrorData& data) { - const std::string sanitizedMessage = utility::replace(message, "'", "''"); + const std::string sanitizedMessage = utility::replace(data.message, "'", "''"); Id id = 0; { m_checkErrorExistsStmt.bind(1, sanitizedMessage.c_str()); - m_checkErrorExistsStmt.bind(2, int(fatal)); - m_checkErrorExistsStmt.bind(3, filePath.str().c_str()); - m_checkErrorExistsStmt.bind(4, int(lineNumber)); - m_checkErrorExistsStmt.bind(5, int(columnNumber)); + m_checkErrorExistsStmt.bind(2, int(data.fatal)); + m_checkErrorExistsStmt.bind(3, data.filePath.str().c_str()); + m_checkErrorExistsStmt.bind(4, int(data.lineNumber)); + m_checkErrorExistsStmt.bind(5, int(data.columnNumber)); CppSQLite3Query checkQuery = executeQuery(m_checkErrorExistsStmt); if (!checkQuery.eof() && checkQuery.numFields() > 0) @@ -271,15 +269,15 @@ Id SqliteIndexStorage::addError(const std::string& message, const std::string& c if (id == 0) { - const std::string sanitizedCommandline = utility::replace(commandline, "'", "''"); + const std::string sanitizedCommandline = utility::replace(data.commandline, "'", "''"); m_insertErrorStmt.bind(1, sanitizedMessage.c_str()); m_insertErrorStmt.bind(2, sanitizedCommandline.c_str()); - m_insertErrorStmt.bind(3, fatal); - m_insertErrorStmt.bind(4, indexed); - m_insertErrorStmt.bind(5, filePath.str().c_str()); - m_insertErrorStmt.bind(6, int(lineNumber)); - m_insertErrorStmt.bind(7, int(columnNumber)); + m_insertErrorStmt.bind(3, data.fatal); + m_insertErrorStmt.bind(4, data.indexed); + m_insertErrorStmt.bind(5, data.filePath.str().c_str()); + m_insertErrorStmt.bind(6, int(data.lineNumber)); + m_insertErrorStmt.bind(7, int(data.columnNumber)); const bool success = executeStatement(m_insertErrorStmt); if (success) @@ -290,7 +288,7 @@ Id SqliteIndexStorage::addError(const std::string& message, const std::string& c m_insertErrorStmt.reset(); } - return id; + return StorageError(id, data); } void SqliteIndexStorage::removeElement(Id id) diff --git a/src/lib/data/storage/sqlite/SqliteIndexStorage.h b/src/lib/data/storage/sqlite/SqliteIndexStorage.h index f0e04a53..a0fdefec 100644 --- a/src/lib/data/storage/sqlite/SqliteIndexStorage.h +++ b/src/lib/data/storage/sqlite/SqliteIndexStorage.h @@ -8,7 +8,16 @@ #include "data/location/SourceLocationFile.h" #include "data/storage/sqlite/SqliteDatabaseIndex.h" #include "data/storage/sqlite/SqliteStorage.h" -#include "data/storage/StorageTypes.h" +#include "data/storage/type/StorageCommentLocation.h" +#include "data/storage/type/StorageComponentAccess.h" +#include "data/storage/type/StorageEdge.h" +#include "data/storage/type/StorageError.h" +#include "data/storage/type/StorageFile.h" +#include "data/storage/type/StorageLocalSymbol.h" +#include "data/storage/type/StorageNode.h" +#include "data/storage/type/StorageOccurrence.h" +#include "data/storage/type/StorageSourceLocation.h" +#include "data/storage/type/StorageSymbol.h" #include "utility/types.h" #include "utility/utility.h" #include "utility/utilityString.h" @@ -29,18 +38,16 @@ public: std::string getProjectSettingsText() const; void setProjectSettingsText(std::string text); - Id addEdge(int type, Id sourceNodeId, Id targetNodeId); - - Id addNode(const int type, const std::string& serializedName); - void addSymbol(const int id, int definitionKind); - void addFile(const int id, const std::string& filePath, const std::string& modificationTime, bool complete); - Id addLocalSymbol(const std::string& name); - Id addSourceLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type); - bool addOccurrence(Id elementId, Id sourceLocationId); - Id addComponentAccess(Id nodeId, int type); - Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol); - Id addError(const std::string& message, const std::string& commandline, const FilePath& filePath, - uint lineNumber, uint columnNumber, bool fatal, bool indexed); + StorageNode addNode(const StorageNodeData& data); + void addSymbol(const StorageSymbol& data); + void addFile(const StorageFile& data); + StorageEdge addEdge(const StorageEdgeData& data); + StorageLocalSymbol addLocalSymbol(const StorageLocalSymbolData& data); + StorageSourceLocation addSourceLocation(const StorageSourceLocationData& data); + bool addOccurrence(const StorageOccurrence& data); + StorageComponentAccess addComponentAccess(const StorageComponentAccessData& data); + StorageCommentLocation addCommentLocation(const StorageCommentLocationData& data); + StorageError addError(const StorageErrorData& data); void removeElement(Id id); void removeElements(const std::vector& ids); diff --git a/src/lib/data/storage/type/StorageBookmark.h b/src/lib/data/storage/type/StorageBookmark.h new file mode 100644 index 00000000..ef7f2d3f --- /dev/null +++ b/src/lib/data/storage/type/StorageBookmark.h @@ -0,0 +1,61 @@ +#ifndef STORAGE_BOOKMARK_H +#define STORAGE_BOOKMARK_H + +#include + +#include "utility/types.h" + +struct StorageBookmarkData +{ + StorageBookmarkData() + : name("") + , comment("") + , timestamp("") + , categoryId(0) + {} + + StorageBookmarkData( + const std::string& name, + const std::string& comment, + const std::string& timestamp, + const Id categoryId + ) + : name(name) + , comment(comment) + , timestamp(timestamp) + , categoryId(categoryId) + {} + + std::string name; + std::string comment; + std::string timestamp; + Id categoryId; +}; + +struct StorageBookmark: public StorageBookmarkData +{ + StorageBookmark() + : StorageBookmarkData() + , id(0) + {} + + StorageBookmark(Id id, const StorageBookmarkData& data) + : StorageBookmarkData(data) + , id(id) + {} + + StorageBookmark( + Id id, + const std::string& name, + const std::string& comment, + const std::string& timestamp, + const Id categoryId + ) + : StorageBookmarkData(name, comment, timestamp, categoryId) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_BOOKMARK_H diff --git a/src/lib/data/storage/type/StorageBookmarkCategory.h b/src/lib/data/storage/type/StorageBookmarkCategory.h new file mode 100644 index 00000000..b83e1c09 --- /dev/null +++ b/src/lib/data/storage/type/StorageBookmarkCategory.h @@ -0,0 +1,41 @@ +#ifndef STORAGE_BOOKMARK_CATEGORY_H +#define STORAGE_BOOKMARK_CATEGORY_H + +#include + +#include "utility/types.h" + +struct StorageBookmarkCategoryData +{ + StorageBookmarkCategoryData() + : name("") + {} + + StorageBookmarkCategoryData(const std::string& name) + : name(name) + {} + + std::string name; +}; + +struct StorageBookmarkCategory: public StorageBookmarkCategoryData +{ + StorageBookmarkCategory() + : StorageBookmarkCategoryData() + , id(0) + {} + + StorageBookmarkCategory(Id id, const StorageBookmarkCategoryData& data) + : StorageBookmarkCategoryData(data) + , id(id) + {} + + StorageBookmarkCategory(Id id, const std::string& name) + : StorageBookmarkCategoryData(name) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_BOOKMARK_CATEGORY_H diff --git a/src/lib/data/storage/type/StorageBookmarkedEdge.h b/src/lib/data/storage/type/StorageBookmarkedEdge.h new file mode 100644 index 00000000..904c748b --- /dev/null +++ b/src/lib/data/storage/type/StorageBookmarkedEdge.h @@ -0,0 +1,72 @@ +#ifndef STORAGE_BOOKMARKED_EDGE_H +#define STORAGE_BOOKMARKED_EDGE_H + +#include + +#include "utility/types.h" + +struct StorageBookmarkedEdgeData +{ + StorageBookmarkedEdgeData() + : bookmarkId(0) + , serializedSourceNodeName("") + , serializedTargetNodeName("") + , edgeType(0) + , sourceNodeActive(false) + {} + + StorageBookmarkedEdgeData( + Id bookmarkId, + const std::string& serializedSourceNodeName, + const std::string& serializedTargetNodeName, + int edgeType, + bool sourceNodeActive + ) + : bookmarkId(bookmarkId) + , serializedSourceNodeName(serializedSourceNodeName) + , serializedTargetNodeName(serializedTargetNodeName) + , edgeType(edgeType) + , sourceNodeActive(sourceNodeActive) + {} + + Id bookmarkId; + std::string serializedSourceNodeName; + std::string serializedTargetNodeName; + int edgeType; + bool sourceNodeActive; +}; + +struct StorageBookmarkedEdge: public StorageBookmarkedEdgeData +{ + StorageBookmarkedEdge() + : StorageBookmarkedEdgeData() + , id(0) + {} + + StorageBookmarkedEdge(Id id, const StorageBookmarkedEdgeData& data) + : StorageBookmarkedEdgeData(data) + , id(id) + {} + + StorageBookmarkedEdge( + Id id, + Id bookmarkId, + const std::string& serializedSourceNodeName, + const std::string& serializedTargetNodeName, + int edgeType, + bool sourceNodeActive + ) + : StorageBookmarkedEdgeData( + bookmarkId, + serializedSourceNodeName, + serializedTargetNodeName, + edgeType, + sourceNodeActive + ) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_BOOKMARKED_EDGE_H diff --git a/src/lib/data/storage/type/StorageBookmarkedNode.h b/src/lib/data/storage/type/StorageBookmarkedNode.h new file mode 100644 index 00000000..8a016ea6 --- /dev/null +++ b/src/lib/data/storage/type/StorageBookmarkedNode.h @@ -0,0 +1,48 @@ +#ifndef STORAGE_BOOKMARKED_NODE_H +#define STORAGE_BOOKMARKED_NODE_H + +#include + +#include "utility/types.h" + +struct StorageBookmarkedNodeData +{ + StorageBookmarkedNodeData() + : bookmarkId(0) + , serializedNodeName("") + {} + + StorageBookmarkedNodeData(Id bookmarkId, const std::string& serializedNodeName) + : bookmarkId(bookmarkId) + , serializedNodeName(serializedNodeName) + {} + + Id bookmarkId; + std::string serializedNodeName; +}; + +struct StorageBookmarkedNode: public StorageBookmarkedNodeData +{ + StorageBookmarkedNode() + : StorageBookmarkedNodeData() + , id(0) + {} + + StorageBookmarkedNode(Id id, const StorageBookmarkedNodeData& data) + : StorageBookmarkedNodeData(data) + , id(id) + {} + + StorageBookmarkedNode( + Id id, + Id bookmarkId, + const std::string& serializedNodeName + ) + : StorageBookmarkedNodeData(bookmarkId, serializedNodeName) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_BOOKMARKED_NODE_H diff --git a/src/lib/data/storage/type/StorageCommentLocation.h b/src/lib/data/storage/type/StorageCommentLocation.h new file mode 100644 index 00000000..7bf6a07a --- /dev/null +++ b/src/lib/data/storage/type/StorageCommentLocation.h @@ -0,0 +1,51 @@ +#ifndef STORAGE_COMMENT_LOCATION_H +#define STORAGE_COMMENT_LOCATION_H + +#include "utility/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) + {} + + 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/data/storage/type/StorageComponentAccess.h b/src/lib/data/storage/type/StorageComponentAccess.h new file mode 100644 index 00000000..bda119b5 --- /dev/null +++ b/src/lib/data/storage/type/StorageComponentAccess.h @@ -0,0 +1,42 @@ +#ifndef STORAGE_COMPONENT_ACCESS_H +#define STORAGE_COMPONENT_ACCESS_H + +#include "utility/types.h" + +struct StorageComponentAccessData +{ + StorageComponentAccessData() + : nodeId(0) + , type(0) + {} + + StorageComponentAccessData(Id nodeId, int type) + : nodeId(nodeId) + , type(type) + {} + + Id nodeId; + int type; +}; + +struct StorageComponentAccess: public StorageComponentAccessData +{ + StorageComponentAccess() + : StorageComponentAccessData() + , id(0) + {} + + StorageComponentAccess(Id id, const StorageComponentAccessData data) + : StorageComponentAccessData(data) + , id(nodeId) + {} + + StorageComponentAccess(Id id, Id nodeId, int type) + : StorageComponentAccessData(nodeId, type) + , id(nodeId) + {} + + Id id; +}; + +#endif // STORAGE_COMPONENT_ACCESS_H diff --git a/src/lib/data/storage/type/StorageEdge.h b/src/lib/data/storage/type/StorageEdge.h new file mode 100644 index 00000000..bf38505f --- /dev/null +++ b/src/lib/data/storage/type/StorageEdge.h @@ -0,0 +1,45 @@ +#ifndef STORAGE_EDGE_H +#define STORAGE_EDGE_H + +#include "utility/types.h" + +struct StorageEdgeData +{ + StorageEdgeData() + : type(0) + , sourceNodeId(0) + , targetNodeId(0) + {} + + StorageEdgeData(int type, Id sourceNodeId, Id targetNodeId) + : type(type) + , sourceNodeId(sourceNodeId) + , targetNodeId(targetNodeId) + {} + + int type; + Id sourceNodeId; + Id targetNodeId; +}; + +struct StorageEdge: public StorageEdgeData +{ + StorageEdge() + : StorageEdgeData() + , id(0) + {} + + StorageEdge(Id id, const StorageEdgeData& data) + : StorageEdgeData(data) + , id(id) + {} + + StorageEdge(Id id, int type, Id sourceNodeId, Id targetNodeId) + : StorageEdgeData(type, sourceNodeId, targetNodeId) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_EDGE_H diff --git a/src/lib/data/storage/type/StorageError.h b/src/lib/data/storage/type/StorageError.h new file mode 100644 index 00000000..044311e5 --- /dev/null +++ b/src/lib/data/storage/type/StorageError.h @@ -0,0 +1,85 @@ +#ifndef STORAGE_ERROR_H +#define STORAGE_ERROR_H + +#include + +#include "utility/file/FilePath.h" +#include "utility/types.h" + +struct StorageErrorData +{ + StorageErrorData() + : message("") + , lineNumber(-1) + , columnNumber(-1) + , fatal(0) + , indexed(0) + {} + + StorageErrorData( + const std::string& message, + const std::string& commandline, + const FilePath& filePath, + uint lineNumber, + uint columnNumber, + bool fatal, + bool indexed + ) + : message(message) + , commandline(commandline) + , filePath(filePath) + , lineNumber(lineNumber) + , columnNumber(columnNumber) + , fatal(fatal) + , indexed(indexed) + {} + + std::string message; + std::string commandline; + + FilePath filePath; + uint lineNumber; + uint columnNumber; + + bool fatal; + bool indexed; +}; + +struct StorageError: public StorageErrorData +{ + StorageError() + : StorageErrorData() + , id(0) + {} + + StorageError(Id id, const StorageErrorData& data) + : StorageErrorData(data) + , id(id) + {} + + StorageError( + Id id, + const std::string& message, + const std::string& commandline, + const FilePath& filePath, + uint lineNumber, + uint columnNumber, + bool fatal, + bool indexed + ) + : StorageErrorData( + message, + commandline, + filePath, + lineNumber, + columnNumber, + fatal, + indexed + ) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_ERROR_H diff --git a/src/lib/data/storage/type/StorageFile.h b/src/lib/data/storage/type/StorageFile.h new file mode 100644 index 00000000..b77dce51 --- /dev/null +++ b/src/lib/data/storage/type/StorageFile.h @@ -0,0 +1,30 @@ +#ifndef STORAGE_FILE_H +#define STORAGE_FILE_H + +#include + +#include "utility/types.h" + +struct StorageFile +{ + StorageFile() + : id(0) + , filePath("") + , modificationTime("") + , complete(true) + {} + + StorageFile(Id id, const std::string& filePath, const std::string& modificationTime, bool complete) + : id(id) + , filePath(filePath) + , modificationTime(modificationTime) + , complete(complete) + {} + + Id id; + std::string filePath; + std::string modificationTime; + bool complete; +}; + +#endif // STORAGE_FILE_H diff --git a/src/lib/data/storage/type/StorageLocalSymbol.h b/src/lib/data/storage/type/StorageLocalSymbol.h new file mode 100644 index 00000000..d6cf33ea --- /dev/null +++ b/src/lib/data/storage/type/StorageLocalSymbol.h @@ -0,0 +1,41 @@ +#ifndef STORAGE_LOCAL_SYMBOL_H +#define STORAGE_LOCAL_SYMBOL_H + +#include + +#include "utility/types.h" + +struct StorageLocalSymbolData +{ + StorageLocalSymbolData() + : name("") + {} + + StorageLocalSymbolData(const std::string& name) + : name(name) + {} + + std::string name; +}; + +struct StorageLocalSymbol: public StorageLocalSymbolData +{ + StorageLocalSymbol() + : StorageLocalSymbolData() + , id(0) + {} + + StorageLocalSymbol(Id id, const StorageLocalSymbolData& data) + : StorageLocalSymbolData(data) + , id(id) + {} + + StorageLocalSymbol(Id id, const std::string& name) + : StorageLocalSymbolData(name) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_LOCAL_SYMBOL_H diff --git a/src/lib/data/storage/type/StorageNode.h b/src/lib/data/storage/type/StorageNode.h new file mode 100644 index 00000000..72a809d8 --- /dev/null +++ b/src/lib/data/storage/type/StorageNode.h @@ -0,0 +1,44 @@ +#ifndef STORAGE_NODE_H +#define STORAGE_NODE_H + +#include + +#include "utility/types.h" + +struct StorageNodeData +{ + StorageNodeData() + : type(0) + , serializedName("") + {} + + StorageNodeData(int type, const std::string& serializedName) + : type(type) + , serializedName(serializedName) + {} + + int type; + std::string serializedName; +}; + +struct StorageNode: public StorageNodeData +{ + StorageNode() + : StorageNodeData() + , id(0) + {} + + StorageNode(Id id, int type, const std::string& serializedName) + : StorageNodeData(type, serializedName) + , id(id) + {} + + StorageNode(Id id, const StorageNodeData& data) + : StorageNodeData(data) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_NODE_H diff --git a/src/lib/data/storage/type/StorageOccurrence.h b/src/lib/data/storage/type/StorageOccurrence.h new file mode 100644 index 00000000..00d2946d --- /dev/null +++ b/src/lib/data/storage/type/StorageOccurrence.h @@ -0,0 +1,22 @@ +#ifndef STORAGE_OCCURRENCE_H +#define STORAGE_OCCURRENCE_H + +#include "utility/types.h" + +struct StorageOccurrence +{ + StorageOccurrence() + : elementId(0) + , sourceLocationId(0) + {} + + StorageOccurrence(Id elementId, Id sourceLocationId) + : elementId(elementId) + , sourceLocationId(sourceLocationId) + {} + + Id elementId; + Id sourceLocationId; +}; + +#endif // STORAGE_OCCURRENCE_H diff --git a/src/lib/data/storage/type/StorageSourceLocation.h b/src/lib/data/storage/type/StorageSourceLocation.h new file mode 100644 index 00000000..2be0ce95 --- /dev/null +++ b/src/lib/data/storage/type/StorageSourceLocation.h @@ -0,0 +1,54 @@ +#ifndef STORAGE_SOURCE_LOCATION_H +#define STORAGE_SOURCE_LOCATION_H + +#include "utility/types.h" + +struct StorageSourceLocationData +{ + StorageSourceLocationData() + : fileNodeId(0) + , startLine(-1) + , startCol(-1) + , endLine(-1) + , endCol(-1) + , type(0) + {} + + StorageSourceLocationData(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) + : fileNodeId(fileNodeId) + , startLine(startLine) + , startCol(startCol) + , endLine(endLine) + , endCol(endCol) + , type(type) + {} + + Id fileNodeId; + uint startLine; + uint startCol; + uint endLine; + uint endCol; + int type; +}; + +struct StorageSourceLocation: public StorageSourceLocationData +{ + StorageSourceLocation() + : StorageSourceLocationData() + , id(0) + {} + + StorageSourceLocation(Id id, const StorageSourceLocationData& data) + : StorageSourceLocationData(data) + , id(id) + {} + + StorageSourceLocation(Id id, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) + : StorageSourceLocationData(fileNodeId, startLine, startCol, endLine, endCol, type) + , id(id) + {} + + Id id; +}; + +#endif // STORAGE_SOURCE_LOCATION_H diff --git a/src/lib/data/storage/type/StorageSymbol.h b/src/lib/data/storage/type/StorageSymbol.h new file mode 100644 index 00000000..88fdd90e --- /dev/null +++ b/src/lib/data/storage/type/StorageSymbol.h @@ -0,0 +1,23 @@ +#ifndef STORAGE_SYMBOL_H +#define STORAGE_SYMBOL_H + +#include "data/DefinitionKind.h" +#include "utility/types.h" + +struct StorageSymbol +{ + StorageSymbol() + : id(0) + , definitionKind(definitionKindToInt(DEFINITION_NONE)) + {} + + StorageSymbol(Id id, int definitionKind) + : id(id) + , definitionKind(definitionKind) + {} + + Id id; + int definitionKind; +}; + +#endif // STORAGE_SYMBOL_H diff --git a/src/test/SqliteBookmarkStorageTestSuite.h b/src/test/SqliteBookmarkStorageTestSuite.h index b644e183..15c72fbc 100644 --- a/src/test/SqliteBookmarkStorageTestSuite.h +++ b/src/test/SqliteBookmarkStorageTestSuite.h @@ -19,8 +19,8 @@ public: for (size_t i = 0; i < bookmarkCount; i++) { - const Id categoryId = storage.addBookmarkCategory("test category"); - storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId); + const Id categoryId = storage.addBookmarkCategory(StorageBookmarkCategoryData("test category")).id; + storage.addBookmark(StorageBookmarkData("test bookmark", "test comment", TimeStamp::now().toString(), categoryId)); } result = storage.getAllBookmarks().size(); @@ -41,12 +41,12 @@ public: SqliteBookmarkStorage storage(databasePath); storage.setup(); - const Id categoryId = storage.addBookmarkCategory("test category"); - const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId); + const Id categoryId = storage.addBookmarkCategory(StorageBookmarkCategoryData("test category")).id; + const Id bookmarkId = storage.addBookmark(StorageBookmarkData("test bookmark", "test comment", TimeStamp::now().toString(), categoryId)).id; for (size_t i = 0; i < bookmarkCount; i++) { - storage.addBookmarkedNode(bookmarkId, "test name"); + storage.addBookmarkedNode(StorageBookmarkedNodeData(bookmarkId, "test name")); } result = storage.getAllBookmarkedNodes().size(); @@ -66,9 +66,9 @@ public: SqliteBookmarkStorage storage(databasePath); storage.setup(); - const Id categoryId = storage.addBookmarkCategory("test category"); - const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId); - storage.addBookmarkedNode(bookmarkId, "test name"); + const Id categoryId = storage.addBookmarkCategory(StorageBookmarkCategoryData("test category")).id; + const Id bookmarkId = storage.addBookmark(StorageBookmarkData("test bookmark", "test comment", TimeStamp::now().toString(), categoryId)).id; + storage.addBookmarkedNode(StorageBookmarkedNodeData(bookmarkId, "test name")); storage.removeBookmark(bookmarkId); @@ -93,9 +93,9 @@ public: SqliteBookmarkStorage storage(databasePath); storage.setup(); - const Id categoryId = storage.addBookmarkCategory("test category"); - const Id bookmarkId = storage.addBookmark("test bookmark", "test comment", TimeStamp::now().toString(), categoryId); - storage.addBookmarkedNode(bookmarkId, "test name"); + const Id categoryId = storage.addBookmarkCategory(StorageBookmarkCategoryData("test category")).id; + const Id bookmarkId = storage.addBookmark(StorageBookmarkData("test bookmark", "test comment", TimeStamp::now().toString(), categoryId)).id; + storage.addBookmarkedNode(StorageBookmarkedNodeData(bookmarkId, "test name")); storage.updateBookmark(bookmarkId, updatedName, updatedComment, categoryId); diff --git a/src/test/SqliteIndexStorageTestSuite.h b/src/test/SqliteIndexStorageTestSuite.h index 859a5161..94ad35ba 100644 --- a/src/test/SqliteIndexStorageTestSuite.h +++ b/src/test/SqliteIndexStorageTestSuite.h @@ -15,7 +15,7 @@ public: SqliteIndexStorage storage(databasePath); storage.setup(); storage.beginTransaction(); - storage.addNode(0, "a"); + storage.addNode(StorageNodeData(0, "a")); storage.commitTransaction(); nodeCount = storage.getNodeCount(); } @@ -32,7 +32,7 @@ public: SqliteIndexStorage storage(databasePath); storage.setup(); storage.beginTransaction(); - int nodeId = storage.addNode(0, "a"); + int nodeId = storage.addNode(StorageNodeData(0, "a")).id; storage.removeElement(nodeId); storage.commitTransaction(); nodeCount = storage.getNodeCount(); @@ -50,9 +50,9 @@ public: SqliteIndexStorage storage(databasePath); storage.setup(); storage.beginTransaction(); - int sourceNodeId = storage.addNode(0, "a"); - int targetNodeId = storage.addNode(0, "b"); - storage.addEdge(0, sourceNodeId, targetNodeId); + int sourceNodeId = storage.addNode(StorageNodeData(0, "a")).id; + int targetNodeId = storage.addNode(StorageNodeData(0, "b")).id; + storage.addEdge(StorageEdgeData(0, sourceNodeId, targetNodeId)); storage.commitTransaction(); edgeCount = storage.getEdgeCount(); } @@ -69,9 +69,9 @@ public: SqliteIndexStorage storage(databasePath); storage.setup(); storage.beginTransaction(); - int sourceNodeId = storage.addNode(0, "a"); - int targetNodeId = storage.addNode(0, "b"); - int edgeId = storage.addEdge(0, sourceNodeId, targetNodeId); + int sourceNodeId = storage.addNode(StorageNodeData(0, "a")).id; + int targetNodeId = storage.addNode(StorageNodeData(0, "b")).id; + int edgeId = storage.addEdge(StorageEdgeData(0, sourceNodeId, targetNodeId)).id; storage.removeElement(edgeId); storage.commitTransaction(); edgeCount = storage.getEdgeCount(); diff --git a/src/test/StorageTestSuite.h b/src/test/StorageTestSuite.h index aa04861e..ceed52bc 100644 --- a/src/test/StorageTestSuite.h +++ b/src/test/StorageTestSuite.h @@ -21,8 +21,8 @@ public: std::string filePath = "path/to/test.h"; std::shared_ptr intermetiateStorage = std::make_shared(); - Id id = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_FILE), NameHierarchy::serialize(NameHierarchy(filePath, NAME_DELIMITER_FILE))); - intermetiateStorage->addFile(id, filePath, "someTime", true); + Id id = intermetiateStorage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_FILE), NameHierarchy::serialize(NameHierarchy(filePath, NAME_DELIMITER_FILE)))); + intermetiateStorage->addFile(StorageFile(id, filePath, "someTime", true)); storage.inject(intermetiateStorage.get()); @@ -37,7 +37,7 @@ public: TestStorage storage; std::shared_ptr intermetiateStorage = std::make_shared(); - intermetiateStorage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(a)); + intermetiateStorage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(a))); storage.inject(intermetiateStorage.get()); @@ -57,12 +57,12 @@ public: std::shared_ptr intermetiateStorage = std::make_shared(); - Id aId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_STRUCT), NameHierarchy::serialize(a)); - intermetiateStorage->addSymbol(aId, DEFINITION_EXPLICIT); + Id aId = intermetiateStorage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_STRUCT), NameHierarchy::serialize(a))); + intermetiateStorage->addSymbol(StorageSymbol(aId, DEFINITION_EXPLICIT)); - Id bId = intermetiateStorage->addNode(Node::typeToInt(Node::NODE_FIELD), NameHierarchy::serialize(b)); - intermetiateStorage->addSymbol(bId, DEFINITION_EXPLICIT); - intermetiateStorage->addEdge(Edge::typeToInt(Edge::EDGE_MEMBER), aId, bId); + Id bId = intermetiateStorage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_FIELD), NameHierarchy::serialize(b))); + intermetiateStorage->addSymbol(StorageSymbol(bId, DEFINITION_EXPLICIT)); + intermetiateStorage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_MEMBER), aId, bId)); storage.inject(intermetiateStorage.get()); diff --git a/src/test/StorageTransformationAnonymousTypedefTestSuite.h b/src/test/StorageTransformationAnonymousTypedefTestSuite.h index a48d61f8..0ea2f39a 100644 --- a/src/test/StorageTransformationAnonymousTypedefTestSuite.h +++ b/src/test/StorageTransformationAnonymousTypedefTestSuite.h @@ -12,9 +12,9 @@ public: { std::shared_ptr storage = std::make_shared(); - Id anonymousTypeId = storage->addNode(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX))); - Id typedefId = storage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX))); - storage->addEdge(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId); + Id anonymousTypeId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX)))); + Id typedefId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX)))); + storage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId)); StorageTransformationAnonymousTypedef::transform(storage); @@ -35,10 +35,10 @@ public: { std::shared_ptr storage = std::make_shared(); - Id anonymousTypeId = storage->addNode(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX))); - Id typedefId = storage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX))); - storage->addEdge(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId); - storage->addEdge(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), 42, typedefId); + Id anonymousTypeId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX)))); + Id typedefId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX)))); + storage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId)); + storage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), 42, typedefId)); StorageTransformationAnonymousTypedef::transform(storage); @@ -69,10 +69,10 @@ public: { std::shared_ptr storage = std::make_shared(); - Id anonymousTypeId = storage->addNode(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX))); - Id typedefId = storage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX))); - storage->addEdge(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId); - storage->addEdge(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), anonymousTypeId, 42); + Id anonymousTypeId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX)))); + Id typedefId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX)))); + storage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId)); + storage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), anonymousTypeId, 42)); StorageTransformationAnonymousTypedef::transform(storage); @@ -103,14 +103,14 @@ public: { std::shared_ptr storage = std::make_shared(); - Id anonymousTypeId = storage->addNode(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX))); - Id typedefId = storage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX))); - storage->addEdge(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId); + Id anonymousTypeId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy("anonymous class (input.cc<1:9>)", NAME_DELIMITER_CXX)))); + Id typedefId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX)))); + storage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, anonymousTypeId)); - Id anonymousTypeMemberId = storage->addNode( + Id anonymousTypeMemberId = storage->addNode(StorageNodeData( Node::typeToInt(Node::NODE_FIELD), NameHierarchy::serialize(NameHierarchy(utility::createVectorFromElements("anonymous class (input.cc<1:9>)", "field"), NAME_DELIMITER_CXX)) - ); + )); StorageTransformationAnonymousTypedef::transform(storage); @@ -131,12 +131,12 @@ public: { std::shared_ptr storage = std::make_shared(); - Id typeId = storage->addNode( + Id typeId = storage->addNode(StorageNodeData( Node::typeToInt(Node::NODE_CLASS), NameHierarchy::serialize(NameHierarchy(utility::createVectorFromElements("anonymous namespace (input.cc<1:9>)", "Type"), NAME_DELIMITER_CXX)) - ); - Id typedefId = storage->addNode(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX))); - storage->addEdge(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, typeId); + )); + Id typedefId = storage->addNode(StorageNodeData(Node::typeToInt(Node::NODE_TYPEDEF), NameHierarchy::serialize(NameHierarchy("ClassTypedef", NAME_DELIMITER_CXX)))); + storage->addEdge(StorageEdgeData(Edge::typeToInt(Edge::EDGE_TYPE_USAGE), typedefId, typeId)); StorageTransformationAnonymousTypedef::transform(storage);