1 cananian 1.1.2.2 // LocalVariableTable.java, created Mon Jan 18 22:44:38 1999 by cananian
  2 cananian 1.1.2.1 // Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
  3 cananian 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
  4 cananian 1.1.2.1 package harpoon.IR.RawClass;
  5 cananian 1.1.2.1 
  6 cananian 1.1.2.1 /** 
  7 cananian 1.1.2.1  * Each object indicates a range of <code>code</code> array offsets
  8 cananian 1.1.2.1  * within which a local variable has a value.
  9 cananian 1.1.2.1  *
 10 cananian 1.1.2.1  * @author  C. Scott Ananian <cananian@alumni.princeton.edu>
 11 cananian 1.2      * @version $Id: LocalVariableTable.java,v 1.2 2002/02/25 21:05:27 cananian Exp $
 12 cananian 1.1.2.1  * @see AttributeLocalVariableTable
 13 cananian 1.1.2.1  */
 14 cananian 1.1.2.1 public class LocalVariableTable {
 15 cananian 1.1.2.1   /** ClassFile in which this attribute information is found. */
 16 cananian 1.1.2.1   protected ClassFile parent;
 17 cananian 1.1.2.1 
 18 cananian 1.1.2.1   /** The given local variable must have a value at indices into the
 19 cananian 1.1.2.1       <code>code</code> array in the closed interval
 20 cananian 1.1.2.1       <code>[start_pc, start_pc + length]</code>.
 21 cananian 1.1.2.1       <p> The value of <code>start_pc</code> must be a valid index
 22 cananian 1.1.2.1       into the <code>code</code> array of this <code>Code</code>
 23 cananian 1.1.2.1       attribute of the opcode of an instruction. */
 24 cananian 1.1.2.1   public int start_pc;
 25 cananian 1.1.2.1   /** The given local variable must have a value at indices into the
 26 cananian 1.1.2.1       <code>code</code> array in the closed interval
 27 cananian 1.1.2.1       <code>[start_pc, start_pc + length]</code>.
 28 cananian 1.1.2.1       <p> The value of <code>start_pc+length</code> must be either a 
 29 cananian 1.1.2.1       valid index into the <code>code</code> array of this
 30 cananian 1.1.2.1       <code>Code</code> attribute of the opcode of an instruction,
 31 cananian 1.1.2.1       or the first index beyond the end of that <code>code</code>
 32 cananian 1.1.2.1       array.  */
 33 cananian 1.1.2.1   public int length;
 34 cananian 1.1.2.1   /** The value of the <code>name_index</code> item must be a valid
 35 cananian 1.1.2.1         index into the <code>constant_pool</code> table.  The
 36 cananian 1.1.2.1         <code>constant_pool</code> entry at that index must contain a
 37 cananian 1.1.2.1         <code>CONSTANT_Utf8_info</codE> structure representing a valid
 38 cananian 1.1.2.1         Java local variable name stored as a simple name. */
 39 cananian 1.1.2.1   public int name_index;
 40 cananian 1.1.2.1   /** The value of the <code>descriptor_index</code> item must be a
 41 cananian 1.1.2.1         valid index into the <code>constant_pool</code> table.  The
 42 cananian 1.1.2.1         <code>constant_pool</code> entry at that index must contain a
 43 cananian 1.1.2.1         <code>CONSTANT_Utf8_info</code> structure representing a valid
 44 cananian 1.1.2.1         descriptor for a Java local variable.  Java local variable
 45 cananian 1.1.2.1         descriptors have the same form as field descriptors. */
 46 cananian 1.1.2.1   public int descriptor_index;
 47 cananian 1.1.2.1   /** The given local variable must be at <code>index</code> in its
 48 cananian 1.1.2.1         method's local variables.  If the local variable at
 49 cananian 1.1.2.1         <code>index</code> is a two-word type (<code>double</code> or
 50 cananian 1.1.2.1         <code>long</code>), it occupies both <code>index</code> and
 51 cananian 1.1.2.1         <code>index+1</code>. */
 52 cananian 1.1.2.1   public int index;
 53 cananian 1.1.2.1 
 54 cananian 1.1.2.1   /** Constructor. */
 55 cananian 1.1.2.1   LocalVariableTable(ClassFile parent, ClassDataInputStream in) 
 56 cananian 1.1.2.1     throws java.io.IOException {
 57 cananian 1.1.2.1     this.parent = parent;
 58 cananian 1.1.2.1 
 59 cananian 1.1.2.1     this.start_pc = in.read_u2();
 60 cananian 1.1.2.1     this.length   = in.read_u2();
 61 cananian 1.1.2.1       
 62 cananian 1.1.2.1     this.name_index       = in.read_u2();
 63 cananian 1.1.2.1     this.descriptor_index = in.read_u2();
 64 cananian 1.1.2.1       
 65 cananian 1.1.2.1     this.index = in.read_u2();
 66 cananian 1.1.2.1   }
 67 cananian 1.1.2.1   /** Constructor. */
 68 cananian 1.1.2.1   public LocalVariableTable(ClassFile parent,
 69 cananian 1.1.2.1                             int start_pc, int length,
 70 cananian 1.1.2.1                             int name_index, int descriptor_index,
 71 cananian 1.1.2.1                             int index) {
 72 cananian 1.1.2.1     this.parent = parent;
 73 cananian 1.1.2.1 
 74 cananian 1.1.2.1     this.start_pc = start_pc;
 75 cananian 1.1.2.1     this.length = length;
 76 cananian 1.1.2.1     this.name_index = name_index;
 77 cananian 1.1.2.1     this.descriptor_index = descriptor_index;
 78 cananian 1.1.2.1     this.index = index;
 79 cananian 1.1.2.1   }
 80 cananian 1.1.2.1   /** Writes to bytecode stream. */
 81 cananian 1.1.2.1   public void write(ClassDataOutputStream out) throws java.io.IOException {
 82 cananian 1.1.2.1     out.write_u2(start_pc);
 83 cananian 1.1.2.1     out.write_u2(length);
 84 cananian 1.1.2.1 
 85 cananian 1.1.2.1     out.write_u2(name_index);
 86 cananian 1.1.2.1     out.write_u2(descriptor_index);
 87 cananian 1.1.2.1       
 88 cananian 1.1.2.1     out.write_u2(index);
 89 cananian 1.1.2.1   }
 90 cananian 1.1.2.1   // convenience functions.
 91 cananian 1.1.2.1   public ConstantUtf8 name_index()
 92 cananian 1.1.2.1   { return (ConstantUtf8) parent.constant_pool[name_index]; }
 93 cananian 1.1.2.1   public ConstantUtf8 descriptor_index()
 94 cananian 1.1.2.1   { return (ConstantUtf8) parent.constant_pool[descriptor_index]; }
 95 cananian 1.1.2.1 
 96 cananian 1.1.2.1   public String name() { return name_index().val; }
 97 cananian 1.1.2.1   public String descriptor() { return descriptor_index().val; }
 98 cananian 1.1.2.1 
 99 cananian 1.1.2.1   public int end_pc() { return start_pc + length; }
100 cananian 1.1.2.1   
101 cananian 1.1.2.1   /** Pretty-print the contents of this attribute.
102 cananian 1.1.2.1    *  @param indent the indentation level to use.
103 cananian 1.1.2.1    */
104 cananian 1.1.2.1   public void print(java.io.PrintWriter pw, int indent) {
105 cananian 1.1.2.1     int in=indent;
106 cananian 1.1.2.1     indent(pw, in, "Valid in pc=["+start_pc+","+(start_pc+length)+"]");
107 cananian 1.1.2.1     indent(pw, in, "Variable index: "+index);
108 cananian 1.1.2.1     indent(pw, in, "Variable name:  "+name()+" {"+name_index+"}");
109 cananian 1.1.2.1     indent(pw, in, "Descriptor:     "+descriptor()+" {"+descriptor_index+"}");
110 cananian 1.1.2.1   }
111 cananian 1.1.2.1   private static void indent(java.io.PrintWriter pw, int indent, String s) {
112 cananian 1.1.2.1     ClassFile.indent(pw,indent,s);
113 cananian 1.1.2.1   }
114 cananian 1.2     }