KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > type > TypeFrame


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

19
20 package edu.umd.cs.findbugs.ba.type;
21
22 import static edu.umd.cs.findbugs.ba.Debug.VERIFY_INTEGRITY;
23
24 import java.util.BitSet JavaDoc;
25
26 import org.apache.bcel.generic.Type;
27
28 import edu.umd.cs.findbugs.ba.DataflowAnalysisException;
29 import edu.umd.cs.findbugs.ba.Frame;
30 import edu.umd.cs.findbugs.ba.vna.ValueNumber;
31
32 /**
33  * A specialization of {@link Frame} for determining the types
34  * of values in the Java stack frame (locals and operand stack).
35  *
36  * @author David Hovemeyer
37  * @see Frame
38  * @see TypeAnalysis
39  */

40 public class TypeFrame extends Frame<Type> {
41     private BitSet JavaDoc exactTypeSet;
42     
43     /**
44      * Constructor.
45      */

46     public TypeFrame(int numLocals) {
47         super(numLocals);
48         this.exactTypeSet = new BitSet JavaDoc();
49     }
50
51     /**
52      * Set whether or not a type in a given slot is exact.
53      *
54      * @param slot the slot
55      * @param isExact true if the slot contains an exact type, false if just an upper bound
56      */

57     public void setExact(int slot, boolean isExact) {
58         exactTypeSet.set(slot, isExact);
59     }
60
61     /**
62      * Get whether or not a type in a given slot is exact.
63      *
64      * @param slot the slot
65      * @return true if the slot contains an exact type, false if just an upper bound
66      */

67     public boolean isExact(int slot) {
68         return exactTypeSet.get(slot);
69     }
70     
71     /**
72      * Clear the exact type set.
73      * The result is that all slots will be assumed <em>not</em> to
74      * contain an exact type.
75      */

76     public void clearExactSet() {
77         exactTypeSet.clear();
78     }
79     
80     @Override JavaDoc
81     public void setTop() {
82         super.setTop();
83         clearExactSet();
84     }
85     
86     @Override JavaDoc
87     public void copyFrom(Frame<Type> other_) {
88         clearExactSet();
89         
90         TypeFrame other = (TypeFrame) other_;
91         
92         this.exactTypeSet.or(other.exactTypeSet);
93         
94         super.copyFrom(other_);
95     }
96
97     @Override JavaDoc
98     protected String JavaDoc valueToString(Type value) {
99         return value.toString() + ",";
100     }
101
102     /**
103      * Get the single instance of the "Top" type.
104      */

105     public static Type getTopType() {
106         return TopType.instance();
107     }
108
109     /**
110      * Get the single instance of the "Bottom" type.
111      */

112     public static Type getBottomType() {
113         return BottomType.instance();
114     }
115
116     /**
117      * Get the single instance of the "LongExtra" type.
118      */

119     public static Type getLongExtraType() {
120         return LongExtraType.instance();
121     }
122
123     /**
124      * Get the single instance of the "DoubleExtra" type.
125      */

126     public static Type getDoubleExtraType() {
127         return DoubleExtraType.instance();
128     }
129
130     /**
131      * Get the single instance of the "Null" type.
132      */

133     public static Type getNullType() {
134         return NullType.instance();
135     }
136
137     @Override JavaDoc
138     public void pushValue(Type value) {
139
140         super.pushValue(value);
141
142         try {
143             exactTypeSet.clear(getStackLocation(0));
144         } catch (DataflowAnalysisException e) {
145             assert false;
146         }
147
148     }
149
150     /**
151      * Pop a value off of the Java operand stack.
152      *
153      * @return the value that was popped
154      * @throws DataflowAnalysisException
155      * if the Java operand stack is empty
156      */

157     @Override JavaDoc
158     public Type popValue() throws DataflowAnalysisException {
159
160         exactTypeSet.clear(getStackLocation(0));
161         return super.popValue();
162     }
163
164     
165     
166
167 }
168
169 // vim:ts=4
170
Popular Tags