Class BinaryExpressionHelper

java.lang.Object
org.codehaus.groovy.classgen.asm.BinaryExpressionHelper
Direct Known Subclasses:
BinaryExpressionMultiTypeDispatcher, IndyBinHelper

public class BinaryExpressionHelper extends Object
Emits bytecode for dynamic binary expressions.
  • Field Details

    • controller

      protected final WriterController controller
      Coordinates the active bytecode-generation state.
  • Constructor Details

    • BinaryExpressionHelper

      public BinaryExpressionHelper(WriterController wc)
      Creates a binary expression helper for the supplied controller.
      Parameters:
      wc - the active writer controller
  • Method Details

    • getController

      public WriterController getController()
      Returns:
      the active writer controller
    • getIsCaseMethod

      public MethodCaller getIsCaseMethod()
      Returns:
      the helper used for isCase dispatch
    • eval

      public void eval(BinaryExpression expression)
      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 dynamic putAt protocol.
      Parameters:
      parent - the original assignment expression
      receiver - the array or indexable receiver
      index - the subscript expression
      rhsValueLoader - an expression that reloads the right-hand value
      safe - whether the receiver access is null-safe
    • evaluateElvisEqual

      public void evaluateElvisEqual(BinaryExpression expression)
      Rewrites and evaluates the Elvis-assignment form.
      Parameters:
      expression - the Elvis-assignment expression
    • evaluateEqual

      public void evaluateEqual(BinaryExpression expression, boolean defineVariable)
      Evaluates an assignment expression.
      Parameters:
      expression - the assignment expression
      defineVariable - whether the left-hand side declares a new variable
    • evaluateCompareExpression

      protected void evaluateCompareExpression(MethodCaller compareMethod, BinaryExpression expression)
      Evaluates a comparison expression, using primitive helpers when possible.
      Parameters:
      compareMethod - the dynamic comparison helper
      expression - the comparison expression
    • evaluateBinaryExpression

      protected void evaluateBinaryExpression(String message, BinaryExpression expression)
      Evaluates a dynamic binary operator by invoking the named helper method.
      Parameters:
      message - the operator method name
      expression - 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 name
      expression - the compound assignment expression
      leftBinExpr - the indexed left-hand side
    • evaluateBinaryExpressionWithAssignment

      protected void evaluateBinaryExpressionWithAssignment(String method, BinaryExpression expression)
      Evaluates an operator-assignment expression such as +=.
      Parameters:
      method - the operator method name
      expression - the assignment expression
    • evaluateCompoundAssign

      protected void evaluateCompoundAssign(String assignName, String baseName, BinaryExpression expression)
      GEP-15: dynamic-mode compound-assign codegen. Routes through ScriptBytecodeAdapter.compoundAssign(Object, Object, String, String) 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.
    • evaluatePostfixMethod

      public void evaluatePostfixMethod(PostfixExpression expression)
      Evaluates a postfix increment or decrement expression.
      Parameters:
      expression - the postfix expression
    • evaluatePrefixMethod

      public void evaluatePrefixMethod(PrefixExpression expression)
      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 type
      method - the helper method name
      expression - the receiver expression
      orig - the original prefix/postfix expression
    • evaluateTernary

      public void evaluateTernary(TernaryExpression expression)
      Evaluates a ternary or Elvis expression.
      Parameters:
      expression - the expression to compile