public Insn<AbstractInsnNode> last() { return new Insn<>(method, instructions.getLast()); }
case LONG: case INT: { if (useConstants && code.getLast() instanceof LdcInsnNode) { LdcInsnNode node = (LdcInsnNode) code.getLast(); code.remove(node); case FLOAT: case DOUBLE: { if (useConstants && code.getLast() instanceof LdcInsnNode) { LdcInsnNode node = (LdcInsnNode) code.getLast(); code.remove(node); if (useConstants && code.getLast() instanceof LdcInsnNode) { LdcInsnNode node = (LdcInsnNode) code.getLast(); code.remove(node);
@Override public void visitJumpInsn(final int opcode, final Label label) { super.visitJumpInsn(opcode, label); LabelNode labelNode = ((JumpInsnNode) instructions.getLast()).label; if (opcode == JSR && !subroutinesInsns.containsKey(labelNode)) { subroutinesInsns.put(labelNode, new BitSet()); } }
@Override public void visitJumpInsn(final int opcode, final Label label) { super.visitJumpInsn(opcode, label); LabelNode labelNode = ((JumpInsnNode) instructions.getLast()).label; if (opcode == JSR && !subroutinesInsns.containsKey(labelNode)) { subroutinesInsns.put(labelNode, new BitSet()); } }
@Override public void visitJumpInsn(final int opcode, final Label label) { super.visitJumpInsn(opcode, label); LabelNode labelNode = ((JumpInsnNode) instructions.getLast()).label; if (opcode == JSR && !subroutinesInsns.containsKey(labelNode)) { subroutinesInsns.put(labelNode, new BitSet()); } }
/** * Detects a JSR instruction and sets a flag to indicate we will need to do * inlining. */ @Override public void visitJumpInsn(final int opcode, final Label lbl) { super.visitJumpInsn(opcode, lbl); LabelNode ln = ((JumpInsnNode) instructions.getLast()).label; if (opcode == JSR && !subroutineHeads.containsKey(ln)) { subroutineHeads.put(ln, new BitSet()); } }
public LabelNode findEndLabel(MethodNode method) { for (AbstractInsnNode instruction = method.instructions.getLast(); instruction != null; instruction = instruction.getPrevious()) { if (instruction instanceof LabelNode) return (LabelNode) instruction; } return null; } }
InsnListIterator(final int index) { if (index == size()) { nextInsn = null; previousInsn = getLast(); } else { nextInsn = get(index); previousInsn = nextInsn.previousInsn; } }
InsnListIterator(int index) { if (index == size()) { next = null; prev = getLast(); } else { next = get(index); prev = next.prev; } }
public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) { if (ENUM_TYPE.equals(context.getSuperClassName()) && CONSTRUCTOR_NAME.equals(methodNode.name) && CONSTRUCTOR_DESC.equals(methodNode.desc) && new Matcher().match(methodNode)) { output.ignore(methodNode.instructions.getFirst(), methodNode.instructions.getLast()); } }
@Override public AnnotationVisitor visitInsnAnnotation( final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { // Find the last real instruction, i.e. the instruction targeted by this annotation. AbstractInsnNode currentInsn = instructions.getLast(); while (currentInsn.getOpcode() == -1) { currentInsn = currentInsn.getPrevious(); } // Add the annotation to this instruction. TypeAnnotationNode typeAnnotation = new TypeAnnotationNode(typeRef, typePath, descriptor); if (visible) { if (currentInsn.visibleTypeAnnotations == null) { currentInsn.visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1); } currentInsn.visibleTypeAnnotations.add(typeAnnotation); } else { if (currentInsn.invisibleTypeAnnotations == null) { currentInsn.invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1); } currentInsn.invisibleTypeAnnotations.add(typeAnnotation); } return typeAnnotation; }
public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) { if ((methodNode.access & Opcodes.ACC_PRIVATE) != 0 && CONSTRUCTOR_NAME.equals(methodNode.name) && CONSTRUCTOR_DESC.equals(methodNode.desc) && new Matcher() .match(methodNode, context.getSuperClassName())) { output.ignore(methodNode.instructions.getFirst(), methodNode.instructions.getLast()); } }
public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) { for (String annotation : context.getClassAnnotations()) { if (matches(annotation)) { output.ignore(methodNode.instructions.getFirst(), methodNode.instructions.getLast()); return; } } if (presentIn(methodNode.invisibleAnnotations) || presentIn(methodNode.visibleAnnotations)) { output.ignore(methodNode.instructions.getFirst(), methodNode.instructions.getLast()); } }
public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) { if ((methodNode.access & Opcodes.ACC_SYNTHETIC) == 0) { return; } if (methodNode.name.startsWith("lambda$")) { return; } if (KotlinGeneratedFilter.isKotlinClass(context)) { if (KotlinDefaultArgumentsFilter .isDefaultArgumentsMethodName(methodNode.name)) { return; } if (KotlinCoroutineFilter.isLastArgumentContinuation(methodNode)) { return; } } output.ignore(methodNode.instructions.getFirst(), methodNode.instructions.getLast()); }
public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) { if (isMethodFiltered(context.getClassName(), context.getSuperClassName(), methodNode.name, methodNode.desc)) { output.ignore(methodNode.instructions.getFirst(), methodNode.instructions.getLast()); } }
public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) { if (context.getSourceFileName() == null) { // probably full debug information is missing // disabled filtering as all methods might be erroneously skipped return; } if (!isKotlinClass(context)) { return; } if (hasLineNumber(methodNode)) { return; } output.ignore(methodNode.instructions.getFirst(), methodNode.instructions.getLast()); }
@Override public void process(@Nonnull final ParserClassNode classNode, @Nonnull final RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); final InsnList instructions = method.instructions; AbstractInsnNode ret = instructions.getLast(); while (ret.getOpcode() != ARETURN) ret = ret.getPrevious(); final CodeBlock block = CodeBlock.newCodeBlock(); block.newobj(CodegenUtils.p(VarFramingMatcher.class)) .dup_x1() .swap(); createVarFieldArray(block, method); block.invokespecial(CodegenUtils.p(VarFramingMatcher.class), "<init>", CodegenUtils.sig(void.class, Rule.class, Var[].class)); instructions.insertBefore(ret, block.getInstructionList()); method.setBodyRewritten(); }
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); InsnList instructions = method.instructions; AbstractInsnNode ret = instructions.getLast(); while (ret.getOpcode() != ARETURN) { ret = ret.getPrevious(); } // stack: <Matcher> instructions.insertBefore(ret, new TypeInsnNode(NEW, VAR_FRAMING_MATCHER.getInternalName())); // stack: <Matcher> :: <VarFramingMatcher> instructions.insertBefore(ret, new InsnNode(DUP_X1)); // stack: <VarFramingMatcher> :: <Matcher> :: <VarFramingMatcher> instructions.insertBefore(ret, new InsnNode(SWAP)); // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher> createVarFieldArray(method, instructions, ret); // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher> :: <VarFieldArray> instructions.insertBefore(ret, new MethodInsnNode(INVOKESPECIAL, VAR_FRAMING_MATCHER.getInternalName(), "<init>", '(' + RULE_DESC + '[' + VAR_DESC + ")V", false)); // stack: <VarFramingMatcher> method.setBodyRewritten(); }
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); if (method.getNumberOfReturns() == 1) return; checkState(method.getNumberOfReturns() > 1); AbstractInsnNode current = method.instructions.getLast(); // find last return while (current.getOpcode() != ARETURN) { current = current.getPrevious(); } LabelNode lastReturnLabel = new LabelNode(); method.instructions.insertBefore(current, lastReturnLabel); // iterate backwards up to first instructions while ((current = current.getPrevious()) != null) { // replace returns with gotos if (current.getOpcode() == ARETURN) { JumpInsnNode gotoInstruction = new JumpInsnNode(GOTO, lastReturnLabel); method.instructions.set(current, gotoInstruction); current = gotoInstruction; } } }
public void process(ParserClassNode classNode, RuleMethod method) throws Exception { checkArgNotNull(classNode, "classNode"); checkArgNotNull(method, "method"); checkState(!method.isSuperMethod()); // super methods have flag moved to the overriding method InsnList instructions = method.instructions; AbstractInsnNode ret = instructions.getLast(); while (ret.getOpcode() != ARETURN) { ret = ret.getPrevious(); } // stack: <rule> instructions.insertBefore(ret, new InsnNode(DUP)); // stack: <rule> :: <rule> LabelNode isNullLabel = new LabelNode(); instructions.insertBefore(ret, new JumpInsnNode(IFNULL, isNullLabel)); // stack: <rule> if (method.hasSuppressNodeAnnotation()) generateMarkerCall(instructions, ret, "suppressNode"); if (method.hasSuppressSubnodesAnnotation()) generateMarkerCall(instructions, ret, "suppressSubnodes"); if (method.hasSkipNodeAnnotation()) generateMarkerCall(instructions, ret, "skipNode"); if (method.hasMemoMismatchesAnnotation()) generateMarkerCall(instructions, ret, "memoMismatches"); // stack: <rule> instructions.insertBefore(ret, isNullLabel); // stack: <rule> }