瀏覽代碼

J2CPS version 1.3.13.2
Place guards over for loops in ClassDesc::writeType.
Tidying up SymbolFile.java, eliminating dead code and dead initializations, and restricting scope of locals.

k_john_gough_cp 13 年之前
父節點
當前提交
03d9060543
共有 3 個文件被更改,包括 79 次插入66 次删除
  1. 70 55
      J2CPS/ClassDesc.java
  2. 1 1
      J2CPS/J2CPS.java
  3. 8 10
      J2CPS/SymbolFile.java

+ 70 - 55
J2CPS/ClassDesc.java

@@ -115,7 +115,16 @@ public class ClassDesc extends TypeDesc  {
 //    }
 //    }
 //*/
 //*/
     cp = new ConstantPool(stream);
     cp = new ConstantPool(stream);
-    access = stream.readUnsignedShort(); 
+    access = stream.readUnsignedShort();
+    // Experimental code to only transform packages that
+    // are reachable from classes that are not private.
+    // Under consideration for next version, controlled 
+    // by a command line option.
+//    if (!ConstantPool.isPublic(access) && !ConstantPool.isProtected(access)) {
+//        cp.EmptyConstantPool();
+//        return true;
+//    }
+    // End experimental code
     ClassRef thisClass = (ClassRef) cp.Get(stream.readUnsignedShort());
     ClassRef thisClass = (ClassRef) cp.Get(stream.readUnsignedShort());
     String clName = thisClass.GetName();
     String clName = thisClass.GetName();
     if (!qualName.equals(clName)) {
     if (!qualName.equals(clName)) {
@@ -430,12 +439,12 @@ public class ClassDesc extends TypeDesc  {
     if (this.packageDesc != thisPack) {
     if (this.packageDesc != thisPack) {
       out.writeByte(SymbolFile.fromS);
       out.writeByte(SymbolFile.fromS);
 // ------------
 // ------------
-      if (this.packageDesc.impNum < 0) {
-        System.out.println("impNum is " + this.packageDesc.impNum);
-        System.out.println("packageDesc " + this.packageDesc.javaName);
-        System.out.println("objName " + objName);
-        this.packageDesc.impNum = 0;
-      }
+//      if (this.packageDesc.impNum < 0) {
+//        System.out.println("impNum is " + this.packageDesc.impNum);
+//        System.out.println("packageDesc " + this.packageDesc.javaName);
+//        System.out.println("objName " + objName);
+//        this.packageDesc.impNum = 0;
+//      }
 // ------------
 // ------------
       SymbolFile.writeOrd(out,this.packageDesc.impNum);
       SymbolFile.writeOrd(out,this.packageDesc.impNum);
       SymbolFile.writeName(out,access,objName);
       SymbolFile.writeName(out,access,objName);
@@ -474,62 +483,68 @@ public class ClassDesc extends TypeDesc  {
         SymbolFile.writeTypeOrd(out,interfaces[i]); 
         SymbolFile.writeTypeOrd(out,interfaces[i]); 
       }
       }
     }
     }
-    for (int i=0; i < fields.length; i++) {
-      if (fields[i].isExported() && !fields[i].isStatic()) {
-        SymbolFile.writeName(out,fields[i].accessFlags,fields[i].name);
-        SymbolFile.writeTypeOrd(out,fields[i].type);
+    if (fields != null && fields.length > 0) {
+      for (int i=0; i < fields.length; i++) {
+        if (fields[i].isExported() && !fields[i].isStatic()) {
+            SymbolFile.writeName(out,fields[i].accessFlags,fields[i].name);
+            SymbolFile.writeTypeOrd(out,fields[i].type);
+        }
       }
       }
     }
     }
-    for (int i=0; i < methods.length; i++) {
-      if (methods[i].isExported() && !methods[i].deprecated &&
-         !methods[i].isStatic() && !methods[i].isInitProc &&
-         !methods[i].isCLInitProc) {
-        out.writeByte(SymbolFile.mthSy);
-// --------------------
-        if (methods[i].userName == null) {
-          System.out.println("packageDesc " + this.packageDesc.javaName);
-          System.out.println("objName " + objName);
-          for (int j=0; j < methods.length; j++) {
-            System.out.println("Method " + j +  
-                (methods[i].userName == null ? " null" : methods[j].userName));
-          }
+    if (methods != null && methods.length > 0) {
+      for (int i=0; i < methods.length; i++) {
+        if (methods[i].isExported() && !methods[i].deprecated &&
+            !methods[i].isStatic() && !methods[i].isInitProc &&
+            !methods[i].isCLInitProc) {
+            out.writeByte(SymbolFile.mthSy);
+    // --------------------
+    //        if (methods[i].userName == null) {
+    //          System.out.println("packageDesc " + this.packageDesc.javaName);
+    //          System.out.println("objName " + objName);
+    //          for (int j=0; j < methods.length; j++) {
+    //            System.out.println("Method " + j +  
+    //                (methods[i].userName == null ? " null" : methods[j].userName));
+    //          }
+    //        }
+    // --------------------
+            SymbolFile.writeName(out,methods[i].accessFlags,methods[i].userName);
+            int attr = 0;
+            if (!methods[i].overridding) { attr = 1; }
+            if (methods[i].isAbstract()) { attr += 2; }
+            else if (!methods[i].isFinal()){ attr += 6; } 
+            out.writeByte(attr); 
+            out.writeByte(0); /* all java receivers are value mode */
+            SymbolFile.writeOrd(out,outTypeNum);
+            SymbolFile.writeString(out,methods[i].name);
+            SymbolFile.WriteFormalType(methods[i],out);
         }
         }
-// --------------------
-        SymbolFile.writeName(out,methods[i].accessFlags,methods[i].userName);
-        int attr = 0;
-        if (!methods[i].overridding) { attr = 1; }
-        if (methods[i].isAbstract()) { attr += 2; }
-        else if (!methods[i].isFinal()){ attr += 6; } 
-        out.writeByte(attr); 
-        out.writeByte(0); /* all java receivers are value mode */
-        SymbolFile.writeOrd(out,outTypeNum);
-        SymbolFile.writeString(out,methods[i].name);
-        SymbolFile.WriteFormalType(methods[i],out);
       }
       }
-    } 
-    for (int i=0; i < fields.length; i++) {
-      if (fields[i].isConstant()) {
-        out.writeByte(SymbolFile.conSy);
-        SymbolFile.writeName(out,fields[i].accessFlags,fields[i].name);
-        SymbolFile.writeLiteral(out,fields[i].GetConstVal());
-      } else if (fields[i].isExported() && fields[i].isStatic()) {
-        out.writeByte(SymbolFile.varSy);
-        SymbolFile.writeName(out,fields[i].accessFlags,fields[i].name);
-        SymbolFile.writeTypeOrd(out,fields[i].type);
+    }
+    if (fields != null && fields.length > 0) {
+      for (int i=0; i < fields.length; i++) {
+        if (fields[i].isConstant()) {
+            out.writeByte(SymbolFile.conSy);
+            SymbolFile.writeName(out,fields[i].accessFlags,fields[i].name);
+            SymbolFile.writeLiteral(out,fields[i].GetConstVal());
+        } else if (fields[i].isExported() && fields[i].isStatic()) {
+            out.writeByte(SymbolFile.varSy);
+            SymbolFile.writeName(out,fields[i].accessFlags,fields[i].name);
+            SymbolFile.writeTypeOrd(out,fields[i].type);
+        }
       }
       }
     }
     }
-    for (int i=0; i < methods.length; i++) {
-      if (methods[i].isExported() && !methods[i].deprecated &&
-          methods[i].isStatic() && !methods[i].isCLInitProc) {
-        out.writeByte(SymbolFile.prcSy);
-        SymbolFile.writeName(out,methods[i].accessFlags,methods[i].userName);
-        SymbolFile.writeString(out,methods[i].name);
-        if (methods[i].isInitProc) { out.writeByte(SymbolFile.truSy); }
-        SymbolFile.WriteFormalType(methods[i],out);
+    if (methods != null && methods.length > 0) {
+      for (int i=0; i < methods.length; i++) {
+        if (methods[i].isExported() && !methods[i].deprecated &&
+            methods[i].isStatic() && !methods[i].isCLInitProc) {
+            out.writeByte(SymbolFile.prcSy);
+            SymbolFile.writeName(out,methods[i].accessFlags,methods[i].userName);
+            SymbolFile.writeString(out,methods[i].name);
+            if (methods[i].isInitProc) { out.writeByte(SymbolFile.truSy); }
+            SymbolFile.WriteFormalType(methods[i],out);
+        }
       }
       }
     }
     }
     out.writeByte(SymbolFile.endRc);
     out.writeByte(SymbolFile.endRc);
   }
   }
-
-
 }
 }

