|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.javascript.jscomp.CallGraph
public class CallGraph
A pass the uses a DefinitionProvider
to compute a call graph for an
AST.
A CallGraph
connects CallGraph.Function
s to CallGraph.Callsite
s and
vice versa: each function in the graph links to the callsites it contains and
each callsite links to the functions it could call. Similarly, each callsite
links to the function that contains it and each function links to the
callsites that could call it.
The callgraph is not precise. That is, a callsite may indicate it can call a function when in fact it does not do so in the running program.
The callgraph is also not complete: in some cases it may be unable to determine some targets of a callsite. In this case, Callsite.hasUnknownTarget() will return true.
The CallGraph doesn't (currently) have functions for externally defined functions; however, callsites that target externs will have hasExternTarget() return true.
TODO(dcc): Have CallGraph (optionally?) include functions for externs.
Nested Class Summary | |
---|---|
class |
CallGraph.Callsite
An inner class that represents call sites in the call graph. |
class |
CallGraph.Function
An inner class that represents functions in the call graph. |
Field Summary | |
---|---|
static String |
MAIN_FUNCTION_NAME
The name we give the main function. |
Constructor Summary | |
---|---|
CallGraph(AbstractCompiler compiler)
Creates a call graph object support both forward and backward lookups. |
|
CallGraph(AbstractCompiler compiler,
boolean computeForwardGraph,
boolean computeBackwardGraph)
Creates a call graph object supporting the specified lookups. |
Method Summary | |
---|---|
Collection<CallGraph.Callsite> |
getAllCallsites()
Returns a collection of all callsites in the call graph. |
Collection<CallGraph.Function> |
getAllFunctions()
Returns a collection of all functions (including the main function) in the call graph. |
DiGraph<CallGraph.Function,CallGraph.Callsite> |
getBackwardDirectedGraph()
Constructs and returns a directed graph where the nodes are functions and the edges are callsites connecting callees to callers. |
CallGraph.Callsite |
getCallsiteForAstNode(Node callsiteNode)
Returns the call graph Callsite object corresponding to the provided AST Token.CALL or Token.NEW node, or null if no such object exists. |
DiGraph<CallGraph.Function,CallGraph.Callsite> |
getForwardDirectedGraph()
Constructs and returns a directed graph where the nodes are functions and the edges are callsites connecting callers to callees. |
CallGraph.Function |
getFunctionForAstNode(Node functionNode)
Returns the call graph Function object corresponding to the provided AST Token.FUNCTION node, or null if no such object exists. |
CallGraph.Function |
getMainFunction()
Returns a Function object representing the "main" global function. |
CallGraph.Function |
getUniqueFunctionWithName(String desiredName)
Finds a function with the given name. |
void |
process(Node externsRoot,
Node jsRoot)
Builds a call graph for the given externsRoot and jsRoot. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String MAIN_FUNCTION_NAME
Constructor Detail |
---|
public CallGraph(AbstractCompiler compiler, boolean computeForwardGraph, boolean computeBackwardGraph)
compiler
- The compilercomputeForwardGraph
- Should the call graph allow lookup of the target
functions a given callsite could call?computeBackwardGraph
- Should the call graph allow lookup of the
callsites that could call a given function?public CallGraph(AbstractCompiler compiler)
Method Detail |
---|
public void process(Node externsRoot, Node jsRoot)
process
in interface CompilerPass
externsRoot
- Top of external JS treejsRoot
- Top of JS treepublic CallGraph.Function getFunctionForAstNode(Node functionNode)
public CallGraph.Function getMainFunction()
public Collection<CallGraph.Function> getAllFunctions()
public CallGraph.Function getUniqueFunctionWithName(String desiredName)
public CallGraph.Callsite getCallsiteForAstNode(Node callsiteNode)
public Collection<CallGraph.Callsite> getAllCallsites()
public DiGraph<CallGraph.Function,CallGraph.Callsite> getForwardDirectedGraph()
public DiGraph<CallGraph.Function,CallGraph.Callsite> getBackwardDirectedGraph()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |