Package org.codehaus.groovy.classgen.asm

# Class BinaryExpressionWriter

java.lang.Object
org.codehaus.groovy.classgen.asm.BinaryExpressionWriter

Direct Known Subclasses:
  `BinaryFloatExpressionHelper`, `BinaryIntExpressionHelper`, `BinaryLongExpressionHelper`, `BinaryObjectExpressionHelper`

public abstract class BinaryExpressionWriter extends Object
Base class for writing primitive typed operations

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final int[]`
  `stdCompareCodes`
  Jump opcodes used for primitive comparison results.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BinaryExpressionWriter(WriterController controller, MethodCaller arraySet, MethodCaller arrayGet)`
  Creates a primitive-operation writer.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `arrayGet(int operation, boolean simulate)`
  Attempts to write an array-read operation.
  `boolean`
  `arraySet(boolean simulate)`
  Writes an array-store operation.
  `protected abstract void`
  `doubleTwoOperands(org.objectweb.asm.MethodVisitor mv)`
  Duplicates the two operands already on the operand stack.
  `protected MethodCaller`
  `getArrayGetCaller()`
  `protected ClassNode`
  `getArrayGetResultType()`
  `protected MethodCaller`
  `getArraySetCaller()`
  `protected abstract int`
  `getBitwiseOperationBytecode(int type)`
  Returns the bitwise opcode for the supplied token.
  `protected abstract int`
  `getCompareCode()`
  `WriterController`
  `getController()`
  return writer controller
  `protected abstract ClassNode`
  `getDevisionOpResultType()`
  `protected abstract ClassNode`
  `getNormalOpResultType()`
  `protected abstract int`
  `getShiftOperationBytecode(int type)`
  Returns the shift opcode for the supplied token.
  `protected abstract int`
  `getStandardOperationBytecode(int type)`
  Returns the arithmetic opcode for the supplied token.
  `protected abstract void`
  `removeTwoOperands(org.objectweb.asm.MethodVisitor mv)`
  Removes the two operands already on the operand stack.
  `void`
  `setArraySetAndGet(MethodCaller arraySet, MethodCaller arrayGet)`
  Replaces the helpers used for primitive array access.
  `protected boolean`
  `supportsDivision()`
  `boolean`
  `write(int operation, boolean simulate)`
  Attempts to write the supplied binary operation.
  `protected boolean`
  `writeBitwiseOp(int type, boolean simulate)`
  writes some the bitwise operations.
  `protected boolean`
  `writeDivision(boolean simulate)`
  Writes a division operation for the current primitive type.
  `protected abstract void`
  `writeMinusMinus(org.objectweb.asm.MethodVisitor mv)`
  Emits a prefix/postfix decrement.
  `protected abstract void`
  `writePlusPlus(org.objectweb.asm.MethodVisitor mv)`
  Emits a prefix/postfix increment.
  `boolean`
  `writePostOrPrefixMethod(int operation, boolean simulate)`
  Attempts to write a postfix or prefix increment/decrement operation.
  `protected boolean`
  `writeShiftOp(int type, boolean simulate)`
  Write shifting operations.
  `protected boolean`
  `writeSpaceship(int type, boolean simulate)`
  Writes a spaceship comparison for the current primitive type.
  `protected boolean`
  `writeStdCompare(int type, boolean simulate)`
  writes some int standard operations for compares
  `protected boolean`
  `writeStdOperators(int type, boolean simulate)`
  Writes a standard arithmetic operator for the current primitive type.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### stdCompareCodes

    protected static final int[] stdCompareCodes
    Jump opcodes used for primitive comparison results.

- ## Constructor Details

  - ### BinaryExpressionWriter

    public BinaryExpressionWriter(WriterController controller, MethodCaller arraySet, MethodCaller arrayGet)
    Creates a primitive-operation writer.
    Parameters:
      `controller` - the active writer controller
      `arraySet` - the helper used for array stores
      `arrayGet` - the helper used for array loads

