test: added GraphFilter and GraphFilterConductor tests
This commit is contained in:
@@ -628,6 +628,11 @@ TokenLocationFile Storage::getTokenLocationsForLinesInFile(
|
||||
return ret;
|
||||
}
|
||||
|
||||
const Graph& Storage::getGraph() const
|
||||
{
|
||||
return m_graph;
|
||||
}
|
||||
|
||||
Token* Storage::getTokenWithId(Id tokenId) const
|
||||
{
|
||||
return m_graph.getTokenById(tokenId);
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
) const;
|
||||
|
||||
protected:
|
||||
const Graph& getGraph() const;
|
||||
Token* getTokenWithId(Id tokenId) const;
|
||||
std::vector<TokenLocation*> getTokenLocationsForId(Id tokenId) const;
|
||||
|
||||
|
||||
@@ -118,13 +118,13 @@ std::string Edge::getTypeString(EdgeType type) const
|
||||
case EDGE_MEMBER:
|
||||
return "child";
|
||||
case EDGE_TYPE_OF:
|
||||
return "type use";
|
||||
return "type_use";
|
||||
case EDGE_RETURN_TYPE_OF:
|
||||
return "return type";
|
||||
return "return_type";
|
||||
case EDGE_PARAMETER_TYPE_OF:
|
||||
return "parameter type";
|
||||
return "parameter_type";
|
||||
case EDGE_TYPE_USAGE:
|
||||
return "type usage";
|
||||
return "type_usage";
|
||||
case EDGE_INHERITANCE:
|
||||
return "inheritance";
|
||||
case EDGE_CALL:
|
||||
|
||||
@@ -30,3 +30,24 @@ void FilterableGraph::print(std::ostream& ostream) const
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void FilterableGraph::printBasic(std::ostream& ostream) const
|
||||
{
|
||||
ostream << getNodeCount() << " nodes:";
|
||||
forEachNode(
|
||||
[&ostream](Node* n)
|
||||
{
|
||||
ostream << ' ' << n->getTypeString() << ':' << n->getFullName();
|
||||
}
|
||||
);
|
||||
ostream << '\n';
|
||||
|
||||
ostream << getEdgeCount() << " edges:";
|
||||
forEachEdge(
|
||||
[&ostream](Edge* e)
|
||||
{
|
||||
ostream << ' ' << e->getName();
|
||||
}
|
||||
);
|
||||
ostream << '\n';
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
virtual size_t getEdgeCount() const = 0;
|
||||
|
||||
void print(std::ostream& ostream) const;
|
||||
void printBasic(std::ostream& ostream) const;
|
||||
};
|
||||
|
||||
#endif // FILTERABLE_GRAPH_H
|
||||
|
||||
@@ -14,6 +14,28 @@ Graph::~Graph()
|
||||
m_nodes.clear();
|
||||
}
|
||||
|
||||
Graph& Graph::operator=(const Graph& other)
|
||||
{
|
||||
if (&other != this)
|
||||
{
|
||||
other.forEachNode(
|
||||
[this](Node* node)
|
||||
{
|
||||
addNodeAsPlainCopy(node);
|
||||
}
|
||||
);
|
||||
|
||||
other.forEachEdge(
|
||||
[this](Edge* edge)
|
||||
{
|
||||
addEdgeAsPlainCopy(edge);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Graph::copy(const FilterableGraph* other)
|
||||
{
|
||||
clear();
|
||||
|
||||
@@ -15,6 +15,7 @@ class Graph
|
||||
public:
|
||||
Graph();
|
||||
virtual ~Graph();
|
||||
Graph& operator=(const Graph& other);
|
||||
|
||||
// FilterableGraph implementation
|
||||
virtual void copy(const FilterableGraph* other);
|
||||
@@ -71,8 +72,6 @@ private:
|
||||
Edge* insertEdge(Edge::EdgeType type, Node* from, Node* to);
|
||||
void removeEdgeInternal(Edge* edge);
|
||||
|
||||
const std::string m_delimiter;
|
||||
|
||||
std::map<Id, std::shared_ptr<Node>> m_nodes;
|
||||
std::map<Id, std::shared_ptr<Edge>> m_edges;
|
||||
};
|
||||
|
||||
@@ -268,7 +268,7 @@ std::string Node::getTypeString(NodeType type) const
|
||||
case NODE_UNDEFINED:
|
||||
return "undefined";
|
||||
case NODE_UNDEFINED_FUNCTION:
|
||||
return "undefined function";
|
||||
return "undefined_function";
|
||||
case NODE_CLASS:
|
||||
return "class";
|
||||
case NODE_STRUCT:
|
||||
|
||||
@@ -56,22 +56,22 @@ class GraphFilterCommandNodeType
|
||||
: public GraphFilter
|
||||
{
|
||||
public:
|
||||
GraphFilterCommandNodeType(Node::NodeType type)
|
||||
: m_type(type)
|
||||
GraphFilterCommandNodeType(Node::NodeTypeMask mask)
|
||||
: m_mask(mask)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void visitNode(Node* node)
|
||||
{
|
||||
if (node->getType() == m_type)
|
||||
if (node->isType(m_mask))
|
||||
{
|
||||
addNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const Node::NodeType m_type;
|
||||
const Node::NodeTypeMask m_mask;
|
||||
};
|
||||
|
||||
class GraphFilterCommandConst
|
||||
@@ -254,7 +254,6 @@ private:
|
||||
const bool m_super;
|
||||
};
|
||||
|
||||
|
||||
class GraphFilterToken
|
||||
: public GraphFilter
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "data/parser/Parser.h"
|
||||
|
||||
Parser::Parser(std::shared_ptr<ParserClient> client)
|
||||
Parser::Parser(ParserClient* client)
|
||||
: m_client(client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ class TextAccess;
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser(std::shared_ptr<ParserClient> client);
|
||||
Parser(ParserClient* client);
|
||||
virtual ~Parser();
|
||||
|
||||
virtual void parseFiles(const std::vector<std::string>& filePaths) = 0;
|
||||
virtual void parseFile(std::shared_ptr<TextAccess> textAccess) = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
ParserClient* m_client;
|
||||
};
|
||||
|
||||
#endif // PARSER_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "data/parser/cxx/ASTAction.h"
|
||||
|
||||
ASTAction::ASTAction(std::shared_ptr<ParserClient> client)
|
||||
ASTAction::ASTAction(ParserClient* client)
|
||||
: m_client(client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
class ASTAction : public clang::ASTFrontendAction
|
||||
{
|
||||
public:
|
||||
explicit ASTAction(std::shared_ptr<ParserClient> client);
|
||||
explicit ASTAction(ParserClient* client);
|
||||
virtual ~ASTAction();
|
||||
|
||||
virtual clang::ASTConsumer* CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
ParserClient* m_client;
|
||||
};
|
||||
|
||||
#endif // AST_ACTION_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "data/parser/cxx/ASTActionFactory.h"
|
||||
|
||||
ASTActionFactory::ASTActionFactory(std::shared_ptr<ParserClient> client)
|
||||
ASTActionFactory::ASTActionFactory(ParserClient* client)
|
||||
: m_client(client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
class ASTActionFactory : public clang::tooling::FrontendActionFactory
|
||||
{
|
||||
public:
|
||||
explicit ASTActionFactory(std::shared_ptr<ParserClient> client);
|
||||
explicit ASTActionFactory(ParserClient* client);
|
||||
virtual ~ASTActionFactory();
|
||||
|
||||
virtual clang::FrontendAction* create();
|
||||
|
||||
private:
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
ParserClient* m_client;
|
||||
};
|
||||
|
||||
#endif // AST_ACTION_FACTORY
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "data/parser/cxx/ASTConsumer.h"
|
||||
|
||||
ASTConsumer::ASTConsumer(clang::ASTContext* context, std::shared_ptr<ParserClient> client)
|
||||
ASTConsumer::ASTConsumer(clang::ASTContext* context, ParserClient* client)
|
||||
: m_visitor(context, client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
class ASTConsumer : public clang::ASTConsumer
|
||||
{
|
||||
public:
|
||||
explicit ASTConsumer(clang::ASTContext* context, std::shared_ptr<ParserClient> client);
|
||||
explicit ASTConsumer(clang::ASTContext* context, ParserClient* client);
|
||||
virtual ~ASTConsumer();
|
||||
|
||||
virtual void HandleTranslationUnit(clang::ASTContext& context);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "data/parser/ParseVariable.h"
|
||||
#include "data/type/DataType.h"
|
||||
|
||||
ASTVisitor::ASTVisitor(clang::ASTContext* context, std::shared_ptr<ParserClient> client)
|
||||
ASTVisitor::ASTVisitor(clang::ASTContext* context, ParserClient* client)
|
||||
: m_context(context)
|
||||
, m_client(client)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef AST_VISITOR_H
|
||||
#define AST_VISITOR_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/RecursiveASTVisitor.h"
|
||||
|
||||
@@ -14,7 +12,7 @@ class ASTVisitor
|
||||
, public ASTBodyVisitorClient
|
||||
{
|
||||
public:
|
||||
ASTVisitor(clang::ASTContext* context, std::shared_ptr<ParserClient> client);
|
||||
ASTVisitor(clang::ASTContext* context, ParserClient* client);
|
||||
virtual ~ASTVisitor();
|
||||
|
||||
// Left for debugging purposes. Uncomment to see a colored ast-dump of the parsed file.
|
||||
@@ -66,7 +64,7 @@ private:
|
||||
ParseFunction getParseFunction(clang::FunctionDecl* declaration) const;
|
||||
|
||||
clang::ASTContext* m_context;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
ParserClient* m_client;
|
||||
};
|
||||
|
||||
#endif // AST_VISITOR_H
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
CxxParser::CxxParser(std::shared_ptr<ParserClient> client)
|
||||
CxxParser::CxxParser(ParserClient* client)
|
||||
: Parser(client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
class CxxParser: public Parser
|
||||
{
|
||||
public:
|
||||
CxxParser(std::shared_ptr<ParserClient> client);
|
||||
CxxParser(ParserClient* client);
|
||||
~CxxParser();
|
||||
|
||||
virtual void parseFiles(const std::vector<std::string>& filePaths);
|
||||
|
||||
Reference in New Issue
Block a user