-
- Type Parameters:
G
- the type of this graphN
- the type ofNode
s in this graphE
- the type ofEdge
s in this graph
- All Known Implementing Classes:
AnalyzedCFG
,BackwardAnalyzedCFG
,BackwardOptimizedAnalyzedCFG
,BaseCallGraph
,BaseGraph
,CallGraph
,CFG
,CodeGraph
,OptimizedAnalyzedCFG
public interface Graph<G extends Graph<G,N,E>,N extends Node<G,N,E>,E extends Edge<G,N,E>>
Interface of a generic graph structure.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <V> void
accept(GraphVisitor<G,N,E,V> visitor, V tool)
Accepts the givenGraphVisitor
.void
addEdge(E edge)
Adds an edge to this graph.void
addNode(N node)
Adds the given node to the set of nodes.void
addNode(N node, boolean entrypoint)
Adds the given node to the set of nodes, optionally marking this as entrypoint (that is, root).boolean
containsEdge(E edge)
Yieldstrue
if the given edge is contained in this graph.boolean
containsNode(N node)
Yieldstrue
if the given node is contained in this graph.java.util.Collection<N>
followersOf(N node)
Yields the collection of the nodes that are followers of the given one, that is, all nodes such that there exist an edge in this control flow graph going from the given node to such node.default java.util.Collection<N>
getCycleEntries()
Yields all the nodes that are part of cycles in the graph that are also reachable from outside the cycle itself (that is, if they are also entrypoints or if they have an incoming back-edge).E
getEdgeConnecting(N source, N destination)
Yields the edge connecting the two given nodes, if any.java.util.Collection<E>
getEdges()
Yields the set of edges of this graph.java.util.Collection<E>
getEdgesConnecting(N source, N destination)
Yields all edges connecting the two given nodes, if any.int
getEdgesCount()
Yields the total number of edges of this graph.java.util.Collection<N>
getEntrypoints()
Yields the nodes of this graph that are entrypoints, that is, roots of the graph.java.util.Collection<E>
getIngoingEdges(N node)
Yields the ingoing edges to the given node.java.util.Collection<N>
getNodes()
Yields the set of nodes of this graph.int
getNodesCount()
Yields the total number of nodes of this graph.java.util.Collection<E>
getOutgoingEdges(N node)
Yields the outgoing edges from the given node.boolean
isEqualTo(G graph)
Checks if this graph is effectively equal to the given one, that is, if they have the same structure while potentially being different instances.java.util.Collection<N>
predecessorsOf(N node)
Yields the collection of the nodes that are predecessors of the given vertex, that is, all nodes such that there exist an edge in this control flow graph going from such node to the given one.default SerializableGraph
toSerializableGraph()
Yields an instance ofSerializableGraph
built from this one.SerializableGraph
toSerializableGraph(java.util.function.BiFunction<G,N,SerializableValue> descriptionGenerator)
Yields an instance ofSerializableGraph
built from this one.
-
-
-
Method Detail
-
getEntrypoints
java.util.Collection<N> getEntrypoints()
Yields the nodes of this graph that are entrypoints, that is, roots of the graph. This usually contains the first node of this graph, but might also contain other ones.- Returns:
- the entrypoints of this graph
-
getNodes
java.util.Collection<N> getNodes()
Yields the set of nodes of this graph.- Returns:
- the collection of nodes
-
getEdges
java.util.Collection<E> getEdges()
Yields the set of edges of this graph.- Returns:
- the collection of edges
-
addNode
void addNode(N node)
Adds the given node to the set of nodes. This is equivalent to invokingaddNode(Node, boolean)
withfalse
as second parameter.- Parameters:
node
- the node to add
-
addNode
void addNode(N node, boolean entrypoint)
Adds the given node to the set of nodes, optionally marking this as entrypoint (that is, root).- Parameters:
node
- the node to addentrypoint
- iftrue
causes the given node to be considered as an entrypoint.
-
addEdge
void addEdge(E edge)
Adds an edge to this graph.- Parameters:
edge
- the edge to add- Throws:
java.lang.UnsupportedOperationException
- if the source or the destination of the given edge are not part of this graph
-
getNodesCount
int getNodesCount()
Yields the total number of nodes of this graph.- Returns:
- the number of nodes
-
getEdgesCount
int getEdgesCount()
Yields the total number of edges of this graph.- Returns:
- the number of edges
-
containsNode
boolean containsNode(N node)
Yieldstrue
if the given node is contained in this graph.- Parameters:
node
- the node to check- Returns:
true
if the node is in this graph
-
containsEdge
boolean containsEdge(E edge)
Yieldstrue
if the given edge is contained in this graph.- Parameters:
edge
- the edge to check- Returns:
true
if the edge is in this graph
-
getEdgeConnecting
E getEdgeConnecting(N source, N destination)
Yields the edge connecting the two given nodes, if any. Yieldsnull
if such edge does not exist, or if one of the two nodes is not inside this graph. If more than one edge connects the two nodes, this method returns one of them arbitrarily (but consistently: successive calls with the same parameters will always return the same edge). To retrieve all such edges, usegetEdgesConnecting(Node, Node)
.- Parameters:
source
- the source nodedestination
- the destination node- Returns:
- the edge connecting
source
todestination
, ornull
-
getEdgesConnecting
java.util.Collection<E> getEdgesConnecting(N source, N destination)
Yields all edges connecting the two given nodes, if any. Yields an empty collection if no edge exists, or if one of the two nodes is not inside this graph.- Parameters:
source
- the source nodedestination
- the destination node- Returns:
- the edges connecting
source
todestination
-
getIngoingEdges
java.util.Collection<E> getIngoingEdges(N node)
Yields the ingoing edges to the given node.- Parameters:
node
- the node- Returns:
- the collection of ingoing edges
-
getOutgoingEdges
java.util.Collection<E> getOutgoingEdges(N node)
Yields the outgoing edges from the given node.- Parameters:
node
- the node- Returns:
- the collection of outgoing edges
-
followersOf
java.util.Collection<N> followersOf(N node)
Yields the collection of the nodes that are followers of the given one, that is, all nodes such that there exist an edge in this control flow graph going from the given node to such node. Yieldsnull
if the node is not in this graph.- Parameters:
node
- the node- Returns:
- the collection of followers
-
predecessorsOf
java.util.Collection<N> predecessorsOf(N node)
Yields the collection of the nodes that are predecessors of the given vertex, that is, all nodes such that there exist an edge in this control flow graph going from such node to the given one. Yieldsnull
if the node is not in this graph.- Parameters:
node
- the node- Returns:
- the collection of predecessors
-
toSerializableGraph
default SerializableGraph toSerializableGraph()
Yields an instance ofSerializableGraph
built from this one. The default implementation of this method is equivalent to invokingtoSerializableGraph(BiFunction)
withnull
as argument.- Returns:
- a
SerializableGraph
instance
-
toSerializableGraph
SerializableGraph toSerializableGraph(java.util.function.BiFunction<G,N,SerializableValue> descriptionGenerator)
Yields an instance ofSerializableGraph
built from this one. IfdescriptionGenerator
is notnull
,SerializableNodeDescription
for each node will be generated using it.- Parameters:
descriptionGenerator
- the function to be used for generating node descriptions, can benull
- Returns:
- a
SerializableGraph
instance
-
isEqualTo
boolean isEqualTo(G graph)
Checks if this graph is effectively equal to the given one, that is, if they have the same structure while potentially being different instances.- Parameters:
graph
- the other graph- Returns:
true
if this graph and the given one are effectively equals
-
accept
default <V> void accept(GraphVisitor<G,N,E,V> visitor, V tool)
Accepts the givenGraphVisitor
. This method first invokesGraphVisitor.visit(Object, Graph)
on this graph, and then proceeds by first invokingGraphVisitor.visit(Object, Graph, Node)
on all the nodes in the order they are returned bygetNodes()
, and later invokingGraphVisitor.visit(Object, Graph, Edge)
on all the edges in the order they are returned bygetEdges()
. The visiting stops at the first of such calls that returnfalse
.- Type Parameters:
V
- the type of auxiliary tool thatvisitor
can use- Parameters:
visitor
- the visitor that is visiting theGraph
containing this graphtool
- the auxiliary tool thatvisitor
can use
-
getCycleEntries
default java.util.Collection<N> getCycleEntries()
Yields all the nodes that are part of cycles in the graph that are also reachable from outside the cycle itself (that is, if they are also entrypoints or if they have an incoming back-edge).- Returns:
- the nodes that are cycle entries
-
-