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 * This class keeps track of operands used. It provides API to let other classes get next elements, and also knows about 025 * which classes have been used recently in super, this and new 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, 080 final int[] bcLocal, final int[] bcLabel, final int[] bcIntRef, final int[] bcFloatRef, final int[] bcLongRef, 081 final int[] bcDoubleRef, final int[] bcStringRef, final int[] bcClassRef, final int[] bcFieldRef, 082 final int[] bcMethodRef, final int[] bcIMethodRef, final int[] bcThisField, final int[] bcSuperField, 083 final int[] bcThisMethod, final int[] bcSuperMethod, final int[] bcInitRef, final int[] wideByteCodes) { 084 this.bcCaseCount = bcCaseCount; 085 this.bcCaseValue = bcCaseValue; 086 this.bcByte = bcByte; 087 this.bcShort = bcShort; 088 this.bcLocal = bcLocal; 089 this.bcLabel = bcLabel; 090 this.bcIntRef = bcIntRef; 091 this.bcFloatRef = bcFloatRef; 092 this.bcLongRef = bcLongRef; 093 this.bcDoubleRef = bcDoubleRef; 094 this.bcStringRef = bcStringRef; 095 this.bcClassRef = bcClassRef; 096 this.bcFieldRef = bcFieldRef; 097 this.bcMethodRef = bcMethodRef; 098 this.bcIMethodRef = bcIMethodRef; 099 100 this.bcThisField = bcThisField; 101 this.bcSuperField = bcSuperField; 102 this.bcThisMethod = bcThisMethod; 103 this.bcSuperMethod = bcSuperMethod; 104 this.bcInitRef = bcInitRef; 105 this.wideByteCodes = wideByteCodes; 106 } 107 108 public String getCurrentClass() { 109 if (null == currentClass) { 110 throw new Error("Current class not set yet"); 111 } 112 return currentClass; 113 } 114 115 public String getNewClass() { 116 if (null == newClass) { 117 throw new Error("New class not set yet"); 118 } 119 return newClass; 120 } 121 122 public String getSuperClass() { 123 if (null == superClass) { 124 throw new Error("SuperClass not set yet"); 125 } 126 return superClass; 127 } 128 129 public SegmentConstantPool globalConstantPool() { 130 return segment.getConstantPool(); 131 } 132 133 public int nextByte() { 134 return bcByte[bcByteIndex++]; 135 } 136 137 public int nextCaseCount() { 138 return bcCaseCount[bcCaseCountIndex++]; 139 } 140 141 public int nextCaseValues() { 142 return bcCaseValue[bcCaseValueIndex++]; 143 } 144 145 public int nextClassRef() { 146 return bcClassRef[bcClassRefIndex++]; 147 } 148 149 public int nextDoubleRef() { 150 return bcDoubleRef[bcDoubleRefIndex++]; 151 } 152 153 public int nextFieldRef() { 154 return bcFieldRef[bcFieldRefIndex++]; 155 } 156 157 public int nextFloatRef() { 158 return bcFloatRef[bcFloatRefIndex++]; 159 } 160 161 public int nextIMethodRef() { 162 return bcIMethodRef[bcIMethodRefIndex++]; 163 } 164 165 public int nextInitRef() { 166 return bcInitRef[bcInitRefIndex++]; 167 } 168 169 public int nextIntRef() { 170 return bcIntRef[bcIntRefIndex++]; 171 } 172 173 public int nextLabel() { 174 return bcLabel[bcLabelIndex++]; 175 } 176 177 public int nextLocal() { 178 return bcLocal[bcLocalIndex++]; 179 } 180 181 public int nextLongRef() { 182 return bcLongRef[bcLongRefIndex++]; 183 } 184 185 public int nextMethodRef() { 186 return bcMethodRef[bcMethodRefIndex++]; 187 } 188 189 public int nextShort() { 190 return bcShort[bcShortIndex++]; 191 } 192 193 public int nextStringRef() { 194 return bcStringRef[bcStringRefIndex++]; 195 } 196 197 public int nextSuperFieldRef() { 198 return bcSuperField[bcSuperFieldIndex++]; 199 } 200 201 public int nextSuperMethodRef() { 202 return bcSuperMethod[bcSuperMethodIndex++]; 203 } 204 205 public int nextThisFieldRef() { 206 return bcThisField[bcThisFieldIndex++]; 207 } 208 209 public int nextThisMethodRef() { 210 return bcThisMethod[bcThisMethodIndex++]; 211 } 212 213 public int nextWideByteCode() { 214 return wideByteCodes[wideByteCodeIndex++]; 215 } 216 217 public void setCurrentClass(final String string) { 218 currentClass = string; 219 } 220 221 public void setNewClass(final String string) { 222 newClass = string; 223 } 224 225 public void setSegment(final Segment segment) { 226 this.segment = segment; 227 } 228 229 public void setSuperClass(final String string) { 230 superClass = string; 231 } 232}