KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > coffi > LocalVariableTypeTable_attribute


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2005 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30
31
32 package soot.coffi;
33 import soot.*;
34
35 import java.io.*;
36
37 /** A debugging attribute, this gives the types of local variables
38  * within blocks of bytecode. - for java 1.5
39  * @see attribute_info
40  * @author Jennifer Lhotak
41  * modified from LocalVariableTable_attribute
42  */

43 class LocalVariableTypeTable_attribute extends attribute_info {
44    /** Length of the local variable type table. */
45    public int local_variable_type_table_length;
46    /** Actual table of local variable types. */
47    public local_variable_type_table_entry local_variable_type_table[];
48
49    /** Locates the first type found for a given local variable.
50     * @param constant_pool constant pool for the associated class.
51     * @param idx local variable type index.
52     * @return type of the local variable, or <i>null</i> if not found.
53     * @see LocalVariableTypeTable_attribute#getLocalVariableType(cp_info[], int, int)
54     */

55    public String JavaDoc getLocalVariableType(cp_info constant_pool[],int idx) {
56       return getLocalVariableType(constant_pool,idx,-1);
57    }
58    /** Locates the type of the given local variable for the specified code offset.
59     * @param constant_pool constant pool for the associated class.
60     * @param idx local variable type index.
61     * @param code code offset for variable name; use -1 to return the first name found
62     * for that local variable.
63     * @return type of the local variable, or <i>null</i> if not found.
64     * @see LocalVariableTypeTable_attribute#getLocalVariableType(cp_info[], int)
65     */

66    public String JavaDoc getLocalVariableType(cp_info constant_pool[],int idx,int code) {
67       local_variable_type_table_entry e;
68       CONSTANT_Utf8_info cu;
69       int i;
70
71       // G.v().out.println("searching for type of local: " + idx + "at: " + code);
72
// now to find that variable
73
for (i=0;i<local_variable_type_table_length;i++) {
74          e = local_variable_type_table[i];
75          if (e.index==idx &&
76              (code==-1 ||
77           (code>=e.start_pc && code<=e.start_pc+e.length))){
78           // (code>=e.start_pc && code<e.start_pc+e.length))) {
79
// found the variable, now find its name.
80

81             //G.v().out.println("found entry: " + i);
82

83             if (constant_pool[e.signature_index] instanceof CONSTANT_Utf8_info)
84         {
85            String JavaDoc n = ((CONSTANT_Utf8_info)(constant_pool[e.signature_index])).convert();
86            G.v().out.println("found type: "+n);
87            //if (Util.v().isValidJimpleName(n))
88
//return n;
89
//else
90
//return null;
91
}
92             else {
93                throw new RuntimeException JavaDoc( "What? A local variable type table "
94                        +"signature_index isn't a UTF8 entry?");
95             }
96          }
97       }
98       return null;
99    }
100    
101    public String JavaDoc toString()
102    {
103         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
104         
105         for(int i = 0; i < local_variable_type_table_length; i++)
106         {
107             buffer.append(local_variable_type_table[i].toString() + "\n");
108         }
109         
110         return buffer.toString();
111    }
112 }
113
114
Popular Tags