private class InstrumentFunctions.InstrumentReturns extends java.lang.Object implements NodeTraversal.Callback
reportFunctionExitName
. If the
function is missing an explicit return statement in some control
path, this pass inserts a call to reportFunctionExitName
as the last statement in the function's body.
Example:
Input:
function f() {
if (pred) {
return a;
}
}
Template:
reportFunctionExitName: "onExitFn"
Output:
function f() {
if (pred) {
return onExitFn(0, a, "f");
}
onExitFn(0, undefined, "f");
}Modifier and Type | Field and Description |
---|---|
private int |
functionId |
private java.lang.String |
functionName |
Constructor and Description |
---|
InstrumentReturns(int functionId,
java.lang.String functionName) |
Modifier and Type | Method and Description |
---|---|
private boolean |
allPathsReturn(Node function) |
private Node |
newReportFunctionExitNode(Node infoNode,
Node returnRhs) |
(package private) void |
process(Node function) |
boolean |
shouldTraverse(NodeTraversal t,
Node n,
Node parent)
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed.
|
void |
visit(NodeTraversal t,
Node n,
Node parent)
Visits a node in postorder (after its children have been visited).
|
private final int functionId
private final java.lang.String functionName
InstrumentReturns(int functionId, java.lang.String functionName)
functionId
- Function identifier computed by FunctionNames;
used as first argument to reportFunctionExitName
reportFunctionExitName
must be a 3 argument function that
returns it's second argument.functionName
- Function name.void process(Node function)
function
- function with id == this.functionIdpublic boolean shouldTraverse(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in pre order (before visiting its children) and decides
whether this node's children should be traversed. If children are
traversed, they will be visited by
NodeTraversal.Callback.visit(NodeTraversal, Node, Node)
in postorder.
Implementations can have side effects (e.g. modifying the parse tree).
shouldTraverse
in interface NodeTraversal.Callback
public void visit(NodeTraversal t, Node n, Node parent)
NodeTraversal.Callback
Visits a node in postorder (after its children have been visited).
A node is visited only if all its parents should be traversed
(NodeTraversal.Callback.shouldTraverse(NodeTraversal, Node, Node)
).
Implementations can have side effects (e.g. modifying the parse tree).
visit
in interface NodeTraversal.Callback
private boolean allPathsReturn(Node function)