[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: note: JasminClass change



Patrick LAM wrote:
On Tue, 27 Apr 2004, Chris Pickett wrote:


I think that

.super

by itself implying super_class = 0 is better.  Either that or an
explicit '.no_super'.  You still need something that writes the
super_class field (well, it's 0, so you don't _really_ need it if the
data is initialized).  Also, if the entire line is optional, then you
don't get parse errors if you forget .super for a non-java.lang.Object
class, which is bad.


I think it's ok to let assembler users shoot themselves in the foot.  (I
would be less in favour of letting Soot users shoot themselves in the foot
that easily).  I think .super by itself isn't so great (it looks like
there's something missing).  .no_super is ok if the syntax says .super foo
| .no_super.

Okay, patches with .no_super are attached for Soot and Jasmin, and I tested the changes on java.lang.Object. It's the first time I've ever submitted a patch (!), so please tell me if there are problems. You might want to run dos2unix on the whole jasmin tree. I didn't do so because the patch would be huge. Also, the soot patch might be a little messed up because I didn't have a good working copy anymore after I tried to run svn up using a 0.37 binary. Would be nice if everyone (Soot, SableVM) could move to 1.0+ now that it's out. Finally, I didn't include the generated files like parser.java and sym.java (not to mention classfiles) in my patch, even though those are in the distribution in the src directory. I don't think src directories should ever contain generated files in a distribution, unless they're required for bootstrapping or something. But it's no big deal.


You won't get parse errors for missing a .super line for
non-java.lang.Object.

That's what I wrote :) I thought you would want parse errors for missing .super lines, but only if the class is not java.lang.Object, and it seemed easier to use .no_super.


Cheers,
Chris
diff -urN src.orig/soot/baf/JasminClass.java src/soot/baf/JasminClass.java
--- src.orig/soot/baf/JasminClass.java	Tue Apr 27 20:01:06 2004
+++ src/soot/baf/JasminClass.java	Tue Apr 27 20:01:59 2004
@@ -230,7 +230,13 @@
                 emit(".class " + Modifier.toString(modifiers) + " " + slashify(sootClass.getName()));
 
 	    if(sootClass.hasSuperclass())
-		emit(".super " + slashify(sootClass.getSuperclass().getName()));
+		{
+		    emit(".super " + slashify(sootClass.getSuperclass().getName()));
+		}
+	    else
+		{
+		    emit(".no_super");
+		}
 
             emit("");
         }
diff -urN src.orig/soot/jimple/JasminClass.java src/soot/jimple/JasminClass.java
--- src.orig/soot/jimple/JasminClass.java	Tue Apr 27 20:00:42 2004
+++ src/soot/jimple/JasminClass.java	Tue Apr 27 20:02:56 2004
@@ -245,7 +245,13 @@
                 emit(".class " + Modifier.toString(modifiers) + " " + slashify(sootClass.getName()));
 
 	    if(sootClass.hasSuperclass())
-		emit(".super " + slashify(sootClass.getSuperclass().getName()));
+		{
+		    emit(".super " + slashify(sootClass.getSuperclass().getName()));
+		}
+	    else
+		{
+		    emit(".no_super");
+		}
 
             emit("");
         }
diff -urN jasmin-sable-1.2.orig/src/jasmin/parser.cup jasmin-sable-1.2/src/jasmin/parser.cup
--- jasmin-sable-1.2.orig/src/jasmin/parser.cup	Tue Oct  9 16:57:25 2001
+++ jasmin-sable-1.2/src/jasmin/parser.cup	Tue Apr 27 19:28:55 2004
@@ -78,7 +78,7 @@
 terminal token
     // Directives (words beginning with a '.')
     DCATCH, DCLASS, DEND, DFIELD, DLIMIT, DLINE, DMETHOD, DSET, DSUPER,
-    DSOURCE, DTHROWS, DVAR, DIMPLEMENTS, DINTERFACE,
+    DNOSUPER, DSOURCE, DTHROWS, DVAR, DIMPLEMENTS, DINTERFACE,
 
    // Attributes
 	DCODE_ATTR, DCLASS_ATTR, DFIELD_ATTR, DMETHOD_ATTR,
@@ -208,6 +208,11 @@
     DSUPER classname:name SEP
         {:
             classFile.setSuperClass(name);
+        :}
+    |
+    DNOSUPER SEP
+        {:
+	    classFile.setNoSuperClass();
         :}
   ;

diff -urN jasmin-sable-1.2.orig/src/jasmin/ClassFile.java jasmin-sable-1.2/src/jasmin/ClassFile.java
--- jasmin-sable-1.2.orig/src/jasmin/ClassFile.java	Tue Apr 17 15:42:18 2001
+++ jasmin-sable-1.2/src/jasmin/ClassFile.java	Tue Apr 27 19:29:50 2004
@@ -68,8 +68,6 @@
     int low_value;
     int high_value;
 
