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