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 */
019package org.apache.bcel.verifier.structurals;
020
021import org.apache.bcel.generic.InstructionHandle;
022
023/**
024 * This interface defines properties of JVM bytecode subroutines. Note that it is 'abused' to maintain the top-level
025 * code in a consistent fashion, too.
026 */
027public interface Subroutine {
028
029    /**
030     * Returns if the given InstructionHandle refers to an instruction that is part of this subroutine. This is a
031     * convenience method that saves iteration over the InstructionHandle objects returned by getInstructions().
032     *
033     * @param inst The InstructionHandle to test.
034     * @return Whether the given InstructionHandle refers to an instruction that is part of this subroutine.
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     * @see Subroutines
071     */
072    InstructionHandle getLeavingRET();
073
074    /**
075     * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed,
076     * write-accessed or both); local variables referenced by subroutines of this subroutine are included.
077     *
078     * @return An int[] containing the indices of the local variable slots.
079     * @see #getAccessedLocalsIndices()
080     */
081    int[] getRecursivelyAccessedLocalsIndices();
082
083    /**
084     * Returns the subroutines that are directly called from this subroutine.
085     *
086     * @return The subroutines that are directly called from this subroutine.
087     */
088    Subroutine[] subSubs();
089}