30 #ifndef GENERICGRAPH_H_
31 #define GENERICGRAPH_H_
41 template <
typename,
typename>
class GenericGraphWriter;
42 template <
typename,
typename>
class GenericGraphReader;
48 template<
class NodeTy>
125 return (rhs->
edgeFlag == this->edgeFlag &&
126 rhs->
getSrcID() == this->getSrcID() &&
127 rhs->
getDstID() == this->getDstID());
301 "the number of ICFGNodeKinds has changed, make sure "
302 "the range is correct");
309 "the number of InterICFGNodeKind has changed, make sure "
310 "the range is correct");
317 "The number of SVFVarKinds has changed, make sure the "
320 return n <= DummyObjNode && n >=
ValNode;
326 "The number of ValVarKinds has changed, make sure the "
328 return n <= DummyValNode && n >=
ValNode;
334 "The number of ObjVarKinds has changed, make sure the "
336 return n <= DummyObjNode && n >=
ObjNode;
342 "The number of VFGNodeKinds has changed, make sure the "
344 return n <= MInterPhi && n >=
Cmp;
350 "The number of ArgumentVFGNodeKinds has changed, make "
351 "sure the range is correct");
352 return n <= FParm && n >=
FRet;
358 "The number of StmtVFGNodeKinds has changed, make sure "
359 "the range is correct");
360 return n <= Load && n >=
Addr;
366 "The number of PHIVFGNodeKinds has changed, make sure "
367 "the range is correct");
368 return n <= TInterPhi && n >=
TPhi;
374 "The number of MRSVFGNodeKinds has changed, make sure "
375 "the range is correct");
376 return n <= MInterPhi && n >=
FPIN;
382 "The number of MSSAPHISVFGNodeKinds has changed, make "
383 "sure the range is correct");
384 return n <= MInterPhi && n >=
MPhi;
392 template<
class NodeTy,
class EdgeTy>
444 return (
InEdges.empty() ==
false);
529 return InEdges.insert(inEdge).second;
533 return OutEdges.insert(outEdge).second;
542 assert(it !=
InEdges.end() &&
"can not find in edge in SVFG node");
549 assert(it !=
OutEdges.end() &&
"can not find out edge in SVFG node");
590 template<
class NodeTy,
class EdgeTy>
656 assert(it !=
IDToNodeMap.end() &&
"Node not found!");
670 assert(node->hasIncomingEdge() ==
false
671 && node->hasOutgoingEdge() ==
false
672 &&
"node which have edges can't be deleted");
674 assert(it !=
IDToNodeMap.end() &&
"can not find the node");
718 template <
typename ItTy,
typename FuncTy,
719 typename FuncReturnTy =
720 decltype(std::declval<FuncTy>()(*std::declval<ItTy>()))>
723 mapped_iter<ItTy, FuncTy>, ItTy,
724 typename std::iterator_traits<ItTy>::iterator_category,
725 typename std::remove_reference<FuncReturnTy>::type>
747 template <
class ItTy,
class FuncTy>
763 return E->getDstNode();
776 return map_iter(N->OutEdgeBegin(), &edge_dest);
780 return map_iter(N->OutEdgeEnd(), &edge_dest);
784 return map_iter(N->directOutEdgeBegin(), &edge_dest);
788 return map_iter(N->directOutEdgeEnd(), &edge_dest);
795 template<
class NodeTy,
class EdgeTy>
803 return E->getSrcNode();
816 return map_iter(N->InEdgeBegin(), &edge_dest);
820 return map_iter(N->InEdgeEnd(), &edge_dest);
843 typedef std::pair<SVF::NodeID, NodeType*>
PairTy;
virtual bool operator==(const GenericEdge< NodeType > *rhs) const
GEdgeKind getEdgeKindWithoutMask() const
struct SVF::GenericEdge::equalGEdge equalGEdge
Add the hash function for std::set (we also can overload operator< to implement this)
virtual ~GenericEdge()
Destructor.
GenericEdge(NodeTy *s, NodeTy *d, GEdgeFlag k)
Constructor.
static constexpr u64_t EdgeKindMask
GEdgeFlag edgeFlag
edge kind
NodeTy * dst
destination node
NodeType * getSrcNode() const
GEdgeKind getEdgeKind() const
NodeID getSrcID() const
get methods of the components
NodeType * getDstNode() const
static constexpr unsigned char EdgeKindMaskBits
We use the lower 8 bits to denote edge kind.
NodeTy NodeType
Node type.
void addGNode(NodeID id, NodeType *node)
Add a Node.
iterator begin()
Iterators.
void removeGNode(NodeType *node)
Delete a node.
u32_t getTotalEdgeNum() const
u32_t edgeNum
total num of node
const_iterator end() const
const_iterator begin() const
u32_t nodeNum
total num of edge
virtual ~GenericGraph()
Destructor.
NodeType * getGNode(NodeID id) const
Get a node.
IDToNodeMapTy IDToNodeMap
node map
IDToNodeMapTy::const_iterator const_iterator
bool hasGNode(NodeID id) const
Has a node.
void incNodeNum()
Increase number of node/edge.
u32_t getTotalNodeNum() const
Get total number of node/edge.
GenericGraph()
Constructor.
IDToNodeMapTy::iterator iterator
Node Iterators.
void destroy()
Release memory.
OrderedMap< NodeID, NodeType * > IDToNodeMapTy
NodeID to GenericNode map.
const_iterator InEdgeEnd() const
OrderedSet< EdgeType *, typename EdgeType::equalGEdge > GEdgeSetTy
Edge kind.
GEdgeSetTy OutEdges
all outgoing edge of this node
bool hasIncomingEdge() const
Has incoming/outgoing edge set.
bool hasOutgoingEdge() const
static bool classof(const SVFBaseNode *)
u32_t removeOutgoingEdge(EdgeType *edge)
virtual iterator directInEdgeEnd()
GEdgeSetTy InEdges
all incoming edge of this node
const GEdgeSetTy & getOutEdges() const
GEdgeSetTy::iterator iterator
virtual ~GenericNode()
Destructor.
virtual iterator directInEdgeBegin()
const_iterator OutEdgeBegin() const
virtual iterator directOutEdgeEnd()
const_iterator InEdgeBegin() const
virtual const_iterator directOutEdgeEnd() const
bool addIncomingEdge(EdgeType *inEdge)
Add incoming and outgoing edges.
u32_t removeIncomingEdge(EdgeType *edge)
EdgeType * hasOutgoingEdge(EdgeType *edge) const
virtual iterator directOutEdgeBegin()
Iterators used for SCC detection, overwrite it in child class if necessary.
iterator OutEdgeBegin()
iterators
virtual const_iterator directInEdgeEnd() const
static bool classof(const GenericNode< NodeTy, EdgeTy > *)
virtual const_iterator directInEdgeBegin() const
GEdgeSetTy::const_iterator const_iterator
GenericNode(NodeID i, GNodeK k)
Constructor.
const_iterator OutEdgeEnd() const
virtual const_iterator directOutEdgeBegin() const
EdgeType * hasIncomingEdge(EdgeType *edge) const
Find incoming and outgoing edges.
bool addOutgoingEdge(EdgeType *outEdge)
const GEdgeSetTy & getInEdges() const
static bool isArgumentVFGNodeKinds(GNodeK n)
virtual const SVFType * getType() const
static bool isObjVarKinds(GNodeK n)
std::string sourceLoc
Source code information of this value.
static bool isVFGNodeKinds(GNodeK n)
const SVFType * type
SVF type.
static bool isMRSVFGNodeKinds(GNodeK n)
static bool isValVarKinds(GNodeK n)
static bool isPHIVFGNodeKinds(GNodeK n)
GNodeK getNodeKind() const
Get node kind.
NodeID getId() const
Get ID.
static bool isICFGNodeKinds(GNodeK n)
Helper functions to check node kinds.
static bool isMSSAPHISVFGNodeKinds(GNodeK n)
GNodeK nodeKind
Node kind.
virtual void setSourceLoc(const std::string &sourceCodeInfo)
static bool isStmtVFGNodeKinds(GNodeK n)
SVFBaseNode(NodeID i, GNodeK k, SVFType *ty=nullptr)
static bool isInterICFGNodeKind(GNodeK n)
static bool isSVFVarKind(GNodeK n)
const std::string valueOnlyToString() const
virtual const std::string getSourceLoc() const
mapped_iter(ItTy U, FuncTy F)
FuncReturnTy operator*() const
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
std::set< Key, Compare, Allocator > OrderedSet
mapped_iter< ItTy, FuncTy > map_iter(ItTy I, FuncTy F)
std::map< Key, Value, Compare, Allocator > OrderedMap
Add the hash function for std::set (we also can overload operator< to implement this)
bool operator()(const GenericEdge< NodeType > *lhs, const GenericEdge< NodeType > *rhs) const
mapped_iter< typename SVF::GenericNode< NodeTy, EdgeTy >::iterator, decltype(&edge_dest)> ChildIteratorType
static ChildIteratorType child_begin(const NodeType *N)
static ChildIteratorType child_end(const NodeType *N)
static NodeType * getEntryNode(Inverse< NodeType * > G)
static unsigned getNodeID(const NodeType *N)
static NodeType * edge_dest(const EdgeType *E)
static unsigned getNodeID(NodeType *N)
static unsigned graphSize(GenericGraphTy *G)
mapped_iter< typename GenericGraphTy::iterator, decltype(&deref_val)> nodes_iterator
static nodes_iterator nodes_end(GenericGraphTy *G)
static NodeType * deref_val(PairTy P)
std::pair< SVF::NodeID, NodeType * > PairTy
static nodes_iterator nodes_begin(GenericGraphTy *G)
SVF::GenericGraph< NodeTy, EdgeTy > GenericGraphTy
static NodeType * getNode(GenericGraphTy *G, SVF::NodeID id)
static NodeType * getEntryNode(GenericGraphTy *pag)
static ChildIteratorType direct_child_begin(const NodeType *N)
static ChildIteratorType child_end(const NodeType *N)
static ChildIteratorType direct_child_end(const NodeType *N)
mapped_iter< typename SVF::GenericNode< NodeTy, EdgeTy >::iterator, decltype(&edge_dest)> ChildIteratorType
static NodeType * getEntryNode(NodeType *pagN)
static NodeType * edge_dest(const EdgeType *E)
static ChildIteratorType child_begin(const NodeType *N)