data: added Graph data structure for storing code semantics in Storage
This change adds graph data structures Token, Node, Edge and Graph for holding code semantics in the Storage and fills them with the parsed data. Things to note: * Token is the base for the classes Edge and Node and holds a unique id. * Graph is the owner of all Nodes and Edges. * A Node saves the Edges it is endpoint of. * An Edge saves the Nodes that are endpoints. * Nodes and Edges are not subclassed. The different Node and Edge types are distinguished by the enums NodeType and EdgeType. Type specific fields are therefore available for all types, a check when assigning them prohibits faulty usage. * Storage uses the Graph::getNodeHierarchy method, which is not strict about knowing type names beforehand. E.g. if A::B is passed in and A doesn't exist so far, then node A gets created as NODE_UNDEFINED with B as it's child. * The Graph methods addNodeAsPlainCopy and addEdgeAsPlainCopy can be used to create a sub-graph without reference to the original, but with the same ids. review id = 19 fortune cookie message = Your cheerful outlook is one of your best assets.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
#ifndef EDGE_H
|
||||
#define EDGE_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "data/graph/Token.h"
|
||||
|
||||
class Node;
|
||||
|
||||
class Edge: public Token
|
||||
{
|
||||
public:
|
||||
enum EdgeType
|
||||
{
|
||||
EDGE_MEMBER,
|
||||
EDGE_TYPE_OF,
|
||||
EDGE_RETURN_TYPE_OF,
|
||||
EDGE_PARAMETER_OF,
|
||||
EDGE_USAGE,
|
||||
EDGE_CALL,
|
||||
EDGE_INHERITANCE
|
||||
};
|
||||
|
||||
enum AccessType
|
||||
{
|
||||
ACCESS_PUBLIC,
|
||||
ACCESS_PROTECTED,
|
||||
ACCESS_PRIVATE,
|
||||
ACCESS_NONE
|
||||
};
|
||||
|
||||
Edge(EdgeType type, Node* from, Node* to);
|
||||
virtual ~Edge();
|
||||
|
||||
std::shared_ptr<Edge> createPlainCopy(Node* from, Node* to) const;
|
||||
|
||||
EdgeType getType() const;
|
||||
|
||||
Node* getFrom() const;
|
||||
Node* getTo() const;
|
||||
|
||||
// Token implementation
|
||||
virtual bool isNode() const;
|
||||
virtual bool isEdge() const;
|
||||
|
||||
// Additional field accessors for different EdgeTypes.
|
||||
AccessType getAccess() const;
|
||||
void setAccess(AccessType access);
|
||||
|
||||
// Logging.
|
||||
std::string getTypeString() const;
|
||||
std::string getAccessString() const;
|
||||
std::string getAsString() const;
|
||||
|
||||
private:
|
||||
// Constructor for plain copies.
|
||||
Edge(Id id, EdgeType type, Node* from, Node* to);
|
||||
|
||||
const EdgeType m_type;
|
||||
|
||||
Node* const m_from;
|
||||
Node* const m_to;
|
||||
|
||||
// Additional fields for different EdgeTypes.
|
||||
AccessType m_access;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& ostream, const Edge& edge);
|
||||
|
||||
#endif // EDGE_H
|
||||
Reference in New Issue
Block a user