KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > compiler > LineNumberTable


1 // Copyright 2001 Finn Bock
2

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 JavaDoc startpc = (Short JavaDoc) lines.elementAt(i);
26             Short JavaDoc lineno = (Short JavaDoc) 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 JavaDoc((short) startpc));
34         lines.addElement(new Short JavaDoc((short) lineno));
35     }
36
37     public int length() {
38         return lines.size() * 2 + 8;
39     }
40 }
41
42
Popular Tags