class ExploitAssigns extends AbstractPeepholeOptimization
Constructor and Description |
---|
ExploitAssigns() |
Modifier and Type | Method and Description |
---|---|
private void |
collapseAssign(Node assign,
Node expr,
Node exprParent)
Try to collapse the given assign into subsequent expressions.
|
private boolean |
collapseAssignEqualTo(Node expr,
Node exprParent,
Node value)
Collapse the given assign expression into the expression directly
following it, if possible.
|
private static boolean |
isCollapsibleValue(Node value,
boolean isLValue)
Determines whether we know enough about the given value to be able
to collapse it into subsequent expressions.
|
private static boolean |
isNameAssignedTo(java.lang.String name,
Node node) |
private boolean |
isSafeReplacement(Node node,
Node replacement)
Checks name referenced in node to determine if it might have
changed.
|
(package private) Node |
optimizeSubtree(Node subtree)
Given a node to optimize and a traversal, optimize the node.
|
areDeclaredGlobalExternsOnWindow, areNodesEqualForInlining, beginTraversal, endTraversal, getCodingConvention, isASTNormalized, isEcmaScript5OrGreater, mayEffectMutableState, mayHaveSideEffects, nodeTypeMayHaveSideEffects, report, reportCodeChange
Node optimizeSubtree(Node subtree)
AbstractPeepholeOptimization
optimizeSubtree
in class AbstractPeepholeOptimization
subtree
- The subtree that will be optimized.subtree
.private void collapseAssign(Node assign, Node expr, Node exprParent)
private static boolean isCollapsibleValue(Node value, boolean isLValue)
x = 3; y = x; // y = x = 3;
a = true; b = true; // b = a = true;
But we won't try to collapse complex expressions.
value
- The value node.isLValue
- Whether it's on the left-hand side of an expr.private boolean collapseAssignEqualTo(Node expr, Node exprParent, Node value)
expr
- The expression that may be moved.exprParent
- The parent of expr
.value
- The value of this expression, expressed as a node. Each
expression may have multiple values, so this function may be called
multiple times for the same expression. For example,
a = true;
is equal to the name "a" and the boolean "true".private boolean isSafeReplacement(Node node, Node replacement)
private static boolean isNameAssignedTo(java.lang.String name, Node node)