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