- ## Method Details

  - ### getController

    public WriterController getController()
    return writer controller
    Since:
      2.5.0

  - ### getCompareCode

    protected abstract int getCompareCode()
    Returns:
      the ASM compare opcode used by this primitive type

  - ### writeStdCompare

    protected boolean writeStdCompare(int type, boolean simulate)
    writes some int standard operations for compares
    Parameters:
      `type` - the token type
    Returns:
      true if a successful std operator write

  - ### doubleTwoOperands

    protected abstract void doubleTwoOperands(org.objectweb.asm.MethodVisitor mv)
    Duplicates the two operands already on the operand stack.
    Parameters:
      `mv` - the current method visitor

  - ### removeTwoOperands

    protected abstract void removeTwoOperands(org.objectweb.asm.MethodVisitor mv)
    Removes the two operands already on the operand stack.
    Parameters:
      `mv` - the current method visitor

  - ### writeSpaceship

    protected boolean writeSpaceship(int type, boolean simulate)
    Writes a spaceship comparison for the current primitive type.
    Parameters:
      `type` - the token type
      `simulate` - whether to probe support without emitting bytecode
    Returns:
      `true` if the operation is supported

  - ### getNormalOpResultType

    protected abstract ClassNode getNormalOpResultType()
    Returns:
      the result type for normal arithmetic operations

  - ### getStandardOperationBytecode

    protected abstract int getStandardOperationBytecode(int type)
    Returns the arithmetic opcode for the supplied token.
    Parameters:
      `type` - the normalized token index
    Returns:
      the ASM opcode

  - ### writeStdOperators

    protected boolean writeStdOperators(int type, boolean simulate)
    Writes a standard arithmetic operator for the current primitive type.
    Parameters:
      `type` - the token type
      `simulate` - whether to probe support without emitting bytecode
    Returns:
      `true` if the operation is supported

  - ### writeDivision

    protected boolean writeDivision(boolean simulate)
    Writes a division operation for the current primitive type.
    Parameters:
      `simulate` - whether to probe support without emitting bytecode
    Returns:
      `true` if division is supported

  - ### supportsDivision

    protected boolean supportsDivision()
    Returns:
      whether this primitive helper supports division bytecode directly

  - ### getDevisionOpResultType

    protected abstract ClassNode getDevisionOpResultType()
    Returns:
      the result type for division operations

  - ### getBitwiseOperationBytecode

    protected abstract int getBitwiseOperationBytecode(int type)
    Returns the bitwise opcode for the supplied token.
    Parameters:
      `type` - the normalized token index
    Returns:
      the ASM opcode

  - ### writeBitwiseOp

    protected boolean writeBitwiseOp(int type, boolean simulate)
    writes some the bitwise operations. type is one of BITWISE_OR, BITWISE_AND, BITWISE_XOR
    Parameters:
      `type` - the token type
    Returns:
      true if a successful bitwise operation write

  - ### getShiftOperationBytecode

    protected abstract int getShiftOperationBytecode(int type)
    Returns the shift opcode for the supplied token.
    Parameters:
      `type` - the normalized token index
    Returns:
      the ASM opcode

  - ### writeShiftOp

    protected boolean writeShiftOp(int type, boolean simulate)
    Write shifting operations. Type is one of LEFT_SHIFT, RIGHT_SHIFT, or RIGHT_SHIFT_UNSIGNED
    Parameters:
      `type` - the token type
    Returns:
      true on a successful shift operation write

  - ### write

    public boolean write(int operation, boolean simulate)
    Attempts to write the supplied binary operation.
    Parameters:
      `operation` - the token type
      `simulate` - whether to probe support without emitting bytecode
    Returns:
      `true` if the operation is supported

  - ### getArrayGetCaller

    protected MethodCaller getArrayGetCaller()
    Returns:
      the helper used for primitive array loads

  - ### getArrayGetResultType

    protected ClassNode getArrayGetResultType()
    Returns:
      the result type produced by `getArrayGetCaller()`

  - ### getArraySetCaller

    protected MethodCaller getArraySetCaller()
    Returns:
      the helper used for primitive array stores

  - ### setArraySetAndGet

    public void setArraySetAndGet(MethodCaller arraySet, MethodCaller arrayGet)
    Replaces the helpers used for primitive array access.
    Parameters:
      `arraySet` - the array-store helper
      `arrayGet` - the array-load helper

  - ### arrayGet

    public boolean arrayGet(int operation, boolean simulate)
    Attempts to write an array-read operation.
    Parameters:
      `operation` - the token type
      `simulate` - whether to probe support without emitting bytecode
    Returns:
      `true` if the operation is an array read

  - ### arraySet

    public boolean arraySet(boolean simulate)
    Writes an array-store operation.
    Parameters:
      `simulate` - whether to probe support without emitting bytecode
    Returns:
      always `true`

  - ### writePostOrPrefixMethod

    public boolean writePostOrPrefixMethod(int operation, boolean simulate)
    Attempts to write a postfix or prefix increment/decrement operation.
    Parameters:
      `operation` - the token type
      `simulate` - whether to probe support without emitting bytecode
    Returns:
      `true` if the operation is supported

  - ### writePlusPlus

    protected abstract void writePlusPlus(org.objectweb.asm.MethodVisitor mv)
    Emits a prefix/postfix increment.
    Parameters:
      `mv` - the current method visitor

  - ### writeMinusMinus

    protected abstract void writeMinusMinus(org.objectweb.asm.MethodVisitor mv)
    Emits a prefix/postfix decrement.
    Parameters:
      `mv` - the current method visitor