CPGen owner; // don't need this yet, but we will to implement ref() and unref()
int n; // this is the refcount if state == OPEN, index if >= STABLE
int tag;
+ Ent e0;
Ent(CPGen owner, int tag) { this.owner = owner; this.tag = tag; }
if(e2 != null) o.writeShort(e2.n);
}
+ private String fixme() { throw new Error("fixme"); }
Object key() throws ClassGen.ClassReadExn {
switch(tag) {
case 7: return new Type.Object(((Utf8Ent)e0).s);
case 8: return (((Utf8Ent)e1).s);
- case 9:
+ case 9: {
NameAndTypeKey nt = (NameAndTypeKey) e2.key();
Type t = Type.fromDescriptor(nt.type);
if(t == null) throw new ClassGen.ClassReadExn("invalid type descriptor");
- return FieldRef((Type.Object)e1.key(), nt.name, t);
- case 10:
+ return new FieldRef((Type.Object)e1.key(), nt.name, t);
+ }
+ case 10: {
NameAndTypeKey nt = (NameAndTypeKey) e2.key();
- return MethodRef((Type.Object)e1.key(),throw new Error("fixme"));
+ return new MethodRef((Type.Object)e1.key(), fixme(), null, null);
+ }
}
+ throw new Error("FIXME");
}
}
Utf8Ent(CPGen owner) { super(owner,1); }
String debugToString() { return s; }
void dump(DataOutput o) throws IOException { super.dump(o); o.writeUTF(s); }
+ Object key() { throw new Error("Brian is lame"); }
}
/*
return ent.n;
}
+ public final Type.Object getType(int index) { return new Type.Object(((Utf8Ent)getByIndex(index)).s); }
+
public final Ent getByIndex(int index) {
if(state < STABLE) throw new IllegalStateException("constant pool is not stable");
Ent e;
}
}
- CPGen(DataInput in) throws ClassGen.ClassReadExn {
- usedSlots = i.readUnsignedShort();
+ CPGen(DataInput in) throws ClassGen.ClassReadExn, IOException {
+ usedSlots = in.readUnsignedShort();
if(usedSlots==0) throw new ClassGen.ClassReadExn("invalid used slots");
// these are to remember the CPRefEnt e0 and e1s we have to fix up
+ int[] e0s = new int[usedSlots];
int[] e1s = new int[usedSlots];
int[] e2s = new int[usedSlots];
entriesByIndex = new Ent[usedSlots];
for(int index=1;index<usedSlots;index++) {
- byte tag = i.readByte();
+ byte tag = in.readByte();
Ent e;
switch(tag) {
case 7: // Object Type
case 12: // NameAndType
{
e = new CPRefEnt(this,tag);
- e1s[index] = i.readUnsignedShort();;
- if(tag != 7 && tag != 8) e2s[index] = i.readUnsignedShort();
+ e1s[index] = in.readUnsignedShort();;
+ if(tag != 7 && tag != 8) e2s[index] = in.readUnsignedShort();
break;
}
case 3: // Integer
{
IntEnt ie;
e = ie = new IntEnt(this,tag);
- ie.i = i.readInt();
+ ie.i = in.readInt();
break;
}
case 5: // Long
{
LongEnt le;
e = le = new LongEnt(this,tag);
- le.l = i.readLong();
+ le.l = in.readLong();
index++;
break;
}
{
Utf8Ent ue;
e = ue = new Utf8Ent(this);
- ue.s = i.readUTF();
+ ue.s = in.readUTF();
break;
}
default:
}
for(int index=1;index<usedSlots;index++) {
+ int i = index;
Ent e = entriesByIndex[index];
if(e == null) throw new Error("should never happen");
if(e instanceof CPRefEnt) {
attributes.dump(o); // attributes
}
- public ClassGen read(File f) throws ClassReadExn {
+ public ClassGen read(File f) throws ClassReadExn, IOException {
InputStream is = new FileInputStream(f);
ClassGen ret = read(is);
is.close();
return ret;
}
- public ClassGen read(InputStream is) throws ClassReadExn {
+ public ClassGen read(InputStream is) throws ClassReadExn, IOException {
return new ClassGen(new DataInputStream(new BufferedInputStream(is)));
}
- ClassGen(DataInput i) throws ClassReadExn {
+ ClassGen(DataInput i) throws ClassReadExn, IOException {
if(i.readInt() != 0xcadebabe) throw new ClassReadExn("invalid magic");
- short minor = i.readInt();
+ short minor = (short)i.readInt();
if(minor != 3) throw new ClassReadExn("invalid minor version: " + minor);
if(i.readInt() != 45) throw new ClassReadExn("invalid major version");
cp = new CPGen(i);
+ flags = (short)i.readShort();
+ thisType = cp.getType(i.readShort());
+ superType = cp.getType(i.readShort());
+ interfaces = new Type.Object[i.readShort()];
+ for(int j=0; j<interfaces.length; j++) interfaces[j] = cp.getType(i.readShort());
+ int numFields = i.readShort();
+ for(int j=0; j<numFields; j++) fields.add(new FieldGen(i));
+ int numMethods = i.readShort();
+ for(int j=0; j<numMethods; j++) methods.add(new MethodGen(i));
+ attributes = new AttrGen(i);
}
/** Thrown when class generation fails for a reason not under the control of the user
private final CPGen cp;
private final Hashtable ht = new Hashtable();
+ public AttrGen(DataInput in) {
+ throw new Error("Brian is superlame");
+ }
public AttrGen(CPGen cp) {
this.cp = cp;
}