    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019
    020package org.apache.commons.compress.harmony.unpack200.bytecode;
    021
    022import org.apache.commons.compress.harmony.unpack200.Segment;
    023import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
    024
    025/**
    026 * 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
    027 * references.
    028 */
    029public 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;
    054    int bcCaseValueIndex;
    055    int bcByteIndex;
    056    int bcShortIndex;
    057    int bcLocalIndex;
    058    int bcLabelIndex;
    059    int bcIntRefIndex;
    060    int bcFloatRefIndex;
    061    int bcLongRefIndex;
    062    int bcDoubleRefIndex;
    063    int bcStringRefIndex;
    064    int bcClassRefIndex;
    065    int bcFieldRefIndex;
    066    int bcMethodRefIndex;
    067    int bcIMethodRefIndex;
    068    int bcThisFieldIndex;
    069    int bcSuperFieldIndex;
    070    int bcThisMethodIndex;
    071    int bcSuperMethodIndex;
    072    int bcInitRefIndex;
    073    int wideByteCodeIndex;
    074
    075    Segment segment;
    076
    077    String currentClass;
    078    String superClass;
    079    String newClass;
    080
    081    public OperandManager(final int[] bcCaseCount, final int[] bcCaseValue, final int[] bcByte, final int[] bcShort, final int[] bcLocal, final int[] bcLabel,
    082            final int[] bcIntRef, final int[] bcFloatRef, final int[] bcLongRef, final int[] bcDoubleRef, final int[] bcStringRef, final int[] bcClassRef,
    083            final int[] bcFieldRef, final int[] bcMethodRef, final int[] bcIMethodRef, final int[] bcThisField, final int[] bcSuperField,
    084            final int[] bcThisMethod, final int[] bcSuperMethod, final int[] bcInitRef, final int[] wideByteCodes) {
    085        this.bcCaseCount = bcCaseCount;
    086        this.bcCaseValue = bcCaseValue;
    087        this.bcByte = bcByte;
    088        this.bcShort = bcShort;
    089        this.bcLocal = bcLocal;
    090        this.bcLabel = bcLabel;
    091        this.bcIntRef = bcIntRef;
    092        this.bcFloatRef = bcFloatRef;
    093        this.bcLongRef = bcLongRef;
    094        this.bcDoubleRef = bcDoubleRef;
    095        this.bcStringRef = bcStringRef;
    096        this.bcClassRef = bcClassRef;
    097        this.bcFieldRef = bcFieldRef;
    098        this.bcMethodRef = bcMethodRef;
    099        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}