public abstract class CompoundAssignmentNormalizer extends Object
Replace problematic compound assignments with a sequence of simpler
operations, all of which are either simple assignments or are non-assigning
operations. When doing so, be careful that side effects happen exactly once
and that the order of any side effects is preserved. The choice of which
assignments to replace is made in subclasses; they must override the three
shouldBreakUp()
methods.
Note that because AST nodes are mutable, they cannot be reused in different parts of the same tree. Instead, the node must be cloned before each insertion into a tree other than the first.
Constructor and Description |
---|
CompoundAssignmentNormalizer() |
Modifier and Type | Method and Description |
---|---|
void |
accept(JNode node) |
protected JExpression |
expressionToReturn(JExpression lhs)
Decide what expression to return when breaking up a compound assignment of
the form
lhs op= rhs . |
protected JExpression |
modifyResultOperation(JBinaryOperation op)
Decide what expression to return when breaking up a compound assignment of
the form
lhs op= rhs . |
protected String |
newTemporaryLocalName(SourceInfo info,
JType type,
JMethodBody methodBody)
Gets a new temporary local variable name in
methodBody . |
protected abstract boolean |
shouldBreakUp(JBinaryOperation x) |
protected abstract boolean |
shouldBreakUp(JPostfixOperation x) |
protected abstract boolean |
shouldBreakUp(JPrefixOperation x) |
public void accept(JNode node)
protected String newTemporaryLocalName(SourceInfo info, JType type, JMethodBody methodBody)
methodBody
. Locals might have duplicate
names as they are always referred to by reference.
GenerateJavaScriptAST
will attempt coalesce variables of same name.
Subclasses might decide on different approaches to naming local temporaries.
protected JExpression expressionToReturn(JExpression lhs)
lhs op= rhs
. By default the lhs
is
returned.protected JExpression modifyResultOperation(JBinaryOperation op)
lhs op= rhs
. The breakup creates an expression of the
form lhs = lhs op rhs
, and the right hand side of the newly
created expression is passed to this method.protected abstract boolean shouldBreakUp(JBinaryOperation x)
protected abstract boolean shouldBreakUp(JPostfixOperation x)
protected abstract boolean shouldBreakUp(JPrefixOperation x)
Copyright © 2018. All rights reserved.