Package com.strobel.reflection.emit
Class CodeGenerator
- java.lang.Object
-
- com.strobel.reflection.emit.CodeGenerator
-
public class CodeGenerator extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CodeGenerator.EmitArrayElementCallback
-
Field Summary
-
Constructor Summary
Constructors Constructor Description CodeGenerator(MethodBuilder methodBuilder)
CodeGenerator(MethodBuilder methodBuilder, int initialSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addFixup(Label label, int offsetOrigin, int fixupPosition, int operandSize)
(package private) byte[]
bakeByteArray()
void
beginCatchBlock(Type<?> caughtType)
Label
beginExceptionBlock()
void
beginFinallyBlock()
void
call(ConstructorInfo constructor)
void
call(OpCode opCode, MethodInfo method)
void
call(MethodInfo method)
private static boolean
canEmitBytecodeConstant(Type<?> type)
static boolean
canEmitConstant(java.lang.Object value, Type<?> type)
LocalBuilder
declareLocal(Type<?> localType)
LocalBuilder
declareLocal(java.lang.String name, Type<?> localType)
Label
defineLabel()
void
dup()
void
dup(Type<?> type)
void
dup2()
void
dup2x1()
void
dup2x2()
void
emit(OpCode opCode)
void
emit(OpCode opCode, byte arg)
void
emit(OpCode opCode, double arg)
void
emit(OpCode opCode, float arg)
void
emit(OpCode opCode, int arg)
void
emit(OpCode opCode, long arg)
void
emit(OpCode opCode, short arg)
void
emit(OpCode opCode, ConstructorInfo constructor)
void
emit(OpCode opCode, Label label)
void
emit(OpCode opCode, FieldInfo field)
void
emit(OpCode opCode, MethodInfo method)
void
emit(OpCode opCode, Type<?> type)
void
emit(OpCode opCode, java.lang.String arg)
void
emitArray(Type<?> elementType, int count, CodeGenerator.EmitArrayElementCallback emit)
void
emitBoolean(boolean value)
void
emitBox(Type<?> type)
private void
emitBoxedToBoxedConversion(Type<?> sourceType, Type<?> targetType)
private void
emitBoxedToReferenceConversion(Type<?> sourceType)
private void
emitBoxedToUnboxedConversion(Type<?> sourceType, Type<?> targetType)
private void
emitBoxedToUnboxedNumericConversion(Type<?> sourceType, Type<?> targetType)
private void
emitBoxingConversion(Type<?> sourceType, Type<?> targetType)
void
emitByte(byte value)
(package private) void
emitByteOperand(int value)
private void
emitCastToType(Type<?> sourceType, Type<?> targetType)
void
emitCharacter(char value)
(package private) void
emitCharOperand(char value)
void
emitConstant(java.lang.Object value)
void
emitConstant(java.lang.Object value, Type<?> type)
void
emitConstantArray(java.lang.Object array)
void
emitConversion(Type<?> sourceType, Type<?> targetType)
void
emitDefaultValue(Type<?> type)
void
emitDouble(double value)
(package private) void
emitDoubleOperand(double value)
void
emitFloat(float value)
(package private) void
emitFloatOperand(float value)
void
emitGoto(Label label)
void
emitInteger(int value)
(package private) void
emitIntOperand(int value)
void
emitLoad(LocalBuilder local)
protected void
emitLoad(Type<?> type, int absoluteIndex)
void
emitLoadArgument(int index)
protected void
emitLoadConstant(int token)
void
emitLoadElement(Type<?> elementType)
protected void
emitLoadLongConstant(int token)
void
emitLong(long value)
(package private) void
emitLongOperand(long value)
void
emitMethod(MethodBase value)
void
emitNew(Type<?> type)
void
emitNewArray(Type<?> arrayType)
void
emitNewArray(Type<?> arrayType, int dimensionsToInitialize)
void
emitNull()
private void
emitNumericConversion(Type<?> sourceType, Type<?> targetType)
void
emitReturn()
void
emitReturn(Type<?> returnType)
void
emitShort(short value)
(package private) void
emitShortOperand(int value)
void
emitStore(LocalBuilder local)
protected void
emitStore(Type<?> type, int absoluteIndex)
void
emitStoreArgument(int index)
void
emitStoreElement(Type<?> elementType)
void
emitString(java.lang.String value)
private void
emitStringHashSwitch(java.lang.String[] keys, StringSwitchCallback callback, SwitchOptions options)
private void
emitStringTrieSwitch(java.lang.String[] keys, StringSwitchCallback callback)
void
emitSwitch(int[] keys, SwitchCallback callback)
void
emitSwitch(int[] keys, SwitchCallback callback, SwitchOptions options)
<E extends java.lang.Enum<E>>
voidemitSwitch(E[] keys, EnumSwitchCallback<E> callback)
<E extends java.lang.Enum<E>>
voidemitSwitch(E[] keys, EnumSwitchCallback<E> callback, SwitchOptions options)
void
emitSwitch(java.lang.String[] keys, StringSwitchCallback callback)
void
emitSwitch(java.lang.String[] keys, StringSwitchCallback callback, SwitchOptions options)
void
emitThis()
void
emitType(Type<?> value)
void
emitUnbox(Type<?> type)
private void
emitUnboxedToBoxedConversion(Type<?> sourceType, Type<?> targetType)
void
endExceptionBlock()
void
endTryBlock()
(package private) static byte[]
enlargeArray(byte[] incoming)
(package private) static byte[]
enlargeArray(byte[] incoming, int requiredSize)
(package private) static int[]
enlargeArray(int[] incoming)
(package private) static <T> T[]
enlargeArray(T[] incoming)
(package private) void
ensureCapacity(int size)
(package private) static byte
getByteOperand(byte[] codes, int index)
(package private) static char
getCharOperand(byte[] codes, int index)
(package private) static double
getDoubleOperand(byte[] codes, int index)
(package private) __ExceptionInfo[]
getExceptions()
void
getField(FieldInfo field)
(package private) static float
getFloatOperand(byte[] codes, int index)
(package private) static int
getIntOperand(byte[] codes, int index)
private int
getLabelPosition(Label label)
private static OpCode
getLocalLoadOpCode(Type<?> type, int localIndex)
private static OpCode
getLocalStoreOpCode(Type<?> type, int localIndex)
(package private) static long
getLongOperand(byte[] codes, int index)
(package private) int
getMaxStackSize()
(package private) static short
getShortOperand(byte[] codes, int index)
private static java.util.Map<java.lang.Integer,java.util.List<java.lang.String>>
getStringSwitchBuckets(java.util.List<java.lang.String> strings, Func1<java.lang.String,java.lang.Integer> keyCallback)
(package private) Type<?>[]
getUnhandledCheckedExceptions()
void
increment(LocalBuilder local, int delta)
(package private) void
internalEmit(OpCode opCode)
void
markLabel(Label label)
int
offset()
void
pop()
void
pop(Type<?> type)
void
pop2()
(package private) static void
putByteOperand(byte[] codes, int index, byte value)
(package private) static void
putCharOperand(byte[] codes, int index, char value)
(package private) static void
putDoubleOperand(byte[] codes, int index, double value)
void
putField(FieldInfo field)
(package private) static void
putFloatOperand(byte[] codes, int index, float value)
(package private) static void
putIntOperand(byte[] codes, int index, int value)
(package private) static void
putLongOperand(byte[] codes, int index, long value)
(package private) static void
putShortOperand(byte[] codes, int index, short value)
private void
registerCheckedExceptions(MethodBase method)
private static SwitchOptions
resolveSwitchOptions(int[] keys, SwitchOptions options)
private static void
sortExceptions(__ExceptionInfo[] exceptions)
private static int
stackSize(Type<?> type)
private void
stringSwitchHelper(java.util.List<java.lang.String> bucket, StringSwitchCallback callback, Label defaultLabel, Label breakTarget, int index)
(package private) int
translateLocal(int localIndex)
(package private) int
translateParameter(int localIndex)
private boolean
tryEmitConstant(java.lang.Object value, Type<?> type)
(package private) void
updateStackSize(OpCode opCode, int stackChange)
-
-
-
Field Detail
-
DefaultSize
static final int DefaultSize
- See Also:
- Constant Field Values
-
DefaultFixupArraySize
static final int DefaultFixupArraySize
- See Also:
- Constant Field Values
-
DefaultLabelArraySize
static final int DefaultLabelArraySize
- See Also:
- Constant Field Values
-
DefaultExceptionArraySize
static final int DefaultExceptionArraySize
- See Also:
- Constant Field Values
-
MIN_BYTE
private static final int MIN_BYTE
- See Also:
- Constant Field Values
-
MAX_BYTE
private static final int MAX_BYTE
- See Also:
- Constant Field Values
-
_codeStream
private final CodeStream _codeStream
-
_labelList
private int[] _labelList
-
_labelCount
private int _labelCount
-
_fixupData
private __FixupData[] _fixupData
-
_fixupCount
private int _fixupCount
-
_exceptionCount
private int _exceptionCount
-
_currentExceptionStackCount
private int _currentExceptionStackCount
-
_unhandledExceptionCount
private int _unhandledExceptionCount
-
_exceptions
private __ExceptionInfo[] _exceptions
-
_currentExceptionStack
private __ExceptionInfo[] _currentExceptionStack
-
_unhandledExceptions
private Type<?>[] _unhandledExceptions
-
scopeTree
ScopeTree scopeTree
-
methodBuilder
final MethodBuilder methodBuilder
-
localCount
int localCount
-
locals
LocalBuilder[] locals
-
_maxStackSize
private int _maxStackSize
-
_maxMidStack
private int _maxMidStack
-
_maxMidStackCur
private int _maxMidStackCur
-
StringCharAtMethod
private static final MethodInfo StringCharAtMethod
-
StringLengthMethod
private static final MethodInfo StringLengthMethod
-
ObjectEqualsMethod
private static final MethodInfo ObjectEqualsMethod
-
ObjectHashCodeMethod
private static final MethodInfo ObjectHashCodeMethod
-
-
Constructor Detail
-
CodeGenerator
public CodeGenerator(MethodBuilder methodBuilder)
-
CodeGenerator
public CodeGenerator(MethodBuilder methodBuilder, int initialSize)
-
-
Method Detail
-
offset
public int offset()
-
beginExceptionBlock
public Label beginExceptionBlock()
-
endExceptionBlock
public void endExceptionBlock()
-
endTryBlock
public void endTryBlock()
-
beginCatchBlock
public void beginCatchBlock(Type<?> caughtType)
-
beginFinallyBlock
public void beginFinallyBlock()
-
defineLabel
public Label defineLabel()
-
markLabel
public void markLabel(Label label)
-
declareLocal
public LocalBuilder declareLocal(Type<?> localType)
-
declareLocal
public LocalBuilder declareLocal(java.lang.String name, Type<?> localType)
-
dup
public void dup()
-
dup2
public void dup2()
-
dup2x1
public void dup2x1()
-
dup2x2
public void dup2x2()
-
dup
public void dup(Type<?> type)
-
pop
public void pop()
-
pop2
public void pop2()
-
pop
public void pop(Type<?> type)
-
emit
public void emit(OpCode opCode)
-
emit
public void emit(OpCode opCode, byte arg)
-
emit
public void emit(OpCode opCode, short arg)
-
emit
public void emit(OpCode opCode, int arg)
-
emit
public void emit(OpCode opCode, long arg)
-
emit
public void emit(OpCode opCode, float arg)
-
emit
public void emit(OpCode opCode, double arg)
-
emit
public void emit(OpCode opCode, java.lang.String arg)
-
emit
public void emit(OpCode opCode, ConstructorInfo constructor)
-
stackSize
private static int stackSize(Type<?> type)
-
emit
public void emit(OpCode opCode, MethodInfo method)
-
call
public void call(MethodInfo method)
-
call
public void call(ConstructorInfo constructor)
-
call
public void call(OpCode opCode, MethodInfo method)
-
emitGoto
public void emitGoto(Label label)
-
emitReturn
public void emitReturn()
-
emitReturn
public void emitReturn(Type<?> returnType)
-
emitNew
public void emitNew(Type<?> type)
-
emitNewArray
public void emitNewArray(Type<?> arrayType)
-
emitNewArray
public void emitNewArray(Type<?> arrayType, int dimensionsToInitialize)
-
emitArray
public final void emitArray(Type<?> elementType, int count, CodeGenerator.EmitArrayElementCallback emit)
-
increment
public void increment(LocalBuilder local, int delta)
-
emitLoad
public void emitLoad(LocalBuilder local)
-
emitStore
public void emitStore(LocalBuilder local)
-
emitThis
public void emitThis()
-
emitLoadArgument
public void emitLoadArgument(int index)
-
emitLoad
protected void emitLoad(Type<?> type, int absoluteIndex)
-
emitStoreArgument
public void emitStoreArgument(int index)
-
emitStore
protected void emitStore(Type<?> type, int absoluteIndex)
-
translateParameter
final int translateParameter(int localIndex)
-
translateLocal
final int translateLocal(int localIndex)
-
emitLoadElement
public void emitLoadElement(Type<?> elementType)
-
emitStoreElement
public void emitStoreElement(Type<?> elementType)
-
getField
public void getField(FieldInfo field)
-
putField
public void putField(FieldInfo field)
-
canEmitConstant
public static boolean canEmitConstant(java.lang.Object value, Type<?> type)
-
emitConstant
public void emitConstant(java.lang.Object value)
-
emitConstantArray
public void emitConstantArray(java.lang.Object array)
-
emitConstant
public void emitConstant(java.lang.Object value, Type<?> type)
-
emitType
public void emitType(Type<?> value)
-
emitMethod
public void emitMethod(MethodBase value)
-
tryEmitConstant
private boolean tryEmitConstant(java.lang.Object value, Type<?> type)
-
emitNull
public void emitNull()
-
emitDefaultValue
public void emitDefaultValue(Type<?> type)
-
emitBoolean
public void emitBoolean(boolean value)
-
emitByte
public void emitByte(byte value)
-
emitCharacter
public void emitCharacter(char value)
-
emitShort
public void emitShort(short value)
-
emitInteger
public void emitInteger(int value)
-
emitLong
public void emitLong(long value)
-
emitFloat
public void emitFloat(float value)
-
emitDouble
public void emitDouble(double value)
-
emitString
public void emitString(java.lang.String value)
-
emitLoadConstant
protected void emitLoadConstant(int token)
-
emitLoadLongConstant
protected void emitLoadLongConstant(int token)
-
canEmitBytecodeConstant
private static boolean canEmitBytecodeConstant(Type<?> type)
-
emitBox
public void emitBox(Type<?> type)
-
emitUnbox
public void emitUnbox(Type<?> type)
-
emitUnboxedToBoxedConversion
private void emitUnboxedToBoxedConversion(Type<?> sourceType, Type<?> targetType)
-
emitBoxedToUnboxedConversion
private void emitBoxedToUnboxedConversion(Type<?> sourceType, Type<?> targetType)
-
emitBoxedToReferenceConversion
private void emitBoxedToReferenceConversion(Type<?> sourceType)
-
emitBoxedToUnboxedNumericConversion
private void emitBoxedToUnboxedNumericConversion(Type<?> sourceType, Type<?> targetType)
-
emitBoxedToBoxedConversion
private void emitBoxedToBoxedConversion(Type<?> sourceType, Type<?> targetType)
-
emitSwitch
public void emitSwitch(int[] keys, SwitchCallback callback)
-
emitSwitch
public void emitSwitch(int[] keys, SwitchCallback callback, SwitchOptions options)
-
resolveSwitchOptions
private static SwitchOptions resolveSwitchOptions(int[] keys, SwitchOptions options)
-
emitSwitch
public <E extends java.lang.Enum<E>> void emitSwitch(E[] keys, EnumSwitchCallback<E> callback)
-
emitSwitch
public <E extends java.lang.Enum<E>> void emitSwitch(E[] keys, EnumSwitchCallback<E> callback, SwitchOptions options)
-
emitSwitch
public void emitSwitch(java.lang.String[] keys, StringSwitchCallback callback)
-
emitSwitch
public void emitSwitch(java.lang.String[] keys, StringSwitchCallback callback, SwitchOptions options)
-
getStringSwitchBuckets
private static java.util.Map<java.lang.Integer,java.util.List<java.lang.String>> getStringSwitchBuckets(java.util.List<java.lang.String> strings, Func1<java.lang.String,java.lang.Integer> keyCallback)
-
emitStringTrieSwitch
private void emitStringTrieSwitch(java.lang.String[] keys, StringSwitchCallback callback) throws java.lang.Exception
- Throws:
java.lang.Exception
-
stringSwitchHelper
private void stringSwitchHelper(java.util.List<java.lang.String> bucket, StringSwitchCallback callback, Label defaultLabel, Label breakTarget, int index)
-
emitStringHashSwitch
private void emitStringHashSwitch(java.lang.String[] keys, StringSwitchCallback callback, SwitchOptions options) throws java.lang.Exception
- Throws:
java.lang.Exception
-
emitByteOperand
final void emitByteOperand(int value)
-
emitCharOperand
final void emitCharOperand(char value)
-
emitShortOperand
final void emitShortOperand(int value)
-
emitIntOperand
final void emitIntOperand(int value)
-
emitLongOperand
final void emitLongOperand(long value)
-
emitFloatOperand
final void emitFloatOperand(float value)
-
emitDoubleOperand
final void emitDoubleOperand(double value)
-
internalEmit
void internalEmit(OpCode opCode)
-
getByteOperand
static byte getByteOperand(byte[] codes, int index)
-
getCharOperand
static char getCharOperand(byte[] codes, int index)
-
getShortOperand
static short getShortOperand(byte[] codes, int index)
-
getIntOperand
static int getIntOperand(byte[] codes, int index)
-
getLongOperand
static long getLongOperand(byte[] codes, int index)
-
getFloatOperand
static float getFloatOperand(byte[] codes, int index)
-
getDoubleOperand
static double getDoubleOperand(byte[] codes, int index)
-
putByteOperand
static void putByteOperand(byte[] codes, int index, byte value)
-
putCharOperand
static void putCharOperand(byte[] codes, int index, char value)
-
putShortOperand
static void putShortOperand(byte[] codes, int index, short value)
-
putIntOperand
static void putIntOperand(byte[] codes, int index, int value)
-
putLongOperand
static void putLongOperand(byte[] codes, int index, long value)
-
putFloatOperand
static void putFloatOperand(byte[] codes, int index, float value)
-
putDoubleOperand
static void putDoubleOperand(byte[] codes, int index, double value)
-
addFixup
private void addFixup(Label label, int offsetOrigin, int fixupPosition, int operandSize)
-
ensureCapacity
final void ensureCapacity(int size)
-
updateStackSize
final void updateStackSize(OpCode opCode, int stackChange)
-
getLabelPosition
private int getLabelPosition(Label label)
-
bakeByteArray
final byte[] bakeByteArray()
-
enlargeArray
static int[] enlargeArray(int[] incoming)
-
enlargeArray
static <T> T[] enlargeArray(T[] incoming)
-
enlargeArray
static byte[] enlargeArray(byte[] incoming)
-
enlargeArray
static byte[] enlargeArray(byte[] incoming, int requiredSize)
-
getExceptions
final __ExceptionInfo[] getExceptions()
-
getUnhandledCheckedExceptions
final Type<?>[] getUnhandledCheckedExceptions()
-
getMaxStackSize
final int getMaxStackSize()
-
sortExceptions
private static void sortExceptions(__ExceptionInfo[] exceptions)
-
registerCheckedExceptions
private void registerCheckedExceptions(MethodBase method)
-
-