rename CPGen -> ConstantPool
authoradam <adam@megacz.com>
Fri, 3 Jun 2005 06:11:17 +0000 (06:11 +0000)
committeradam <adam@megacz.com>
Fri, 3 Jun 2005 06:11:17 +0000 (06:11 +0000)
darcs-hash:20050603061117-5007d-6ca1dbc81fa228dc450bd3e27a76b29a8d698f72.gz

src/org/ibex/classgen/ClassFile.java
src/org/ibex/classgen/ConstantPool.java [moved from src/org/ibex/classgen/CPGen.java with 99% similarity]
src/org/ibex/classgen/FieldGen.java
src/org/ibex/classgen/MethodGen.java

index 788c0cb..b926d85 100644 (file)
@@ -15,7 +15,7 @@ public class ClassFile implements CGConst {
     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) {
@@ -61,21 +61,7 @@ public class ClassFile implements CGConst {
         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");
@@ -86,7 +72,7 @@ public class ClassFile implements CGConst {
         this.minor = 3;
         this.major = 45;
         
-        cp = new CPGen();
+        cp = new ConstantPool();
         attributes = new AttrGen(cp);
     }
     
@@ -218,7 +204,7 @@ public class ClassFile implements CGConst {
         //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());
@@ -242,17 +228,17 @@ public class ClassFile implements CGConst {
     }
     
     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();
@@ -270,7 +256,7 @@ public class ClassFile implements CGConst {
 
         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;
         }
         
@@ -292,9 +278,9 @@ public class ClassFile implements CGConst {
                     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");
                 }
similarity index 99%
rename from src/org/ibex/classgen/CPGen.java
rename to src/org/ibex/classgen/ConstantPool.java
index edc4d9c..70ea083 100644 (file)
@@ -5,7 +5,7 @@ import java.io.*;
 
 import org.ibex.classgen.util.*;
 
-class CPGen {
+class ConstantPool {
     private final Hashtable entries = new Hashtable();
     private Ent[] entriesByIndex; // only valid when stable
     
@@ -15,7 +15,7 @@ class CPGen {
     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
@@ -310,7 +310,7 @@ class CPGen {
         }
     }
     
-    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");
         
index cf269d0..ef4edcb 100644 (file)
@@ -5,7 +5,7 @@ import java.io.*;
 /** Class representing a field in a generated classfile
     @see ClassFile#addField */
 public class FieldGen implements CGConst {
-    private final CPGen cp;
+    private final ConstantPool cp;
     private final String name;
     private final Type type;
     private final int flags;
@@ -23,7 +23,7 @@ public class FieldGen implements CGConst {
         // FIXME: attrs
     }
     
-    FieldGen(CPGen cp, DataInput in) throws IOException {
+    FieldGen(ConstantPool cp, DataInput in) throws IOException {
         this.cp = cp;
         flags = in.readShort();
         name = cp.getUtf8ByIndex(in.readShort());
index ba055bf..2dcb4e3 100644 (file)
@@ -12,7 +12,7 @@ public class MethodGen implements CGConst {
     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;
@@ -50,7 +50,7 @@ public class MethodGen implements CGConst {
         // 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();
@@ -89,8 +89,8 @@ public class MethodGen implements CGConst {
         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;
@@ -280,7 +280,7 @@ public class MethodGen implements CGConst {
             }
         }
         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);
         }
@@ -460,7 +460,7 @@ public class MethodGen implements CGConst {
                     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:
@@ -581,7 +581,7 @@ public class MethodGen implements CGConst {
                             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");
@@ -620,7 +620,7 @@ public class MethodGen implements CGConst {
         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;