public class BinaryExpressionHelper
extends Object
Emits bytecode for dynamic binary expressions.
| Modifiers | Name | Description |
|---|---|---|
protected WriterController |
controller |
Coordinates the active bytecode-generation state. |
| Constructor and description |
|---|
BinaryExpressionHelper(WriterController wc)Creates a binary expression helper for the supplied controller. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
assignToArray(Expression parent, Expression receiver, Expression index, Expression rhsValueLoader, boolean safe)Emits an array-style assignment using the dynamic putAt protocol.
|
|
public void |
eval(BinaryExpression expression)Evaluates the supplied binary expression. |
|
protected void |
evaluateArrayAssignmentWithOperator(String method, BinaryExpression expression, BinaryExpression leftBinExpr)Evaluates a compound assignment whose left-hand side is a subscript expression. |
|
protected void |
evaluateBinaryExpression(String message, BinaryExpression expression)Evaluates a dynamic binary operator by invoking the named helper method. |
|
protected void |
evaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression)Evaluates an operator-assignment expression such as +=. |
|
protected void |
evaluateCompareExpression(MethodCaller compareMethod, BinaryExpression expression)Evaluates a comparison expression, using primitive helpers when possible. |
|
protected void |
evaluateCompoundAssign(String assignName, String baseName, BinaryExpression expression)GEP-15: dynamic-mode compound-assign codegen. |
|
public void |
evaluateElvisEqual(BinaryExpression expression)Rewrites and evaluates the Elvis-assignment form. |
|
public void |
evaluateEqual(BinaryExpression expression, boolean defineVariable)Evaluates an assignment expression. |
|
public void |
evaluatePostfixMethod(PostfixExpression expression)Evaluates a postfix increment or decrement expression. |
|
public void |
evaluatePrefixMethod(PrefixExpression expression)Evaluates a prefix increment or decrement expression. |
|
public void |
evaluateTernary(TernaryExpression expression)Evaluates a ternary or Elvis expression. |
|
protected void |
finishPreservedRhs(Expression rhs, boolean keepValue, int[] slot, ClassNode[] keptType)Leaves the assignment value on the operand stack when keepValue
is set, and clears a temporary allocated by preserveSubscriptRhs. |
|
public WriterController |
getController()
|
|
public MethodCaller |
getIsCaseMethod()
|
|
protected Expression |
preserveSubscriptRhs(Expression rhs, boolean keepValue, int[] slot, ClassNode[] keptType)Returns the expression to pass as the putAt value. |
|
protected void |
releaseTemporary(ClassNode type, int index)Drops a temporary. |
|
public void |
writeIsCase(int selectorIndex, ClassNode selectorType, Expression caseValue)Loads the stored switch selector, evaluates caseValue, and invokes
ScriptBytecodeAdapter.isCase.
|
|
protected void |
writePostOrPrefixMethod(int op, String method, Expression expression, Expression orig)Emits the method call used to implement a prefix or postfix operation. |
Coordinates the active bytecode-generation state.
Creates a binary expression helper for the supplied controller.
wc - the active writer controller Emits an array-style assignment using the dynamic putAt protocol.
The receiver, the index and the right-hand side are evaluated in that order.
When the assignment value is required, it is left on the operand stack.
A right-hand side that is not already a slot is kept in one temporary
across the call, and that temporary is cleared before this method returns.
See preserveSubscriptRhs for why a stack duplicate is not used here.
parent - the original assignment expressionreceiver - the array or indexable receiverindex - the subscript expressionrhsValueLoader - the right-hand side, or a loader that reloads itsafe - whether the receiver access is null-safeEvaluates the supplied binary expression.
expression - the expression to compileEvaluates a compound assignment whose left-hand side is a subscript expression.
method - the operator method nameexpression - the compound assignment expressionleftBinExpr - the indexed left-hand sideEvaluates a dynamic binary operator by invoking the named helper method.
message - the operator method nameexpression - the expression to compile Evaluates an operator-assignment expression such as +=.
method - the operator method nameexpression - the assignment expressionEvaluates a comparison expression, using primitive helpers when possible.
compareMethod - the dynamic comparison helperexpression - the comparison expression GEP-15: dynamic-mode compound-assign codegen. Routes through
ScriptBytecodeAdapter.compoundAssign
which dispatches to assignName when the receiver responds to it,
and falls back to baseName otherwise. The caller stores the helper's
return value into the LHS — for the in-place branch this is a no-op store
of the receiver back to itself; for the fallback branch it is the usual
"x = x.op(y)" assignment.
Rewrites and evaluates the Elvis-assignment form.
expression - the Elvis-assignment expressionEvaluates an assignment expression.
expression - the assignment expressiondefineVariable - whether the left-hand side declares a new variableEvaluates a postfix increment or decrement expression.
expression - the postfix expressionEvaluates a prefix increment or decrement expression.
expression - the prefix expressionEvaluates a ternary or Elvis expression.
expression - the expression to compile Leaves the assignment value on the operand stack when keepValue
is set, and clears a temporary allocated by preserveSubscriptRhs.
isCase dispatch Returns the expression to pass as the putAt value. When the
assignment value is required and the right-hand side is not already a
slot, the wrapper evaluates it once and stores a temporary.
An array store can duplicate that value under its two operands
(OperandStack.dupUnderTwo). A putAt call cannot share
that duplicate. The classic call site pushes a CallSite under
the receiver and the index, three words below the value, and there is
no DUP_X3. A copy inserted only under the receiver and the index
would become the invokeinterface receiver. The invokedynamic
backend has no call-site operand, but the copy would have to be emitted
inside that backend after the arguments are on the stack. One reference
temporary, cleared by finishPreservedRhs, is the path shared
by both backends.
Drops a temporary. A reference slot is cleared first so the value does
not stay reachable after removeVar, which only forgets the slot.
Primitive slots are not null stores; they do not keep a heap object live.
Loads the stored switch selector, evaluates caseValue, and invokes
ScriptBytecodeAdapter.isCase.
Shared by switch statements and switch expressions so both keep the
operand stack consistent.
selectorIndex - local slot holding the selectorselectorType - type stored in that slotcaseValue - the case label expressionEmits the method call used to implement a prefix or postfix operation.
op - the token typemethod - the helper method nameexpression - the receiver expressionorig - the original prefix/postfix expressionCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.