View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one or more
3    *  contributor license agreements.  See the NOTICE file distributed with
4    *  this work for additional information regarding copyright ownership.
5    *  The ASF licenses this file to You under the Apache License, Version 2.0
6    *  (the "License"); you may not use this file except in compliance with
7    *  the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  
18  package org.apache.commons.compress.harmony.unpack200.bytecode;
19  
20  import org.apache.commons.compress.harmony.unpack200.Segment;
21  import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
22  
23  /**
24   * 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
25   * references.
26   */
27  public class OperandManager {
28  
29      int[] bcCaseCount;
30      int[] bcCaseValue;
31      int[] bcByte;
32      int[] bcShort;
33      int[] bcLocal;
34      int[] bcLabel;
35      int[] bcIntRef;
36      int[] bcFloatRef;
37      int[] bcLongRef;
38      int[] bcDoubleRef;
39      int[] bcStringRef;
40      int[] bcClassRef;
41      int[] bcFieldRef;
42      int[] bcMethodRef;
43      int[] bcIMethodRef;
44      int[] bcThisField;
45      int[] bcSuperField;
46      int[] bcThisMethod;
47      int[] bcSuperMethod;
48      int[] bcInitRef;
49      int[] wideByteCodes;
50  
51      int bcCaseCountIndex;
52      int bcCaseValueIndex;
53      int bcByteIndex;
54      int bcShortIndex;
55      int bcLocalIndex;
56      int bcLabelIndex;
57      int bcIntRefIndex;
58      int bcFloatRefIndex;
59      int bcLongRefIndex;
60      int bcDoubleRefIndex;
61      int bcStringRefIndex;
62      int bcClassRefIndex;
63      int bcFieldRefIndex;
64      int bcMethodRefIndex;
65      int bcIMethodRefIndex;
66      int bcThisFieldIndex;
67      int bcSuperFieldIndex;
68      int bcThisMethodIndex;
69      int bcSuperMethodIndex;
70      int bcInitRefIndex;
71      int wideByteCodeIndex;
72  
73      Segment segment;
74  
75      String currentClass;
76      String superClass;
77      String newClass;
78  
79      public OperandManager(final int[] bcCaseCount, final int[] bcCaseValue, final int[] bcByte, final int[] bcShort, final int[] bcLocal, final int[] bcLabel,
80              final int[] bcIntRef, final int[] bcFloatRef, final int[] bcLongRef, final int[] bcDoubleRef, final int[] bcStringRef, final int[] bcClassRef,
81              final int[] bcFieldRef, final int[] bcMethodRef, final int[] bcIMethodRef, final int[] bcThisField, final int[] bcSuperField,
82              final int[] bcThisMethod, final int[] bcSuperMethod, final int[] bcInitRef, final int[] wideByteCodes) {
83          this.bcCaseCount = bcCaseCount;
84          this.bcCaseValue = bcCaseValue;
85          this.bcByte = bcByte;
86          this.bcShort = bcShort;
87          this.bcLocal = bcLocal;
88          this.bcLabel = bcLabel;
89          this.bcIntRef = bcIntRef;
90          this.bcFloatRef = bcFloatRef;
91          this.bcLongRef = bcLongRef;
92          this.bcDoubleRef = bcDoubleRef;
93          this.bcStringRef = bcStringRef;
94          this.bcClassRef = bcClassRef;
95          this.bcFieldRef = bcFieldRef;
96          this.bcMethodRef = bcMethodRef;
97          this.bcIMethodRef = bcIMethodRef;
98  
99          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 }