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: * <tt>ShiftExpr</tt> represents a bit shift operation.
027: */
028: public class ShiftExpr extends Expr {
029: int dir;
030:
031: Expr expr;
032:
033: Expr bits;
034:
035: public static final int LEFT = 0;
036:
037: public static final int RIGHT = 1;
038:
039: public static final int UNSIGNED_RIGHT = 2;
040:
041: /**
042: * Constructor.
043: *
044: * @param dir
045: * The direction (LEFT, RIGHT, or UNSIGNED_RIGHT) in which to
046: * shift.
047: * @param expr
048: * The expression to shift.
049: * @param bits
050: * The number of bits to shift.
051: * @param type
052: * The type of this expression.
053: */
054: public ShiftExpr(final int dir, final Expr expr, final Expr bits,
055: final Type type) {
056: super (type);
057: this .dir = dir;
058: this .expr = expr;
059: this .bits = bits;
060:
061: expr.setParent(this );
062: bits.setParent(this );
063: }
064:
065: public int dir() {
066: return dir;
067: }
068:
069: public Expr expr() {
070: return expr;
071: }
072:
073: public Expr bits() {
074: return bits;
075: }
076:
077: public void visitForceChildren(final TreeVisitor visitor) {
078: if (visitor.reverse()) {
079: bits.visit(visitor);
080: expr.visit(visitor);
081: } else {
082: expr.visit(visitor);
083: bits.visit(visitor);
084: }
085: }
086:
087: public void visit(final TreeVisitor visitor) {
088: visitor.visitShiftExpr(this );
089: }
090:
091: public int exprHashCode() {
092: return 19 + dir ^ expr.exprHashCode() ^ bits.exprHashCode();
093: }
094:
095: public boolean equalsExpr(final Expr other) {
096: return (other != null) && (other instanceof ShiftExpr)
097: && (((ShiftExpr) other).dir == dir)
098: && ((ShiftExpr) other).expr.equalsExpr(expr)
099: && ((ShiftExpr) other).bits.equalsExpr(bits);
100: }
101:
102: public Object clone() {
103: return copyInto(new ShiftExpr(dir, (Expr) expr.clone(),
104: (Expr) bits.clone(), type));
105: }
106: }
|