001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.editor;
022:
023: /**
024: * LocalVariable represents a local variable index operand to various
025: * instructions.
026: *
027: * @author Nate Nystrom (<a
028: * href="mailto:nystrom@cs.purdue.edu">nystrom@cs.purdue.edu</a>)
029: */
030: public class LocalVariable {
031: private String name;
032:
033: private Type type;
034:
035: private int index;
036:
037: /**
038: * Constructor.
039: *
040: * @param index
041: * The index of the local variable in the method's local variable
042: * array.
043: */
044: public LocalVariable(final int index) {
045: this .name = null;
046: this .type = null;
047: this .index = index;
048: }
049:
050: /**
051: * Constructor.
052: *
053: * @param name
054: * The name of the local variable.
055: * @param type
056: * The descriptor (or index into the constant pool) representing
057: * the variable type.
058: * @param index
059: * The index of the local variable in the method's local variable
060: * array.
061: */
062: public LocalVariable(final String name, final Type type,
063: final int index) {
064: this .name = name;
065: this .type = type;
066: this .index = index;
067: }
068:
069: /**
070: * Hash the local variable.
071: *
072: * A stricter hashing than using the index will break Hashtable lookups
073: * since a variable could have a name assigned to it after its first use.
074: *
075: * @return The hash code.
076: */
077: public int hashCode() {
078: return index;
079: }
080:
081: /**
082: * Check if an object is equal to this variable.
083: *
084: * A stricter comparison than comparing indices will break Hashtable lookups
085: * since a variable could have a name assigned to it after its first use.
086: *
087: * @param obj
088: * The object to compare against.
089: * @return true if equal, false if not.
090: */
091: public boolean equals(final Object obj) {
092: return (obj != null) && (obj instanceof LocalVariable)
093: && (((LocalVariable) obj).index == index);
094: }
095:
096: /**
097: * Get the name of the local variable.
098: *
099: * @return The name of the local variable.
100: */
101: public String name() {
102: return name;
103: }
104:
105: /**
106: * Get the type of the local variable.
107: *
108: * @return The type of the local variable.
109: */
110: public Type type() {
111: return type;
112: }
113:
114: /**
115: * Get the index into the local variable array.
116: *
117: * @return The index into the local variable array.
118: */
119: public int index() {
120: return index;
121: }
122:
123: /**
124: * Convert the variable to a string.
125: *
126: * @return A string representation of the variable.
127: */
128: public String toString() {
129: if (name == null) {
130: return "Local$" + index;
131: }
132:
133: return name + "$" + index;
134: }
135: }
|