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: * CallMethodExpr represents the invocation of an object's method. In addition
027: * to knowing what method is being called and its parameters, it also knows what
028: * "kind" of method call it is (<tt>VIRTUAL</tt>, <tt>NONVIRTUAL</tt>, or
029: * <tt>INTERFACE</tt>) and the object that is the reciever of this method
030: * call.
031: *
032: * @see CallStaticExpr
033: */
034: public class CallMethodExpr extends CallExpr {
035: // Different kinds of methods to call...
036: public static final int VIRTUAL = 0; // invokevirtual
037:
038: public static final int NONVIRTUAL = 1; // invokespecial
039:
040: public static final int INTERFACE = 2; // invokeinterface
041:
042: Expr receiver;
043:
044: int kind;
045:
046: /**
047: * Constructor.
048: *
049: * @param kind
050: * The kind (VIRTUAL, NONVIRTUAL, or INTERFACE) of method that is
051: * being called.
052: * @param receiver
053: * The expression (object) whose method is being called.
054: * @param params
055: * Parameters to the method.
056: * @param method
057: * The method being called.
058: * @param type
059: * The type of this expression.
060: */
061: public CallMethodExpr(final int kind, final Expr receiver,
062: final Expr[] params, final MemberRef method, final Type type) {
063: super (params, method, type);
064: this .receiver = receiver;
065: this .kind = kind;
066:
067: receiver.setParent(this );
068: }
069:
070: public int kind() {
071: return kind;
072: }
073:
074: public Expr receiver() {
075: return receiver;
076: }
077:
078: public void visitForceChildren(final TreeVisitor visitor) {
079: if (visitor.reverse()) {
080: for (int i = params.length - 1; i >= 0; i--) {
081: params[i].visit(visitor);
082: }
083:
084: receiver.visit(visitor);
085: } else {
086: receiver.visit(visitor);
087:
088: for (int i = 0; i < params.length; i++) {
089: params[i].visit(visitor);
090: }
091: }
092: }
093:
094: public void visit(final TreeVisitor visitor) {
095: visitor.visitCallMethodExpr(this );
096: }
097:
098: public int exprHashCode() {
099: int v = 5 + kind ^ receiver.exprHashCode();
100:
101: for (int i = 0; i < params.length; i++) {
102: v ^= params[i].exprHashCode();
103: }
104:
105: return v;
106: }
107:
108: public boolean equalsExpr(final Expr other) {
109: return false;
110: }
111:
112: public Object clone() {
113: final Expr[] p = new Expr[params.length];
114:
115: for (int i = 0; i < params.length; i++) {
116: p[i] = (Expr) params[i].clone();
117: }
118:
119: return copyInto(new CallMethodExpr(kind, (Expr) receiver
120: .clone(), p, method, type));
121: }
122: }
|