Class CodeGenerator

java.lang.Object
com.strobel.reflection.emit.CodeGenerator

public class CodeGenerator extends Object
  • Field Details

    • DefaultSize

      static final int DefaultSize
      See Also:
    • DefaultFixupArraySize

      static final int DefaultFixupArraySize
      See Also:
    • DefaultLabelArraySize

      static final int DefaultLabelArraySize
      See Also:
    • DefaultExceptionArraySize

      static final int DefaultExceptionArraySize
      See Also:
    • MIN_BYTE

      private static final int MIN_BYTE
      See Also:
    • MAX_BYTE

      private static final int MAX_BYTE
      See Also:
    • _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 Details

    • CodeGenerator

      public CodeGenerator(MethodBuilder methodBuilder)
    • CodeGenerator

      public CodeGenerator(MethodBuilder methodBuilder, int initialSize)
  • Method Details

    • 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(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, String arg)
    • emit

      public void emit(OpCode opCode, Type<?> type)
    • emit

      public void emit(OpCode opCode, ConstructorInfo constructor)
    • stackSize

      private static int stackSize(Type<?> type)
    • emit

      public void emit(OpCode opCode, MethodInfo method)
    • emit

      public void emit(OpCode opCode, FieldInfo field)
    • emit

      public void emit(OpCode opCode, Label label)
    • 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)
    • getLocalLoadOpCode

      private static OpCode getLocalLoadOpCode(Type<?> type, int localIndex)
    • getLocalStoreOpCode

      private static OpCode getLocalStoreOpCode(Type<?> type, int localIndex)
    • 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(Object value, Type<?> type)
    • emitConstant

      public void emitConstant(Object value)
    • emitConstantArray

      public void emitConstantArray(Object array)
    • emitConstant

      public void emitConstant(Object value, Type<?> type)
    • emitType

      public void emitType(Type<?> value)
    • emitMethod

      public void emitMethod(MethodBase value)
    • tryEmitConstant

      private boolean tryEmitConstant(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(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)
    • emitConversion

      public void emitConversion(Type<?> sourceType, Type<?> targetType)
    • emitBoxingConversion

      private void emitBoxingConversion(Type<?> sourceType, Type<?> targetType)
    • 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)
    • emitCastToType

      private void emitCastToType(Type<?> sourceType, Type<?> targetType)
    • emitNumericConversion

      private void emitNumericConversion(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 Enum<E>> void emitSwitch(E[] keys, EnumSwitchCallback<E> callback)
    • emitSwitch

      public <E extends Enum<E>> void emitSwitch(E[] keys, EnumSwitchCallback<E> callback, SwitchOptions options)
    • emitSwitch

      public void emitSwitch(String[] keys, StringSwitchCallback callback)
    • emitSwitch

      public void emitSwitch(String[] keys, StringSwitchCallback callback, SwitchOptions options)
    • getStringSwitchBuckets

      private static Map<Integer,List<String>> getStringSwitchBuckets(List<String> strings, Func1<String,Integer> keyCallback)
    • emitStringTrieSwitch

      private void emitStringTrieSwitch(String[] keys, StringSwitchCallback callback) throws Exception
      Throws:
      Exception
    • stringSwitchHelper

      private void stringSwitchHelper(List<String> bucket, StringSwitchCallback callback, Label defaultLabel, Label breakTarget, int index)
    • emitStringHashSwitch

      private void emitStringHashSwitch(String[] keys, StringSwitchCallback callback, SwitchOptions options) throws Exception
      Throws:
      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)