01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package EDU.purdue.cs.bloat.tree;
22:
23: import EDU.purdue.cs.bloat.editor.*;
24:
25: /**
26: * ArrayRefExpr represents an expression that references an element in an array.
27: */
28: public class ArrayRefExpr extends MemRefExpr {
29: Expr array;
30:
31: Expr index;
32:
33: Type elementType;
34:
35: /**
36: * Constructor.
37: *
38: * @param array
39: * The array whose element we are indexing.
40: * @param index
41: * The index into the array.
42: * @param elementType
43: * The type of elements in array.
44: * @param type
45: * The type of this expression.
46: */
47: public ArrayRefExpr(final Expr array, final Expr index,
48: final Type elementType, final Type type) {
49: super (type);
50: this .array = array;
51: this .index = index;
52: this .elementType = elementType;
53:
54: array.setParent(this );
55: index.setParent(this );
56: }
57:
58: public Expr array() {
59: return array;
60: }
61:
62: public Expr index() {
63: return index;
64: }
65:
66: public Type elementType() {
67: return elementType;
68: }
69:
70: public void visitForceChildren(final TreeVisitor visitor) {
71: if (visitor.reverse()) {
72: index.visit(visitor);
73: array.visit(visitor);
74: } else {
75: array.visit(visitor);
76: index.visit(visitor);
77: }
78: }
79:
80: public void visit(final TreeVisitor visitor) {
81: visitor.visitArrayRefExpr(this );
82: }
83:
84: public int exprHashCode() {
85: return 4 + array.exprHashCode() ^ index.exprHashCode();
86: }
87:
88: public boolean equalsExpr(final Expr other) {
89: return (other != null) && (other instanceof ArrayRefExpr)
90: && ((ArrayRefExpr) other).array.equalsExpr(array)
91: && ((ArrayRefExpr) other).index.equalsExpr(index);
92: }
93:
94: public Object clone() {
95: return copyInto(new ArrayRefExpr((Expr) array.clone(),
96: (Expr) index.clone(), elementType, type));
97: }
98: }
|