1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.verifier.statics;
18
19
20 import org.apache.bcel.generic.Type;
21 import org.apache.bcel.verifier.exc.AssertionViolatedException;
22 import org.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException;
23
24 /***
25 * A utility class holding the information about
26 * the names and the types of the local variables in
27 * a given method.
28 *
29 * @version $Id: LocalVariablesInfo.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author Enver Haase
31 */
32 public class LocalVariablesInfo{
33
34 /*** The information about the local variables is stored here. */
35 private LocalVariableInfo[] localVariableInfos;
36
37 /*** The constructor. */
38 LocalVariablesInfo(int max_locals){
39 localVariableInfos = new LocalVariableInfo[max_locals];
40 for (int i=0; i<max_locals; i++){
41 localVariableInfos[i] = new LocalVariableInfo();
42 }
43 }
44
45 /*** Returns the LocalVariableInfo for the given slot. */
46 public LocalVariableInfo getLocalVariableInfo(int slot){
47 if (slot < 0 || slot >= localVariableInfos.length){
48 throw new AssertionViolatedException("Slot number for local variable information out of range.");
49 }
50 return localVariableInfos[slot];
51 }
52
53 /***
54 * Adds information about the local variable in slot 'slot'. Automatically
55 * adds information for slot+1 if 't' is Type.LONG or Type.DOUBLE.
56 * @throws LocalVariableInfoInconsistentException if the new information conflicts
57 * with already gathered information.
58 */
59 public void add(int slot, String name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{
60
61
62 if (slot < 0 || slot >= localVariableInfos.length){
63 throw new AssertionViolatedException("Slot number for local variable information out of range.");
64 }
65
66 localVariableInfos[slot].add(name, startpc, length, t);
67 if (t == Type.LONG) {
68 localVariableInfos[slot+1].add(name, startpc, length, LONG_Upper.theInstance());
69 }
70 if (t == Type.DOUBLE) {
71 localVariableInfos[slot+1].add(name, startpc, length, DOUBLE_Upper.theInstance());
72 }
73 }
74 }