Search in sources :

Example 1 with Exception_data

use of com.sun.tools.classfile.Code_attribute.Exception_data in project ceylon-compiler by ceylon.

the class TryBlockWriter method reset.

public void reset(Code_attribute attr) {
    indexMap = new HashMap<Exception_data, Integer>();
    pcMap = new HashMap<Integer, List<Exception_data>>();
    for (int i = 0; i < attr.exception_table.length; i++) {
        Exception_data entry = attr.exception_table[i];
        indexMap.put(entry, i);
        put(entry.start_pc, entry);
        put(entry.end_pc, entry);
        put(entry.handler_pc, entry);
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Exception_data(com.sun.tools.classfile.Code_attribute.Exception_data)

Example 2 with Exception_data

use of com.sun.tools.classfile.Code_attribute.Exception_data in project ceylon-compiler by ceylon.

the class TryBlockWriter method writeTrys.

public void writeTrys(Instruction instr, NoteKind kind) {
    // get from Options?
    String indent = space(2);
    int pc = instr.getPC();
    List<Exception_data> entries = pcMap.get(pc);
    if (entries != null) {
        for (ListIterator<Exception_data> iter = entries.listIterator(kind == NoteKind.END ? entries.size() : 0); kind == NoteKind.END ? iter.hasPrevious() : iter.hasNext(); ) {
            Exception_data entry = kind == NoteKind.END ? iter.previous() : iter.next();
            if (kind.match(entry, pc)) {
                print(indent);
                print(kind.text);
                print("[");
                print(indexMap.get(entry));
                print("] ");
                if (entry.catch_type == 0)
                    print("finally");
                else {
                    print("#" + entry.catch_type);
                    print(" // ");
                    constantWriter.write(entry.catch_type);
                }
                println();
            }
        }
    }
}
Also used : Exception_data(com.sun.tools.classfile.Code_attribute.Exception_data)

Example 3 with Exception_data

use of com.sun.tools.classfile.Code_attribute.Exception_data in project ceylon-compiler by ceylon.

the class Pos05 method verifyMulticatchExceptionRanges.

void verifyMulticatchExceptionRanges(File f) {
    System.err.println("verify: " + f);
    try {
        int count = 0;
        ClassFile cf = ClassFile.read(f);
        Method testMethod = null;
        for (Method m : cf.methods) {
            if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
                testMethod = m;
                break;
            }
        }
        if (testMethod == null) {
            throw new Error("Test method not found");
        }
        Code_attribute ea = (Code_attribute) testMethod.attributes.get(Attribute.Code);
        if (testMethod == null) {
            throw new Error("Code attribute for test() method not found");
        }
        Exception_data firstExceptionTable = null;
        for (int i = 0; i < ea.exception_table_langth; i++) {
            if (firstExceptionTable == null) {
                firstExceptionTable = ea.exception_table[i];
            }
            if (ea.exception_table[i].handler_pc != firstExceptionTable.handler_pc || ea.exception_table[i].start_pc != firstExceptionTable.start_pc || ea.exception_table[i].end_pc != firstExceptionTable.end_pc) {
                throw new Error("Multiple overlapping catch clause found in generated code");
            }
            count++;
        }
        if (count != TYPES_IN_MULTICATCH) {
            throw new Error("Wrong number of exception data found: " + count);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Error("error reading " + f + ": " + e);
    }
}
Also used : ClassFile(com.sun.tools.classfile.ClassFile) Code_attribute(com.sun.tools.classfile.Code_attribute) Method(com.sun.tools.classfile.Method) Exception_data(com.sun.tools.classfile.Code_attribute.Exception_data)

Aggregations

Exception_data (com.sun.tools.classfile.Code_attribute.Exception_data)3 ClassFile (com.sun.tools.classfile.ClassFile)1 Code_attribute (com.sun.tools.classfile.Code_attribute)1 Method (com.sun.tools.classfile.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1