001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.flow.java;
018:
019: import java.util.EmptyStackException;
020:
021: /**
022: * Stack to store the frame information along the invocation trace.
023: *
024: * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
025: * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
026: * @version CVS $Id: ContinuationStack.java 433543 2006-08-22 06:22:54Z crossley $
027: */
028: public class ContinuationStack implements java.io.Serializable {
029:
030: private int[] istack;
031: private float[] fstack;
032: private double[] dstack;
033: private long[] lstack;
034: private Object[] astack;
035: private Object[] tstack;
036: private int iTop, fTop, dTop, lTop, aTop, tTop;
037:
038: public ContinuationStack() {
039: istack = new int[10];
040: lstack = new long[5];
041: dstack = new double[5];
042: fstack = new float[5];
043: astack = new Object[10];
044: tstack = new Object[5];
045: }
046:
047: public ContinuationStack(ContinuationStack parent) {
048: istack = new int[parent.istack.length];
049: lstack = new long[parent.lstack.length];
050: dstack = new double[parent.dstack.length];
051: fstack = new float[parent.fstack.length];
052: astack = new Object[parent.astack.length];
053: tstack = new Object[parent.tstack.length];
054: System.arraycopy(parent.istack, 0, istack, 0,
055: parent.istack.length);
056: System.arraycopy(parent.lstack, 0, lstack, 0,
057: parent.lstack.length);
058: System.arraycopy(parent.dstack, 0, dstack, 0,
059: parent.dstack.length);
060: System.arraycopy(parent.fstack, 0, fstack, 0,
061: parent.fstack.length);
062: System.arraycopy(parent.astack, 0, astack, 0,
063: parent.astack.length);
064: System.arraycopy(parent.tstack, 0, tstack, 0,
065: parent.tstack.length);
066: iTop = parent.iTop;
067: fTop = parent.fTop;
068: dTop = parent.dTop;
069: lTop = parent.lTop;
070: aTop = parent.aTop;
071: tTop = parent.tTop;
072: }
073:
074: public double popDouble() {
075: if (dTop == 0)
076: throw new EmptyStackException();
077: double d = dstack[--dTop];
078: //System.out.println("pop double "+d+" "+toString());
079: return d;
080: }
081:
082: public float popFloat() {
083: if (fTop == 0)
084: throw new EmptyStackException();
085: float f = fstack[--fTop];
086: //System.out.println("pop float "+f+" "+toString());
087: return f;
088: }
089:
090: public int popInt() {
091: if (iTop == 0)
092: throw new EmptyStackException();
093: int i = istack[--iTop];
094: //System.out.println("pop int "+i+" "+toString());
095: return i;
096: }
097:
098: public long popLong() {
099: if (lTop == 0)
100: throw new EmptyStackException();
101: long l = lstack[--lTop];
102: //System.out.println("pop long "+l+" "+toString());
103: return l;
104: }
105:
106: public Object popObject() {
107: if (aTop == 0)
108: throw new EmptyStackException();
109: Object o = astack[--aTop];
110: //System.out.println("pop object "+o+" "+toString());
111: return o;
112: }
113:
114: public Object popReference() {
115: if (tTop == 0)
116: throw new EmptyStackException();
117: Object o = tstack[--tTop];
118: //System.out.println("pop reference "+o+" "+toString());
119: return o;
120: }
121:
122: public void pushDouble(double d) {
123: dstack[dTop++] = d;
124: //System.out.println("push double "+d+" "+toString());
125: if (dTop == dstack.length) {
126: double[] hlp = new double[dstack.length + 10];
127: System.arraycopy(dstack, 0, hlp, 0, dstack.length);
128: dstack = hlp;
129: }
130: }
131:
132: public void pushFloat(float f) {
133: fstack[fTop++] = f;
134: //System.out.println("push float "+f+" "+toString());
135: if (fTop == fstack.length) {
136: float[] hlp = new float[fstack.length + 10];
137: System.arraycopy(fstack, 0, hlp, 0, fstack.length);
138: fstack = hlp;
139: }
140: }
141:
142: public void pushInt(int i) {
143: istack[iTop++] = i;
144: //System.out.println("push int "+i+" "+toString());
145: if (iTop == istack.length) {
146: int[] hlp = new int[istack.length + 10];
147: System.arraycopy(istack, 0, hlp, 0, istack.length);
148: istack = hlp;
149: }
150: }
151:
152: public void pushLong(long l) {
153: lstack[lTop++] = l;
154: //System.out.println("push long "+l+" "+toString());
155: if (lTop == lstack.length) {
156: long[] hlp = new long[lstack.length + 10];
157: System.arraycopy(lstack, 0, hlp, 0, lstack.length);
158: lstack = hlp;
159: }
160: }
161:
162: public void pushObject(Object o) {
163: astack[aTop++] = o;
164: //System.out.println("push object "+o+" "+toString());
165: if (aTop == astack.length) {
166: Object[] hlp = new Object[astack.length + 10];
167: System.arraycopy(astack, 0, hlp, 0, astack.length);
168: astack = hlp;
169: }
170: }
171:
172: public void pushReference(Object o) {
173: tstack[tTop++] = o;
174: //System.out.println("push reference "+o+" "+toString());
175: if (tTop == tstack.length) {
176: Object[] hlp = new Object[tstack.length + 10];
177: System.arraycopy(tstack, 0, hlp, 0, tstack.length);
178: tstack = hlp;
179: }
180: }
181:
182: public String toString() {
183: return "i=" + iTop + ",l=" + lTop + ",d=" + dTop + ",f=" + fTop
184: + ",a=" + aTop + ",t=" + tTop;
185: }
186: }
|