From: adam Date: Sun, 3 Jul 2005 02:43:23 +0000 (+0000) Subject: added Type.Field.Body and Type.Class.Body X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=commitdiff_plain;h=f1822de91ca3a0ecb3f744766176d39dd166ea07 added Type.Field.Body and Type.Class.Body darcs-hash:20050703024323-5007d-4bd60b17ae5fb293f0c5f0c35886b764e4638964.gz --- diff --git a/src/org/ibex/classgen/ClassFile.java b/src/org/ibex/classgen/ClassFile.java index dd8b424..f41a44f 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; @@ -64,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; @@ -202,15 +203,22 @@ public class ClassFile implements CGConst { public ClassFile(DataInput i) throws IOException { this(i, false); } public ClassFile(DataInput i, boolean ssa) throws IOException { - int magic = i.readInt(); + 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"); } + public boolean isClassInitializer() { return getName().equals(""); } public String debugToString() { StringBuffer sb = new StringBuffer(); if (name.equals("")) sb.append("static "); @@ -169,6 +187,7 @@ public class Type implements CGConst { this.argTypes = argTypes; this.returnType = returnType; } + //public Method.Body getBody(Context cx) { } public String getDescriptor() { StringBuffer sb = new StringBuffer(argTypes.length*4); sb.append("("); @@ -177,7 +196,7 @@ public class Type implements CGConst { sb.append(returnType.getDescriptor()); return sb.toString(); } - public abstract class Body implements HasFlags { + public abstract class Body extends HasFlags { public abstract java.util.Hashtable getThrownExceptions(); public abstract void debugBodyToString(StringBuffer sb); public void debugToString(StringBuffer sb, String constructorName) {