way more Arena functionality
[org.ibex.classgen.git] / src / org / ibex / classgen / ConstantPool.java
index eb2497d..67f4245 100644 (file)
@@ -23,7 +23,6 @@ class ConstantPool implements CGConst {
         Object key;
         Ent(int tag) { this.tag = tag; }
         void dump(DataOutput o) throws IOException { o.writeByte(tag); }
-        String debugToString() { return toString(); } // so we can remove this method when not debugging
         abstract Object _key();
         final Object key() { return key == null ? (key = _key()) : key; }
         int slots() { return 1; } // number of slots this ent takes up
@@ -41,7 +40,7 @@ class ConstantPool implements CGConst {
         String s;
         Utf8Ent() { super(CONSTANT_UTF8); }
         Utf8Ent(String s) { this();  this.s = s; }
-        String debugToString() { return s; }
+        public String toString() { return s; }
         void dump(DataOutput o) throws IOException { super.dump(o); o.writeUTF(s); }
         Object _key() { return new Utf8Key(s); }
     }
@@ -86,9 +85,11 @@ class ConstantPool implements CGConst {
         ClassEnt(String s) { this(); this.utf8 = (Utf8Ent) addUtf8(s); }
         void dump(DataOutput o) throws IOException { super.dump(o); o.writeShort(utf8.n); }
         Type.Class getTypeClass() { return  (Type.Class) key(); }
-        Object _key() { return new Type.Class(utf8.s); }
+        Object _key() {
+            return Type.fromDescriptor(utf8.s.startsWith("[") ? utf8.s : "L" + utf8.s + ";"); 
+        }
         void unref() { utf8.unref(); super.unref(); }
-        String debugToString() { return "[Class: " + utf8.s + "]"; }
+        public String toString() { return "[Class: " + utf8.s + "]"; }
     }
     
     class NameAndTypeEnt extends Ent {
@@ -196,7 +197,7 @@ class ConstantPool implements CGConst {
     
     String getUtf8KeyByIndex(int index) {
         Ent e = getByIndex(index);
-        if(!(e instanceof Utf8Ent)) throw new IllegalArgumentException("that isn't a utf8 (" + e.debugToString() + ")");
+        if(!(e instanceof Utf8Ent)) throw new IllegalArgumentException("that isn't a utf8 (" + e.toString() + ")");
         return ((Utf8Ent)e).s;
     }
     
@@ -218,7 +219,7 @@ class ConstantPool implements CGConst {
             return ent;
         }
         
-        if (o instanceof Type.Class) { ent = new ClassEnt(((Type.Class)o).internalForm()); }
+        if (o instanceof Type.Ref) { ent = new ClassEnt(((Type.Ref)o).internalForm()); }
         else if (o instanceof String) { ent = new StringLitEnt((String)o); }
         else if (o instanceof Integer) { ent = new IntLitEnt(((Integer)o).intValue()); }
         else if (o instanceof Float) { ent = new FloatLitEnt(((Float)o).floatValue()); }
@@ -239,7 +240,7 @@ class ConstantPool implements CGConst {
             ent = new MemberEnt(tag, m.getDeclaringClass(), m.name, m.getTypeDescriptor());
         } 
         else {
-            throw new IllegalArgumentException("Unknown type passed to add");
+            throw new IllegalArgumentException("Unknown type " + o + " passed to add");
         }
         
         int spaces = ent.slots();        
@@ -309,7 +310,7 @@ class ConstantPool implements CGConst {
         Sort.sort(ents, compareFunc);
         o.writeShort(usedSlots);
         for(int i=0;i<ents.length;i++) {
-            //System.err.println("" + ents[i].n + ": " + ents[i].debugToString());
+            //System.err.println("" + ents[i].n + ": " + ents[i].toString());
             ents[i].dump(o);
         }
     }