286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/Apackage com.sun.org.apache.bcel.internal.generic;
286N/A
286N/A/* ====================================================================
286N/A * The Apache Software License, Version 1.1
286N/A *
286N/A * Copyright (c) 2001 The Apache Software Foundation. All rights
286N/A * reserved.
286N/A *
286N/A * Redistribution and use in source and binary forms, with or without
286N/A * modification, are permitted provided that the following conditions
286N/A * are met:
286N/A *
286N/A * 1. Redistributions of source code must retain the above copyright
286N/A * notice, this list of conditions and the following disclaimer.
286N/A *
286N/A * 2. Redistributions in binary form must reproduce the above copyright
286N/A * notice, this list of conditions and the following disclaimer in
286N/A * the documentation and/or other materials provided with the
286N/A * distribution.
286N/A *
286N/A * 3. The end-user documentation included with the redistribution,
286N/A * if any, must include the following acknowledgment:
286N/A * "This product includes software developed by the
286N/A * Apache Software Foundation (http://www.apache.org/)."
286N/A * Alternately, this acknowledgment may appear in the software itself,
286N/A * if and wherever such third-party acknowledgments normally appear.
286N/A *
286N/A * 4. The names "Apache" and "Apache Software Foundation" and
286N/A * "Apache BCEL" must not be used to endorse or promote products
286N/A * derived from this software without prior written permission. For
286N/A * written permission, please contact apache@apache.org.
286N/A *
286N/A * 5. Products derived from this software may not be called "Apache",
286N/A * "Apache BCEL", nor may "Apache" appear in their name, without
286N/A * prior written permission of the Apache Software Foundation.
286N/A *
286N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
286N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
286N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
286N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
286N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
286N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
286N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
286N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
286N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
286N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
286N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
286N/A * SUCH DAMAGE.
286N/A * ====================================================================
286N/A *
286N/A * This software consists of voluntary contributions made by many
286N/A * individuals on behalf of the Apache Software Foundation. For more
286N/A * information on the Apache Software Foundation, please see
286N/A * <http://www.apache.org/>.
286N/A */
286N/Aimport java.io.*;
286N/Aimport com.sun.org.apache.bcel.internal.util.ByteSequence;
286N/A
286N/A/**
286N/A * IINC - Increment local variable by constant
286N/A *
286N/A * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
286N/A */
286N/Apublic class IINC extends LocalVariableInstruction {
286N/A private boolean wide;
286N/A private int c;
286N/A
286N/A /**
286N/A * Empty constructor needed for the Class.newInstance() statement in
286N/A * Instruction.readInstruction(). Not to be used otherwise.
286N/A */
286N/A IINC() {}
286N/A
286N/A /**
286N/A * @param n index of local variable
286N/A * @param c increment factor
286N/A */
286N/A public IINC(int n, int c) {
286N/A super(); // Default behaviour of LocalVariableInstruction causes error
286N/A
286N/A this.opcode = com.sun.org.apache.bcel.internal.Constants.IINC;
286N/A this.length = (short)3;
286N/A
286N/A setIndex(n); // May set wide as side effect
286N/A setIncrement(c);
286N/A }
286N/A
286N/A /**
286N/A * Dump instruction as byte code to stream out.
286N/A * @param out Output stream
286N/A */
286N/A public void dump(DataOutputStream out) throws IOException {
286N/A if(wide) // Need WIDE prefix ?
286N/A out.writeByte(com.sun.org.apache.bcel.internal.Constants.WIDE);
286N/A
286N/A out.writeByte(opcode);
286N/A
286N/A if(wide) {
286N/A out.writeShort(n);
286N/A out.writeShort(c);
286N/A } else {
286N/A out.writeByte(n);
286N/A out.writeByte(c);
286N/A }
286N/A }
286N/A
286N/A private final void setWide() {
286N/A if(wide = ((n > com.sun.org.apache.bcel.internal.Constants.MAX_SHORT) ||
286N/A (Math.abs(c) > Byte.MAX_VALUE)))
286N/A length = 6; // wide byte included
286N/A else
286N/A length = 3;
286N/A }
286N/A
286N/A /**
286N/A * Read needed data (e.g. index) from file.
286N/A */
286N/A protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
286N/A {
286N/A this.wide = wide;
286N/A
286N/A if(wide) {
286N/A length = 6;
286N/A n = bytes.readUnsignedShort();
286N/A c = bytes.readShort();
286N/A } else {
286N/A length = 3;
286N/A n = bytes.readUnsignedByte();
286N/A c = bytes.readByte();
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * @return mnemonic for instruction
286N/A */
286N/A public String toString(boolean verbose) {
286N/A return super.toString(verbose) + " " + c;
286N/A }
286N/A
286N/A /**
286N/A * Set index of local variable.
286N/A */
286N/A public final void setIndex(int n) {
286N/A if(n < 0)
286N/A throw new ClassGenException("Negative index value: " + n);
286N/A
286N/A this.n = n;
286N/A setWide();
286N/A }
286N/A
286N/A /**
286N/A * @return increment factor
286N/A */
286N/A public final int getIncrement() { return c; }
286N/A
286N/A /**
286N/A * Set increment factor.
286N/A */
286N/A public final void setIncrement(int c) {
286N/A this.c = c;
286N/A setWide();
286N/A }
286N/A
286N/A /** @return int type
286N/A */
286N/A public Type getType(ConstantPoolGen cp) {
286N/A return Type.INT;
286N/A }
286N/A
286N/A /**
286N/A * Call corresponding visitor method(s). The order is:
286N/A * Call visitor methods of implemented interfaces first, then
286N/A * call methods according to the class hierarchy in descending order,
286N/A * i.e., the most specific visitXXX() call comes last.
286N/A *
286N/A * @param v Visitor object
286N/A */
286N/A public void accept(Visitor v) {
286N/A v.visitLocalVariableInstruction(this);
286N/A v.visitIINC(this);
286N/A }
286N/A}