Example usage for org.objectweb.asm.tree AbstractInsnNode LABEL

List of usage examples for org.objectweb.asm.tree AbstractInsnNode LABEL

Introduction

In this page you can find the example usage for org.objectweb.asm.tree AbstractInsnNode LABEL.

Prototype

int LABEL

To view the source code for org.objectweb.asm.tree AbstractInsnNode LABEL.

Click Source Link

Document

The type of LabelNode "instructions".

Usage

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AbstractCreateDispatchCodeAdapter.java

License:Open Source License

private LabelNode findBreakLabel(InsnList instructions) {
    for (int i = instructions.size() - 1; i >= 0; i--) {
        AbstractInsnNode node = instructions.get(i);
        if (node.getType() == AbstractInsnNode.LABEL) {
            return (LabelNode) node;
        }/*  w w  w. j  a v a2s.  c  o m*/
    }
    throw new RuntimeException("Can't find break label to create dispatch code");
}

From source file:org.eclipse.objectteams.otredyn.bytecode.asm.AbstractTransformableClassNode.java

License:Open Source License

/**
 * Adds a new Label to an existing switch statement
 * @param instructions the instructions, in which the switch statement is defined
 * @param newInstructions the instructions of the new label
 * @param labelIndex the index of the label
 *///from  w w w  .  ja  va2 s .  c  o m
@SuppressWarnings("unchecked")
protected void addNewLabelToSwitch(InsnList instructions, InsnList newInstructions, int labelIndex) {
    ListIterator<AbstractInsnNode> iter = instructions.iterator();
    LookupSwitchInsnNode lSwitch = null;
    while (iter.hasNext()) {
        AbstractInsnNode node = (AbstractInsnNode) iter.next();
        if (node.getType() == AbstractInsnNode.LOOKUPSWITCH_INSN) {
            lSwitch = (LookupSwitchInsnNode) node;
            LabelNode label = new LabelNode();
            boolean labelAdded = false;
            for (int i = 0; i < lSwitch.keys.size(); i++) {
                Integer key = (Integer) lSwitch.keys.get(i);
                if (key >= labelIndex) {
                    lSwitch.keys.add(i, labelIndex);
                    lSwitch.labels.add(i, label);
                    labelAdded = true;
                    break;
                }
            }
            if (!labelAdded) {
                lSwitch.labels.add(label);
                lSwitch.keys.add(labelIndex);
            }
            boolean foundDefLabel = false;
            AbstractInsnNode prevNode = node;
            while (iter.hasNext()) {
                node = (AbstractInsnNode) iter.next();
                if (node.getType() == AbstractInsnNode.LABEL) {
                    if (!foundDefLabel) {
                        foundDefLabel = true;
                    } else {
                        break;
                    }
                }
                prevNode = node;
            }
            instructions.insert(prevNode, label);
            instructions.insert(label, newInstructions);
        }
    }
    if (lSwitch == null) {
        throw new RuntimeException("No switch statement found.");
    }
}

From source file:org.evosuite.instrumentation.NodeRegularExpression.java

License:Open Source License

/**
 * <p>matches</p>//from  w  ww  . j av  a2s .  c  o m
 *
 * @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a boolean.
 */
public boolean matches(InsnList instructions) {
    int match = 0;

    AbstractInsnNode node = instructions.getFirst();
    while (node != instructions.getLast()) {
        if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL
                || node.getType() == AbstractInsnNode.LINE) {
            node = node.getNext();
            continue;
        } else {
            boolean found = false;
            for (int opcode : pattern[match]) {
                if (node.getOpcode() == opcode) {
                    match++;
                    found = true;
                    break;
                }
            }
            if (!found)
                match = 0;
        }
        if (match == pattern.length)
            return true;

        node = node.getNext();
    }

    return false;
}

From source file:org.evosuite.instrumentation.NodeRegularExpression.java

License:Open Source License

/**
 * <p>getNextMatch</p>//from   w w w  .  j a  v  a2  s  .c  om
 *
 * @param start a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 * @param instructions a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a {@link org.objectweb.asm.tree.AbstractInsnNode} object.
 */
public AbstractInsnNode getNextMatch(AbstractInsnNode start, InsnList instructions) {
    int match = 0;

    AbstractInsnNode node = start;
    AbstractInsnNode startNode = start;
    while (node != instructions.getLast()) {
        if (node.getType() == AbstractInsnNode.FRAME || node.getType() == AbstractInsnNode.LABEL
                || node.getType() == AbstractInsnNode.LINE) {
            node = node.getNext();
            continue;
        } else {
            boolean found = false;
            for (int opcode : pattern[match]) {
                if (node.getOpcode() == opcode) {
                    if (match == 0)
                        startNode = node;
                    match++;
                    found = true;
                    break;
                }
            }
            if (!found)
                match = 0;
        }
        if (match == pattern.length) {
            return startNode;
        }

        node = node.getNext();
    }

    return null;

}

From source file:org.jacoco.core.internal.analysis.filter.AbstractMatcher.java

License:Open Source License

