    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 all the JsrInstructions that have the first instruction of this subroutine as their target. <B>Must not
    030     * be invoked on the 'top-level subroutine'.</B>
    031     *
    032     * @return The JsrInstructions that have the first instruction of this subroutine as their target.
    033     */
    034    InstructionHandle[] getEnteringJsrInstructions();
    035
    036    /**
    037     * Returns the one and only RET that leaves the subroutine. Note that JustIce has a pretty rigid notion of a
    038     * subroutine. <B>Must not be invoked on the 'top-level subroutine'.</B>
    039     *
    040     * @return The one and only RET that leaves the subroutine.
    041     *
    042     * @see Subroutines
    043     */
    044    InstructionHandle getLeavingRET();
    045
    046    /**
    047     * Returns all instructions that together form this subroutine. Note that an instruction is part of exactly one
    048     * subroutine (the top-level code is considered to be a special subroutine) - else it is not reachable at all (dead
    049     * code).
    050     *
    051     * @return All instructions that together form this subroutine.
    052     */
    053    InstructionHandle[] getInstructions();
    054
    055    /**
    056     * Returns if the given InstructionHandle refers to an instruction that is part of this subroutine. This is a
    057     * convenience method that saves iteration over the InstructionHandle objects returned by getInstructions().
    058     *
    059     * @param inst The InstructionHandle to test.
    060     * @return Whether the given InstructionHandle refers to an instruction that is part of this subroutine.
    061     *
    062     * @see #getInstructions()
    063     */
    064    boolean contains(InstructionHandle inst);
    065
    066    /**
    067     * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed,
    068     * write-accessed or both); local variables referenced by subroutines of this subroutine are not included.
    069     *
    070     * @return An int[] containing the indices of the local variable slots.
    071     * @see #getRecursivelyAccessedLocalsIndices()
    072     */
    073    int[] getAccessedLocalsIndices();
    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}