OperandManager.java

  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. package org.apache.commons.compress.harmony.unpack200.bytecode;

  18. import org.apache.commons.compress.harmony.unpack200.Segment;
  19. import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;

  20. /**
  21.  * 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
  22.  * references.
  23.  */
  24. public class OperandManager {

  25.     int[] bcCaseCount;
  26.     int[] bcCaseValue;
  27.     int[] bcByte;
  28.     int[] bcShort;
  29.     int[] bcLocal;
  30.     int[] bcLabel;
  31.     int[] bcIntRef;
  32.     int[] bcFloatRef;
  33.     int[] bcLongRef;
  34.     int[] bcDoubleRef;
  35.     int[] bcStringRef;
  36.     int[] bcClassRef;
  37.     int[] bcFieldRef;
  38.     int[] bcMethodRef;
  39.     int[] bcIMethodRef;
  40.     int[] bcThisField;
  41.     int[] bcSuperField;
  42.     int[] bcThisMethod;
  43.     int[] bcSuperMethod;
  44.     int[] bcInitRef;
  45.     int[] wideByteCodes;

  46.     int bcCaseCountIndex;
  47.     int bcCaseValueIndex;
  48.     int bcByteIndex;
  49.     int bcShortIndex;
  50.     int bcLocalIndex;
  51.     int bcLabelIndex;
  52.     int bcIntRefIndex;
  53.     int bcFloatRefIndex;
  54.     int bcLongRefIndex;
  55.     int bcDoubleRefIndex;
  56.     int bcStringRefIndex;
  57.     int bcClassRefIndex;
  58.     int bcFieldRefIndex;
  59.     int bcMethodRefIndex;
  60.     int bcIMethodRefIndex;
  61.     int bcThisFieldIndex;
  62.     int bcSuperFieldIndex;
  63.     int bcThisMethodIndex;
  64.     int bcSuperMethodIndex;
  65.     int bcInitRefIndex;
  66.     int wideByteCodeIndex;

  67.     Segment segment;

  68.     String currentClass;
  69.     String superClass;
  70.     String newClass;

  71.     public OperandManager(final int[] bcCaseCount, final int[] bcCaseValue, final int[] bcByte, final int[] bcShort, final int[] bcLocal, final int[] bcLabel,
  72.             final int[] bcIntRef, final int[] bcFloatRef, final int[] bcLongRef, final int[] bcDoubleRef, final int[] bcStringRef, final int[] bcClassRef,
  73.             final int[] bcFieldRef, final int[] bcMethodRef, final int[] bcIMethodRef, final int[] bcThisField, final int[] bcSuperField,
  74.             final int[] bcThisMethod, final int[] bcSuperMethod, final int[] bcInitRef, final int[] wideByteCodes) {
  75.         this.bcCaseCount = bcCaseCount;
  76.         this.bcCaseValue = bcCaseValue;
  77.         this.bcByte = bcByte;
  78.         this.bcShort = bcShort;
  79.         this.bcLocal = bcLocal;
  80.         this.bcLabel = bcLabel;
  81.         this.bcIntRef = bcIntRef;
  82.         this.bcFloatRef = bcFloatRef;
  83.         this.bcLongRef = bcLongRef;
  84.         this.bcDoubleRef = bcDoubleRef;
  85.         this.bcStringRef = bcStringRef;
  86.         this.bcClassRef = bcClassRef;
  87.         this.bcFieldRef = bcFieldRef;
  88.         this.bcMethodRef = bcMethodRef;
  89.         this.bcIMethodRef = bcIMethodRef;

  90.         this.bcThisField = bcThisField;
  91.         this.bcSuperField = bcSuperField;
  92.         this.bcThisMethod = bcThisMethod;
  93.         this.bcSuperMethod = bcSuperMethod;
  94.         this.bcInitRef = bcInitRef;
  95.         this.wideByteCodes = wideByteCodes;
  96.     }

  97.     public String getCurrentClass() {
  98.         if (null == currentClass) {
  99.             throw new Error("Current class not set yet");
  100.         }
  101.         return currentClass;
  102.     }

  103.     public String getNewClass() {
  104.         if (null == newClass) {
  105.             throw new Error("New class not set yet");
  106.         }
  107.         return newClass;
  108.     }

  109.     public String getSuperClass() {
  110.         if (null == superClass) {
  111.             throw new Error("SuperClass not set yet");
  112.         }
  113.         return superClass;
  114.     }

  115.     public SegmentConstantPool globalConstantPool() {
  116.         return segment.getConstantPool();
  117.     }

  118.     public int nextByte() {
  119.         return bcByte[bcByteIndex++];
  120.     }

  121.     public int nextCaseCount() {
  122.         return bcCaseCount[bcCaseCountIndex++];
  123.     }

  124.     public int nextCaseValues() {
  125.         return bcCaseValue[bcCaseValueIndex++];
  126.     }

  127.     public int nextClassRef() {
  128.         return bcClassRef[bcClassRefIndex++];
  129.     }

  130.     public int nextDoubleRef() {
  131.         return bcDoubleRef[bcDoubleRefIndex++];
  132.     }

  133.     public int nextFieldRef() {
  134.         return bcFieldRef[bcFieldRefIndex++];
  135.     }

  136.     public int nextFloatRef() {
  137.         return bcFloatRef[bcFloatRefIndex++];
  138.     }

  139.     public int nextIMethodRef() {
  140.         return bcIMethodRef[bcIMethodRefIndex++];
  141.     }

  142.     public int nextInitRef() {
  143.         return bcInitRef[bcInitRefIndex++];
  144.     }

  145.     public int nextIntRef() {
  146.         return bcIntRef[bcIntRefIndex++];
  147.     }

  148.     public int nextLabel() {
  149.         return bcLabel[bcLabelIndex++];
  150.     }

  151.     public int nextLocal() {
  152.         return bcLocal[bcLocalIndex++];
  153.     }

  154.     public int nextLongRef() {
  155.         return bcLongRef[bcLongRefIndex++];
  156.     }

  157.     public int nextMethodRef() {
  158.         return bcMethodRef[bcMethodRefIndex++];
  159.     }

  160.     public int nextShort() {
  161.         return bcShort[bcShortIndex++];
  162.     }

  163.     public int nextStringRef() {
  164.         return bcStringRef[bcStringRefIndex++];
  165.     }

  166.     public int nextSuperFieldRef() {
  167.         return bcSuperField[bcSuperFieldIndex++];
  168.     }

  169.     public int nextSuperMethodRef() {
  170.         return bcSuperMethod[bcSuperMethodIndex++];
  171.     }

  172.     public int nextThisFieldRef() {
  173.         return bcThisField[bcThisFieldIndex++];
  174.     }

  175.     public int nextThisMethodRef() {
  176.         return bcThisMethod[bcThisMethodIndex++];
  177.     }

  178.     public int nextWideByteCode() {
  179.         return wideByteCodes[wideByteCodeIndex++];
  180.     }

  181.     public void setCurrentClass(final String string) {
  182.         currentClass = string;
  183.     }

  184.     public void setNewClass(final String string) {
  185.         newClass = string;
  186.     }

  187.     public void setSegment(final Segment segment) {
  188.         this.segment = segment;
  189.     }

  190.     public void setSuperClass(final String string) {
  191.         superClass = string;
  192.     }
  193. }