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 interfaceCodeGenerator.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 voidaddFixup(Label label, int offsetOrigin, int fixupPosition, int operandSize)(package private) byte[]bakeByteArray()voidbeginCatchBlock(Type<?> caughtType)LabelbeginExceptionBlock()voidbeginFinallyBlock()voidcall(ConstructorInfo constructor)voidcall(OpCode opCode, MethodInfo method)voidcall(MethodInfo method)private static booleancanEmitBytecodeConstant(Type<?> type)static booleancanEmitConstant(java.lang.Object value, Type<?> type)LocalBuilderdeclareLocal(Type<?> localType)LocalBuilderdeclareLocal(java.lang.String name, Type<?> localType)LabeldefineLabel()voiddup()voiddup(Type<?> type)voiddup2()voiddup2x1()voiddup2x2()voidemit(OpCode opCode)voidemit(OpCode opCode, byte arg)voidemit(OpCode opCode, double arg)voidemit(OpCode opCode, float arg)voidemit(OpCode opCode, int arg)voidemit(OpCode opCode, long arg)voidemit(OpCode opCode, short arg)voidemit(OpCode opCode, ConstructorInfo constructor)voidemit(OpCode opCode, Label label)voidemit(OpCode opCode, FieldInfo field)voidemit(OpCode opCode, MethodInfo method)voidemit(OpCode opCode, Type<?> type)voidemit(OpCode opCode, java.lang.String arg)voidemitArray(Type<?> elementType, int count, CodeGenerator.EmitArrayElementCallback emit)voidemitBoolean(boolean value)voidemitBox(Type<?> type)private voidemitBoxedToBoxedConversion(Type<?> sourceType, Type<?> targetType)private voidemitBoxedToReferenceConversion(Type<?> sourceType)private voidemitBoxedToUnboxedConversion(Type<?> sourceType, Type<?> targetType)private voidemitBoxedToUnboxedNumericConversion(Type<?> sourceType, Type<?> targetType)private voidemitBoxingConversion(Type<?> sourceType, Type<?> targetType)voidemitByte(byte value)(package private) voidemitByteOperand(int value)private voidemitCastToType(Type<?> sourceType, Type<?> targetType)voidemitCharacter(char value)(package private) voidemitCharOperand(char value)voidemitConstant(java.lang.Object value)voidemitConstant(java.lang.Object value, Type<?> type)voidemitConstantArray(java.lang.Object array)voidemitConversion(Type<?> sourceType, Type<?> targetType)voidemitDefaultValue(Type<?> type)voidemitDouble(double value)(package private) voidemitDoubleOperand(double value)voidemitFloat(float value)(package private) voidemitFloatOperand(float value)voidemitGoto(Label label)voidemitInteger(int value)(package private) voidemitIntOperand(int value)voidemitLoad(LocalBuilder local)protected voidemitLoad(Type<?> type, int absoluteIndex)voidemitLoadArgument(int index)protected voidemitLoadConstant(int token)voidemitLoadElement(Type<?> elementType)protected voidemitLoadLongConstant(int token)voidemitLong(long value)(package private) voidemitLongOperand(long value)voidemitMethod(MethodBase value)voidemitNew(Type<?> type)voidemitNewArray(Type<?> arrayType)voidemitNewArray(Type<?> arrayType, int dimensionsToInitialize)voidemitNull()private voidemitNumericConversion(Type<?> sourceType, Type<?> targetType)voidemitReturn()voidemitReturn(Type<?> returnType)voidemitShort(short value)(package private) voidemitShortOperand(int value)voidemitStore(LocalBuilder local)protected voidemitStore(Type<?> type, int absoluteIndex)voidemitStoreArgument(int index)voidemitStoreElement(Type<?> elementType)voidemitString(java.lang.String value)private voidemitStringHashSwitch(java.lang.String[] keys, StringSwitchCallback callback, SwitchOptions options)private voidemitStringTrieSwitch(java.lang.String[] keys, StringSwitchCallback callback)voidemitSwitch(int[] keys, SwitchCallback callback)voidemitSwitch(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)voidemitSwitch(java.lang.String[] keys, StringSwitchCallback callback)voidemitSwitch(java.lang.String[] keys, StringSwitchCallback callback, SwitchOptions options)voidemitThis()voidemitType(Type<?> value)voidemitUnbox(Type<?> type)private voidemitUnboxedToBoxedConversion(Type<?> sourceType, Type<?> targetType)voidendExceptionBlock()voidendTryBlock()(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) voidensureCapacity(int size)(package private) static bytegetByteOperand(byte[] codes, int index)(package private) static chargetCharOperand(byte[] codes, int index)(package private) static doublegetDoubleOperand(byte[] codes, int index)(package private) __ExceptionInfo[]getExceptions()voidgetField(FieldInfo field)(package private) static floatgetFloatOperand(byte[] codes, int index)(package private) static intgetIntOperand(byte[] codes, int index)private intgetLabelPosition(Label label)private static OpCodegetLocalLoadOpCode(Type<?> type, int localIndex)private static OpCodegetLocalStoreOpCode(Type<?> type, int localIndex)(package private) static longgetLongOperand(byte[] codes, int index)(package private) intgetMaxStackSize()(package private) static shortgetShortOperand(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()voidincrement(LocalBuilder local, int delta)(package private) voidinternalEmit(OpCode opCode)voidmarkLabel(Label label)intoffset()voidpop()voidpop(Type<?> type)voidpop2()(package private) static voidputByteOperand(byte[] codes, int index, byte value)(package private) static voidputCharOperand(byte[] codes, int index, char value)(package private) static voidputDoubleOperand(byte[] codes, int index, double value)voidputField(FieldInfo field)(package private) static voidputFloatOperand(byte[] codes, int index, float value)(package private) static voidputIntOperand(byte[] codes, int index, int value)(package private) static voidputLongOperand(byte[] codes, int index, long value)(package private) static voidputShortOperand(byte[] codes, int index, short value)private voidregisterCheckedExceptions(MethodBase method)private static SwitchOptionsresolveSwitchOptions(int[] keys, SwitchOptions options)private static voidsortExceptions(__ExceptionInfo[] exceptions)private static intstackSize(Type<?> type)private voidstringSwitchHelper(java.util.List<java.lang.String> bucket, StringSwitchCallback callback, Label defaultLabel, Label breakTarget, int index)(package private) inttranslateLocal(int localIndex)(package private) inttranslateParameter(int localIndex)private booleantryEmitConstant(java.lang.Object value, Type<?> type)(package private) voidupdateStackSize(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)
-
-