cleanup of MethodRef, FieldRef, MemberRef
authoradam <adam@megacz.com>
Fri, 3 Jun 2005 05:41:15 +0000 (05:41 +0000)
committeradam <adam@megacz.com>
Fri, 3 Jun 2005 05:41:15 +0000 (05:41 +0000)
darcs-hash:20050603054115-5007d-9aeb9a21fee4f1c7cc65a2ebd3921fcddc11ef29.gz

src/org/ibex/classgen/CPGen.java
src/org/ibex/classgen/FieldRef.java
src/org/ibex/classgen/MemberRef.java
src/org/ibex/classgen/MethodGen.java
src/org/ibex/classgen/MethodRef.java

index 6b59a28..ec956d6 100644 (file)
@@ -220,7 +220,7 @@ class CPGen {
             if(tag == 0) throw new Error("should never happen");
             CPRefEnt ce = new CPRefEnt(tag);
             ce.e1 = add(key.klass);
-            ce.e2 = addNameAndType(key.name, key.descriptor);
+            ce.e2 = addNameAndType(key.name, key.getDescriptor());
             ent = ce;
         } else {
             throw new IllegalArgumentException("Unknown type passed to add");
index 331ebe4..b13fd4d 100644 (file)
@@ -9,9 +9,8 @@ GETFIELD, PUTFIELD, GETSTATIC, and PUTSTATCI bytecodes
 */
 public class FieldRef extends MemberRef {
     /** Create a reference to field <i>name</i> of class <i>c</i> with the type <i>t</i>  */    
-    public FieldRef(Type.Class c, String name, Type t) { super(c, name, t.getDescriptor()); }
-    /** Equivalent to FieldRef(new Type.Class(s), ...)
-        @see #FieldRef(Type.Class, String, Type, )
-    */
-    public FieldRef(String s, String name, Type t) { this(Type.instance(s).asClass(), name, t); }
+    public final Type type;
+    public FieldRef(Type.Class c, String name, Type t) { super(c, name); this.type = t; }
+    public String getDescriptor() { return name; }
 }
+
index 3c09960..ca39c93 100644 (file)
@@ -10,17 +10,19 @@ import java.io.*;
     @see FieldRef
 */
 public abstract class MemberRef {
-    Type.Class klass;
-    String name;
-    String descriptor;
+    public final Type.Class klass;
+    public final String name;
         
-    MemberRef(Type.Class klass, String name, String descriptor) { this.klass = klass; this.name = name; this.descriptor = descriptor; }
-    MemberRef(MemberRef o) { this.klass = o.klass; this.name = o.name; this.descriptor = o.descriptor; }
+    MemberRef(Type.Class klass, String name) {
+        this.klass = klass;
+        this.name = name;
+    }
+    public abstract String getDescriptor();
     public boolean equals(Object o_) {
         if(!(o_ instanceof MemberRef)) return false;
         MemberRef o = (MemberRef) o_;
-        return o.klass.equals(klass) && o.name.equals(name) && o.descriptor.equals(descriptor);
+        return o.klass.equals(klass) && o.name.equals(name) && o.getDescriptor().equals(getDescriptor());
     }
-    public int hashCode() { return klass.hashCode() ^ name.hashCode() ^ descriptor.hashCode(); }
+    public int hashCode() { return klass.hashCode() ^ name.hashCode() ^ getDescriptor().hashCode(); }
 }
     
index e2d3b68..32fd705 100644 (file)
@@ -83,7 +83,7 @@ public class MethodGen implements CGConst {
     }
     
     /** Returns the descriptor string for this method */
-    public String getDescriptor() { return MethodRef.getDescriptor(ret, args); }
+    public String getDescriptor() { return new MethodRef(null, name, ret, args).getDescriptor(); }
     
     private class ExnTableEnt {
         public int start;
@@ -275,9 +275,11 @@ public class MethodGen implements CGConst {
                 
                 if(arg instanceof Long || arg instanceof Double) op = LDC2_W;
                 break;
-            case INVOKEINTERFACE:
-                if(arg instanceof MethodRef) arg = new MethodRef.I((MethodRef)arg);
+            case INVOKEINTERFACE: {
+                MethodRef mr = (MethodRef)arg;
+                if(arg instanceof MethodRef) arg = new MethodRef.I(mr.klass, mr.name, mr.returnType, mr.argTypes);
                 break;
+            }
         }
         int opdata = OP_DATA[op&0xff];
         if((opdata&OP_CPENT_FLAG) != 0 && !(arg instanceof CPGen.Ent))
index 4810bbb..399195c 100644 (file)
@@ -8,25 +8,24 @@ package org.ibex.classgen;
     @see CGConst#INVOKEINTERFACE
 */
 public class MethodRef extends MemberRef {
+    
+    final Type[] argTypes;
+    final Type   returnType;
+
     /** Create a reference to method <i>name</i> of class <i>c</i> with the return type <i>ret</i> and the
         arguments <i>args</i> */
-    public MethodRef(Type.Class c, String name, Type ret, Type[] args) {
-        super(c, name, getDescriptor(ret, args));
-    }
-    /** Equivalent to MethodRef(new Type.Class(s), ...)
-        @see #MethodRef(Type.Class, String, Type, Type[])
-    */
-    public MethodRef(String s, String name, Type ret, Type[] args) {
-        this(Type.instance(s).asClass(), name, ret, args);
+    public MethodRef(Type.Class c, String name, Type returnType, Type[] argTypes) {
+        super(c, name);
+        this.argTypes = argTypes;
+        this.returnType = returnType;
     }
-    MethodRef(MethodRef i) { super(i); }
     
-    static String getDescriptor(Type ret, Type[] args) {
-        StringBuffer sb = new StringBuffer(args.length*4);
+    public String getDescriptor() {
+        StringBuffer sb = new StringBuffer(argTypes.length*4);
         sb.append("(");
-        for(int i=0;i<args.length;i++) sb.append(args[i].getDescriptor());
+        for(int i=0;i<argTypes.length;i++) sb.append(argTypes[i].getDescriptor());
         sb.append(")");
-        sb.append(ret.getDescriptor());
+        sb.append(returnType.getDescriptor());
         return sb.toString();
     }
     
@@ -36,7 +35,5 @@ public class MethodRef extends MemberRef {
         to MethodRef.I's when they are applied to an INVOKEINTERFACE bytecode */
     public static class I extends MethodRef {
         public I(Type.Class c, String name, Type ret, Type[] args) { super(c, name, ret, args); }
-        public I(String s, String name, Type ret, Type[] args) { super(s, name, ret, args); }
-        I(MethodRef m) { super(m); }
     }
 }