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: * NewMultiArrayExpr represents the <tt>multianewarray</tt> opcode which
027: * creates a new multidimensional array.
028: */
029: public class NewMultiArrayExpr extends Expr {
030: // multianewarray
031:
032: Expr[] dimensions;
033:
034: Type elementType;
035:
036: /**
037: * Constructor.
038: *
039: * @param dimensions
040: * Expressions representing the size of each of the dimensions in
041: * the array.
042: * @param elementType
043: * The type of the elements in the array.
044: * @param type
045: * The type of this expression.
046: */
047: public NewMultiArrayExpr(final Expr[] dimensions,
048: final Type elementType, final Type type) {
049: super (type);
050: this .elementType = elementType;
051: this .dimensions = dimensions;
052:
053: for (int i = 0; i < dimensions.length; i++) {
054: dimensions[i].setParent(this );
055: }
056: }
057:
058: public Expr[] dimensions() {
059: return dimensions;
060: }
061:
062: public Type elementType() {
063: return elementType;
064: }
065:
066: public void visitForceChildren(final TreeVisitor visitor) {
067: if (visitor.reverse()) {
068: for (int i = dimensions.length - 1; i >= 0; i--) {
069: dimensions[i].visit(visitor);
070: }
071: } else {
072: for (int i = 0; i < dimensions.length; i++) {
073: dimensions[i].visit(visitor);
074: }
075: }
076: }
077:
078: public void visit(final TreeVisitor visitor) {
079: visitor.visitNewMultiArrayExpr(this );
080: }
081:
082: public int exprHashCode() {
083: int v = 17;
084:
085: for (int i = 0; i < dimensions.length; i++) {
086: v ^= dimensions[i].hashCode();
087: }
088:
089: return v;
090: }
091:
092: public boolean equalsExpr(final Expr other) {
093: return false;
094: }
095:
096: public Object clone() {
097: final Expr[] d = new Expr[dimensions.length];
098:
099: for (int i = 0; i < dimensions.length; i++) {
100: d[i] = (Expr) dimensions[i].clone();
101: }
102:
103: return copyInto(new NewMultiArrayExpr(d, elementType, type));
104: }
105: }
|