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: * StoreExpr represents a store of an expression into a memory location.
027: *
028: * @see MemExpr
029: */
030: public class StoreExpr extends Expr implements Assign {
031: MemExpr target;
032:
033: Expr expr;
034:
035: /**
036: * Constructor.
037: *
038: * @param target
039: * The memory location (or local variable, etc.) into which expr
040: * is stored.
041: * @param expr
042: * An expression whose value is to be stored.
043: * @param type
044: * The type of this expression.
045: */
046: public StoreExpr(final MemExpr target, final Expr expr,
047: final Type type) {
048: super (type);
049:
050: this .target = target;
051: this .expr = expr;
052:
053: target.setParent(this );
054: expr.setParent(this );
055: }
056:
057: /**
058: * Returns the <tt>MemExpr</tt> into which the expression is stored.
059: */
060: public DefExpr[] defs() {
061: return new DefExpr[] { target };
062: }
063:
064: /**
065: * Returns the memory location (or local variable) into which the expression
066: * is stored.
067: */
068: public MemExpr target() {
069: return target;
070: }
071:
072: /**
073: * Returns the expression being stored.
074: */
075: public Expr expr() {
076: return expr;
077: }
078:
079: public void visitForceChildren(final TreeVisitor visitor) {
080: if (visitor.reverse()) {
081: target.visitOnly(visitor);
082: expr.visit(visitor);
083: target.visitChildren(visitor);
084: } else {
085: target.visitChildren(visitor);
086: expr.visit(visitor);
087: target.visitOnly(visitor);
088: }
089: }
090:
091: public void visit(final TreeVisitor visitor) {
092: visitor.visitStoreExpr(this );
093: }
094:
095: public int exprHashCode() {
096: return 22 + target.exprHashCode() ^ expr.exprHashCode();
097: }
098:
099: public boolean equalsExpr(final Expr other) {
100: return (other instanceof StoreExpr)
101: && ((StoreExpr) other).target.equalsExpr(target)
102: && ((StoreExpr) other).expr.equalsExpr(expr);
103: }
104:
105: public Object clone() {
106: return copyInto(new StoreExpr((MemExpr) target.clone(),
107: (Expr) expr.clone(), type));
108: }
109: }
|