View Javadoc
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   */
18  package org.apache.bcel.verifier.structurals;
19  
20  import org.apache.bcel.generic.InstructionHandle;
21  
22  /**
23   * This interface defines properties of JVM bytecode subroutines. Note that it is 'abused' to maintain the top-level
24   * code in a consistent fashion, too.
25   */
26  public interface Subroutine {
27  
28      /**
29       * Returns all the JsrInstructions that have the first instruction of this subroutine as their target. <B>Must not
30       * be invoked on the 'top-level subroutine'.</B>
31       *
32       * @return The JsrInstructions that have the first instruction of this subroutine as their target.
33       */
34      InstructionHandle[] getEnteringJsrInstructions();
35  
36      /**
37       * Returns the one and only RET that leaves the subroutine. Note that JustIce has a pretty rigid notion of a
38       * subroutine. <B>Must not be invoked on the 'top-level subroutine'.</B>
39       *
40       * @return The one and only RET that leaves the subroutine.
41       *
42       * @see Subroutines
43       */
44      InstructionHandle getLeavingRET();
45  
46      /**
47       * Returns all instructions that together form this subroutine. Note that an instruction is part of exactly one
48       * subroutine (the top-level code is considered to be a special subroutine) - else it is not reachable at all (dead
49       * code).
50       *
51       * @return All instructions that together form this subroutine.
52       */
53      InstructionHandle[] getInstructions();
54  
55      /**
56       * Returns if the given InstructionHandle refers to an instruction that is part of this subroutine. This is a
57       * convenience method that saves iteration over the InstructionHandle objects returned by getInstructions().
58       *
59       * @param inst The InstructionHandle to test.
60       * @return Whether the given InstructionHandle refers to an instruction that is part of this subroutine.
61       *
62       * @see #getInstructions()
63       */
64      boolean contains(InstructionHandle inst);
65  
66      /**
67       * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed,
68       * write-accessed or both); local variables referenced by subroutines of this subroutine are not included.
69       *
70       * @return An int[] containing the indices of the local variable slots.
71       * @see #getRecursivelyAccessedLocalsIndices()
72       */
73      int[] getAccessedLocalsIndices();
74  
75      /**
76       * Returns an int[] containing the indices of the local variable slots accessed by this Subroutine (read-accessed,
77       * write-accessed or both); local variables referenced by subroutines of this subroutine are included.
78       *
79       * @return An int[] containing the indices of the local variable slots.
80       * @see #getAccessedLocalsIndices()
81       */
82      int[] getRecursivelyAccessedLocalsIndices();
83  
84      /**
85       * Returns the subroutines that are directly called from this subroutine.
86       *
87       * @return The subroutines that are directly called from this subroutine.
88       */
89      Subroutine[] subSubs();
90  }