1 /**
2  * Line number table attributes are embedded into Code attributes
3  * and used for further debugging information.
4  * @see CodeAttr#setLineTable
5  * @author $Author: jonmeyerny $
6  * @version $Revision: 1.1 $
7  */
8 
9 package jas;
10 
11 import java.io.*;
12 import java.util.*;
13 
14 public class LineTableAttr
15 {
16   static final CP attr = new AsciiCP("LineNumberTable");
17 
18   Vector line, pc;
19 
20   /**
21    * Note: A line table is associated with a <em>method</em>, so you
22    * need to create a new LineTableAttr for each method for which you add
23    * debugging information.
24    * @see CodeAttr#setLineTable
25    */
LineTableAttr()26   public LineTableAttr()
27   { line = new Vector(); pc = new Vector(); }
28 
29   /**
30    * Add a pc to line number entry to the line table.
31    * @param l to the location in the class file
32    * @param line Corresponding line number in the source file
33    */
34 
addEntry(Label l, int line)35   public void addEntry(Label l, int line)
36   {
37     pc.addElement(l);
38     this.line.addElement(new Integer(line));
39   }
40 
resolve(ClassEnv e)41   void resolve(ClassEnv e)
42   { e.addCPItem(attr); }
43 
size()44   int size()
45   { return
46       (2 +			// name_idx
47        4 +			// attr_len
48        2 +			// line table len spec
49        4*(pc.size()));		// table
50   }
51 
write(ClassEnv e, CodeAttr ce, DataOutputStream out)52   void write(ClassEnv e, CodeAttr ce, DataOutputStream out)
53     throws IOException, jasError
54   {
55     out.writeShort(e.getCPIndex(attr));
56     out.writeInt(2 + 4*(pc.size()));
57     out.writeShort(pc.size());
58     for (Enumeration en = pc.elements(), ien = line.elements();
59 	 en.hasMoreElements();)
60       {
61 	Label l = (Label)(en.nextElement());
62 	Integer i = (Integer)(ien.nextElement());
63 	l.writeOffset(ce, null, out);
64 	out.writeShort((int) i.intValue());
65       }
66   }
67 }
68