View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.commons.compress.harmony.unpack200.bytecode;
21  
22  import org.apache.commons.compress.harmony.unpack200.Segment;
23  import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
24  
25  /**
26   * 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
27   * references.
28   */
29  public class OperandManager {
30  
31      int[] bcCaseCount;
32      int[] bcCaseValue;
33      int[] bcByte;
34      int[] bcShort;
35      int[] bcLocal;
36      int[] bcLabel;
37      int[] bcIntRef;
38      int[] bcFloatRef;
39      int[] bcLongRef;
40      int[] bcDoubleRef;
41      int[] bcStringRef;
42      int[] bcClassRef;
43      int[] bcFieldRef;
44      int[] bcMethodRef;
45      int[] bcIMethodRef;
46      int[] bcThisField;
47      int[] bcSuperField;
48      int[] bcThisMethod;
49      int[] bcSuperMethod;
50      int[] bcInitRef;
51      int[] wideByteCodes;
52  
53      int bcCaseCountIndex;
54      int bcCaseValueIndex;
55      int bcByteIndex;
56      int bcShortIndex;
57      int bcLocalIndex;
58      int bcLabelIndex;
59      int bcIntRefIndex;
60      int bcFloatRefIndex;
61      int bcLongRefIndex;
62      int bcDoubleRefIndex;
63      int bcStringRefIndex;
64      int bcClassRefIndex;
65      int bcFieldRefIndex;
66      int bcMethodRefIndex;
67      int bcIMethodRefIndex;
68      int bcThisFieldIndex;
69      int bcSuperFieldIndex;
70      int bcThisMethodIndex;
71      int bcSuperMethodIndex;
72      int bcInitRefIndex;
73      int wideByteCodeIndex;
74  
75      Segment segment;
76  
77      String currentClass;
78      String superClass;
79      String newClass;
80  
81      public OperandManager(final int[] bcCaseCount, final int[] bcCaseValue, final int[] bcByte, final int[] bcShort, final int[] bcLocal, final int[] bcLabel,
82              final int[] bcIntRef, final int[] bcFloatRef, final int[] bcLongRef, final int[] bcDoubleRef, final int[] bcStringRef, final int[] bcClassRef,
83              final int[] bcFieldRef, final int[] bcMethodRef, final int[] bcIMethodRef, final int[] bcThisField, final int[] bcSuperField,
84              final int[] bcThisMethod, final int[] bcSuperMethod, final int[] bcInitRef, final int[] wideByteCodes) {
85          this.bcCaseCount = bcCaseCount;
86          this.bcCaseValue = bcCaseValue;
87          this.bcByte = bcByte;
88          this.bcShort = bcShort;
89          this.bcLocal = bcLocal;
90          this.bcLabel = bcLabel;
91          this.bcIntRef = bcIntRef;
92          this.bcFloatRef = bcFloatRef;
93          this.bcLongRef = bcLongRef;
94          this.bcDoubleRef = bcDoubleRef;
95          this.bcStringRef = bcStringRef;
96          this.bcClassRef = bcClassRef;
97          this.bcFieldRef = bcFieldRef;
98          this.bcMethodRef = bcMethodRef;
99          this.bcIMethodRef = bcIMethodRef;
100 
101         this.bcThisField = bcThisField;
102         this.bcSuperField = bcSuperField;
103         this.bcThisMethod = bcThisMethod;
104         this.bcSuperMethod = bcSuperMethod;
105         this.bcInitRef = bcInitRef;
106         this.wideByteCodes = wideByteCodes;
107     }
108 
109     public String getCurrentClass() {
110         if (null == currentClass) {
111             throw new Error("Current class not set yet");
112         }
113         return currentClass;
114     }
115 
116     public String getNewClass() {
117         if (null == newClass) {
118             throw new Error("New class not set yet");
119         }
120         return newClass;
121     }
122 
123     public String getSuperClass() {
124         if (null == superClass) {
125             throw new Error("SuperClass not set yet");
126         }
127         return superClass;
128     }
129 
130     public SegmentConstantPool globalConstantPool() {
131         return segment.getConstantPool();
132     }
133 
134     public int nextByte() {
135         return bcByte[bcByteIndex++];
136     }
137 
138     public int nextCaseCount() {
139         return bcCaseCount[bcCaseCountIndex++];
140     }
141 
142     public int nextCaseValues() {
143         return bcCaseValue[bcCaseValueIndex++];
144     }
145 
146     public int nextClassRef() {
147         return bcClassRef[bcClassRefIndex++];
148     }
149 
150     public int nextDoubleRef() {
151         return bcDoubleRef[bcDoubleRefIndex++];
152     }
153 
154     public int nextFieldRef() {
155         return bcFieldRef[bcFieldRefIndex++];
156     }
157 
158     public int nextFloatRef() {
159         return bcFloatRef[bcFloatRefIndex++];
160     }
161 
162     public int nextIMethodRef() {
163         return bcIMethodRef[bcIMethodRefIndex++];
164     }
165 
166     public int nextInitRef() {
167         return bcInitRef[bcInitRefIndex++];
168     }
169 
170     public int nextIntRef() {
171         return bcIntRef[bcIntRefIndex++];
172     }
173 
174     public int nextLabel() {
175         return bcLabel[bcLabelIndex++];
176     }
177 
178     public int nextLocal() {
179         return bcLocal[bcLocalIndex++];
180     }
181 
182     public int nextLongRef() {
183         return bcLongRef[bcLongRefIndex++];
184     }
185 
186     public int nextMethodRef() {
187         return bcMethodRef[bcMethodRefIndex++];
188     }
189 
190     public int nextShort() {
191         return bcShort[bcShortIndex++];
192     }
193 
194     public int nextStringRef() {
195         return bcStringRef[bcStringRefIndex++];
196     }
197 
198     public int nextSuperFieldRef() {
199         return bcSuperField[bcSuperFieldIndex++];
200     }
201 
202     public int nextSuperMethodRef() {
203         return bcSuperMethod[bcSuperMethodIndex++];
204     }
205 
206     public int nextThisFieldRef() {
207         return bcThisField[bcThisFieldIndex++];
208     }
209 
210     public int nextThisMethodRef() {
211         return bcThisMethod[bcThisMethodIndex++];
212     }
213 
214     public int nextWideByteCode() {
215         return wideByteCodes[wideByteCodeIndex++];
216     }
217 
218     public void setCurrentClass(final String string) {
219         currentClass = string;
220     }
221 
222     public void setNewClass(final String string) {
223         newClass = string;
224     }
225 
226     public void setSegment(final Segment segment) {
227         this.segment = segment;
228     }
229 
230     public void setSuperClass(final String string) {
231         superClass = string;
232     }
233 }