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
This commit is contained in:
Eberhard Graether
2015-09-23 09:26:03 +02:00
parent e9d45a507a
commit 78c1b32797
27 changed files with 308 additions and 260 deletions
-89
View File
@@ -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
+1 -1
View File
@@ -278,7 +278,7 @@ std::shared_ptr<QtGraphNode> QtGraphView::createNodeRecursive(
std::shared_ptr<QtGraphNode> newNode;
if (node.isGraphNode())
{
newNode = std::make_shared<QtGraphNodeData>(node.data, node.hasNamespace, node.childVisible);
newNode = std::make_shared<QtGraphNodeData>(node.data, node.hasParent, node.childVisible);
}
else if (node.isAccessNode())
{
@@ -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());
}
@@ -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;
+13 -14
View File
@@ -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<FilePath> 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<TaskParseCxx>(
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<FilePath> headerSearchSubPaths;
for(FilePath p : projSettings->getHeaderSearchPaths())
{
std::vector<FilePath> tempPaths = FileSystem::getSubDirectories(p);
headerSearchSubPaths.insert( headerSearchSubPaths.end(), tempPaths.begin(), tempPaths.end() );
}
// std::vector<FilePath> headerSearchSubPaths;
// for(FilePath p : projSettings->getHeaderSearchPaths())
// {
// std::vector<FilePath> 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());
@@ -49,13 +49,13 @@ void CodeController::handleMessage(MessageActivateTokens* message)
return;
}
TokenLocationCollection collection = m_storageAccess->getTokenLocationsForTokenIds(activeTokenIds);
view->showCodeSnippets(getSnippetsForActiveTokenLocations(collection, declarationId));
std::shared_ptr<TokenLocationCollection> 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<TokenLocationCollection> collection =
m_storageAccess->getTokenLocationsForLocationIds(std::vector<Id>(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<CodeView::CodeSnippetParams> snippets = getSnippetsForActiveTokenLocations(collection, 0);
std::vector<CodeView::CodeSnippetParams> snippets = getSnippetsForActiveTokenLocations(collection.get(), 0);
if (snippets.size() != 1)
{
@@ -150,11 +150,11 @@ CodeView* CodeController::getView()
}
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocations(
const TokenLocationCollection& collection, Id declarationId
const TokenLocationCollection* collection, Id declarationId
) const {
std::vector<CodeView::CodeSnippetParams> snippets;
collection.forEachTokenLocationFile(
collection->forEachTokenLocationFile(
[&](std::shared_ptr<TokenLocationFile> file) -> void
{
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
@@ -47,7 +47,7 @@ private:
CodeView* getView();
std::vector<CodeView::CodeSnippetParams> getSnippetsForActiveTokenLocations(
const TokenLocationCollection& collection, Id declarationId) const;
const TokenLocationCollection* collection, Id declarationId) const;
std::vector<CodeView::CodeSnippetParams> getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const;
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
TokenLocation* location, SnippetMerger& fileScopedMerger, std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
@@ -164,6 +164,11 @@ void GraphController::createDummyGraphForTokenIds(const std::vector<Id>& tokenId
}
);
for (DummyNode& node : dummyNodes)
{
node.hasParent = false;
}
m_dummyNodes = dummyNodes;
autoExpandActiveNode(tokenIds);
@@ -290,14 +295,14 @@ std::vector<DummyNode> GraphController::splitNamespaceNodesRecursive(const Dummy
std::vector<DummyNode> 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<DummyNode> 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::vector<DummyNode
{
if (node.isGraphNode())
{
if (node.data->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE))
if (node.data->isType(Node::NODE_NOT_VISIBLE))
{
DummyNode* result = findDummyNodeRecursive(node.subNodes, tokenId);
if (result != nullptr)
@@ -52,6 +52,9 @@ private:
void createDummyGraphForTokenIds(const std::vector<Id>& tokenIds);
DummyNode createDummyNodeTopDown(Node* node);
void splitNamespaceNodes();
std::vector<DummyNode> splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel);
void autoExpandActiveNode(const std::vector<Id>& activeTokenIds);
void setActiveAndVisibility(const std::vector<Id>& activeTokenIds);
@@ -59,9 +62,6 @@ private:
bool setNodeVisibilityRecursiveBottomUp(DummyNode& node) const;
void setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const;
void splitNamespaceNodes();
std::vector<DummyNode> splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel);
void bundleNodes();
void bundleNodesMatching(std::function<bool(const DummyNode&)> matcher, size_t count, const std::string& name);
bool isTypeNodeWithSingleAggregation(const DummyNode& node, TokenComponentAggregation::Direction direction) const;
@@ -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;
+10
View File
@@ -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<StorageFile> 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;");
+1
View File
@@ -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<StorageFile> getAllFiles() const;
void setNodeType(int type, Id nodeId);
+137 -72
View File
@@ -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<FilePath> Storage::getDependingFilePaths(const FilePath& filePath)
{
std::set<FilePath> dependingFilePaths;
Id fileNodeId = m_sqliteStorage.getFileByName(filePath.fileName()).id;
Id fileNodeId = getFileNodeId(filePath);
std::vector<StorageEdge> incomingEdges = m_sqliteStorage.getEdgesByTargetType(
fileNodeId, Edge::typeToInt(Edge::EDGE_INCLUDE)
);
@@ -93,11 +95,16 @@ std::set<FilePath> 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<NameElement>(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<SearchMatch> Storage::getAutocompletionMatches(const std::string& qu
return matches;
}
#include "utility/utility.h"
#include <iostream>
std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const
{
std::shared_ptr<Graph> g = std::make_shared<Graph>();
@@ -692,17 +711,40 @@ std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>&
{
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<StorageEdge> 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<Id> Storage::getTokenIdsForAggregationEdge(Id sourceId, Id targetId)
return edgeIds;
}
TokenLocationCollection Storage::getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const
std::shared_ptr<TokenLocationCollection> Storage::getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const
{
TokenLocationCollection collection;
std::shared_ptr<TokenLocationCollection> collection = std::make_shared<TokenLocationCollection>();
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<Id>& locationIds) const
std::shared_ptr<TokenLocationCollection> Storage::getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const
{
TokenLocationCollection collection;
std::shared_ptr<TokenLocationCollection> collection = std::make_shared<TokenLocationCollection>();
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<FilePath, Id>::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<StorageEdge> 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<StorageEdge> unprocessedEdges;
node = addNodeToGraph(nodeId, graph);
std::vector<StorageEdge> memberEdges = m_sqliteStorage.getEdgesBySourceType(nodeId, Edge::EDGE_MEMBER);
for (const StorageEdge& edge : memberEdges)
{
std::vector<StorageEdge> 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<StorageEdge> 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<TokenComponentNameCached>(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<TokenComponentNameCached>(m_tokenIndex.getNameHierarchyForTokenId(nodeId))
);
}
return node;
}
TokenComponentAccess::AccessType Storage::convertAccessType(ParserClient::AccessType access) const
+11 -2
View File
@@ -27,7 +27,9 @@ public:
void clearFileElements(const FilePath& filePath);
std::set<FilePath> getDependingFilePaths(const std::set<FilePath>& filePaths);
std::set<FilePath> 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<Id> getTokenIdsForAggregationEdge(Id sourceId, Id targetId) const;
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
virtual std::shared_ptr<TokenLocationFile> 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<Id> getDirectChildNodeIds(const Id nodeId) const;
std::vector<Id> getAllChildNodeIds(const Id nodeId) const;
@@ -167,6 +174,8 @@ private:
SearchIndex m_tokenIndex;
SqliteStorage m_sqliteStorage;
std::map <FilePath, Id> m_fileNodeIds;
TokenLocationCollection m_errorLocationCollection;
std::vector<std::string> m_errorMessages;
};
+2 -2
View File
@@ -41,8 +41,8 @@ public:
virtual Id getTokenIdForFileNode(const FilePath& filePath) const = 0;
virtual std::vector<Id> getTokenIdsForAggregationEdge(Id sourceId, Id targetId) const = 0;
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const = 0;
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const = 0;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const = 0;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
+4 -4
View File
@@ -153,24 +153,24 @@ std::vector<Id> StorageAccessProxy::getTokenIdsForAggregationEdge(Id sourceId, I
return std::vector<Id>();
}
TokenLocationCollection StorageAccessProxy::getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const
{
if (hasSubject())
{
return m_subject->getTokenLocationsForTokenIds(tokenIds);
}
return TokenLocationCollection();
return std::make_shared<TokenLocationCollection>();
}
TokenLocationCollection StorageAccessProxy::getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const
{
if (hasSubject())
{
return m_subject->getTokenLocationsForLocationIds(locationIds);
}
return TokenLocationCollection();
return std::make_shared<TokenLocationCollection>();
}
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationsForFile(const std::string& filePath) const
+2 -2
View File
@@ -32,8 +32,8 @@ public:
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
virtual std::vector<Id> getTokenIdsForAggregationEdge(Id sourceId, Id targetId) const;
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
virtual std::shared_ptr<TokenLocationCollection> getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
+2
View File
@@ -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)
+2
View File
@@ -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<TokenComponentName> nameComponent);
Node(const Node& other);
virtual ~Node();
+3
View File
@@ -51,6 +51,9 @@ public:
ParserClient();
virtual ~ParserClient();
virtual void startParsing() = 0;
virtual void finishParsing() = 0;
virtual void prepareParsingFile() = 0;
virtual void finishParsingFile() = 0;
+6
View File
@@ -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(
+20
View File
@@ -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<Id, SearchNode*>::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);
+5
View File
@@ -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<SearchMatch> runFuzzySearchAndGetMatches(const std::string& query) const;
@@ -44,6 +47,8 @@ private:
SearchNode m_root;
Dictionary m_dictionary;
std::map<Id, SearchNode*> m_tokenIds;
friend std::ostream& operator<<(std::ostream& ostream, const SearchIndex& index);
};
+4 -3
View File
@@ -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<std::string> SearchNode::getNameHierarchy() const
NameHierarchy SearchNode::getNameHierarchy() const
{
std::vector<std::string> nameHierarchy;
NameHierarchy nameHierarchy;
const SearchNode* parent = getParent();
if (parent && parent->m_nameId)
{
nameHierarchy = parent->getNameHierarchy();
}
nameHierarchy.push_back(getName());
nameHierarchy.push(std::make_shared<NameElement>(getName()));
return nameHierarchy;
}
+2 -1
View File
@@ -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<std::string> getNameHierarchy() const;
NameHierarchy getNameHierarchy() const;
std::string getFullName() const;
Id getNameId() const;
+8
View File
@@ -2457,6 +2457,14 @@ private:
class TestParserClient: public ParserClient
{
public:
virtual void startParsing()
{
}
virtual void finishParsing()
{
}
virtual void prepareParsingFile()
{
}
+47 -47
View File
@@ -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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenComponentStatic>());
TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id);
TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1);
std::shared_ptr<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenComponentAccess>());
//TS_ASSERT_EQUALS(edge->getComponent<TokenComponentAccess>()->getAccess(), TokenComponentAccess::ACCESS_PUBLIC);
TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id);
TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1);
std::shared_ptr<TokenLocationCollection> 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<TokenComponentAccess>());
//TS_ASSERT_EQUALS(edge->getComponent<TokenComponentAccess>()->getAccess(), TokenComponentAccess::ACCESS_PUBLIC);
TokenLocationCollection tlc = storage.getLocationCollectionForTokenId(id);
TS_ASSERT_EQUALS(tlc.getTokenLocationCount(), 1);
std::shared_ptr<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> 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<TokenLocationCollection> getLocationCollectionForTokenId(Id id) const
{
std::vector<Id> tokenIds;
tokenIds.push_back(id);