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: * CastExpr represents an expression that casts an object to a given type.
27: */
28: public class CastExpr extends Expr {
29: Expr expr; // An expression (object) to cast
30:
31: Type castType; // The Type to cast expr to
32:
33: /**
34: * Constructor.
35: *
36: * @param expr
37: * Expression (object) to be cast.
38: * @param type
39: * The type to which to cast expr and as well as the type of this
40: * expression.
41: */
42: public CastExpr(final Expr expr, final Type type) {
43: this (expr, type, type);
44: }
45:
46: /**
47: * Constructor.
48: *
49: * @param expr
50: * Expression (object) to be cast.
51: * @param castType
52: * The type to which to cast expr.
53: * @param type
54: * The type of this expression.
55: */
56: public CastExpr(final Expr expr, final Type castType,
57: final Type type) {
58: super (type);
59: this .expr = expr;
60: this .castType = castType;
61:
62: expr.setParent(this );
63: }
64:
65: public Expr expr() {
66: return expr;
67: }
68:
69: public Type castType() {
70: return castType;
71: }
72:
73: public void visitForceChildren(final TreeVisitor visitor) {
74: if (visitor.reverse()) {
75: expr.visit(visitor);
76: } else {
77: expr.visit(visitor);
78: }
79: }
80:
81: public void visit(final TreeVisitor visitor) {
82: visitor.visitCastExpr(this );
83: }
84:
85: public int exprHashCode() {
86: return 7 + expr.exprHashCode();
87: }
88:
89: public boolean equalsExpr(final Expr other) {
90: return (other != null) && (other instanceof CastExpr)
91: && ((CastExpr) other).castType.equals(castType)
92: && ((CastExpr) other).expr.equalsExpr(expr);
93: }
94:
95: public Object clone() {
96: return copyInto(new CastExpr((Expr) expr.clone(), castType,
97: type));
98: }
99: }
|