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