From 5de87156f94849f27baf77740d76adfb9ada2a07 Mon Sep 17 00:00:00 2001 From: chiba Date: Tue, 20 Oct 2009 02:09:31 +0000 Subject: [PATCH] for JIRA-95 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@500 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- .../javassist/bytecode/ClassFileWriter.java | 5 ++ src/main/javassist/bytecode/StackMap.java | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/main/javassist/bytecode/ClassFileWriter.java b/src/main/javassist/bytecode/ClassFileWriter.java index 816ab824..2dcbfc1c 100644 --- a/src/main/javassist/bytecode/ClassFileWriter.java +++ b/src/main/javassist/bytecode/ClassFileWriter.java @@ -113,6 +113,11 @@ public class ClassFileWriter { StackMapTable.Printer.print((StackMapTable)ai, out); out.println(""); } + else if (ai instanceof StackMap) { + out.println(""); + StackMap.Printer.print((StackMap)ai, out); + out.println(""); + } else if (ai instanceof SignatureAttribute) { SignatureAttribute sa = (SignatureAttribute)ai; String sig = sa.getSignature(); diff --git a/src/main/javassist/bytecode/StackMap.java b/src/main/javassist/bytecode/StackMap.java index caef3d80..06b637ee 100644 --- a/src/main/javassist/bytecode/StackMap.java +++ b/src/main/javassist/bytecode/StackMap.java @@ -156,6 +156,53 @@ public class StackMap extends AttributeInfo { return pos; } + /** + * Printer + */ + public static class Printer { + /** + * Prints a StackMap attribute. + * + * @param sm the StackMap attribute. + * @param cp the ConstPool of the class file + * containing the StackMap 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. */ -- 2.39.5