Search in sources :

Example 21 with Label

use of org.mvel2.asm.Label in project mvel by mvel.

the class CheckMethodAdapter method visitMaxs.

@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
    checkStartCode();
    checkEndCode();
    endCode = true;
    for (Label l : usedLabels) {
        if (labels.get(l) == null) {
            throw new IllegalStateException("Undefined label used");
        }
    }
    for (int i = 0; i < handlers.size(); ) {
        Integer start = labels.get(handlers.get(i++));
        Integer end = labels.get(handlers.get(i++));
        if (start == null || end == null) {
            throw new IllegalStateException("Undefined try catch block labels");
        }
        if (end.intValue() <= start.intValue()) {
            throw new IllegalStateException("Emty try catch block handler range");
        }
    }
    checkUnsignedShort(maxStack, "Invalid max stack");
    checkUnsignedShort(maxLocals, "Invalid max locals");
    super.visitMaxs(maxStack, maxLocals);
}
Also used : Label(org.mvel2.asm.Label)

Example 22 with Label

use of org.mvel2.asm.Label in project mvel by mvel.

the class Textifier method visitLocalVariable.

@Override
public void visitLocalVariable(final String name, final String desc, final String signature, final Label start, final Label end, final int index) {
    buf.setLength(0);
    buf.append(tab2).append("LOCALVARIABLE ").append(name).append(' ');
    appendDescriptor(FIELD_DESCRIPTOR, desc);
    buf.append(' ');
    appendLabel(start);
    buf.append(' ');
    appendLabel(end);
    buf.append(' ').append(index).append('\n');
    if (signature != null) {
        buf.append(tab2);
        appendDescriptor(FIELD_SIGNATURE, signature);
        TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
        SignatureReader r = new SignatureReader(signature);
        r.acceptType(sv);
        buf.append(tab2).append("// declaration: ").append(sv.getDeclaration()).append('\n');
    }
    text.add(buf.toString());
}
Also used : SignatureReader(org.mvel2.asm.signature.SignatureReader)

Example 23 with Label

use of org.mvel2.asm.Label in project mvel by mvel.

the class TraceMethodVisitor method visitLocalVariableAnnotation.

@Override
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) {
    Printer p = this.p.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible);
    AnnotationVisitor av = mv == null ? null : mv.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible);
    return new TraceAnnotationVisitor(av, p);
}
Also used : AnnotationVisitor(org.mvel2.asm.AnnotationVisitor)

Example 24 with Label

use of org.mvel2.asm.Label in project mvel by mvel.

the class AnalyzerAdapter method visitTypeInsn.

@Override
public void visitTypeInsn(final int opcode, final String type) {
    if (opcode == Opcodes.NEW) {
        if (labels == null) {
            Label l = new Label();
            labels = new ArrayList<Label>(3);
            labels.add(l);
            if (mv != null) {
                mv.visitLabel(l);
            }
        }
        for (int i = 0; i < labels.size(); ++i) {
            uninitializedTypes.put(labels.get(i), type);
        }
    }
    if (mv != null) {
        mv.visitTypeInsn(opcode, type);
    }
    execute(opcode, 0, type);
}
Also used : Label(org.mvel2.asm.Label)

Example 25 with Label

use of org.mvel2.asm.Label in project mvel by mvel.

the class GeneratorAdapter method tableSwitch.

/**
 * Generates the instructions for a switch statement.
 *
 * @param keys
 *            the switch case keys.
 * @param generator
 *            a generator to generate the code for the switch cases.
 * @param useTable
 *            <tt>true</tt> to use a TABLESWITCH instruction, or
 *            <tt>false</tt> to use a LOOKUPSWITCH instruction.
 */
public void tableSwitch(final int[] keys, final TableSwitchGenerator generator, final boolean useTable) {
    for (int i = 1; i < keys.length; ++i) {
        if (keys[i] < keys[i - 1]) {
            throw new IllegalArgumentException("keys must be sorted ascending");
        }
    }
    Label def = newLabel();
    Label end = newLabel();
    if (keys.length > 0) {
        int len = keys.length;
        int min = keys[0];
        int max = keys[len - 1];
        int range = max - min + 1;
        if (useTable) {
            Label[] labels = new Label[range];
            Arrays.fill(labels, def);
            for (int i = 0; i < len; ++i) {
                labels[keys[i] - min] = newLabel();
            }
            mv.visitTableSwitchInsn(min, max, def, labels);
            for (int i = 0; i < range; ++i) {
                Label label = labels[i];
                if (label != def) {
                    mark(label);
                    generator.generateCase(i + min, end);
                }
            }
        } else {
            Label[] labels = new Label[len];
            for (int i = 0; i < len; ++i) {
                labels[i] = newLabel();
            }
            mv.visitLookupSwitchInsn(def, keys, labels);
            for (int i = 0; i < len; ++i) {
                mark(labels[i]);
                generator.generateCase(keys[i], end);
            }
        }
    }
    mark(def);
    generator.generateDefault();
    mark(end);
}
Also used : Label(org.mvel2.asm.Label)

Aggregations

Label (org.mvel2.asm.Label)97 MethodVisitor (org.mvel2.asm.MethodVisitor)49 FieldDefinition (org.drools.core.factmodel.FieldDefinition)24 Map (java.util.Map)18 Type (org.mvel2.asm.Type)12 IOException (java.io.IOException)10 BitSet (java.util.BitSet)8 FieldVisitor (org.mvel2.asm.FieldVisitor)8 Method (java.lang.reflect.Method)7 CompiledInvoker (org.drools.core.spi.CompiledInvoker)7 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)5 ObjectInput (java.io.ObjectInput)4 ObjectOutput (java.io.ObjectOutput)4 Collection (java.util.Collection)4 Thing (org.drools.core.factmodel.traits.Thing)4 Declaration (org.drools.core.rule.Declaration)4 ClassGenerator (org.drools.core.rule.builder.dialect.asm.ClassGenerator)4 ClassWriter (org.mvel2.asm.ClassWriter)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3