-
-
     int lastInstSize;
     Method currentMethod;
     Var currentField;
@@ -81,11 +79,6 @@
 	code.addSootCodeAttr(name, value);
     }
     
-
-
-
-
-
     public void addGenericAttrToMethod(String name, byte[] value)
     {
 	if(currentMethod == null) 
@@ -111,8 +104,6 @@
 	class_env.addGenericAttr(g);
     }
 
-
-
     static final String BGN_METHOD = "bgnmethod:";
     static final String END_METHOD = "endmethod:";
 
@@ -151,7 +142,6 @@
         source_name = name;
     }
 
-
     //
     // called by the .class directive
     //
@@ -166,6 +156,13 @@
     //
     void setSuperClass(String name) {
         class_env.setSuperClass(new ClassCP(name));
+    }
+
+    //
+    // called by the .no_super directive 
+    // (for java.lang.Object only)
+    void setNoSuperClass() {
+	class_env.setNoSuperClass();
     }
 
     //
diff -urN jasmin-sable-1.2.orig/src/jasmin/ReservedWords.java jasmin-sable-1.2/src/jasmin/ReservedWords.java
--- jasmin-sable-1.2.orig/src/jasmin/ReservedWords.java	Tue Apr 17 15:42:18 2001
+++ jasmin-sable-1.2/src/jasmin/ReservedWords.java	Tue Apr 27 19:22:55 2004
@@ -44,13 +44,14 @@
         reserved_words.put(".set", new Symbol(sym.DSET));
         reserved_words.put(".source", new Symbol(sym.DSOURCE));
         reserved_words.put(".super", new Symbol(sym.DSUPER));
+	reserved_words.put(".no_super", new Symbol(sym.DNOSUPER));
         reserved_words.put(".throws", new Symbol(sym.DTHROWS));
         reserved_words.put(".var", new Symbol(sym.DVAR));
 
 	reserved_words.put(".class_attribute", new Symbol(sym.DCLASS_ATTR));	
-reserved_words.put(".field_attribute", new Symbol(sym.DFIELD_ATTR));
-       reserved_words.put(".method_attribute", new Symbol(sym.DMETHOD_ATTR));
-       reserved_words.put(".code_attribute", new Symbol(sym.DCODE_ATTR));
+	reserved_words.put(".field_attribute", new Symbol(sym.DFIELD_ATTR));
+	reserved_words.put(".method_attribute", new Symbol(sym.DMETHOD_ATTR));
+	reserved_words.put(".code_attribute", new Symbol(sym.DCODE_ATTR));
 	
         // reserved_words used in Jasmin directives
         reserved_words.put("from", new Symbol(sym.FROM));
diff -urN jasmin-sable-1.2.orig/lib/jas/src/jas/ClassEnv.java jasmin-sable-1.2/lib/jas/src/jas/ClassEnv.java
--- jasmin-sable-1.2.orig/lib/jas/src/jas/ClassEnv.java	Tue Apr 17 15:42:18 2001
+++ jasmin-sable-1.2/lib/jas/src/jas/ClassEnv.java	Tue Apr 27 19:33:45 2004
@@ -6,8 +6,6 @@
 import java.util.Enumeration;
 import java.util.Vector;
 
-
-
 /**
  * This is the place where all information about the class to
  * be created resides.
@@ -28,6 +26,7 @@
   Vector methods;
   SourceAttr source;
   Vector generic;
+  boolean hasSuperClass;
 
   public ClassEnv()
   {
@@ -51,13 +50,27 @@
    */
   public void setClass(CP name)
   {  this_class = name; addCPItem(name); }
+
   /**
    * Define this class to have this superclass
    * @param name CPE representing name for class. (This is usually
    * a ClassCP)
    */
   public void setSuperClass(CP name)
-  {  super_class = name; addCPItem(name); }
+  { 
+    hasSuperClass = true;   
+    super_class = name; 
+    addCPItem(name);
+  }
+
+  /**
+   * Define this class to have no superclass.  Should only ever
+   * be used for java.lang.Object
+   */
+  public void setNoSuperClass()
+  {  
+    hasSuperClass = false;
+  }
 
   /**
    * Set the class access for this class. Constants understood
@@ -139,8 +152,17 @@
 				// Class hierarchy/access
     out.writeShort(class_access);
     out.writeShort(getCPIndex(this_class));
-    out.writeShort(getCPIndex(super_class));
-                                // interfaces
+
+    if (hasSuperClass)
+      {
+        out.writeShort(getCPIndex(super_class));
+      }       
+    else
+      {
+	out.writeShort(0);
+      }
+ 
+                         // interfaces
     out.writeShort(interfaces.size());
     for (Enumeration e = interfaces.elements(); e.hasMoreElements();)
       {