/**
 * Returns first instruction from given and following it that is not
 * {@link AbstractInsnNode#FRAME}, {@link AbstractInsnNode#LABEL},
 * {@link AbstractInsnNode#LINE}./* w  w  w.jav a  2s. c om*/
 */
static AbstractInsnNode skipNonOpcodes(AbstractInsnNode cursor) {
    while (cursor != null && (cursor.getType() == AbstractInsnNode.FRAME
            || cursor.getType() == AbstractInsnNode.LABEL || cursor.getType() == AbstractInsnNode.LINE)) {
        cursor = cursor.getNext();
    }
    return cursor;
}

From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java

License:Open Source License

private static void filter(final IFilterOutput output, final List<TryCatchBlockNode> tryCatchBlocks,
        final TryCatchBlockNode catchAnyBlock) {
    final AbstractInsnNode e = next(catchAnyBlock.handler);
    final int size = size(e);
    if (size <= 0) {
        return;//ww w  .  j a  v  a2 s .  c  o  m
    }

    // Determine instructions inside regions
    final Set<AbstractInsnNode> inside = new HashSet<AbstractInsnNode>();
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            AbstractInsnNode i = t.start;
            while (i != t.end) {
                inside.add(i);
                i = i.getNext();
            }
        }
    }

    // Find and merge duplicates at exits of regions
    for (final TryCatchBlockNode t : tryCatchBlocks) {
        if (t.handler == catchAnyBlock.handler) {
            boolean continues = false;
            AbstractInsnNode i = t.start;

            while (i != t.end) {
                switch (i.getType()) {
                case AbstractInsnNode.FRAME:
                case AbstractInsnNode.LINE:
                case AbstractInsnNode.LABEL:
                    break;
                case AbstractInsnNode.JUMP_INSN:
                    final AbstractInsnNode jumpTarget = next(((JumpInsnNode) i).label);
                    if (!inside.contains(jumpTarget)) {
                        merge(output, size, e, jumpTarget);
                    }
                    continues = i.getOpcode() != Opcodes.GOTO;
                    break;
                default:
                    switch (i.getOpcode()) {
                    case Opcodes.IRETURN:
                    case Opcodes.LRETURN:
                    case Opcodes.FRETURN:
                    case Opcodes.DRETURN:
                    case Opcodes.ARETURN:
                    case Opcodes.RETURN:
                    case Opcodes.ATHROW:
                        continues = false;
                        break;
                    default:
                        continues = true;
                        break;
                    }
                    break;
                }
                i = i.getNext();
            }

            i = next(i);
            if (continues && !inside.contains(i)) {
                merge(output, size, e, i);
            }
        }

        if (t != catchAnyBlock && t.start == catchAnyBlock.start && t.end == catchAnyBlock.end) {
            final AbstractInsnNode i = next(next(t.handler));
            if (!inside.contains(i)) {
                // javac's empty catch - merge after ASTORE
                merge(output, size, e, i);
            }
        }
    }
}

From source file:org.jacoco.core.internal.analysis.filter.FinallyFilter.java

License:Open Source License

private static AbstractInsnNode next(AbstractInsnNode i) {
    do {/*from   w  w w  .  j  ava 2s . co  m*/
        i = i.getNext();
    } while (i != null && (AbstractInsnNode.FRAME == i.getType() || AbstractInsnNode.LABEL == i.getType()
            || AbstractInsnNode.LINE == i.getType()));
    return i;
}

From source file:org.jacoco.playground.filter.InsnSequenceMatcher.java

License:Open Source License

private boolean isIgnored(AbstractInsnNode node) {
    switch (node.getType()) {
    case AbstractInsnNode.LABEL:
    case AbstractInsnNode.LINE:
        return true;
    default:/*from  www.  ja  v a2  s .  co m*/
        return false;
    }
}

From source file:org.jacoco.playground.filter.JavacFinallyFilter.java

License:Open Source License

private AbstractInsnNode skipIgnoredForward(final AbstractInsnNode node) {
    if (node == null) {
        return null;
    }//from  w ww  .j av  a  2  s.  co m
    if (node.getType() == AbstractInsnNode.LABEL) {
        return getNext(node);
    }
    if (node.getType() == AbstractInsnNode.LINE) {
        return getNext(node);
    }
    return node;
}

From source file:org.jacoco.playground.filter.MethodDumper.java

License:Open Source License

private static void insertLabels(InsnList list, TestCaseDumper printer) {
    boolean hasLabel = false;
    for (AbstractInsnNode node = list.getFirst(); node != null; node = node.getNext()) {
        switch (node.getType()) {
        case AbstractInsnNode.LINE:
            break;
        case AbstractInsnNode.LABEL:
            printer.declareLabel(((LabelNode) node).getLabel());
            hasLabel = true;/*from ww w. j  a  va  2  s .  c  o  m*/
            break;
        default:
            if (hasLabel) {
                hasLabel = false;
            } else {
                final Label label = new Label();
                printer.declareLabel(label);
                list.insertBefore(node, new LabelNode(label));
            }
            break;
        }
    }
}