got it to compile
authoradam <adam@megacz.com>
Thu, 2 Jun 2005 07:46:53 +0000 (07:46 +0000)
committeradam <adam@megacz.com>
Thu, 2 Jun 2005 07:46:53 +0000 (07:46 +0000)
darcs-hash:20050602074653-5007d-e6eaa6b619b266a9cff720683a66e176e1d25dc6.gz

src/org/ibex/classgen/CPGen.java
src/org/ibex/classgen/ClassGen.java
src/org/ibex/classgen/FieldGen.java
src/org/ibex/classgen/MethodGen.java

index 6527816..25f22be 100644 (file)
@@ -24,6 +24,7 @@ class CPGen {
         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;
         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; }
         
         
         Ent(CPGen owner, int tag) { this.owner = owner; this.tag = tag; }
         
@@ -84,19 +85,23 @@ class CPGen {
             if(e2 != null) o.writeShort(e2.n);
         }
         
             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);
         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");
                     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();
                     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");
         }
     }
         
         }
     }
         
@@ -105,6 +110,7 @@ class CPGen {
         Utf8Ent(CPGen owner) { super(owner,1); }
         String debugToString() { return s; }
         void dump(DataOutput o) throws IOException { super.dump(o); o.writeUTF(s); }
         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"); }
     }
     
     /*
     }
     
     /*
@@ -150,6 +156,8 @@ class CPGen {
         return ent.n;
     }
 
         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;
     public final Ent getByIndex(int index) {
         if(state < STABLE) throw new IllegalStateException("constant pool is not stable");
         Ent e;
@@ -299,18 +307,19 @@ class CPGen {
         }
     }
     
         }
     }
     
-    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
         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++) {
         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
             Ent e;
             switch(tag) {
                 case 7: // Object Type
@@ -321,8 +330,8 @@ class CPGen {
                 case 12: // NameAndType
                 {
                     e = new CPRefEnt(this,tag);
                 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
                     break;
                 }
                 case 3: // Integer
@@ -330,7 +339,7 @@ class CPGen {
                 {
                     IntEnt ie;
                     e = ie = new IntEnt(this,tag);
                 {
                     IntEnt ie;
                     e = ie = new IntEnt(this,tag);
-                    ie.i = i.readInt();
+                    ie.i = in.readInt();
                     break;
                 }
                 case 5: // Long
                     break;
                 }
                 case 5: // Long
@@ -338,7 +347,7 @@ class CPGen {
                 {
                     LongEnt le;
                     e = le = new LongEnt(this,tag);
                 {
                     LongEnt le;
                     e = le = new LongEnt(this,tag);
-                    le.l = i.readLong();
+                    le.l = in.readLong();
                     index++;
                     break;
                 }
                     index++;
                     break;
                 }
@@ -346,7 +355,7 @@ class CPGen {
                 {
                     Utf8Ent ue;
                     e = ue = new Utf8Ent(this);
                 {
                     Utf8Ent ue;
                     e = ue = new Utf8Ent(this);
-                    ue.s = i.readUTF();
+                    ue.s = in.readUTF();
                     break;
                 }
                 default:
                     break;
                 }
                 default:
@@ -356,6 +365,7 @@ class CPGen {
         }
         
         for(int index=1;index<usedSlots;index++) {
         }
         
         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) {
             Ent e = entriesByIndex[index];
             if(e == null) throw new Error("should never happen");
             if(e instanceof CPRefEnt) {
index 451bb74..c4b7e77 100644 (file)
@@ -155,23 +155,33 @@ public class ClassGen implements CGConst {
         attributes.dump(o); // attributes        
     }
     
         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;
     }
     
         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)));
     }
 
         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");
         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);
         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
     }
     
     /** Thrown when class generation fails for a reason not under the control of the user
@@ -209,6 +219,9 @@ public class ClassGen implements CGConst {
         private final CPGen cp;
         private final Hashtable ht = new Hashtable();
         
         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;
         }
         public AttrGen(CPGen cp) {
             this.cp = cp;
         }
index 826eb78..e4f6763 100644 (file)
@@ -13,6 +13,7 @@ public class FieldGen implements CGConst {
     
     private Object constantValue;
     
     
     private Object constantValue;
     
+    FieldGen(DataInput in) { throw new Error("Brian is lame"); }
     FieldGen(ClassGen owner, String name,Type type, int flags) {
         if((flags & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_VOLATILE|ACC_TRANSIENT|ACC_STATIC|ACC_FINAL)) != 0)
             throw new IllegalArgumentException("invalid flags");
     FieldGen(ClassGen owner, String name,Type type, int flags) {
         if((flags & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_VOLATILE|ACC_TRANSIENT|ACC_STATIC|ACC_FINAL)) != 0)
             throw new IllegalArgumentException("invalid flags");
index 703ab97..547330d 100644 (file)
@@ -29,6 +29,7 @@ public class MethodGen implements CGConst {
     private byte[] op;
     private Object[] arg;
     
     private byte[] op;
     private Object[] arg;
     
+    MethodGen(DataInput in) { throw new Error("Brian is lame"); }
     MethodGen(ClassGen owner, String name, Type ret, Type[] args, int flags) {
         if((flags & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE|ACC_ABSTRACT|ACC_STRICT)) != 0)
             throw new IllegalArgumentException("invalid flags");
     MethodGen(ClassGen owner, String name, Type ret, Type[] args, int flags) {
         if((flags & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE|ACC_ABSTRACT|ACC_STRICT)) != 0)
             throw new IllegalArgumentException("invalid flags");