1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.bcel.verifier.structurals; 18 19 import org.apache.bcel.generic.InstructionHandle; 20 21 /** 22 * This interface defines properties of JVM bytecode subroutines. Note that it is 'abused' to maintain the top-level 23 * code in a consistent fashion, too. 24 */ 25 public interface Subroutine { 26 27 /** 28 * Returns if the given InstructionHandle refers to an instruction that is part of this subroutine. This is a 29 * convenience method that saves iteration over the InstructionHandle objects returned by getInstructions(). 30 * 31 * @param inst The InstructionHandle to test. 32 * @return Whether the given InstructionHandle refers to an instruction that is part of this subroutine. 33 * 34 * @see #getInstructions() 35 */ 36 boolean contains(InstructionHandle inst); 37 38 /** 39 * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed, 40 * write-accessed or both); local variables referenced by subroutines of this subroutine are not included. 41 * 42 * @return An int[] containing the indices of the local variable slots. 43 * @see #getRecursivelyAccessedLocalsIndices() 44 */ 45 int[] getAccessedLocalsIndices(); 46 47 /** 48 * Returns all the JsrInstructions that have the first instruction of this subroutine as their target. <B>Must not be 49 * invoked on the 'top-level subroutine'.</B> 50 * 51 * @return The JsrInstructions that have the first instruction of this subroutine as their target. 52 */ 53 InstructionHandle[] getEnteringJsrInstructions(); 54 55 /** 56 * Returns all instructions that together form this subroutine. Note that an instruction is part of exactly one 57 * subroutine (the top-level code is considered to be a special subroutine) - else it is not reachable at all (dead 58 * code). 59 * 60 * @return All instructions that together form this subroutine. 61 */ 62 InstructionHandle[] getInstructions(); 63 64 /** 65 * Returns the one and only RET that leaves the subroutine. Note that JustIce has a pretty rigid notion of a subroutine. 66 * <B>Must not be invoked on the 'top-level subroutine'.</B> 67 * 68 * @return The one and only RET that leaves the subroutine. 69 * 70 * @see Subroutines 71 */ 72 InstructionHandle getLeavingRET(); 73 74 /** 75 * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed, 76 * write-accessed or both); local variables referenced by subroutines of this subroutine are included. 77 * 78 * @return An int[] containing the indices of the local variable slots. 79 * @see #getAccessedLocalsIndices() 80 */ 81 int[] getRecursivelyAccessedLocalsIndices(); 82 83 /** 84 * Returns the subroutines that are directly called from this subroutine. 85 * 86 * @return The subroutines that are directly called from this subroutine. 87 */ 88 Subroutine[] subSubs(); 89 }