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.tree;
022:
023: import EDU.purdue.cs.bloat.editor.*;
024:
025: /**
026: * ConstantExpr represents a constant expression. It is used when opcodes <i>ldc</i>,
027: * <i>iinc</i>, and <i>getstatic</i> are visited. It value must be an Integer,
028: * Long, Float, Double, or String.
029: */
030: public class ConstantExpr extends Expr implements LeafExpr {
031: // ldc
032:
033: Object value; // The operand to the ldc instruction
034:
035: /**
036: * Constructor.
037: *
038: * @param value
039: * The operand of the ldc instruction
040: * @param type
041: * The Type of the operand
042: */
043: public ConstantExpr(final Object value, final Type type) {
044: super (type);
045: this .value = value;
046: }
047:
048: /**
049: * @return The operand of the ldc instruction
050: */
051: public Object value() {
052: return value;
053: }
054:
055: public void visitForceChildren(final TreeVisitor visitor) {
056: }
057:
058: public void visit(final TreeVisitor visitor) {
059: visitor.visitConstantExpr(this );
060: }
061:
062: /**
063: * @return A hash code for this expression.
064: */
065: public int exprHashCode() {
066: if (value != null) {
067: return 10 + value.hashCode();
068: }
069:
070: return 10;
071: }
072:
073: /**
074: * Compare this ConstantExpr to another Expr.
075: *
076: * @param other
077: * An Expr to compare this to.
078: *
079: * @return True, if this and other are the same (that is, have the same
080: * contents).
081: */
082: public boolean equalsExpr(final Expr other) {
083: if (!(other instanceof ConstantExpr)) {
084: return false;
085: }
086:
087: if (value == null) {
088: return ((ConstantExpr) other).value == null;
089: }
090:
091: if (((ConstantExpr) other).value == null) {
092: return false;
093: }
094:
095: return ((ConstantExpr) other).value.equals(value);
096: }
097:
098: public Object clone() {
099: return copyInto(new ConstantExpr(value, type));
100: }
101: }
|