1 4 package gnu.bytecode; 5 import java.io.*; 6 7 11 12 public class LineNumbersAttr extends Attribute 13 { 14 short[] linenumber_table; 18 int linenumber_count; 20 21 22 public LineNumbersAttr(CodeAttr code) 23 { 24 super("LineNumberTable"); 25 addToFrontOf(code); 26 code.lines = this; 27 } 28 29 public LineNumbersAttr(short[] numbers, CodeAttr code) 30 { 31 this(code); 32 linenumber_table = numbers; 33 linenumber_count = numbers.length >> 1; 34 } 35 36 39 public void put (int linenumber, int PC) 40 { 41 if (linenumber_table == null) 42 linenumber_table = new short[32]; 43 else if (2 * linenumber_count >= linenumber_table.length) 44 { 45 short[] new_linenumbers = new short [2 * linenumber_table.length]; 46 System.arraycopy (linenumber_table, 0, new_linenumbers, 0, 47 2 * linenumber_count); 48 linenumber_table = new_linenumbers; 49 } 50 linenumber_table[2 * linenumber_count] = (short) PC; 51 linenumber_table[2 * linenumber_count + 1] = (short) linenumber; 52 linenumber_count++; 53 } 54 55 56 public final int getLength() { return 2 + 4 * linenumber_count; } 57 58 public int getLineCount () { return linenumber_count; } 59 public short[] getLineNumberTable () { return linenumber_table; } 60 61 public void write (DataOutputStream dstr) throws java.io.IOException 62 { 63 dstr.writeShort (linenumber_count); 64 int count = 2 * linenumber_count; 65 for (int i = 0; i < count; i++) 66 { 67 dstr.writeShort(linenumber_table[i]); 68 } 69 } 70 71 public void print (ClassTypeWriter dst) 72 { 73 dst.print("Attribute \""); 74 dst.print(getName()); 75 dst.print("\", length:"); 76 dst.print(getLength()); 77 dst.print(", count: "); 78 dst.println(linenumber_count); 79 for (int i = 0; i < linenumber_count; i++) 80 { 81 dst.print(" line: "); 82 dst.print(linenumber_table[2 * i + 1] & 0xFFFF); dst.print(" at pc: "); 84 dst.println(linenumber_table[2 * i] & 0xFFFF); } 86 } 87 } 88 | Popular Tags |