]> source.dussan.org Git - javassist.git/commitdiff
for JIRA-95
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 20 Oct 2009 02:09:31 +0000 (02:09 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 20 Oct 2009 02:09:31 +0000 (02:09 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@500 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/bytecode/ClassFileWriter.java
src/main/javassist/bytecode/StackMap.java

index 816ab8242fbcb53717ace9152c06440789846d00..2dcbfc1ccfda78b72f061839f4a502005b18599c 100644 (file)
@@ -113,6 +113,11 @@ public class ClassFileWriter {
                 StackMapTable.Printer.print((StackMapTable)ai, out);
                 out.println("<stack map table end>");
             }
+            else if (ai instanceof StackMap) {
+                out.println("<stack map begin>");
+                StackMap.Printer.print((StackMap)ai, out);
+                out.println("<stack map end>");
+            }
             else if (ai instanceof SignatureAttribute) {
                 SignatureAttribute sa = (SignatureAttribute)ai;
                 String sig = sa.getSignature();
index caef3d80a3ed75babcb4d7ebb1fe2ede31bc96fe..06b637ee43258d7843c4a2c47d672485fba6ab4f 100644 (file)
@@ -156,6 +156,53 @@ public class StackMap extends AttributeInfo {
         return pos;
     }
 
+    /**
+     * Printer
+     */
+    public static class Printer {
+        /**
+         * Prints a <code>StackMap</code> attribute.
+         *
+         * @param sm        the <code>StackMap</code> attribute.
+         * @param cp        the <code>ConstPool</code> of the class file
+         *                  containing the <code>StackMap</code> attribute.
+         */
+        public static void print(StackMap sm, java.io.PrintWriter out) {
+            int num = sm.numOfEntries();
+            out.println(num + " entries");
+            byte[] srcInfo = sm.get();
+            int pos = 2;
+            for (int i = 0; i < num; i++) {
+                int offset = ByteArray.readU16bit(srcInfo, pos);
+                out.println("  * offset " + offset);
+                pos += 2;
+                int numLoc = ByteArray.readU16bit(srcInfo, pos);
+                pos = printFrames(srcInfo, pos + 2, numLoc);
+                int numStack = ByteArray.readU16bit(srcInfo, pos);
+                pos = printFrames(srcInfo, pos + 2, numStack);
+            }
+        }
+
+        private static int printFrames(byte[] srcInfo, int pos,
+                                       int numFrames) {
+            for (int k = 0; k < numFrames; k++) {
+                byte tag = srcInfo[pos];
+                if (tag == OBJECT) {
+                    ByteArray.readU16bit(srcInfo, pos + 1);
+                    pos += 3;
+                }
+                else if (tag == UNINIT) {
+                    ByteArray.readU16bit(srcInfo, pos + 1);
+                    pos += 3;
+                }
+                else
+                    pos++;
+            }
+
+            return pos;
+        }
+    }
+
     /**
      * Internal use only.
      */