Package org.codehaus.groovy.classgen.asm
Class BinaryExpressionWriter
java.lang.Object
org.codehaus.groovy.classgen.asm.BinaryExpressionWriter
- Direct Known Subclasses:
BinaryFloatExpressionHelper,BinaryIntExpressionHelper,BinaryLongExpressionHelper,BinaryObjectExpressionHelper
Base class for writing primitive typed operations
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int[]Jump opcodes used for primitive comparison results. -
Constructor Summary
ConstructorsConstructorDescriptionBinaryExpressionWriter(WriterController controller, MethodCaller arraySet, MethodCaller arrayGet) Creates a primitive-operation writer. -
Method Summary
Modifier and TypeMethodDescriptionbooleanarrayGet(int operation, boolean simulate) Attempts to write an array-read operation.booleanarraySet(boolean simulate) Writes an array-store operation.protected abstract voiddoubleTwoOperands(org.objectweb.asm.MethodVisitor mv) Duplicates the two operands already on the operand stack.protected MethodCallerprotected ClassNodeprotected MethodCallerprotected abstract intgetBitwiseOperationBytecode(int type) Returns the bitwise opcode for the supplied token.protected abstract intreturn writer controllerprotected abstract ClassNodeprotected abstract ClassNodeprotected abstract intgetShiftOperationBytecode(int type) Returns the shift opcode for the supplied token.protected abstract intgetStandardOperationBytecode(int type) Returns the arithmetic opcode for the supplied token.protected abstract voidremoveTwoOperands(org.objectweb.asm.MethodVisitor mv) Removes the two operands already on the operand stack.voidsetArraySetAndGet(MethodCaller arraySet, MethodCaller arrayGet) Replaces the helpers used for primitive array access.protected booleanbooleanwrite(int operation, boolean simulate) Attempts to write the supplied binary operation.protected booleanwriteBitwiseOp(int type, boolean simulate) writes some the bitwise operations.protected booleanwriteDivision(boolean simulate) Writes a division operation for the current primitive type.protected abstract voidwriteMinusMinus(org.objectweb.asm.MethodVisitor mv) Emits a prefix/postfix decrement.protected abstract voidwritePlusPlus(org.objectweb.asm.MethodVisitor mv) Emits a prefix/postfix increment.booleanwritePostOrPrefixMethod(int operation, boolean simulate) Attempts to write a postfix or prefix increment/decrement operation.protected booleanwriteShiftOp(int type, boolean simulate) Write shifting operations.protected booleanwriteSpaceship(int type, boolean simulate) Writes a spaceship comparison for the current primitive type.protected booleanwriteStdCompare(int type, boolean simulate) writes some int standard operations for comparesprotected booleanwriteStdOperators(int type, boolean simulate) Writes a standard arithmetic operator for the current primitive type.
-
Field Details
-
stdCompareCodes
protected static final int[] stdCompareCodesJump 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 controllerarraySet- the helper used for array storesarrayGet- the helper used for array loads
-
-
Method Details
-
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 typesimulate- whether to probe support without emitting bytecode- Returns:
trueif the operation is supported
-
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 typesimulate- whether to probe support without emitting bytecode- Returns:
trueif 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:
trueif division is supported
-
supportsDivision
protected boolean supportsDivision()- Returns:
- whether this primitive helper supports division bytecode directly
-
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 typesimulate- whether to probe support without emitting bytecode- Returns:
trueif the operation is supported
-
getArrayGetCaller
- Returns:
- the helper used for primitive array loads
-
getArrayGetResultType
- Returns:
- the result type produced by
getArrayGetCaller()
-
getArraySetCaller
- Returns:
- the helper used for primitive array stores
-
setArraySetAndGet
Replaces the helpers used for primitive array access.- Parameters:
arraySet- the array-store helperarrayGet- the array-load helper
-
arrayGet
public boolean arrayGet(int operation, boolean simulate) Attempts to write an array-read operation.- Parameters:
operation- the token typesimulate- whether to probe support without emitting bytecode- Returns:
trueif 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 typesimulate- whether to probe support without emitting bytecode- Returns:
trueif 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
-