001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba.vna;
021:
022: /**
023: * A "value number" is a value produced somewhere in a methods.
024: * We use value numbers as dataflow values in Frames. When two frame
025: * slots have the same value number, then the same value is in both
026: * of those slots.
027: * <p/>
028: * <p> Instances of ValueNumbers produced by the same
029: * {@link ValueNumberFactory ValueNumberFactory} are unique, so reference equality may
030: * be used to determine whether or not two value numbers are the same.
031: * In general, ValueNumbers from different factories cannot be compared.
032: *
033: * @author David Hovemeyer
034: * @see ValueNumberAnalysis
035: */
036: public class ValueNumber implements Comparable<ValueNumber> {
037: /**
038: * The value number.
039: */
040: int number;
041:
042: /**
043: * Flags representing meta information about the value.
044: */
045: int flags;
046:
047: /**
048: * Flag specifying that this value was the return value
049: * of a called method.
050: */
051: public static final int RETURN_VALUE = 1;
052:
053: public static final int ARRAY_VALUE = 2;
054:
055: public static final int CONSTANT_CLASS_OBJECT = 4;
056:
057: public static final int PHI_NODE = 8;
058:
059: /**
060: * Constructor.
061: *
062: * @param number the value number
063: */
064: ValueNumber(int number) {
065: this .number = number;
066: this .flags = 0;
067: }
068:
069: public int getNumber() {
070: return number;
071: }
072:
073: public int getFlags() {
074: return flags;
075: }
076:
077: public void setFlags(int flags) {
078: this .flags = flags;
079: }
080:
081: public void setFlag(int flag) {
082: flags |= flag;
083: }
084:
085: public boolean hasFlag(int flag) {
086: return (flags & flag) == flag;
087: }
088:
089: @Override
090: public String toString() {
091: if (flags != 0)
092: return number + "(" + flags + "),";
093: return number + ",";
094: }
095:
096: @Override
097: public int hashCode() {
098: return number;
099: }
100:
101: @Override
102: public boolean equals(Object o) {
103: if (o instanceof ValueNumber)
104: return number == ((ValueNumber) o).number;
105: return false;
106: }
107:
108: public int compareTo(ValueNumber other) {
109: return number - other.number;
110: }
111: /*
112:
113: public int hashCode() {
114: return number;
115: }
116:
117:
118: public boolean equals(Object obj) {
119: if (obj == null || obj.getClass() != this.getClass())
120: return false;
121: ValueNumber other = (ValueNumber) obj;
122: return this.number == other.number;
123: }
124: */
125: }
126:
127: // vim:ts=4
|