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;
}
public Type.Class getType() { return thisType; }
+ public int getFlags() { return flags; }
String debugToString() { return debugToString(new StringBuffer(4096)).toString(); }
StringBuffer debugToString(StringBuffer sb) {
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;
}
}
- 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<interfaces.length; j++) interfaces[j] = (Type.Class) cp.getKeyByIndex(i.readShort());
int numFields = i.readShort();
for(int j=0; j<numFields; j++) fields.addElement(new FieldGen(i, cp));
int numMethods = i.readShort();
- for(int j=0; j<numMethods; j++) methods.addElement(new MethodGen(this.getType(), i, cp));
+ for(int j=0; j<numMethods; j++) methods.addElement(ssa
+ ? new JSSA(this.getType(), i, cp)
+ : new MethodGen(this.getType(), i, cp));
attributes = new AttrGen(i, cp);
// FEATURE: Support these