KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > vna > ValueNumber


1 /*
2  * Bytecode Analysis Framework
3  * Copyright (C) 2003,2004 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.vna;
21
22
23
24 /**
25  * A "value number" is a value produced somewhere in a methods.
26  * We use value numbers as dataflow values in Frames. When two frame
27  * slots have the same value number, then the same value is in both
28  * of those slots.
29  * <p/>
30  * <p> Instances of ValueNumbers produced by the same
31  * {@link ValueNumberFactory ValueNumberFactory} are unique, so reference equality may
32  * be used to determine whether or not two value numbers are the same.
33  * In general, ValueNumbers from different factories cannot be compared.
34  *
35  * @author David Hovemeyer
36  * @see ValueNumberAnalysis
37  */

38 public class ValueNumber implements Comparable JavaDoc<ValueNumber> {
39     /**
40      * The value number.
41      */

42     int number;
43
44     /**
45      * Flags representing meta information about the value.
46      */

47     int flags;
48
49     /**
50      * Flag specifying that this value was the return value
51      * of a called method.
52      */

53     public static final int RETURN_VALUE = 1;
54     
55     public static final int ARRAY_VALUE = 2;
56     
57     public static final int CONSTANT_CLASS_OBJECT = 4;
58     
59     public static final int PHI_NODE = 8;
60
61     /**
62      * Constructor.
63      *
64      * @param number the value number
65      */

66     ValueNumber(int number) {
67         this.number = number;
68         this.flags = 0;
69     }
70
71     public int getNumber() {
72         return number;
73     }
74
75     public int getFlags() {
76         return flags;
77     }
78
79     public void setFlags(int flags) {
80         this.flags = flags;
81     }
82
83     public void setFlag(int flag) {
84         flags |= flag;
85     }
86
87     public boolean hasFlag(int flag) {
88         return (flags & flag) == flag;
89     }
90
91     @Override JavaDoc
92          public String JavaDoc toString() {
93         if (flags != 0) return number+"("+flags+"),";
94         return number + ",";
95     }
96
97     public int hashCode() {
98         return number;
99     }
100     public boolean equals(Object JavaDoc o) {
101         if (o instanceof ValueNumber)
102             return number == ((ValueNumber)o).number;
103         return false;
104     }
105     public int compareTo(ValueNumber other) {
106         return number - other.number;
107     }
108 /*
109     //@Override
110     public int hashCode() {
111         return number;
112     }
113     
114     //@Override
115     public boolean equals(Object obj) {
116         if (obj == null || obj.getClass() != this.getClass())
117             return false;
118         ValueNumber other = (ValueNumber) obj;
119         return this.number == other.number;
120     }
121 */

122 }
123
124 // vim:ts=4
125
Popular Tags