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: /**
024: * StackManipStmt represents the opcodes that manipulate the stack such as
025: * <tt>swap</tt> and <tt>dup</tt>.
026: */
027: public class StackManipStmt extends Stmt implements Assign {
028: StackExpr[] target;
029:
030: StackExpr[] source;
031:
032: int kind;
033:
034: // 0 1 -> 1 0
035: public static final int SWAP = 0;
036:
037: // 0 -> 0 0
038: public static final int DUP = 1;
039:
040: // 0 1 -> 1 0 1
041: public static final int DUP_X1 = 2;
042:
043: // 0 1 2 -> 2 0 1 2
044: public static final int DUP_X2 = 3;
045:
046: // 0 1 -> 0 1 0 1
047: public static final int DUP2 = 4;
048:
049: // 0 1 2 -> 1 2 0 1 2
050: public static final int DUP2_X1 = 5;
051:
052: // 0 1 2 3 -> 2 3 0 1 2 3
053: public static final int DUP2_X2 = 6;
054:
055: /**
056: * Constructor.
057: *
058: * @param target
059: * The new contents of the stack
060: * @param source
061: * The old contents of the stack
062: * @param kind
063: * The kind of stack manipulation (SWAP, DUP, etc.) to take
064: * place.
065: */
066: public StackManipStmt(final StackExpr[] target,
067: final StackExpr[] source, final int kind) {
068: this .kind = kind;
069:
070: this .target = target;
071:
072: for (int i = 0; i < target.length; i++) {
073: this .target[i].setParent(this );
074: }
075:
076: this .source = source;
077:
078: for (int i = 0; i < source.length; i++) {
079: this .source[i].setParent(this );
080: }
081: }
082:
083: public DefExpr[] defs() {
084: return target;
085: }
086:
087: public StackExpr[] target() {
088: return target;
089: }
090:
091: public StackExpr[] source() {
092: return source;
093: }
094:
095: public int kind() {
096: return kind;
097: }
098:
099: public void visit(final TreeVisitor visitor) {
100: visitor.visitStackManipStmt(this );
101: }
102:
103: public void visitForceChildren(final TreeVisitor visitor) {
104: if (visitor.reverse()) {
105: for (int i = target.length - 1; i >= 0; i--) {
106: target[i].visit(visitor);
107: }
108:
109: for (int i = source.length - 1; i >= 0; i--) {
110: source[i].visit(visitor);
111: }
112: } else {
113: for (int i = 0; i < source.length; i++) {
114: source[i].visit(visitor);
115: }
116:
117: for (int i = 0; i < target.length; i++) {
118: target[i].visit(visitor);
119: }
120: }
121: }
122:
123: public Object clone() {
124: final StackExpr[] t = new StackExpr[target.length];
125:
126: for (int i = 0; i < target.length; i++) {
127: t[i] = (StackExpr) target[i].clone();
128: }
129:
130: final StackExpr[] s = new StackExpr[source.length];
131:
132: for (int i = 0; i < source.length; i++) {
133: s[i] = (StackExpr) source[i].clone();
134: }
135:
136: return copyInto(new StackManipStmt(t, s, kind));
137: }
138: }
|