private final Vector fields = new Vector();
private final Vector methods = new Vector();
- final CPGen cp;
+ final ConstantPool cp;
private final AttrGen attributes;
public static String flagsToString(int flags) {
sb.append("}");
}
- /** @see #ClassFile(Type.Class, Type.Class, int) */
- public ClassFile(String name, String superName, int flags) {
- this(Type.instance(name).asClass(), Type.instance(superName).asClass(), flags);
- }
-
- /** @see #ClassFile(Type.Class, Type.Class, int, Type.Class[]) */
- public ClassFile(Type.Class thisType, Type.Class superType, int flags) {
- this(thisType, superType, flags, null);
- }
-
- /** Creates a new ClassFile object
- @param thisType The type of the class to generate
- @param superType The superclass of the generated class (commonly Type.OBJECT)
- @param flags The access flags for this class (ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_INTERFACE, and ACC_ABSTRACT)
- */
+ 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) {
if((flags & ~(ACC_PUBLIC|ACC_FINAL|ACC_SUPER|ACC_INTERFACE|ACC_ABSTRACT)) != 0)
throw new IllegalArgumentException("invalid flags");
this.minor = 3;
this.major = 45;
- cp = new CPGen();
+ cp = new ConstantPool();
attributes = new AttrGen(cp);
}
//if (minor != 3) throw new ClassReadExn("invalid minor version: " + minor);
major = i.readShort();
//if (major != 45 && major != 46) throw new ClassReadExn("invalid major version");
- cp = new CPGen(i);
+ cp = new ConstantPool(i);
flags = i.readShort();
thisType = (Type.Class)cp.getType(i.readShort());
superType = (Type.Class)cp.getType(i.readShort());
}
static class AttrGen {
- private final CPGen cp;
+ private final ConstantPool cp;
private final Hashtable ht = new Hashtable();
- public AttrGen(CPGen cp) { this.cp = cp; }
- public AttrGen(CPGen cp, DataInput in) throws IOException {
+ public AttrGen(ConstantPool cp) { this.cp = cp; }
+ public AttrGen(ConstantPool cp, DataInput in) throws IOException {
this(cp);
int size = in.readShort();
for(int i=0; i<size; i++) {
String name = null;
int idx = in.readShort();
- CPGen.Ent e = cp.getByIndex(idx);
+ ConstantPool.Ent e = cp.getByIndex(idx);
Object key = e.key();
if (key instanceof String) name = (String)key;
else name = ((Type)key).getDescriptor();
public Object get(String s) {
Object ret = ht.get(s);
- if (ret instanceof CPGen.Utf8Ent) return ((CPGen.Utf8Ent)ret).s;
+ if (ret instanceof ConstantPool.Utf8Ent) return ((ConstantPool.Utf8Ent)ret).s;
return ret;
}
byte[] buf = (byte[]) val;
o.writeInt(buf.length);
o.write(buf);
- } else if (val instanceof CPGen.Ent) {
+ } else if (val instanceof ConstantPool.Ent) {
o.writeInt(2);
- o.writeShort(cp.getIndex((CPGen.Ent)val));
+ o.writeShort(cp.getIndex((ConstantPool.Ent)val));
} else {
throw new Error("should never happen");
}
import org.ibex.classgen.util.*;
-class CPGen {
+class ConstantPool {
private final Hashtable entries = new Hashtable();
private Ent[] entriesByIndex; // only valid when stable
private static final int STABLE = 1; // existing entries won't change
private static final int SEALED = 2; // no new entries
- CPGen() { }
+ ConstantPool() { }
public abstract class Ent {
int n; // this is the refcount if state == OPEN, index if >= STABLE
}
}
- CPGen(DataInput in) throws ClassFile.ClassReadExn, IOException {
+ ConstantPool(DataInput in) throws ClassFile.ClassReadExn, IOException {
usedSlots = in.readUnsignedShort();
if(usedSlots==0) throw new ClassFile.ClassReadExn("invalid used slots");
private static final int FINISHED = -2;
private final ClassFile owner;
- private final CPGen cp;
+ private final ConstantPool cp;
private final String name;
private final Type ret;
private final Type[] args;
// FIXME: attrs, body
}
- MethodGen(CPGen cp, DataInput in, ClassFile owner) throws IOException {
+ MethodGen(ConstantPool cp, DataInput in, ClassFile owner) throws IOException {
this.cp = cp;
this.owner = owner;
flags = in.readShort();
public int start;
public int end;
public int handler;
- public CPGen.Ent typeEnt;
- public ExnTableEnt(int start, int end, int handler, CPGen.Ent typeEnt) {
+ public ConstantPool.Ent typeEnt;
+ public ExnTableEnt(int start, int end, int handler, ConstantPool.Ent typeEnt) {
this.start = start;
this.end = end;
this.handler = handler;
}
}
int opdata = OP_DATA[op&0xff];
- if((opdata&OP_CPENT_FLAG) != 0 && !(arg instanceof CPGen.Ent)) {
+ if((opdata&OP_CPENT_FLAG) != 0 && !(arg instanceof ConstantPool.Ent)) {
if (op==INVOKEINTERFACE) arg = cp.add(arg, true);
else arg = cp.add(arg);
}
break;
}
case LDC:
- j = cp.getIndex((CPGen.Ent)arg[i]);
+ j = cp.getIndex((ConstantPool.Ent)arg[i]);
if(j >= 256) this.op[i] = op = LDC_W;
break;
default:
throw new Error("should never happen");
}
} else if((opdata & OP_CPENT_FLAG) != 0) {
- int v = cp.getIndex((CPGen.Ent)arg);
+ int v = cp.getIndex((ConstantPool.Ent)arg);
if(argLength == 1) o.writeByte(v);
else if(argLength == 2) o.writeShort(v);
else throw new Error("should never happen");
baos.reset();
o.writeShort(thrownExceptions.size());
for(Enumeration e = thrownExceptions.keys();e.hasMoreElements();)
- o.writeShort(cp.getIndex((CPGen.Ent)thrownExceptions.get(e.nextElement())));
+ o.writeShort(cp.getIndex((ConstantPool.Ent)thrownExceptions.get(e.nextElement())));
attrs.add("Exceptions", baos.toByteArray());
size = capacity = FINISHED;