KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bcel > verifier > statics > LocalVariablesInfo


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 JavaDoc name, int startpc, int length, Type t) throws LocalVariableInfoInconsistentException{
60         // The add operation on LocalVariableInfo may throw the '...Inconsistent...' exception, we don't throw it explicitely here.
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 }
75
Popular Tags