1 3 package org.python.compiler; 4 5 import java.io.*; 6 import java.util.*; 7 8 public class LineNumberTable extends Attribute { 9 int attName; 10 ConstantPool pool; 11 Vector lines; 12 13 public LineNumberTable(ConstantPool pool) throws IOException { 14 this.pool = pool; 15 attName = pool.UTF8("LineNumberTable"); 16 lines = new Vector(); 17 } 18 19 public void write(DataOutputStream stream) throws IOException { 20 stream.writeShort(attName); 21 int n = lines.size(); 22 stream.writeInt(n * 2 + 2); 23 stream.writeShort(n / 2); 24 for (int i = 0; i < n; i += 2) { 25 Short startpc = (Short ) lines.elementAt(i); 26 Short lineno = (Short ) lines.elementAt(i+1); 27 stream.writeShort(startpc.shortValue()); 28 stream.writeShort(lineno.shortValue()); 29 } 30 } 31 32 public void addLine(int startpc, int lineno) { 33 lines.addElement(new Short ((short) startpc)); 34 lines.addElement(new Short ((short) lineno)); 35 } 36 37 public int length() { 38 return lines.size() * 2 + 8; 39 } 40 } 41 42 | Popular Tags |