From 78c1b32797a852558957f3874d5887cfc2464a75 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Wed, 23 Sep 2015 09:26:03 +0200 Subject: [PATCH] data: increased parse and graph assembly performance * removed header search in subdirectories of header search paths * cache file node ids in Storage for faster lookup * retrieve node names from SearchIndex * fixed addNodeAndAllChildren also called for member edges * added check if node already present in addEdgeAndAllChildren --- bin/test/data/log/test_log.txt | 89 -------- src/app/qt/view/QtGraphView.cpp | 2 +- .../qt/view/graphElements/QtGraphNodeData.cpp | 4 +- .../qt/view/graphElements/QtGraphNodeData.h | 2 +- src/lib/Project.cpp | 27 ++- .../component/controller/CodeController.cpp | 18 +- src/lib/component/controller/CodeController.h | 2 +- .../component/controller/GraphController.cpp | 15 +- .../component/controller/GraphController.h | 6 +- .../component/controller/helper/DummyNode.h | 4 +- src/lib/data/SqliteStorage.cpp | 10 + src/lib/data/SqliteStorage.h | 1 + src/lib/data/Storage.cpp | 209 ++++++++++++------ src/lib/data/Storage.h | 13 +- src/lib/data/access/StorageAccess.h | 4 +- src/lib/data/access/StorageAccessProxy.cpp | 8 +- src/lib/data/access/StorageAccessProxy.h | 4 +- src/lib/data/graph/Node.cpp | 2 + src/lib/data/graph/Node.h | 2 + src/lib/data/parser/ParserClient.h | 3 + src/lib/data/parser/cxx/TaskParseCxx.cpp | 6 + src/lib/data/search/SearchIndex.cpp | 20 ++ src/lib/data/search/SearchIndex.h | 5 + src/lib/data/search/SearchNode.cpp | 7 +- src/lib/data/search/SearchNode.h | 3 +- src/test/CxxParserTestSuite.h | 8 + src/test/StorageTestSuite.h | 94 ++++---- 27 files changed, 308 insertions(+), 260 deletions(-) diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index da3732af..8cdb1410 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -234,95 +234,6 @@ ConfigManager.cpp WARNING: value Int is not present in config. ConfigManager.cpp WARNING: value Float is not present in config. ConfigManager.cpp WARNING: value String is not present in config. ConfigManager.cpp WARNING: value NewBool is not present in config. -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp -Storage.cpp ERROR: No filenode created for file: file.cpp TextAccess.cpp WARNING: Index 'firstLine' has to be lower or equal index 'lastLine', is 3 > 2 TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp index 93f79153..50b0d9f0 100644 --- a/src/app/qt/view/QtGraphView.cpp +++ b/src/app/qt/view/QtGraphView.cpp @@ -278,7 +278,7 @@ std::shared_ptr QtGraphView::createNodeRecursive( std::shared_ptr newNode; if (node.isGraphNode()) { - newNode = std::make_shared(node.data, node.hasNamespace, node.childVisible); + newNode = std::make_shared(node.data, node.hasParent, node.childVisible); } else if (node.isAccessNode()) { diff --git a/src/app/qt/view/graphElements/QtGraphNodeData.cpp b/src/app/qt/view/graphElements/QtGraphNodeData.cpp index 86eee87e..f3432970 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeData.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeData.cpp @@ -5,13 +5,13 @@ #include "utility/messaging/type/MessageFocusOut.h" #include "utility/messaging/type/MessageGraphNodeMove.h" -QtGraphNodeData::QtGraphNodeData(const Node* data, bool hasNamespace, bool childVisible) +QtGraphNodeData::QtGraphNodeData(const Node* data, bool hasParent, bool childVisible) : m_data(data) , m_childVisible(childVisible) { this->setAcceptHoverEvents(true); - if (hasNamespace) + if (!hasParent) { this->setName(data->getFullName()); } diff --git a/src/app/qt/view/graphElements/QtGraphNodeData.h b/src/app/qt/view/graphElements/QtGraphNodeData.h index 94abe24a..8d2aa246 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeData.h +++ b/src/app/qt/view/graphElements/QtGraphNodeData.h @@ -7,7 +7,7 @@ class QtGraphNodeData : public QtGraphNode { public: - QtGraphNodeData(const Node* data, bool hasNamespace, bool childVisible); + QtGraphNodeData(const Node* data, bool hasParent, bool childVisible); virtual ~QtGraphNodeData(); const Node* getData() const; diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 787cbb0c..f446a617 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -87,21 +87,19 @@ void Project::parseCode() utility::append(updatedFilePaths, m_storage->getDependingFilePaths(updatedFilePaths)); utility::append(removedFilePaths, m_storage->getDependingFilePaths(removedFilePaths)); + MessageStatus("Clearing updated files").dispatch(); m_storage->clearFileElements(updatedFilePaths); + + MessageStatus("Clearing removed files").dispatch(); m_storage->clearFileElements(removedFilePaths); + MessageStatus("Cleaning up names").dispatch(); m_storage->removeUnusedNames(); std::vector filesToParse; filesToParse.insert(filesToParse.end(), addedFilePaths.begin(), addedFilePaths.end()); filesToParse.insert(filesToParse.end(), updatedFilePaths.begin(), updatedFilePaths.end()); - if (filesToParse.size() == 0) - { - MessageFinishedParsing(0, 0, 0, m_storage->getErrorCount()).dispatch(); - return; - } - Task::dispatch(std::make_shared( m_storage.get(), &m_fileManager, @@ -158,15 +156,16 @@ Parser::Arguments Project::getParserArguments() const // Add the include paths as HeaderSearchPaths as well, so clang will also look here when searching include files. utility::append(args.systemHeaderSearchPaths, m_fileManager.getIncludePaths()); - std::vector headerSearchSubPaths; - for(FilePath p : projSettings->getHeaderSearchPaths()) - { - std::vector tempPaths = FileSystem::getSubDirectories(p); - headerSearchSubPaths.insert( headerSearchSubPaths.end(), tempPaths.begin(), tempPaths.end() ); - } + // std::vector headerSearchSubPaths; + // for(FilePath p : projSettings->getHeaderSearchPaths()) + // { + // std::vector tempPaths = FileSystem::getSubDirectories(p); + // headerSearchSubPaths.insert( headerSearchSubPaths.end(), tempPaths.begin(), tempPaths.end() ); + // } + + // std::unique(headerSearchSubPaths.begin(),headerSearchSubPaths.end()); + // utility::append(args.systemHeaderSearchPaths, headerSearchSubPaths); - std::unique(headerSearchSubPaths.begin(),headerSearchSubPaths.end()); - utility::append(args.systemHeaderSearchPaths, headerSearchSubPaths); utility::append(args.systemHeaderSearchPaths, projSettings->getHeaderSearchPaths()); utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPaths()); diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 593e5e11..409f5651 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -49,13 +49,13 @@ void CodeController::handleMessage(MessageActivateTokens* message) return; } - TokenLocationCollection collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds); - view->showCodeSnippets(getSnippetsForActiveTokenLocations(collection, declarationId)); + std::shared_ptr collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds); + view->showCodeSnippets(getSnippetsForActiveTokenLocations(collection.get(), declarationId)); if (!message->isFromSystem) { - size_t fileCount = collection.getTokenLocationFileCount(); - size_t referenceCount = collection.getTokenLocationCount(); + size_t fileCount = collection->getTokenLocationFileCount(); + size_t referenceCount = collection->getTokenLocationCount(); std::stringstream ss; ss << message->tokenIds.size() << ' '; @@ -123,17 +123,17 @@ void CodeController::handleMessage(MessageShowFile* message) void CodeController::handleMessage(MessageShowScope* message) { - TokenLocationCollection collection = + std::shared_ptr collection = m_storageAccess->getTokenLocationsForLocationIds(std::vector(1, message->scopeLocationId)); - TokenLocation* location = collection.findTokenLocationById(message->scopeLocationId); + TokenLocation* location = collection->findTokenLocationById(message->scopeLocationId); if (!location || !location->isScopeTokenLocation() || !location->getOtherTokenLocation()) { LOG_ERROR("MessageShowScope did not contain a valid scope location id"); return; } - std::vector snippets = getSnippetsForActiveTokenLocations(collection, 0); + std::vector snippets = getSnippetsForActiveTokenLocations(collection.get(), 0); if (snippets.size() != 1) { @@ -150,11 +150,11 @@ CodeView* CodeController::getView() } std::vector CodeController::getSnippetsForActiveTokenLocations( - const TokenLocationCollection& collection, Id declarationId + const TokenLocationCollection* collection, Id declarationId ) const { std::vector snippets; - collection.forEachTokenLocationFile( + collection->forEachTokenLocationFile( [&](std::shared_ptr file) -> void { std::vector fileSnippets = getSnippetsForFile(file); diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index 0a642fad..81ef6165 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -47,7 +47,7 @@ private: CodeView* getView(); std::vector getSnippetsForActiveTokenLocations( - const TokenLocationCollection& collection, Id declarationId) const; + const TokenLocationCollection* collection, Id declarationId) const; std::vector getSnippetsForFile(std::shared_ptr file) const; std::shared_ptr buildMergerHierarchy( TokenLocation* location, SnippetMerger& fileScopedMerger, std::map>& mergers) const; diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index d7723103..26dd2728 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -164,6 +164,11 @@ void GraphController::createDummyGraphForTokenIds(const std::vector& tokenId } ); + for (DummyNode& node : dummyNodes) + { + node.hasParent = false; + } + m_dummyNodes = dummyNodes; autoExpandActiveNode(tokenIds); @@ -290,14 +295,14 @@ std::vector GraphController::splitNamespaceNodesRecursive(const Dummy std::vector nodes; active |= node.active; - if (node.isGraphNode() && node.data->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE)) + if (node.isGraphNode() && node.data->isType(Node::NODE_NOT_VISIBLE)) { for (const DummyNode& subNode : node.subNodes) { std::vector newNodes = splitNamespaceNodesRecursive(subNode, active, false); for (DummyNode& newNode : newNodes) { - newNode.hasNamespace = true; + newNode.hasParent = false; } nodes.insert(nodes.end(), newNodes.begin(), newNodes.end()); @@ -416,7 +421,7 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool pa if ((node.isGraphNode() && node.isExpanded()) || (node.isAccessNode() && parentExpanded) || (node.isGraphNode() && node.data->isType(Node::NODE_ENUM)) || - (node.isGraphNode() && node.data->isType(Node::NODE_NAMESPACE | Node::NODE_UNDEFINED))) + (node.isGraphNode() && node.data->isType(Node::NODE_NOT_VISIBLE))) { for (DummyNode& subNode : node.subNodes) { @@ -681,7 +686,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const if (node.isGraphNode()) { - if (node.hasNamespace) + if (!node.hasParent) { width = margins.charWidth * node.data->getFullName().size(); } @@ -887,7 +892,7 @@ DummyNode* GraphController::findTopLevelDummyNodeRecursive(std::vectorisType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE)) + if (node.data->isType(Node::NODE_NOT_VISIBLE)) { DummyNode* result = findDummyNodeRecursive(node.subNodes, tokenId); if (result != nullptr) diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 1824c491..7c9f5a66 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -52,6 +52,9 @@ private: void createDummyGraphForTokenIds(const std::vector& tokenIds); DummyNode createDummyNodeTopDown(Node* node); + void splitNamespaceNodes(); + std::vector splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel); + void autoExpandActiveNode(const std::vector& activeTokenIds); void setActiveAndVisibility(const std::vector& activeTokenIds); @@ -59,9 +62,6 @@ private: bool setNodeVisibilityRecursiveBottomUp(DummyNode& node) const; void setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const; - void splitNamespaceNodes(); - std::vector splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel); - void bundleNodes(); void bundleNodesMatching(std::function matcher, size_t count, const std::string& name); bool isTypeNodeWithSingleAggregation(const DummyNode& node, TokenComponentAggregation::Direction direction) const; diff --git a/src/lib/component/controller/helper/DummyNode.h b/src/lib/component/controller/helper/DummyNode.h index afd761c0..14f20424 100644 --- a/src/lib/component/controller/helper/DummyNode.h +++ b/src/lib/component/controller/helper/DummyNode.h @@ -21,7 +21,7 @@ public: , active(false) , connected(false) , expanded(false) - , hasNamespace(false) + , hasParent(true) , accessType(TokenComponentAccess::ACCESS_NONE) , invisibleSubNodeCount(0) { @@ -117,7 +117,7 @@ public: bool active; bool connected; bool expanded; - bool hasNamespace; + bool hasParent; // AccessNode TokenComponentAccess::AccessType accessType; diff --git a/src/lib/data/SqliteStorage.cpp b/src/lib/data/SqliteStorage.cpp index 6a4f5a9a..3dd1d2b6 100644 --- a/src/lib/data/SqliteStorage.cpp +++ b/src/lib/data/SqliteStorage.cpp @@ -432,6 +432,16 @@ StorageFile SqliteStorage::getFileByName(const std::string& fileName) const return storageFile; } +StorageFile SqliteStorage::getFileByPath(const std::string& filePath) const +{ + StorageFile storageFile = getFirstFile( + "SELECT node.id, node.name_id, file.path, file.modification_time FROM node INNER JOIN file ON node.id = file.id " + "WHERE file.path == '" + filePath + "';" + ); + + return storageFile; +} + std::vector SqliteStorage::getAllFiles() const { return getAllFiles("SELECT file.id, node.name_id, file.path, file.modification_time FROM file INNER JOIN node ON file.id = node.id;"); diff --git a/src/lib/data/SqliteStorage.h b/src/lib/data/SqliteStorage.h index e06de557..daf92c61 100644 --- a/src/lib/data/SqliteStorage.h +++ b/src/lib/data/SqliteStorage.h @@ -60,6 +60,7 @@ public: StorageFile getFileById(const Id id) const; StorageFile getFileByName(const std::string& fileName) const; + StorageFile getFileByPath(const std::string& filePath) const; std::vector getAllFiles() const; void setNodeType(int type, Id nodeId); diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index f80d336e..8b2685d4 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -35,6 +35,8 @@ void Storage::clear() m_sqliteStorage.clear(); m_tokenIndex.clear(); + m_fileNodeIds.clear(); + m_errorMessages.clear(); m_errorLocationCollection.clear(); } @@ -72,7 +74,7 @@ std::set Storage::getDependingFilePaths(const FilePath& filePath) { std::set dependingFilePaths; - Id fileNodeId = m_sqliteStorage.getFileByName(filePath.fileName()).id; + Id fileNodeId = getFileNodeId(filePath); std::vector incomingEdges = m_sqliteStorage.getEdgesByTargetType( fileNodeId, Edge::typeToInt(Edge::EDGE_INCLUDE) ); @@ -93,11 +95,16 @@ std::set Storage::getDependingFilePaths(const FilePath& filePath) void Storage::removeUnusedNames() { m_sqliteStorage.removeUnusedNameHierarchyElements(); + m_fileNodeIds.clear(); +} + +void Storage::buildSearchIndex() +{ m_tokenIndex.clear(); for (StorageNode node: m_sqliteStorage.getAllNodes()) { - m_tokenIndex.addNode(m_sqliteStorage.getNameHierarchyById(node.nameId))->addTokenId(node.id); + m_tokenIndex.addTokenId(m_tokenIndex.addNode(m_sqliteStorage.getNameHierarchyById(node.nameId)), node.id); } } @@ -117,6 +124,15 @@ void Storage::logStats() const { } +void Storage::startParsing() +{ +} + +void Storage::finishParsing() +{ + buildSearchIndex(); +} + void Storage::prepareParsingFile() { m_sqliteStorage.beginTransaction(); @@ -547,7 +563,7 @@ Id Storage::onFileParsed(const FileInfo& fileInfo) nameHierarchyElementId = m_sqliteStorage.addNameHierarchyElement(fileName); } - Id fileNodeId = m_sqliteStorage.getFileByName(fileName).id; + Id fileNodeId = getFileNodeId(fileInfo.path); if (fileNodeId == 0) { fileNodeId = m_sqliteStorage.addFile( @@ -559,7 +575,6 @@ Id Storage::onFileParsed(const FileInfo& fileInfo) NameHierarchy nameHierarchy; nameHierarchy.push(std::make_shared(fileName)); - m_tokenIndex.addNode(nameHierarchy)->addTokenId(fileNodeId); return fileNodeId; } @@ -640,6 +655,7 @@ std::string Storage::getNameForNodeWithId(Id nodeId) const { Id nameHierarchyElementId = m_sqliteStorage.getNameHierarchyElementIdByNodeId(nodeId); return m_sqliteStorage.getNameHierarchyById(nameHierarchyElementId).getFullName(); + // return m_tokenIndex.getNameHierarchyForTokenId(nodeId).getFullName(); } Node::NodeType Storage::getNodeTypeForNodeWithId(Id nodeId) const @@ -679,6 +695,9 @@ std::vector Storage::getAutocompletionMatches(const std::string& qu return matches; } +#include "utility/utility.h" +#include + std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& tokenIds) const { std::shared_ptr g = std::make_shared(); @@ -692,17 +711,40 @@ std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& { const StorageNode node = m_sqliteStorage.getNodeById(elementId); - addNodeAndAllChildrenToGraph(getLastParentNodeId(node.id), graph); + float a = utility::duration( + [&]() + { + addNodeAndAllChildrenToGraph(getLastParentNodeId(node.id), graph); + } + ); + std::cout << "add node and children " << a << std::endl; std::vector edges = m_sqliteStorage.getEdgesBySourceId(node.id); utility::append(edges, m_sqliteStorage.getEdgesByTargetId(node.id)); - for (size_t i = 0; i < edges.size(); i++) - { - addEdgeAndAllChildrenToGraph(edges[i].id, graph); - } + float b = utility::duration( + [&]() + { + for (size_t i = 0; i < edges.size(); i++) + { + if (Edge::intToType(edges[i].type) != Edge::EDGE_MEMBER) + { + addEdgeAndAllChildrenToGraph(edges[i].id, graph); + } + } + } + ); + std::cout << "add edge and children " << b << std::endl; - addAggregationEdgesToGraph(elementId, graph); + + + float c = utility::duration( + [&]() + { + addAggregationEdgesToGraph(elementId, graph); + } + ); + std::cout << "add aggregation " << c << std::endl << std::endl; } else { @@ -846,16 +888,16 @@ std::vector Storage::getTokenIdsForAggregationEdge(Id sourceId, Id targetId) return edgeIds; } -TokenLocationCollection Storage::getTokenLocationsForTokenIds(const std::vector& tokenIds) const +std::shared_ptr Storage::getTokenLocationsForTokenIds(const std::vector& tokenIds) const { - TokenLocationCollection collection; + std::shared_ptr collection = std::make_shared(); for (Id elementId: tokenIds) { if (m_sqliteStorage.isFile(elementId)) { StorageFile storageFile = m_sqliteStorage.getFileById(elementId); - collection.addTokenLocationFileAsPlainCopy(m_sqliteStorage.getTokenLocationsForFile(storageFile.filePath).get()); + collection->addTokenLocationFileAsPlainCopy(m_sqliteStorage.getTokenLocationsForFile(storageFile.filePath).get()); } else { @@ -866,7 +908,7 @@ TokenLocationCollection Storage::getTokenLocationsForTokenIds(const std::vector< const StorageSourceLocation& location = locations[i]; StorageFile storageFile = m_sqliteStorage.getFileById(location.fileNodeId); - collection.addTokenLocation( + collection->addTokenLocation( location.id, location.elementId, storageFile.filePath, @@ -882,14 +924,14 @@ TokenLocationCollection Storage::getTokenLocationsForTokenIds(const std::vector< return collection; } -TokenLocationCollection Storage::getTokenLocationsForLocationIds(const std::vector& locationIds) const +std::shared_ptr Storage::getTokenLocationsForLocationIds(const std::vector& locationIds) const { - TokenLocationCollection collection; + std::shared_ptr collection = std::make_shared(); for (size_t i = 0; i < locationIds.size(); i++) { StorageSourceLocation location = m_sqliteStorage.getSourceLocationById(locationIds[i]); - collection.addTokenLocation( + collection->addTokenLocation( location.id, location.elementId, m_sqliteStorage.getFileById(location.fileNodeId).filePath, // TODO: optimize: only once per file! @@ -1059,8 +1101,6 @@ Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarch parentNodeId = nodeId; } - m_tokenIndex.addNode(nameHierarchy)->addTokenId(parentNodeId); - return parentNodeId; } @@ -1131,12 +1171,7 @@ int Storage::addSourceLocation(int elementNodeId, const ParseLocation& location, } else { - Id fileNodeId = m_sqliteStorage.getFileByName(location.filePath.fileName()).id; - if (fileNodeId == 0) - { - LOG_ERROR("No filenode created for file: " + location.filePath.str()); - fileNodeId = onFileParsed(FileSystem::getFileInfoForPath(location.filePath)); - } + Id fileNodeId = getFileNodeId(location.filePath); int locationId = m_sqliteStorage.addSourceLocation( elementNodeId, fileNodeId, location.startLineNumber, location.startColumnNumber, location.endLineNumber, location.endColumnNumber, isScope @@ -1152,6 +1187,33 @@ Id Storage::addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type, Parse return edgeId; } +Id Storage::getFileNodeId(const FilePath& filePath) +{ + std::map::const_iterator it = m_fileNodeIds.find(filePath); + + if (it != m_fileNodeIds.end()) + { + return it->second; + } + + if (filePath.empty()) + { + LOG_ERROR("No file path set"); + return 0; + } + + StorageFile storageFile = m_sqliteStorage.getFileByPath(filePath.str()); + + if (storageFile.id == 0) + { + return 0; + } + + m_fileNodeIds.emplace(filePath, storageFile.id); + + return storageFile.id; +} + Id Storage::getLastParentNodeId(const Id nodeId) const { Id currentNodeId = 0; @@ -1161,7 +1223,18 @@ Id Storage::getLastParentNodeId(const Id nodeId) const currentNodeId = parentNodeId; std::vector memberEdges = m_sqliteStorage.getEdgesByTargetType(currentNodeId, Edge::EDGE_MEMBER); - parentNodeId = (memberEdges.size() > 0) ? memberEdges[0].sourceNodeId : 0; + if (!memberEdges.size()) + { + break; + } + + parentNodeId = memberEdges[0].sourceNodeId; + + StorageNode parentNode = m_sqliteStorage.getNodeById(parentNodeId); + if (Node::intToType(parentNode.type) & Node::NODE_NOT_VISIBLE) + { + break; + } } return currentNodeId; } @@ -1203,57 +1276,42 @@ void Storage::addEdgeAndAllChildrenToGraph(const Id edgeId, Graph* graph) const { StorageEdge storageEdge = m_sqliteStorage.getEdgeById(edgeId); - addNodeAndAllChildrenToGraph(getLastParentNodeId(storageEdge.sourceNodeId), graph); // TODO: optimize: look for node in graph first - addNodeAndAllChildrenToGraph(getLastParentNodeId(storageEdge.targetNodeId), graph); - Node* sourceNode = graph->getNodeById(storageEdge.sourceNodeId); Node* targetNode = graph->getNodeById(storageEdge.targetNodeId); + if (!sourceNode) + { + addNodeAndAllChildrenToGraph(getLastParentNodeId(storageEdge.sourceNodeId), graph); + sourceNode = graph->getNodeById(storageEdge.sourceNodeId); + } + + if (!targetNode) + { + addNodeAndAllChildrenToGraph(getLastParentNodeId(storageEdge.targetNodeId), graph); + targetNode = graph->getNodeById(storageEdge.targetNodeId); + } + graph->createEdge(edgeId, Edge::intToType(storageEdge.type), sourceNode, targetNode); } Node* Storage::addNodeAndAllChildrenToGraph(const Id nodeId, Graph* graph) const { - Node* node = nullptr; - if (!graph->getNodeById(nodeId)) + Node* node = graph->getNodeById(nodeId); + if (node) { - node = addNodeToGraph(nodeId, graph); + return node; } - std::queue unprocessedEdges; + node = addNodeToGraph(nodeId, graph); + + std::vector memberEdges = m_sqliteStorage.getEdgesBySourceType(nodeId, Edge::EDGE_MEMBER); + for (const StorageEdge& edge : memberEdges) { - std::vector edges = m_sqliteStorage.getEdgesBySourceType(nodeId, Edge::EDGE_MEMBER); - for (size_t i = 0; i < edges.size(); i++) + Node* targetNode = addNodeAndAllChildrenToGraph(edge.targetNodeId, graph); + + if (node && targetNode) { - unprocessedEdges.push(edges[i]); - } - } - - while (unprocessedEdges.size() > 0) - { - const StorageEdge& storageEdge = unprocessedEdges.front(); - unprocessedEdges.pop(); - - Node* sourceNode = graph->getNodeById(storageEdge.sourceNodeId); - if (!sourceNode) - { - sourceNode = addNodeToGraph(storageEdge.sourceNodeId, graph); - } - - Node* targetNode = graph->getNodeById(storageEdge.targetNodeId); - if (!targetNode) - { - targetNode = addNodeToGraph(storageEdge.targetNodeId, graph); - } - - graph->createEdge(storageEdge.id, Edge::intToType(storageEdge.type), sourceNode, targetNode); - - { - std::vector edges = m_sqliteStorage.getEdgesBySourceType(storageEdge.targetNodeId, Edge::EDGE_MEMBER); - for (size_t i = 0; i < edges.size(); i++) - { - unprocessedEdges.push(edges[i]); - } + graph->createEdge(edge.id, Edge::intToType(edge.type), node, targetNode); } } @@ -1324,7 +1382,7 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const { Node::NodeType type = Node::intToType(m_sqliteStorage.getNodeById(memberEdges[0].sourceNodeId).type); - if (type != Node::NODE_UNDEFINED && type != Node::NODE_NAMESPACE) + if ((type & Node::NODE_NOT_VISIBLE) == 0) { parentNodeId = memberEdges[0].sourceNodeId; } @@ -1350,7 +1408,7 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const if (!targetNode) { targetNode = addNodeAndAllChildrenToGraph(getLastParentNodeId(aggregationTargetNodeId), graph); - if (targetNode->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE)) + if (targetNode->isType(Node::NODE_NOT_VISIBLE)) { targetNode = addNodeToGraph(aggregationTargetNodeId, graph); } @@ -1369,13 +1427,20 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const Node* Storage::addNodeToGraph(const Id nodeId, Graph* graph) const { - StorageNode storageNode = m_sqliteStorage.getNodeById(nodeId); + Node* node = graph->getNodeById(nodeId); - return graph->createNode( - storageNode.id, - Node::intToType(storageNode.type), - std::make_shared(m_sqliteStorage.getNameHierarchyById(storageNode.nameId)) - ); + if (!node) + { + StorageNode storageNode = m_sqliteStorage.getNodeById(nodeId); + + node = graph->createNode( + storageNode.id, + Node::intToType(storageNode.type), + std::make_shared(m_tokenIndex.getNameHierarchyForTokenId(nodeId)) + ); + } + + return node; } TokenComponentAccess::AccessType Storage::convertAccessType(ParserClient::AccessType access) const diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 18f18f4e..362a5cd2 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -27,7 +27,9 @@ public: void clearFileElements(const FilePath& filePath); std::set getDependingFilePaths(const std::set& filePaths); std::set getDependingFilePaths(const FilePath& filePath); + void removeUnusedNames(); + void buildSearchIndex(); void logGraph() const; void logLocations() const; @@ -35,6 +37,9 @@ public: void logStats() const; // ParserClient implementation + virtual void startParsing(); + virtual void finishParsing(); + virtual void prepareParsingFile(); virtual void finishParsingFile(); @@ -132,8 +137,8 @@ public: virtual Id getTokenIdForFileNode(const FilePath& filePath) const; virtual std::vector getTokenIdsForAggregationEdge(Id sourceId, Id targetId) const; - virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector& tokenIds) const; - virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector& locationIds) const; + virtual std::shared_ptr getTokenLocationsForTokenIds(const std::vector& tokenIds) const; + virtual std::shared_ptr getTokenLocationsForLocationIds(const std::vector& locationIds) const; virtual std::shared_ptr getTokenLocationsForFile(const std::string& filePath) const; virtual std::shared_ptr getTokenLocationsForLinesInFile( const std::string& filePath, uint firstLineNumber, uint lastLineNumber @@ -152,6 +157,8 @@ private: int addSourceLocation(int elementNodeId, const ParseLocation& location, bool isScope = false); Id addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type, ParseLocation location); + Id getFileNodeId(const FilePath& filePath); + Id getLastParentNodeId(const Id nodeId) const; std::vector getDirectChildNodeIds(const Id nodeId) const; std::vector getAllChildNodeIds(const Id nodeId) const; @@ -167,6 +174,8 @@ private: SearchIndex m_tokenIndex; SqliteStorage m_sqliteStorage; + std::map m_fileNodeIds; + TokenLocationCollection m_errorLocationCollection; std::vector m_errorMessages; }; diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 63510487..75b6d2cc 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -41,8 +41,8 @@ public: virtual Id getTokenIdForFileNode(const FilePath& filePath) const = 0; virtual std::vector getTokenIdsForAggregationEdge(Id sourceId, Id targetId) const = 0; - virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector& tokenIds) const = 0; - virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector& locationIds) const = 0; + virtual std::shared_ptr getTokenLocationsForTokenIds(const std::vector& tokenIds) const = 0; + virtual std::shared_ptr getTokenLocationsForLocationIds(const std::vector& locationIds) const = 0; virtual std::shared_ptr getTokenLocationsForFile(const std::string& filePath) const = 0; virtual std::shared_ptr getTokenLocationsForLinesInFile( const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index e47ef425..db02693a 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -153,24 +153,24 @@ std::vector StorageAccessProxy::getTokenIdsForAggregationEdge(Id sourceId, I return std::vector(); } -TokenLocationCollection StorageAccessProxy::getTokenLocationsForTokenIds(const std::vector& tokenIds) const +std::shared_ptr StorageAccessProxy::getTokenLocationsForTokenIds(const std::vector& tokenIds) const { if (hasSubject()) { return m_subject->getTokenLocationsForTokenIds(tokenIds); } - return TokenLocationCollection(); + return std::make_shared(); } -TokenLocationCollection StorageAccessProxy::getTokenLocationsForLocationIds(const std::vector& locationIds) const +std::shared_ptr StorageAccessProxy::getTokenLocationsForLocationIds(const std::vector& locationIds) const { if (hasSubject()) { return m_subject->getTokenLocationsForLocationIds(locationIds); } - return TokenLocationCollection(); + return std::make_shared(); } std::shared_ptr StorageAccessProxy::getTokenLocationsForFile(const std::string& filePath) const diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 8090d9e4..9c13adec 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -32,8 +32,8 @@ public: virtual Id getTokenIdForFileNode(const FilePath& filePath) const; virtual std::vector getTokenIdsForAggregationEdge(Id sourceId, Id targetId) const; - virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector& tokenIds) const; - virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector& locationIds) const; + virtual std::shared_ptr getTokenLocationsForTokenIds(const std::vector& tokenIds) const; + virtual std::shared_ptr getTokenLocationsForLocationIds(const std::vector& locationIds) const; virtual std::shared_ptr getTokenLocationsForFile(const std::string& filePath) const; virtual std::shared_ptr getTokenLocationsForLinesInFile( const std::string& filePath, uint firstLineNumber, uint lastLineNumber diff --git a/src/lib/data/graph/Node.cpp b/src/lib/data/graph/Node.cpp index b02250ce..01290343 100644 --- a/src/lib/data/graph/Node.cpp +++ b/src/lib/data/graph/Node.cpp @@ -11,6 +11,8 @@ #include "data/graph/token_component/TokenComponentSignature.h" #include "data/graph/token_component/TokenComponentFilePath.h" +const Node::NodeTypeMask Node::NODE_NOT_VISIBLE = Node::NODE_UNDEFINED | Node::NODE_NAMESPACE; + std::string Node::getTypeString(NodeType type) { switch (type) diff --git a/src/lib/data/graph/Node.h b/src/lib/data/graph/Node.h index 16256f23..1987045a 100644 --- a/src/lib/data/graph/Node.h +++ b/src/lib/data/graph/Node.h @@ -48,6 +48,8 @@ public: static int typeToInt(NodeType type); static NodeType intToType(int value); + static const NodeTypeMask NODE_NOT_VISIBLE; + Node(Id id, NodeType type, std::shared_ptr nameComponent); Node(const Node& other); virtual ~Node(); diff --git a/src/lib/data/parser/ParserClient.h b/src/lib/data/parser/ParserClient.h index 43102983..2c7ee34b 100644 --- a/src/lib/data/parser/ParserClient.h +++ b/src/lib/data/parser/ParserClient.h @@ -51,6 +51,9 @@ public: ParserClient(); virtual ~ParserClient(); + virtual void startParsing() = 0; + virtual void finishParsing() = 0; + virtual void prepareParsingFile() = 0; virtual void finishParsingFile() = 0; diff --git a/src/lib/data/parser/cxx/TaskParseCxx.cpp b/src/lib/data/parser/cxx/TaskParseCxx.cpp index 148bec4c..89f38349 100644 --- a/src/lib/data/parser/cxx/TaskParseCxx.cpp +++ b/src/lib/data/parser/cxx/TaskParseCxx.cpp @@ -31,6 +31,8 @@ void TaskParseCxx::enter() { m_sourcePaths.push(path.absolute().str()); } + + m_client->startParsing(); } Task::TaskState TaskParseCxx::update() @@ -83,6 +85,10 @@ Task::TaskState TaskParseCxx::update() void TaskParseCxx::exit() { + MessageStatus("Building search index").dispatch(); + + m_client->finishParsing(); + FileRegister* fileRegister = m_parser.getFileRegister(); MessageFinishedParsing( diff --git a/src/lib/data/search/SearchIndex.cpp b/src/lib/data/search/SearchIndex.cpp index 1162d036..1b76d1e8 100644 --- a/src/lib/data/search/SearchIndex.cpp +++ b/src/lib/data/search/SearchIndex.cpp @@ -35,6 +35,7 @@ void SearchIndex::clear() { m_root.m_nodes.clear(); m_dictionary.clear(); + m_tokenIds.clear(); } size_t SearchIndex::getNodeCount() const @@ -134,6 +135,25 @@ bool SearchIndex::removeNodeIfUnreferencedRecursive(SearchNode* searchNode) return false; } +void SearchIndex::addTokenId(SearchNode* node, Id tokenId) +{ + node->addTokenId(tokenId); + m_tokenIds.emplace(tokenId, node); +} + +NameHierarchy SearchIndex::getNameHierarchyForTokenId(Id tokenId) const +{ + std::map::const_iterator it = m_tokenIds.find(tokenId); + + if (it != m_tokenIds.end()) + { + SearchNode* node = it->second; + return node->getNameHierarchy(); + } + + return NameHierarchy(); +} + SearchResults SearchIndex::runFuzzySearch(const std::string& query) const { return m_root.runFuzzySearch(query); diff --git a/src/lib/data/search/SearchIndex.h b/src/lib/data/search/SearchIndex.h index f4a65282..5b51d629 100644 --- a/src/lib/data/search/SearchIndex.h +++ b/src/lib/data/search/SearchIndex.h @@ -35,6 +35,9 @@ public: void removeNode(SearchNode* searchNode); bool removeNodeIfUnreferencedRecursive(SearchNode* searchNode); + void addTokenId(SearchNode* node, Id tokenId); + NameHierarchy getNameHierarchyForTokenId(Id tokenId) const; + SearchResults runFuzzySearch(const std::string& query) const; std::vector runFuzzySearchAndGetMatches(const std::string& query) const; @@ -44,6 +47,8 @@ private: SearchNode m_root; Dictionary m_dictionary; + std::map m_tokenIds; + friend std::ostream& operator<<(std::ostream& ostream, const SearchIndex& index); }; diff --git a/src/lib/data/search/SearchNode.cpp b/src/lib/data/search/SearchNode.cpp index 9ed301cc..131d8cd2 100644 --- a/src/lib/data/search/SearchNode.cpp +++ b/src/lib/data/search/SearchNode.cpp @@ -4,6 +4,7 @@ #include "utility/text/Dictionary.h" +#include "data/name/NameHierarchy.h" #include "data/search/SearchIndex.h" #include "data/search/SearchMatch.h" #include "data/search/SearchResult.h" @@ -36,15 +37,15 @@ const std::string& SearchNode::getName() const return m_name; } -std::vector SearchNode::getNameHierarchy() const +NameHierarchy SearchNode::getNameHierarchy() const { - std::vector nameHierarchy; + NameHierarchy nameHierarchy; const SearchNode* parent = getParent(); if (parent && parent->m_nameId) { nameHierarchy = parent->getNameHierarchy(); } - nameHierarchy.push_back(getName()); + nameHierarchy.push(std::make_shared(getName())); return nameHierarchy; } diff --git a/src/lib/data/search/SearchNode.h b/src/lib/data/search/SearchNode.h index fe0af701..1052a2ac 100644 --- a/src/lib/data/search/SearchNode.h +++ b/src/lib/data/search/SearchNode.h @@ -13,6 +13,7 @@ #include "data/search/SearchResult.h" class Dictionary; +class NameHierarchy; class SearchIndex; struct SearchMatch; @@ -25,7 +26,7 @@ public: size_t getNodeCount() const; const std::string& getName() const; - std::vector getNameHierarchy() const; + NameHierarchy getNameHierarchy() const; std::string getFullName() const; Id getNameId() const; diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index aa77c6c2..b5aac793 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -2457,6 +2457,14 @@ private: class TestParserClient: public ParserClient { public: + virtual void startParsing() + { + } + + virtual void finishParsing() + { + } + virtual void prepareParsingFile() { } diff --git a/src/test/StorageTestSuite.h b/src/test/StorageTestSuite.h index 62c2c390..1810eb67 100644 --- a/src/test/StorageTestSuite.h +++ b/src/test/StorageTestSuite.h @@ -33,8 +33,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_TYPEDEF_OF) + ":type->int") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_class() @@ -45,9 +45,9 @@ public: TS_ASSERT_EQUALS(storage.getNameForNodeWithId(id), "Class"); TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(id), Node::NODE_CLASS); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 2); - TS_ASSERT_EQUALS(tlc.getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 2); + TS_ASSERT_EQUALS(tlc->getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); } void test_storage_saves_struct() @@ -58,9 +58,9 @@ public: TS_ASSERT_EQUALS(storage.getNameForNodeWithId(id), "Struct"); TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(id), Node::NODE_STRUCT); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 2); - TS_ASSERT_EQUALS(tlc.getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 2); + TS_ASSERT_EQUALS(tlc->getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); } void test_storage_saves_global_variable() @@ -75,8 +75,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_TYPE_OF) + ":Global->char") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_global_variable_static() @@ -89,8 +89,8 @@ public: //TS_ASSERT(node->getComponent()); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_field() @@ -105,8 +105,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_TYPE_OF) + ":m_field->bool") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_field_as_member() @@ -128,8 +128,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_TYPE_OF) + ":Struct::m_field->bool") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_function() @@ -147,9 +147,9 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_RETURN_TYPE_OF) + ":isTrue->bool") != 0); TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_PARAMETER_TYPE_OF) + ":isTrue->char") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 2); - TS_ASSERT_EQUALS(tlc.getTokenLocations().find(4)->second->getType(), TokenLocation::LOCATION_SCOPE); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 2); + TS_ASSERT_EQUALS(tlc->getTokenLocations().find(4)->second->getType(), TokenLocation::LOCATION_SCOPE); } void test_storage_saves_method() @@ -171,9 +171,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_RETURN_TYPE_OF) + ":isMethod->void") != 0); TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_PARAMETER_TYPE_OF) + ":isMethod->bool") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 2); - TS_ASSERT_EQUALS(tlc.getTokenLocations().find(4)->second->getType(), TokenLocation::LOCATION_SCOPE); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 2); } void test_storage_saves_method_static() @@ -226,9 +225,9 @@ public: TS_ASSERT_EQUALS(storage.getNameForNodeWithId(id), "utility"); TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(id), Node::NODE_NAMESPACE); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 2); - TS_ASSERT_EQUALS(tlc.getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 2); + TS_ASSERT_EQUALS(tlc->getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); } void test_storage_saves_enum() @@ -239,9 +238,9 @@ public: TS_ASSERT_EQUALS(storage.getNameForNodeWithId(id), "Category"); TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(id), Node::NODE_ENUM); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 2); - TS_ASSERT_EQUALS(tlc.getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 2); + TS_ASSERT_EQUALS(tlc->getTokenLocations().find(2)->second->getType(), TokenLocation::LOCATION_SCOPE); } void test_storage_saves_enum_as_member() @@ -268,8 +267,8 @@ public: TS_ASSERT_EQUALS(storage.getNameForNodeWithId(id), "VALUE"); TS_ASSERT_EQUALS(storage.getNodeTypeForNodeWithId(id), Node::NODE_ENUM_CONSTANT); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_class_inheritance() @@ -286,8 +285,8 @@ public: //TS_ASSERT(edge->getComponent()); //TS_ASSERT_EQUALS(edge->getComponent()->getAccess(), TokenComponentAccess::ACCESS_PUBLIC); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_struct_inheritance() @@ -305,8 +304,8 @@ public: //TS_ASSERT(edge->getComponent()); //TS_ASSERT_EQUALS(edge->getComponent()->getAccess(), TokenComponentAccess::ACCESS_PUBLIC); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_method_override() @@ -341,8 +340,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_CALL) + ":isTrue->func") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_call_in_global_variable_declaration() @@ -361,8 +360,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_CALL) + ":global->isTrue") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_field_usage() @@ -383,8 +382,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_USAGE) + ":isTrue->Foo::m_field") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_global_variable_usage() @@ -403,8 +402,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_USAGE) + ":isTrue->global") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_saves_type_usage() @@ -424,8 +423,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_TYPE_USAGE) + ":isTrue->Struct") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_clears_single_file_data_of_single_file_storage() @@ -565,8 +564,8 @@ public: TS_ASSERT(storage.getIdForEdgeWithName(Edge::getTypeString(Edge::EDGE_INCLUDE) + ":file.cpp->file.h") != 0); - TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id); - TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1); + std::shared_ptr tlc = storage.getLocationCollectionForTokenId(id); + TS_ASSERT_EQUALS(tlc->getTokenLocationCount(), 1); } void test_storage_finds_and_removes_depending_file_nodes() @@ -605,9 +604,10 @@ private: : Storage("data/test.sqlite") { clear(); + onFileParsed(FileInfo("file.cpp")); } - TokenLocationCollection getLocationCollectionForTokenId(Id id) const + std::shared_ptr getLocationCollectionForTokenId(Id id) const { std::vector tokenIds; tokenIds.push_back(id);