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  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: MarkerInstruction.java 1225426 2011-12-29 04:13:08Z mrglavas $
020     */
021    
022    package org.apache.xalan.xsltc.compiler.util;
023    
024    import java.io.DataOutputStream;
025    import java.io.IOException;
026    
027    import org.apache.bcel.Constants;
028    import org.apache.bcel.generic.ConstantPoolGen;
029    import org.apache.bcel.generic.Instruction;
030    import org.apache.bcel.generic.Visitor;
031    
032    /**
033     * A special abstract dummy subclass of
034     * {@link org.apache.bcel.generic.Instruction} used to mark locations of
035     * interest in an {@link org.apache.bcel.generic.InstructionList}.  It and
036     * its subclasses are only used as placeholders, and do not contribute to the
037     * actual byte code instruction stream.
038     */
039    abstract class MarkerInstruction extends Instruction {
040        /**
041         * Zero-argument constructor.  Sets the opcode to an invalid value and 
042         * sets the length to zero, as it will not be written as part of the
043         * generated byte code.
044         */
045        public MarkerInstruction() {
046            super(Constants.UNDEFINED, (short) 0);
047        }
048    
049        /**
050         * {@link org.apache.bcel.generic.Visitor}s will know nothing about this
051         * kind of {@link org.apche.bcel.generic.Instruction}, so this method does
052         * nothing.
053         */
054        public void accept(Visitor v) {
055        }
056    
057        /**
058         * The number of JVM stack entries consumed by the instruction.
059         * This instruction is just a place holder, so it does not consume any
060         * stack entries.
061         * @param cpg The {@link org.apache.bcel.generic.ConstantPoolGen} for the
062         * current {@link org.apache.bcel.generic.ClassGen}
063         * @return <code>0</code> always 
064         */
065        final public int consumeStack(ConstantPoolGen cpg) {
066            return 0;
067        }
068        /**
069         * The number of JVM stack entries produced by the instruction.
070         * This instruction is just a place holder, so it does not produce any
071         * stack entries.
072         * @param cpg The {@link org.apache.bcel.generic.ConstantPoolGen} for the
073         * current {@link org.apache.bcel.generic.ClassGen}
074         * @return <code>0</code> always 
075         */
076        final public int produceStack(ConstantPoolGen cpg) {
077            return 0;
078        }
079    
080        /**
081         * Produce a copy of the instruction.  By default a
082         * {@link MarkerInstruction} has no parameters, so the base implementation
083         * of {@link #copy()} returns the instruction itself.
084         * @return The instruction itself.
085         */
086        public Instruction copy() {
087            return this;
088        }
089        /**
090         * Dump instruction as byte code to stream out.  A {@link MarkerInstruction}
091         * has no effect on the generated byte code so it is never emitted to the
092         * output stream.
093         * @param out Output stream
094         */
095        final public void dump(DataOutputStream out) throws IOException {
096        }
097    }