Search in sources :

Example 6 with ConstantPool

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

the class StackMapWriter method print.

void print(verification_type_info entry) {
    if (entry == null) {
        print("ERROR");
        return;
    }
    switch(entry.tag) {
        case -1:
            print(((CustomVerificationTypeInfo) entry).text);
            break;
        case ITEM_Top:
            print("top");
            break;
        case ITEM_Integer:
            print("int");
            break;
        case ITEM_Float:
            print("float");
            break;
        case ITEM_Long:
            print("long");
            break;
        case ITEM_Double:
            print("double");
            break;
        case ITEM_Null:
            print("null");
            break;
        case ITEM_UninitializedThis:
            print("uninit_this");
            break;
        case ITEM_Object:
            try {
                ConstantPool cp = classWriter.getClassFile().constant_pool;
                ConstantPool.CONSTANT_Class_info class_info = cp.getClassInfo(((Object_variable_info) entry).cpool_index);
                print(cp.getUTF8Value(class_info.name_index));
            } catch (ConstantPoolException e) {
                print("??");
            }
            break;
        case ITEM_Uninitialized:
            print(((Uninitialized_variable_info) entry).offset);
            break;
    }
}
Also used : ConstantPool(com.sun.tools.classfile.ConstantPool) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException)

Example 7 with ConstantPool

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

the class StackMapWriter method setStackMap.

void setStackMap(StackMapTable_attribute attr) {
    if (attr == null) {
        map = null;
        return;
    }
    Method m = classWriter.getMethod();
    Descriptor d = m.descriptor;
    String[] args;
    try {
        ConstantPool cp = classWriter.getClassFile().constant_pool;
        String argString = d.getParameterTypes(cp);
        args = argString.substring(1, argString.length() - 1).split("[, ]+");
    } catch (ConstantPoolException e) {
        return;
    } catch (InvalidDescriptor e) {
        return;
    }
    boolean isStatic = m.access_flags.is(AccessFlags.ACC_STATIC);
    verification_type_info[] initialLocals = new verification_type_info[(isStatic ? 0 : 1) + args.length];
    if (!isStatic)
        initialLocals[0] = new CustomVerificationTypeInfo("this");
    for (int i = 0; i < args.length; i++) {
        initialLocals[(isStatic ? 0 : 1) + i] = new CustomVerificationTypeInfo(args[i].replace(".", "/"));
    }
    map = new HashMap<Integer, StackMap>();
    StackMapBuilder builder = new StackMapBuilder();
    // using -1 as the pc for the initial frame effectively compensates for
    // the difference in behavior for the first stack map frame (where the
    // pc offset is just offset_delta) compared to subsequent frames (where
    // the pc offset is always offset_delta+1).
    int pc = -1;
    map.put(pc, new StackMap(initialLocals, empty));
    for (int i = 0; i < attr.entries.length; i++) pc = attr.entries[i].accept(builder, pc);
}
Also used : Method(com.sun.tools.classfile.Method) StackMapTable_attribute.verification_type_info(com.sun.tools.classfile.StackMapTable_attribute.verification_type_info) ConstantPool(com.sun.tools.classfile.ConstantPool) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor) Descriptor(com.sun.tools.classfile.Descriptor) InvalidDescriptor(com.sun.tools.classfile.Descriptor.InvalidDescriptor)

Example 8 with ConstantPool

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

the class ClassWriter method writeConstantPool.

protected void writeConstantPool() {
    ConstantPool pool = classFile.constant_pool;
    int size = pool.size();
    out.writeShort(size);
    for (CPInfo cpInfo : pool.entries()) constantPoolWriter.write(cpInfo, out);
}
Also used : ConstantPool(com.sun.tools.classfile.ConstantPool)

Aggregations

ConstantPool (com.sun.tools.classfile.ConstantPool)8 ConstantPoolException (com.sun.tools.classfile.ConstantPoolException)5 Descriptor (com.sun.tools.classfile.Descriptor)4 InvalidDescriptor (com.sun.tools.classfile.Descriptor.InvalidDescriptor)4 Method (com.sun.tools.classfile.Method)2 AccessFlags (com.sun.tools.classfile.AccessFlags)1 Attributes (com.sun.tools.classfile.Attributes)1 ClassFile (com.sun.tools.classfile.ClassFile)1 ClassWriter (com.sun.tools.classfile.ClassWriter)1 Field (com.sun.tools.classfile.Field)1 LocalVariableTable_attribute (com.sun.tools.classfile.LocalVariableTable_attribute)1 LocalVariableTypeTable_attribute (com.sun.tools.classfile.LocalVariableTypeTable_attribute)1 Signature (com.sun.tools.classfile.Signature)1 StackMapTable_attribute.verification_type_info (com.sun.tools.classfile.StackMapTable_attribute.verification_type_info)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1