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.bcel.verifier.structurals;
019
020import org.apache.bcel.generic.InstructionHandle;
021
022/**
023 * This interface defines properties of JVM bytecode subroutines. Note that it is 'abused' to maintain the top-level
024 * code in a consistent fashion, too.
025 */
026public interface Subroutine {
027
028    /**
029     * Returns if the given InstructionHandle refers to an instruction that is part of this subroutine. This is a
030     * convenience method that saves iteration over the InstructionHandle objects returned by getInstructions().
031     *
032     * @param inst The InstructionHandle to test.
033     * @return Whether the given InstructionHandle refers to an instruction that is part of this subroutine.
034     *
035     * @see #getInstructions()
036     */
037    boolean contains(InstructionHandle inst);
038
039    /**
040     * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed,
041     * write-accessed or both); local variables referenced by subroutines of this subroutine are not included.
042     *
043     * @return An int[] containing the indices of the local variable slots.
044     * @see #getRecursivelyAccessedLocalsIndices()
045     */
046    int[] getAccessedLocalsIndices();
047
048    /**
049     * Returns all the JsrInstructions that have the first instruction of this subroutine as their target. <B>Must not be
050     * invoked on the 'top-level subroutine'.</B>
051     *
052     * @return The JsrInstructions that have the first instruction of this subroutine as their target.
053     */
054    InstructionHandle[] getEnteringJsrInstructions();
055
056    /**
057     * Returns all instructions that together form this subroutine. Note that an instruction is part of exactly one
058     * subroutine (the top-level code is considered to be a special subroutine) - else it is not reachable at all (dead
059     * code).
060     *
061     * @return All instructions that together form this subroutine.
062     */
063    InstructionHandle[] getInstructions();
064
065    /**
066     * Returns the one and only RET that leaves the subroutine. Note that JustIce has a pretty rigid notion of a subroutine.
067     * <B>Must not be invoked on the 'top-level subroutine'.</B>
068     *
069     * @return The one and only RET that leaves the subroutine.
070     *
071     * @see Subroutines
072     */
073    InstructionHandle getLeavingRET();
074
075    /**
076     * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed,
077     * write-accessed or both); local variables referenced by subroutines of this subroutine are included.
078     *
079     * @return An int[] containing the indices of the local variable slots.
080     * @see #getAccessedLocalsIndices()
081     */
082    int[] getRecursivelyAccessedLocalsIndices();
083
084    /**
085     * Returns the subroutines that are directly called from this subroutine.
086     *
087     * @return The subroutines that are directly called from this subroutine.
088     */
089    Subroutine[] subSubs();
090}