removed ClassFile.sourceFile; use attributes.get() instead
authoradam <adam@megacz.com>
Fri, 3 Jun 2005 06:03:59 +0000 (06:03 +0000)
committeradam <adam@megacz.com>
Fri, 3 Jun 2005 06:03:59 +0000 (06:03 +0000)
darcs-hash:20050603060359-5007d-970d3717d07bcee02b294a3962fcc375dc238c34.gz

src/org/ibex/classgen/ClassFile.java
src/org/ibex/classgen/Type.java

index 29b8d7f..788c0cb 100644 (file)
@@ -12,7 +12,6 @@ public class ClassFile implements CGConst {
     private short major;
     final int flags;
     
     private short major;
     final int flags;
     
-    private String sourceFile; 
     private final Vector fields = new Vector();
     private final Vector methods = new Vector();
     
     private final Vector fields = new Vector();
     private final Vector methods = new Vector();
     
@@ -46,6 +45,7 @@ public class ClassFile implements CGConst {
         for(int i=0; i<interfaces.length; i++) sb.append((i==0?" ":", ")+interfaces[i]);
         sb.append(" {");
         sb.append(" // [jcf v"+major+"."+minor+"]");
         for(int i=0; i<interfaces.length; i++) sb.append((i==0?" ":", ")+interfaces[i]);
         sb.append(" {");
         sb.append(" // [jcf v"+major+"."+minor+"]");
+        String sourceFile = (String)attributes.get("SourceFile");
         if (sourceFile != null) sb.append(" from " + sourceFile);
         sb.append("\n");
         for(int i=0; i<fields.size(); i++) {
         if (sourceFile != null) sb.append(" from " + sourceFile);
         sb.append("\n");
         for(int i=0; i<fields.size(); i++) {
@@ -126,7 +126,7 @@ public class ClassFile implements CGConst {
     /** Sets the source value of the SourceFile attribute of this class 
         @param sourceFile The string to be uses as the SourceFile of this class
     */
     /** Sets the source value of the SourceFile attribute of this class 
         @param sourceFile The string to be uses as the SourceFile of this class
     */
-    public void setSourceFile(String sourceFile) { this.sourceFile = sourceFile; }
+    public void setSourceFile(String sourceFile) { attributes.add("SourceFile", sourceFile); }
     
     /** Writes the classfile data to the file specifed
         @see ClassFile#dump(OutputStream)
     
     /** Writes the classfile data to the file specifed
         @see ClassFile#dump(OutputStream)
@@ -171,7 +171,6 @@ public class ClassFile implements CGConst {
         cp.add(thisType);
         cp.add(superType);
         if(interfaces != null) for(int i=0;i<interfaces.length;i++) cp.add(interfaces[i]);
         cp.add(thisType);
         cp.add(superType);
         if(interfaces != null) for(int i=0;i<interfaces.length;i++) cp.add(interfaces[i]);
-        if(sourceFile != null && !attributes.contains("SourceFile")) attributes.add("SourceFile", cp.addUtf8(sourceFile));
                 
         for(int i=0;i<methods.size();i++) ((MethodGen)methods.elementAt(i)).finish();
         for(int i=0;i<fields.size();i++) ((FieldGen)fields.elementAt(i)).finish();
                 
         for(int i=0;i<methods.size();i++) ((MethodGen)methods.elementAt(i)).finish();
         for(int i=0;i<fields.size();i++) ((FieldGen)fields.elementAt(i)).finish();
@@ -230,7 +229,6 @@ public class ClassFile implements CGConst {
         int numMethods = i.readShort();
         for(int j=0; j<numMethods; j++) methods.add(new MethodGen(cp, i, this));
         attributes = new AttrGen(cp, i);
         int numMethods = i.readShort();
         for(int j=0; j<numMethods; j++) methods.add(new MethodGen(cp, i, this));
         attributes = new AttrGen(cp, i);
-        sourceFile = (String)attributes.get("SourceFile");
     }
     
     /** 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
@@ -294,7 +292,7 @@ public class ClassFile implements CGConst {
                     byte[] buf = (byte[]) val;
                     o.writeInt(buf.length);
                     o.write(buf);
                     byte[] buf = (byte[]) val;
                     o.writeInt(buf.length);
                     o.write(buf);
-                } else if(val instanceof CPGen.Ent) {
+                } else if (val instanceof CPGen.Ent) {
                     o.writeInt(2);
                     o.writeShort(cp.getIndex((CPGen.Ent)val));
                 } else {
                     o.writeInt(2);
                     o.writeShort(cp.getIndex((CPGen.Ent)val));
                 } else {
index 491cc12..21b2f03 100644 (file)
@@ -69,6 +69,13 @@ public class Type {
         public    boolean  isRef() { return true; }
     }
 
         public    boolean  isRef() { return true; }
     }
 
+    public static class Array extends Type.Ref {
+        protected Array(Type t) { super("[" + t.getDescriptor(), t.toString() + "[]"); }
+        public Type.Array asArray() { return this; }
+        public boolean isArray() { return true; }
+        public int dimension() { return getDescriptor().lastIndexOf('['); }
+    }
+
     public static class Class extends Type.Ref {
         protected Class(String s) { super(_initHelper(s), _initHelper2(s)); }
         public Type.Class asClass() { return this; }
     public static class Class extends Type.Ref {
         protected Class(String s) { super(_initHelper(s), _initHelper2(s)); }
         public Type.Class asClass() { return this; }
@@ -109,7 +116,6 @@ public class Type {
         }
     
         public class Field extends Member {
         }
     
         public class Field extends Member {
-            /** Create a reference to field <i>name</i> of class <i>c</i> with the type <i>t</i>  */    
             public final Type type;
             private Field(String name, Type t) { super(name); this.type = t; }
             public String getDescriptor() { return name; }
             public final Type type;
             private Field(String name, Type t) { super(name); this.type = t; }
             public String getDescriptor() { return name; }
@@ -134,12 +140,4 @@ public class Type {
         }
 
     }    
         }
 
     }    
-
-    public static class Array extends Type.Ref {
-        protected Array(Type t) { super("[" + t.getDescriptor(), t.toString() + "[]"); }
-        public Type.Array asArray() { return this; }
-        public boolean isArray() { return true; }
-        public int dimension() { return getDescriptor().lastIndexOf('['); }
-    }
-
 }
 }