Skip to content

Commit

Permalink
Delete all CppNodes recursively when deleting one on incremental pars…
Browse files Browse the repository at this point in the history
…ing maintenance.
  • Loading branch information
mcserep committed Jun 26, 2018
1 parent f333077 commit 09d2685
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
3 changes: 3 additions & 0 deletions plugins/cpp/parser/include/cppparser/cppparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#define CC_PARSER_CXXPARSER_H

#include <map>
#include <set>
#include <unordered_set>
#include <vector>

#include <clang/Tooling/JSONCompilationDatabase.h>
#include <clang/Tooling/Tooling.h>

#include <model/buildaction.h>
#include <model/cppnode.h>

#include <parser/abstractparser.h>
#include <parser/parsercontext.h>
Expand Down Expand Up @@ -88,6 +90,7 @@ class CppParser : public AbstractParser
void incrementalParse();
void markAsModified(const model::File& file_);
void initBuildActions();
std::set<model::CppNodeId> collectNodeSet(model::CppNodeId node_) const;

std::unordered_set<std::uint64_t> _parsedCommandHashes;
std::unordered_map<std::string, IncrementalStatus> _fileStatus;
Expand Down
59 changes: 53 additions & 6 deletions plugins/cpp/parser/src/cppparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,16 @@ void CppParser::incrementalParse()
_ctx.db->erase<model::CppFriendship>(friendship.id);
}

// Delete CppNode (connected to CppAstNode)
// Delete CppNode (connected to CppAstNode) with all its connected CppNodes
auto delNodes = _ctx.db->query<model::CppNode>(
odb::query<model::CppNode>::domainId == std::to_string(astNode.id) &&
odb::query<model::CppNode>::domain == model::CppNode::CPPASTNODE);
for(const model::CppNode& node : delNodes)
for(model::CppNode& node : delNodes)
{
_ctx.db->erase<model::CppNode>(node.id);
for(model::CppNodeId nodeId : collectNodeSet(node.id))
{
_ctx.db->erase<model::CppNode>(nodeId);
}
}
}

Expand All @@ -440,13 +443,16 @@ void CppParser::incrementalParse()
_ctx.db->erase<model::BuildAction>(source.action->id);
}

// Delete CppNode (connected to File)
// Delete CppNode (connected to File) with all its connected CppNodes
auto delNodes = _ctx.db->query<model::CppNode>(
odb::query<model::CppNode>::domainId == std::to_string(delFile->id) &&
odb::query<model::CppNode>::domain == model::CppNode::FILE);
for(const model::CppNode& node : delNodes)
for(model::CppNode& node : delNodes)
{
_ctx.db->erase<model::CppNode>(node.id);
for(model::CppNodeId nodeId : collectNodeSet(node.id))
{
_ctx.db->erase<model::CppNode>(nodeId);
}
}

// Delete File and FileContent (only when no other File references it)
Expand Down Expand Up @@ -488,6 +494,47 @@ bool CppParser::parse()
return success;
}

std::set<model::CppNodeId> CppParser::collectNodeSet(model::CppNodeId node_) const
{
std::set<model::CppNodeId> nodes;
std::queue<model::CppNodeId> processQueue;

nodes.insert(node_);
processQueue.push(node_);

while(!processQueue.empty())
{
auto nodeId = processQueue.front();
processQueue.pop();

// Fetch nodes on edges where current node has a 'from' role
auto fromEdges = _ctx.db->query<model::CppEdge>(
odb::query<model::CppEdge>::from == nodeId);
for (const model::CppEdge &edge : fromEdges)
{
if (!nodes.count(edge.to->id))
{
nodes.insert(edge.to->id);
processQueue.push(edge.to->id);
}
}

// Fetch nodes on edges where current node has a 'to' role
auto toEdges = _ctx.db->query<model::CppEdge>(
odb::query<model::CppEdge>::to == nodeId);
for (const model::CppEdge &edge : toEdges)
{
if (!nodes.count(edge.from->id))
{
nodes.insert(edge.from->id);
processQueue.push(edge.from->id);
}
}
}

return nodes;
}

void CppParser::initBuildActions()
{
(util::OdbTransaction(_ctx.db))([&, this] {
Expand Down

0 comments on commit 09d2685

Please sign in to comment.