X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FClassFile.java;h=32bda60d830125e2dc5c590adde31a0b2510e419;hp=f70ed48b37c02e7183394a3449175b5bf57547e1;hb=e70f9a95d3058a30dc93d8d45078ece8bb7a7dc6;hpb=e2310783b3b5cf06044d90387938209726054980 diff --git a/src/org/ibex/classgen/ClassFile.java b/src/org/ibex/classgen/ClassFile.java index f70ed48..32bda60 100644 --- a/src/org/ibex/classgen/ClassFile.java +++ b/src/org/ibex/classgen/ClassFile.java @@ -4,7 +4,7 @@ import java.util.*; import java.io.*; /** Class generation object representing the whole classfile */ -public class ClassFile implements CGConst { +public class ClassFile extends Type.Class.Body { private final Type.Class thisType; private final Type.Class superType; private final Type.Class[] interfaces; @@ -13,7 +13,7 @@ public class ClassFile implements CGConst { final int flags; private final Vector fields = new Vector(); - private final Vector methods = new Vector(); + public final Vector methods = new Vector(); private final AttrGen attributes; @@ -34,6 +34,7 @@ public class ClassFile implements CGConst { } public Type.Class getType() { return thisType; } + public int getFlags() { return flags; } String debugToString() { return debugToString(new StringBuffer(4096)).toString(); } StringBuffer debugToString(StringBuffer sb) { @@ -63,9 +64,10 @@ public class ClassFile implements CGConst { public ClassFile(Type.Class thisType, Type.Class superType, int flags) { this(thisType, superType, flags, null); } public ClassFile(Type.Class thisType, Type.Class superType, int flags, Type.Class[] interfaces) { + thisType.super(); + this.thisType = thisType; if((flags & ~(PUBLIC|FINAL|SUPER|INTERFACE|ABSTRACT)) != 0) throw new IllegalArgumentException("invalid flags"); - this.thisType = thisType; this.superType = superType; this.interfaces = interfaces; this.flags = flags; @@ -86,7 +88,7 @@ public class ClassFile implements CGConst { @see CGConst */ public final MethodGen addMethod(String name, Type ret, Type[] args, int flags) { - MethodGen mg = new MethodGen(this.getType(), name, ret, args, flags, (this.flags & INTERFACE) != 0); + MethodGen mg = new MethodGen(getType().method(name, ret, args), flags); methods.addElement(mg); return mg; } @@ -102,7 +104,7 @@ public class ClassFile implements CGConst { @see CGConst */ public final FieldGen addField(String name, Type type, int flags) { - FieldGen fg = new FieldGen(this, name, type, flags); + FieldGen fg = new FieldGen(getType().field(name, type), flags); fields.addElement(fg); return fg; } @@ -199,23 +201,33 @@ public class ClassFile implements CGConst { } } - ClassFile(DataInput i) throws IOException { - int magic = i.readInt(); + public ClassFile(DataInput i) throws IOException { this(i, false); } + public ClassFile(DataInput i, boolean ssa) throws IOException { + this(i.readInt(), i.readShort(), i.readShort(), new ConstantPool(i), i.readShort(), i, ssa); + } + private ClassFile(int magic, short minor, short major, ConstantPool cp, + short flags, DataInput i, boolean ssa) throws IOException { + this(magic, minor, major, cp, flags, (Type.Class)cp.getKeyByIndex(i.readShort()), i, ssa); + } + private ClassFile(int magic, short minor, short major, ConstantPool cp, short flags, + Type.Class thisType, DataInput i, boolean ssa) throws IOException { + thisType.super(); if (magic != 0xcafebabe) throw new ClassReadExn("invalid magic: " + Long.toString(0xffffffffL & magic, 16)); - minor = i.readShort(); - major = i.readShort(); - ConstantPool cp = new ConstantPool(i); - flags = i.readShort(); + this.minor = minor; + this.major = major; + this.flags = flags; if((flags & ~(PUBLIC|FINAL|SUPER|INTERFACE|ABSTRACT)) != 0) throw new ClassReadExn("invalid flags: " + Integer.toString(flags,16)); - thisType = (Type.Class) cp.getKeyByIndex(i.readShort()); + this.thisType = thisType; superType = (Type.Class) cp.getKeyByIndex(i.readShort()); interfaces = new Type.Class[i.readShort()]; for(int j=0; j