+ 1 - 1
J2CPS/J2CPS.java

@@ -20,7 +20,7 @@ public class J2CPS {
     String filename = null;
     String filename = null;
     TypeDesc.InitTypes();
     TypeDesc.InitTypes();
     if (argLen == 0) {
     if (argLen == 0) {
-      System.err.println("J2CPS version 1.3.12 (Nov. 2011)");
+      System.err.println("J2CPS version 1.3.13.2 (August 2012)");
       System.err.println("Usage: java J2CPS [options] packagename");
       System.err.println("Usage: java J2CPS [options] packagename");
       System.err.println("Options may be in any order.");
       System.err.println("Options may be in any order.");
       System.err.println("  -d dir  symbol file directory");
       System.err.println("  -d dir  symbol file directory");

+ 8 - 10
J2CPS/SymbolFile.java

@@ -600,7 +600,6 @@ class SymbolFile {
 
 
     ClearTypeList();
     ClearTypeList();
     ClassDesc aClass, impClass;
     ClassDesc aClass, impClass;
-    PackageDesc impPack;
     int maxInNum = 0;
     int maxInNum = 0;
     FileInputStream fIn = new FileInputStream(symFile);
     FileInputStream fIn = new FileInputStream(symFile);
     in = new DataInputStream(fIn);
     in = new DataInputStream(fIn);
@@ -655,19 +654,18 @@ class SymbolFile {
     }
     }
     Expect(start);
     Expect(start);
     while (sSym != close) {
     while (sSym != close) {
-      int impNum = -1;
-      impPack = null;
+      PackageDesc impPack;
       impClass = null;
       impClass = null;
-      String impName = null, impModName = null;
+      String impModName = null;
       int impAcc = 0, impModAcc = 0;
       int impAcc = 0, impModAcc = 0;
       Check(tDefS); 
       Check(tDefS); 
       int tNum = tOrd; GetSym(); 
       int tNum = tOrd; GetSym(); 
       if (tNum > maxInNum) { maxInNum = tNum; }
       if (tNum > maxInNum) { maxInNum = tNum; }
-      if (sSym == fromS) { 
-        impNum = tOrd - 1;
+      if (sSym == fromS) {
+        int impNum = tOrd - 1;
         GetSym(); 
         GetSym(); 
         Check(namSy);
         Check(namSy);
-        impName = name;
+        String impName = name;
         impAcc = acc; 
         impAcc = acc; 
         if (impNum < 0) {
         if (impNum < 0) {
           impPack = thisPack;
           impPack = thisPack;
@@ -816,9 +814,7 @@ class SymbolFile {
     fIn.close();
     fIn.close();
     // do fix ups...
     // do fix ups...
     for (int i = TypeDesc.specT; i <= maxInNum; i++) {
     for (int i = TypeDesc.specT; i <= maxInNum; i++) {
-      int size = 0;
       if ((typeList[i] != null) && (typeList[i] instanceof ClassDesc)) {
       if ((typeList[i] != null) && (typeList[i] instanceof ClassDesc)) {
-        aClass = (ClassDesc)typeList[i];
         if (!((ClassDesc)typeList[i]).read) {
         if (!((ClassDesc)typeList[i]).read) {
           aClass = (ClassDesc)typeList[i];
           aClass = (ClassDesc)typeList[i];
           if (aClass.superNum != 0) {
           if (aClass.superNum != 0) {
@@ -828,7 +824,9 @@ class SymbolFile {
           for (int j=0; j < aClass.numInts; j++) {
           for (int j=0; j < aClass.numInts; j++) {
             aClass.interfaces[j] = (ClassDesc) GetFixUpType(aClass.intNums[j]); 
             aClass.interfaces[j] = (ClassDesc) GetFixUpType(aClass.intNums[j]); 
           }
           }
-          if (aClass.fieldList == null) { size = 0; 
+          int size;
+          if (aClass.fieldList == null) { 
+            size = 0; 
           } else {
           } else {
             size = aClass.fieldList.size(); 
             size = aClass.fieldList.size(); 
           }
           }