1 30 31 package oracle.toplink.libraries.asm.util.attrs; 32 33 import java.util.List ; 34 import java.util.Map ; 35 36 import oracle.toplink.libraries.asm.Attribute; 37 import oracle.toplink.libraries.asm.ClassReader; 38 import oracle.toplink.libraries.asm.Label; 39 import oracle.toplink.libraries.asm.attrs.StackMapAttribute; 40 import oracle.toplink.libraries.asm.attrs.StackMapFrame; 41 import oracle.toplink.libraries.asm.attrs.StackMapType; 42 43 48 49 public class ASMStackMapAttribute extends StackMapAttribute 50 implements ASMifiable 51 { 52 53 protected Attribute read (ClassReader cr, int off, 54 int len, char[] buf, int codeOff, Label[] labels) 55 { 56 StackMapAttribute attr = 57 (StackMapAttribute)super.read(cr, off, len, buf, codeOff, labels); 58 59 ASMStackMapAttribute result = new ASMStackMapAttribute(); 60 result.frames = attr.frames; 61 return result; 62 } 63 64 public void asmify (StringBuffer buf, String varName, Map labelNames) { 65 buf.append("{\n"); 66 buf.append("StackMapAttribute ").append(varName).append("Attr"); 67 buf.append(" = new StackMapAttribute();\n"); 68 if (frames.size() > 0) { 69 for (int i = 0; i < frames.size(); i++) { 70 asmify((StackMapFrame)frames.get(i), buf, varName + "frame" + i, labelNames); 71 } 72 } 73 buf.append(varName).append(".visitAttribute(").append(varName); 74 buf.append("Attr);\n}\n"); 75 } 76 77 void asmify (StackMapFrame f, StringBuffer buf, String varName, Map labelNames) { 78 declareLabel(buf, labelNames, f.label); 79 buf.append("{\n"); 80 81 buf.append("StackMapFrame ").append(varName).append( " = new StackMapFrame();\n"); 82 83 buf.append(varName).append(".label = ") 84 .append(labelNames.get(f.label)).append(";\n"); 85 86 asmifyTypeInfo(buf, varName, labelNames, f.locals, "locals"); 87 asmifyTypeInfo(buf, varName, labelNames, f.stack, "stack"); 88 89 buf.append( "cvAttr.frames.add(").append(varName).append(");\n"); 90 buf.append("}\n"); 91 } 92 93 void asmifyTypeInfo (StringBuffer buf, String varName, 94 Map labelNames, List infos, String field) { 95 if (infos.size() > 0) { 96 buf.append("{\n"); 97 for (int i = 0; i < infos.size(); i++) { 98 StackMapType typeInfo = (StackMapType)infos.get(i); 99 String localName = varName + "Info" + i; 100 int type = typeInfo.getType(); 101 buf.append("StackMapType ").append(localName) 102 .append(" = StackMapType.getTypeInfo( StackMapType.ITEM_") 103 .append(StackMapType.ITEM_NAMES[type]).append(");\n"); 104 105 switch (type) { 106 case StackMapType.ITEM_Object: buf.append(localName).append(".setObject(\"") 108 .append(typeInfo.getObject()).append("\");\n"); 109 break; 110 111 case StackMapType.ITEM_Uninitialized: declareLabel(buf, labelNames, typeInfo.getLabel()); 113 buf.append(localName).append(".setLabel(") 114 .append(labelNames.get(typeInfo.getLabel())).append(");\n"); 115 break; 116 } 117 buf.append(varName).append(".").append(field) 118 .append(".add(").append(localName).append(");\n"); 119 } 120 buf.append("}\n"); 121 } 122 } 123 124 static void declareLabel (StringBuffer buf, Map labelNames, Label l) { 125 String name = (String )labelNames.get(l); 126 if (name == null) { 127 name = "l" + labelNames.size(); 128 labelNames.put(l, name); 129 buf.append("Label ").append(name).append(" = new Label();\n"); 130 } 131 } 132 } 133 | Popular Tags |