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: * FieldExpr represents the <i>getfield</i> opcode which fetches a field from
27: * an object.
28: *
29: * @see MemberRef
30: */
31: public class FieldExpr extends MemRefExpr {
32: // getfield
33:
34: Expr object; // The object whose field we are fetching
35:
36: MemberRef field; // The field to fetch
37:
38: /**
39: * Constructor.
40: *
41: * @param object The object (result of an Expr) whose field is to be
42: * fetched.
43: * @param field
44: * The field of object to be fetched.
45: * @param type
46: * The type of this expression.
47: */
48: public FieldExpr(final Expr object, final MemberRef field,
49: final Type type) {
50: super (type);
51: this .object = object;
52: this .field = field;
53:
54: object.setParent(this );
55: }
56:
57: public Expr object() {
58: return object;
59: }
60:
61: public MemberRef field() {
62: return field;
63: }
64:
65: public void visitForceChildren(final TreeVisitor visitor) {
66: if (visitor.reverse()) {
67: object.visit(visitor);
68: } else {
69: object.visit(visitor);
70: }
71: }
72:
73: public void visit(final TreeVisitor visitor) {
74: visitor.visitFieldExpr(this );
75: }
76:
77: public int exprHashCode() {
78: return 11 + object.exprHashCode() ^ type.simple().hashCode();
79: }
80:
81: public boolean equalsExpr(final Expr other) {
82: return (other != null) && (other instanceof FieldExpr)
83: && ((FieldExpr) other).field.equals(field)
84: && ((FieldExpr) other).object.equalsExpr(object);
85: }
86:
87: public Object clone() {
88: return copyInto(new FieldExpr((Expr) object.clone(), field,
89: type));
90: }
91: }
|