class NameReferenceGraph extends LinkedDirectedGraph<NameReferenceGraph.Name,NameReferenceGraph.Reference> implements DefinitionProvider
The NameReferenceGraph G for a program P is a directed graph G = (V, E) where:
V (NameReferenceGraph.Name
) represents all global names in P and E = (v, v'), v and
v' in V (NameReferenceGraph.Reference
represents a reference use or definition from the
name v to v' in P.
There are two core results we are trying to compute. The first being able
to precisely identify the function body at any given call site with
getReferencesAt(Node)
.
The second result come directly from the previous one. The directed edge provides us with dependency information. If A->B, B might be needed (in this module) if A is needed (in this module). The converse of the this result is more useful. B is not needed if A is not needed.
Modifier and Type | Class and Description |
---|---|
(package private) class |
NameReferenceGraph.Name
Represents function or variable names that can be referenced globally.
|
(package private) static class |
NameReferenceGraph.Reference
A reference site for a function or a variable reference.
|
LinkedDirectedGraph.LinkedDirectedGraphNode<N,E>
DiGraph.DiGraphEdge<N,E>, DiGraph.DiGraphNode<N,E>
Graph.GraphEdge<N,E>
GraphvizGraph.GraphvizEdge, GraphvizGraph.GraphvizNode
Modifier and Type | Field and Description |
---|---|
(package private) AbstractCompiler |
compiler |
(package private) NameReferenceGraph.Name |
main |
private java.util.Map<java.lang.String,NameReferenceGraph.Name> |
nameMap |
private com.google.common.collect.Multimap<Node,NameReferenceGraph.Name> |
referenceMap |
(package private) NameReferenceGraph.Name |
unknown |
(package private) NameReferenceGraph.Name |
window |
nodes
Constructor and Description |
---|
NameReferenceGraph(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
void |
connect(NameReferenceGraph.Name src,
NameReferenceGraph.Reference ref,
NameReferenceGraph.Name dest)
Connects two nodes in the graph with an edge.
|
GraphNode<NameReferenceGraph.Name,NameReferenceGraph.Reference> |
createNode(NameReferenceGraph.Name value)
Gets a node from the graph given a value.
|
NameReferenceGraph.Name |
defineNameIfNotExists(java.lang.String name,
boolean isExtern) |
java.util.Collection<DefinitionsRemover.Definition> |
getDefinitionsReferencedAt(Node useSite)
Returns a collection of definitions that characterize the
possible values of a variable or property.
|
java.util.List<NameReferenceGraph.Name> |
getReferencesAt(Node site)
Retrieves a list of all possible Names that this site is referring to.
|
NameReferenceGraph.Name |
getSymbol(java.lang.String name) |
connect, connectIfNotConnectedInDirection, create, createDirectedGraphNode, createWithoutAnnotations, disconnect, disconnectInDirection, getDirectedGraphEdges, getDirectedGraphNode, getDirectedGraphNodes, getDirectedPredNodes, getDirectedPredNodes, getDirectedSuccNodes, getDirectedSuccNodes, getEdges, getEdges, getFirstEdge, getGraphvizEdges, getGraphvizNodes, getInEdges, getName, getNeighborNodes, getNode, getNodeDegree, getNodes, getOutEdges, isConnectedInDirection, isConnectedInDirection, isConnectedInDirection, isDirected, newSubGraph
isConnected, isConnected
clearEdgeAnnotations, clearNodeAnnotations, connectIfNotFound, getWeight, hasNode, popEdgeAnnotations, popNodeAnnotations, pushEdgeAnnotations, pushNodeAnnotations
private final com.google.common.collect.Multimap<Node,NameReferenceGraph.Name> referenceMap
private java.util.Map<java.lang.String,NameReferenceGraph.Name> nameMap
final NameReferenceGraph.Name unknown
final NameReferenceGraph.Name main
final NameReferenceGraph.Name window
final AbstractCompiler compiler
public NameReferenceGraph(AbstractCompiler compiler)
public NameReferenceGraph.Name defineNameIfNotExists(java.lang.String name, boolean isExtern)
public java.util.List<NameReferenceGraph.Name> getReferencesAt(Node site)
public java.util.Collection<DefinitionsRemover.Definition> getDefinitionsReferencedAt(Node useSite)
DefinitionProvider
getDefinitionsReferencedAt
in interface DefinitionProvider
public NameReferenceGraph.Name getSymbol(java.lang.String name)
public GraphNode<NameReferenceGraph.Name,NameReferenceGraph.Reference> createNode(NameReferenceGraph.Name value)
Graph
Object.equals
.createNode
in class LinkedDirectedGraph<NameReferenceGraph.Name,NameReferenceGraph.Reference>
value
- The node's value.public void connect(NameReferenceGraph.Name src, NameReferenceGraph.Reference ref, NameReferenceGraph.Name dest)
Graph
connect
in class LinkedDirectedGraph<NameReferenceGraph.Name,NameReferenceGraph.Reference>
src
- First node.ref
- The edge.dest
- Second node.