class FunctionToBlockMutator
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
FunctionToBlockMutator.LabelNameSupplier |
Modifier and Type | Field and Description |
---|---|
private AbstractCompiler |
compiler |
private com.google.common.base.Supplier<java.lang.String> |
safeNameIdSupplier |
Constructor and Description |
---|
FunctionToBlockMutator(AbstractCompiler compiler,
com.google.common.base.Supplier<java.lang.String> safeNameIdSupplier) |
Modifier and Type | Method and Description |
---|---|
private static void |
addDummyAssignment(Node node,
java.lang.String resultName)
Example:
a = (void) 0;
|
private Node |
aliasAndInlineArguments(Node fnTemplateRoot,
java.util.LinkedHashMap<java.lang.String,Node> argMap,
java.util.Set<java.lang.String> namesToAlias)
Inlines the arguments within the node tree using the given argument map,
replaces "unsafe" names with local aliases.
|
private static void |
convertLastReturnToStatement(Node block,
java.lang.String resultName)
Replace the 'return' statement with its child expression.
|
private static Node |
createAssignStatementNode(java.lang.String name,
Node expression)
Create a valid statement Node containing an assignment to name of the
given expression.
|
private static void |
fixUnitializedVarDeclarations(Node n)
For all VAR node with uninitialized declarations, set
the values to be "undefined".
|
private java.lang.String |
getLabelNameForFunction(java.lang.String fnName)
Create a unique label name.
|
private static Node |
getReplacementReturnStatement(Node node,
java.lang.String resultName)
Replace the 'return' statement with its child expression.
|
private java.lang.String |
getUniqueThisName()
Create a unique "this" name.
|
private static boolean |
hasReturnAtExit(Node block) |
private void |
makeLocalNamesUnique(Node fnNode,
boolean isCallInLoop)
Fix-up all local names to be unique for this subtree.
|
(package private) Node |
mutate(java.lang.String fnName,
Node fnNode,
Node callNode,
java.lang.String resultName,
boolean needsDefaultResult,
boolean isCallInLoop) |
private static Node |
replaceReturns(Node block,
java.lang.String resultName,
java.lang.String labelName,
boolean resultMustBeSet)
Convert returns to assignments and breaks, as needed.
|
private static Node |
replaceReturnWithBreak(Node current,
Node parent,
java.lang.String resultName,
java.lang.String labelName)
Replace the 'return' statement with its child expression.
|
private static void |
rewriteFunctionDeclarations(Node n) |
private AbstractCompiler compiler
private com.google.common.base.Supplier<java.lang.String> safeNameIdSupplier
FunctionToBlockMutator(AbstractCompiler compiler, com.google.common.base.Supplier<java.lang.String> safeNameIdSupplier)
Node mutate(java.lang.String fnName, Node fnNode, Node callNode, java.lang.String resultName, boolean needsDefaultResult, boolean isCallInLoop)
fnName
- The name to use when preparing human readable names.fnNode
- The function to prepare.callNode
- The call node that will be replaced.resultName
- Function results should be assigned to this name.needsDefaultResult
- Whether the result value must be set.isCallInLoop
- Whether the function body must be prepared to be
injected into the body of a loop.private static void rewriteFunctionDeclarations(Node n)
n
- The node to inspectprivate static void fixUnitializedVarDeclarations(Node n)
private void makeLocalNamesUnique(Node fnNode, boolean isCallInLoop)
fnNode
- A mutable instance of the function to be inlined.private java.lang.String getLabelNameForFunction(java.lang.String fnName)
private java.lang.String getUniqueThisName()
private Node aliasAndInlineArguments(Node fnTemplateRoot, java.util.LinkedHashMap<java.lang.String,Node> argMap, java.util.Set<java.lang.String> namesToAlias)
private static Node replaceReturns(Node block, java.lang.String resultName, java.lang.String labelName, boolean resultMustBeSet)
resultMustBeSet
- Whether the result must always be set to a value.private static void addDummyAssignment(Node node, java.lang.String resultName)
private static void convertLastReturnToStatement(Node block, java.lang.String resultName)
block
- resultName
- private static Node createAssignStatementNode(java.lang.String name, Node expression)
private static Node getReplacementReturnStatement(Node node, java.lang.String resultName)
private static boolean hasReturnAtExit(Node block)
private static Node replaceReturnWithBreak(Node current, Node parent, java.lang.String resultName, java.lang.String labelName)