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
018package org.apache.commons.compress.harmony.unpack200.bytecode;
019
020import org.apache.commons.compress.harmony.unpack200.Segment;
021import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
022
023/**
024 * Tracks operands, provides methods to let other classes get next elements, and also knows about which classes have been used recently in super, this and new
025 * references.
026 */
027public class OperandManager {
028
029    int[] bcCaseCount;
030    int[] bcCaseValue;
031    int[] bcByte;
032    int[] bcShort;
033    int[] bcLocal;
034    int[] bcLabel;
035    int[] bcIntRef;
036    int[] bcFloatRef;
037    int[] bcLongRef;
038    int[] bcDoubleRef;
039    int[] bcStringRef;
040    int[] bcClassRef;
041    int[] bcFieldRef;
042    int[] bcMethodRef;
043    int[] bcIMethodRef;
044    int[] bcThisField;
045    int[] bcSuperField;
046    int[] bcThisMethod;
047    int[] bcSuperMethod;
048    int[] bcInitRef;
049    int[] wideByteCodes;
050
051    int bcCaseCountIndex;
052    int bcCaseValueIndex;
053    int bcByteIndex;
054    int bcShortIndex;
055    int bcLocalIndex;
056    int bcLabelIndex;
057    int bcIntRefIndex;
058    int bcFloatRefIndex;
059    int bcLongRefIndex;
060    int bcDoubleRefIndex;
061    int bcStringRefIndex;
062    int bcClassRefIndex;
063    int bcFieldRefIndex;
064    int bcMethodRefIndex;
065    int bcIMethodRefIndex;
066    int bcThisFieldIndex;
067    int bcSuperFieldIndex;
068    int bcThisMethodIndex;
069    int bcSuperMethodIndex;
070    int bcInitRefIndex;
071    int wideByteCodeIndex;
072
073    Segment segment;
074
075    String currentClass;
076    String superClass;
077    String newClass;
078
079    public OperandManager(final int[] bcCaseCount, final int[] bcCaseValue, final int[] bcByte, final int[] bcShort, final int[] bcLocal, final int[] bcLabel,
080            final int[] bcIntRef, final int[] bcFloatRef, final int[] bcLongRef, final int[] bcDoubleRef, final int[] bcStringRef, final int[] bcClassRef,
081            final int[] bcFieldRef, final int[] bcMethodRef, final int[] bcIMethodRef, final int[] bcThisField, final int[] bcSuperField,
082            final int[] bcThisMethod, final int[] bcSuperMethod, final int[] bcInitRef, final int[] wideByteCodes) {
083        this.bcCaseCount = bcCaseCount;
084        this.bcCaseValue = bcCaseValue;
085        this.bcByte = bcByte;
086        this.bcShort = bcShort;
087        this.bcLocal = bcLocal;
088        this.bcLabel = bcLabel;
089        this.bcIntRef = bcIntRef;
090        this.bcFloatRef = bcFloatRef;
091        this.bcLongRef = bcLongRef;
092        this.bcDoubleRef = bcDoubleRef;
093        this.bcStringRef = bcStringRef;
094        this.bcClassRef = bcClassRef;
095        this.bcFieldRef = bcFieldRef;
096        this.bcMethodRef = bcMethodRef;
097        this.bcIMethodRef = bcIMethodRef;
098
099        this.bcThisField = bcThisField;
100        this.bcSuperField = bcSuperField;
101        this.bcThisMethod = bcThisMethod;
102        this.bcSuperMethod = bcSuperMethod;
103        this.bcInitRef = bcInitRef;
104        this.wideByteCodes = wideByteCodes;
105    }
106
107    public String getCurrentClass() {
108        if (null == currentClass) {
109            throw new Error("Current class not set yet");
110        }
111        return currentClass;
112    }
113
114    public String getNewClass() {
115        if (null == newClass) {
116            throw new Error("New class not set yet");
117        }
118        return newClass;
119    }
120
121    public String getSuperClass() {
122        if (null == superClass) {
123            throw new Error("SuperClass not set yet");
124        }
125        return superClass;
126    }
127
128    public SegmentConstantPool globalConstantPool() {
129        return segment.getConstantPool();
130    }
131
132    public int nextByte() {
133        return bcByte[bcByteIndex++];
134    }
135
136    public int nextCaseCount() {
137        return bcCaseCount[bcCaseCountIndex++];
138    }
139
140    public int nextCaseValues() {
141        return bcCaseValue[bcCaseValueIndex++];
142    }
143
144    public int nextClassRef() {
145        return bcClassRef[bcClassRefIndex++];
146    }
147
148    public int nextDoubleRef() {
149        return bcDoubleRef[bcDoubleRefIndex++];
150    }
151
152    public int nextFieldRef() {
153        return bcFieldRef[bcFieldRefIndex++];
154    }
155
156    public int nextFloatRef() {
157        return bcFloatRef[bcFloatRefIndex++];
158    }
159
160    public int nextIMethodRef() {
161        return bcIMethodRef[bcIMethodRefIndex++];
162    }
163
164    public int nextInitRef() {
165        return bcInitRef[bcInitRefIndex++];
166    }
167
168    public int nextIntRef() {
169        return bcIntRef[bcIntRefIndex++];
170    }
171
172    public int nextLabel() {
173        return bcLabel[bcLabelIndex++];
174    }
175
176    public int nextLocal() {
177        return bcLocal[bcLocalIndex++];
178    }
179
180    public int nextLongRef() {
181        return bcLongRef[bcLongRefIndex++];
182    }
183
184    public int nextMethodRef() {
185        return bcMethodRef[bcMethodRefIndex++];
186    }
187
188    public int nextShort() {
189        return bcShort[bcShortIndex++];
190    }
191
192    public int nextStringRef() {
193        return bcStringRef[bcStringRefIndex++];
194    }
195
196    public int nextSuperFieldRef() {
197        return bcSuperField[bcSuperFieldIndex++];
198    }
199
200    public int nextSuperMethodRef() {
201        return bcSuperMethod[bcSuperMethodIndex++];
202    }
203
204    public int nextThisFieldRef() {
205        return bcThisField[bcThisFieldIndex++];
206    }
207
208    public int nextThisMethodRef() {
209        return bcThisMethod[bcThisMethodIndex++];
210    }
211
212    public int nextWideByteCode() {
213        return wideByteCodes[wideByteCodeIndex++];
214    }
215
216    public void setCurrentClass(final String string) {
217        currentClass = string;
218    }
219
220    public void setNewClass(final String string) {
221        newClass = string;
222    }
223
224    public void setSegment(final Segment segment) {
225        this.segment = segment;
226    }
227
228    public void setSuperClass(final String string) {
229        superClass = string;
230    }
231}