Package org.codehaus.groovy.classgen.asm
Class BinaryExpressionHelper
java.lang.Object
org.codehaus.groovy.classgen.asm.BinaryExpressionHelper
- Direct Known Subclasses:
BinaryExpressionMultiTypeDispatcher,IndyBinHelper
Emits bytecode for dynamic binary expressions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final WriterControllerCoordinates the active bytecode-generation state. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a binary expression helper for the supplied controller. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassignToArray(Expression parent, Expression receiver, Expression index, Expression rhsValueLoader, boolean safe) Emits an array-style assignment using the dynamicputAtprotocol.voideval(BinaryExpression expression) Evaluates the supplied binary expression.protected voidevaluateArrayAssignmentWithOperator(String method, BinaryExpression expression, BinaryExpression leftBinExpr) Evaluates a compound assignment whose left-hand side is a subscript expression.protected voidevaluateBinaryExpression(String message, BinaryExpression expression) Evaluates a dynamic binary operator by invoking the named helper method.protected voidevaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression) Evaluates an operator-assignment expression such as+=.protected voidevaluateCompareExpression(MethodCaller compareMethod, BinaryExpression expression) Evaluates a comparison expression, using primitive helpers when possible.protected voidevaluateCompoundAssign(String assignName, String baseName, BinaryExpression expression) GEP-15: dynamic-mode compound-assign codegen.voidevaluateElvisEqual(BinaryExpression expression) Rewrites and evaluates the Elvis-assignment form.voidevaluateEqual(BinaryExpression expression, boolean defineVariable) Evaluates an assignment expression.voidevaluatePostfixMethod(PostfixExpression expression) Evaluates a postfix increment or decrement expression.voidevaluatePrefixMethod(PrefixExpression expression) Evaluates a prefix increment or decrement expression.voidevaluateTernary(TernaryExpression expression) Evaluates a ternary or Elvis expression.voidwriteIsCase(int selectorIndex, ClassNode selectorType, Expression caseValue) Loads the stored switch selector, evaluatescaseValue, and invokesScriptBytecodeAdapter.isCase(Object, Object).protected voidwritePostOrPrefixMethod(int op, String method, Expression expression, Expression orig) Emits the method call used to implement a prefix or postfix operation.
-
Field Details
-
controller
Coordinates the active bytecode-generation state.
-
-
Constructor Details
-
BinaryExpressionHelper
Creates a binary expression helper for the supplied controller.- Parameters:
wc- the active writer controller
-
-
Method Details
-
getController
- Returns:
- the active writer controller
-
getIsCaseMethod
- Returns:
- the helper used for
isCasedispatch
-
writeIsCase
Loads the stored switch selector, evaluatescaseValue, and invokesScriptBytecodeAdapter.isCase(Object, Object). Shared by switch statements and switch expressions so both keep the operand stack consistent.- Parameters:
selectorIndex- local slot holding the selectorselectorType- type stored in that slotcaseValue- the case label expression
-
eval
Evaluates the supplied binary expression.- Parameters:
expression- the expression to compile
-
assignToArray
protected void assignToArray(Expression parent, Expression receiver, Expression index, Expression rhsValueLoader, boolean safe) Emits an array-style assignment using the dynamicputAtprotocol.- Parameters:
parent- the original assignment expressionreceiver- the array or indexable receiverindex- the subscript expressionrhsValueLoader- an expression that reloads the right-hand valuesafe- whether the receiver access is null-safe
-
evaluateElvisEqual
Rewrites and evaluates the Elvis-assignment form.- Parameters:
expression- the Elvis-assignment expression
-
evaluateEqual
Evaluates an assignment expression.- Parameters:
expression- the assignment expressiondefineVariable- whether the left-hand side declares a new variable
-
evaluateCompareExpression
Evaluates a comparison expression, using primitive helpers when possible.- Parameters:
compareMethod- the dynamic comparison helperexpression- the comparison expression
-
evaluateBinaryExpression
Evaluates a dynamic binary operator by invoking the named helper method.- Parameters:
message- the operator method nameexpression- the expression to compile
-
evaluateArrayAssignmentWithOperator
protected void evaluateArrayAssignmentWithOperator(String method, BinaryExpression expression, BinaryExpression leftBinExpr) Evaluates a compound assignment whose left-hand side is a subscript expression.- Parameters:
method- the operator method nameexpression- the compound assignment expressionleftBinExpr- the indexed left-hand side
-
evaluateBinaryExpressionWithAssignment
Evaluates an operator-assignment expression such as+=.- Parameters:
method- the operator method nameexpression- the assignment expression
-
evaluateCompoundAssign
protected void evaluateCompoundAssign(String assignName, String baseName, BinaryExpression expression) GEP-15: dynamic-mode compound-assign codegen. Routes throughScriptBytecodeAdapter.compoundAssign(Object, Object, String, String)which dispatches toassignNamewhen the receiver responds to it, and falls back tobaseNameotherwise. 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. -
evaluatePostfixMethod
Evaluates a postfix increment or decrement expression.- Parameters:
expression- the postfix expression
-
evaluatePrefixMethod
Evaluates a prefix increment or decrement expression.- Parameters:
expression- the prefix expression
-
writePostOrPrefixMethod
protected void writePostOrPrefixMethod(int op, String method, Expression expression, Expression orig) Emits the method call used to implement a prefix or postfix operation.- Parameters:
op- the token typemethod- the helper method nameexpression- the receiver expressionorig- the original prefix/postfix expression
-
evaluateTernary
Evaluates a ternary or Elvis expression.- Parameters:
expression- the expression to compile
-