java.lang.Object
org.glavo.classfile.impl.AbstractDirectBuilder<CodeModel>
org.glavo.classfile.impl.DirectCodeBuilder
- All Implemented Interfaces:
Consumer<CodeElement>,ClassFileBuilder<CodeElement,,CodeBuilder> CodeBuilder,LabelContext,TerminalCodeBuilder
public final class DirectCodeBuilder
extends AbstractDirectBuilder<CodeModel>
implements TerminalCodeBuilder, LabelContext
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.glavo.classfile.CodeBuilder
CodeBuilder.BlockCodeBuilder, CodeBuilder.CatchBuilder -
Field Summary
Fields inherited from class org.glavo.classfile.impl.AbstractDirectBuilder
attributes, constantPool, context, original -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCharacterRange(CharacterRange element) voidaddHandler(ExceptionCatch element) voidaddLocalVariable(LocalVariable element) voidaddLocalVariableType(LocalVariableType element) intallocateLocal(TypeKind typeKind) Returns the local variable slot of a fresh local variable.static Attribute<CodeAttribute> build(MethodInfo methodInfo, Consumer<? super CodeBuilder> handler, SplitConstantPool constantPool, ClassFileImpl context, CodeModel original) intcurPc()intendLabel()Returns the label associated with the end of the current block.getLabel(int bci) intlabelToBci(Label label) newLabel()Returns a fresh unbound label.intparameterSlot(int paramNo) Returns the local variable slot associated with the specified parameter.intReturns the local variable slot associated with the receiver.voidsetLabelTarget(Label label) voidsetLabelTarget(Label label, int bci) voidsetLineNumber(int lineNo) Returns the label associated with the beginning of the current block.toString()with(CodeElement element) Integrate theClassFileElementinto the entity being built.voidwriteArgumentConstant(Opcode opcode, int value) voidwriteBranch(Opcode op, Label target) voidwriteBytecode(Opcode opcode) voidwriteFieldAccess(Opcode opcode, FieldRefEntry ref) voidwriteIncrement(int slot, int val) voidvoidwriteInvokeInterface(Opcode opcode, InterfaceMethodRefEntry ref, int count) voidwriteInvokeNormal(Opcode opcode, MemberRefEntry ref) voidwriteLoadConstant(Opcode opcode, LoadableConstantEntry value) voidwriteLocalVar(Opcode opcode, int localVar) voidwriteLookupSwitch(Label defaultTarget, List<SwitchCase> cases) voidwriteNewMultidimensionalArray(int dimensions, ClassEntry type) voidwriteNewObject(ClassEntry type) voidwriteNewPrimitiveArray(int newArrayCode) voidvoidwriteTableSwitch(int low, int high, Label defaultTarget, List<SwitchCase> cases) voidwriteTypeCheck(Opcode opcode, ClassEntry type) Methods inherited from class org.glavo.classfile.impl.AbstractDirectBuilder
constantPool, original, setOriginal, writeAttributeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.glavo.classfile.ClassFileBuilder
accept, canWriteDirect, constantPool, transformMethods inherited from interface org.glavo.classfile.CodeBuilder
aaload, aastore, aconst_null, aload, anewarray, anewarray, areturn, arraylength, arrayLoadInstruction, arrayStoreInstruction, astore, athrow, baload, bastore, bipush, block, branchInstruction, caload, castore, characterRange, checkcast, checkcast, constantInstruction, constantInstruction, convertInstruction, d2f, d2i, d2l, dadd, daload, dastore, dcmpg, dcmpl, dconst_0, dconst_1, ddiv, dload, dmul, dneg, drem, dreturn, dstore, dsub, dup, dup_x1, dup_x2, dup2, dup2_x1, dup2_x2, exceptionCatch, exceptionCatch, exceptionCatch, exceptionCatchAll, f2d, f2i, f2l, fadd, faload, fastore, fcmpg, fcmpl, fconst_0, fconst_1, fconst_2, fdiv, fieldInstruction, fieldInstruction, fload, fmul, fneg, frem, freturn, fstore, fsub, getfield, getfield, getstatic, getstatic, goto_, goto_w, i2b, i2c, i2d, i2f, i2l, i2s, iadd, iaload, iand, iastore, iconst_0, iconst_1, iconst_2, iconst_3, iconst_4, iconst_5, iconst_m1, idiv, if_acmpeq, if_acmpne, if_icmpeq, if_icmpge, if_icmpgt, if_icmple, if_icmplt, if_icmpne, if_nonnull, if_null, ifeq, ifge, ifgt, ifle, iflt, ifne, ifThen, ifThen, ifThenElse, ifThenElse, iinc, iload, imul, incrementInstruction, ineg, instanceof_, instanceof_, invokedynamic, invokedynamic, invokeDynamicInstruction, invokeDynamicInstruction, invokeInstruction, invokeInstruction, invokeinterface, invokeinterface, invokespecial, invokespecial, invokespecial, invokespecial, invokestatic, invokestatic, invokestatic, invokestatic, invokevirtual, invokevirtual, ior, irem, ireturn, ishl, ishr, istore, isub, iushr, ixor, l2d, l2f, l2i, labelBinding, ladd, laload, land, lastore, lcmp, lconst_0, lconst_1, ldc, ldc, ldiv, lineNumber, lload, lmul, lneg, loadInstruction, localVariable, localVariable, localVariableType, localVariableType, lookupswitch, lookupSwitchInstruction, lor, lrem, lreturn, lshl, lshr, lstore, lsub, lushr, lxor, monitorenter, monitorexit, monitorInstruction, multianewarray, multianewarray, new_, new_, newarray, newBoundLabel, newMultidimensionalArrayInstruction, newMultidimensionalArrayInstruction, newObjectInstruction, newObjectInstruction, newPrimitiveArrayInstruction, newReferenceArrayInstruction, newReferenceArrayInstruction, nop, nopInstruction, operatorInstruction, original, pop, pop2, putfield, putfield, putstatic, putstatic, return_, returnInstruction, saload, sastore, sipush, stackInstruction, storeInstruction, swap, tableswitch, tableswitch, tableSwitchInstruction, throwInstruction, transforming, trying, typeCheckInstruction, typeCheckInstruction
-
Method Details
-
build
public static Attribute<CodeAttribute> build(MethodInfo methodInfo, Consumer<? super CodeBuilder> handler, SplitConstantPool constantPool, ClassFileImpl context, CodeModel original) -
with
Description copied from interface:ClassFileBuilderIntegrate theClassFileElementinto the entity being built.- Specified by:
within interfaceClassFileBuilder<CodeElement,CodeBuilder> - Parameters:
element- the element- Returns:
- this builder
-
newLabel
Description copied from interface:CodeBuilderReturns a fresh unbound label.- Specified by:
newLabelin interfaceCodeBuilder- Specified by:
newLabelin interfaceLabelContext- Returns:
- a fresh unbound label
-
startLabel
Description copied from interface:CodeBuilderReturns the label associated with the beginning of the current block. If the current CodeBuilder is not a "block" builder, such as those provided byCodeBuilder.block(Consumer)orCodeBuilder.ifThenElse(Consumer, Consumer), the current block will be the entire method body.- Specified by:
startLabelin interfaceCodeBuilder- Returns:
- the label associated with the beginning of the current block
-
endLabel
Description copied from interface:CodeBuilderReturns the label associated with the end of the current block. If the current CodeBuilder is not a "block" builder, such as those provided byCodeBuilder.block(Consumer)orCodeBuilder.ifThenElse(Consumer, Consumer), the current block will be the entire method body.- Specified by:
endLabelin interfaceCodeBuilder- Returns:
- the label associated with the end of the current block
-
receiverSlot
public int receiverSlot()Description copied from interface:CodeBuilderReturns the local variable slot associated with the receiver..- Specified by:
receiverSlotin interfaceCodeBuilder- Returns:
- the local variable slot associated with the receiver
-
parameterSlot
public int parameterSlot(int paramNo) Description copied from interface:CodeBuilderReturns the local variable slot associated with the specified parameter.. The returned value is adjusted for the receiver slot (if the method is an instance method) and for the requirement thatlonganddoublevalues require two slots.- Specified by:
parameterSlotin interfaceCodeBuilder- Parameters:
paramNo- the index of the parameter- Returns:
- the local variable slot associated with the specified parameter
-
curTopLocal
public int curTopLocal() -
allocateLocal
Description copied from interface:CodeBuilderReturns the local variable slot of a fresh local variable. This method makes reasonable efforts to determine which slots are in use and which are not. When transforming a method, fresh locals begin at themaxLocalsof the original method. For a method being built directly, fresh locals begin after the last parameter slot.If the current code builder is a "block" code builder provided by
CodeBuilder.block(Consumer),CodeBuilder.ifThen(Consumer), orCodeBuilder.ifThenElse(Consumer, Consumer), at the end of the block, locals are reset to their value at the beginning of the block.- Specified by:
allocateLocalin interfaceCodeBuilder- Parameters:
typeKind- the type of the local variable- Returns:
- the local variable slot of a fresh local variable
-
curPc
public int curPc() -
methodInfo
-
writeBytecode
-
writeLocalVar
-
writeIncrement
public void writeIncrement(int slot, int val) -
writeBranch
-
writeLookupSwitch
-
writeTableSwitch
-
writeFieldAccess
-
writeInvokeNormal
-
writeInvokeInterface
-
writeInvokeDynamic
-
writeNewObject
-
writeNewPrimitiveArray
public void writeNewPrimitiveArray(int newArrayCode) -
writeNewReferenceArray
-
writeNewMultidimensionalArray
-
writeTypeCheck
-
writeArgumentConstant
-
writeLoadConstant
-
getLabel
- Specified by:
getLabelin interfaceLabelContext
-
labelToBci
- Specified by:
labelToBciin interfaceLabelContext
-
setLineNumber
public void setLineNumber(int lineNo) -
setLabelTarget
-
setLabelTarget
- Specified by:
setLabelTargetin interfaceLabelContext
-
addCharacterRange
-
addHandler
-
addLocalVariable
-
addLocalVariableType
-
toString
-