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  package org.apache.bcel.verifier.structurals;
18  
19  /**
20   * This class represents a JVM execution frame; that means, a local variable array and an operand stack.
21   */
22  
23  public class Frame {
24  
25      /**
26       * For instance initialization methods, it is important to remember which instance it is that is not initialized yet. It
27       * will be initialized invoking another constructor later. NULL means the instance already *is* initialized.
28       *
29       * @deprecated Use the getter/setter to access the field as it may be made private in a later release
30       */
31      @Deprecated
32      protected static UninitializedObjectType _this;
33  
34      /**
35       * @return the _this
36       * @since 6.0
37       */
38      public static UninitializedObjectType getThis() {
39          return _this;
40      }
41  
42      /**
43       * @param _this the _this to set
44       * @since 6.0
45       */
46      public static void setThis(final UninitializedObjectType _this) {
47          Frame._this = _this;
48      }
49  
50      /**
51       */
52      private final LocalVariables locals;
53  
54      /**
55       */
56      private final OperandStack stack;
57  
58      /**
59       */
60      public Frame(final int maxLocals, final int maxStack) {
61          locals = new LocalVariables(maxLocals);
62          stack = new OperandStack(maxStack);
63      }
64  
65      /**
66       */
67      public Frame(final LocalVariables locals, final OperandStack stack) {
68          this.locals = locals;
69          this.stack = stack;
70      }
71  
72      /**
73       */
74      @Override
75      protected Object clone() {
76          return new Frame(locals.getClone(), stack.getClone());
77      }
78  
79      /**
80       */
81      @Override
82      public boolean equals(final Object o) {
83          if (!(o instanceof Frame)) {
84              return false; // implies "null" is non-equal.
85          }
86          final Frame f = (Frame) o;
87          return this.stack.equals(f.stack) && this.locals.equals(f.locals);
88      }
89  
90      /**
91       */
92      public Frame getClone() {
93          return (Frame) clone();
94      }
95  
96      /**
97       */
98      public LocalVariables getLocals() {
99          return locals;
100     }
101 
102     /**
103      */
104     public OperandStack getStack() {
105         return stack;
106     }
107 
108     /**
109      * @return a hash code value for the object.
110      */
111     @Override
112     public int hashCode() {
113         return stack.hashCode() ^ locals.hashCode();
114     }
115 
116     /**
117      * Returns a String representation of the Frame instance.
118      */
119     @Override
120     public String toString() {
121         final StringBuilder s = new StringBuilder("Local Variables:\n");
122         s.append(locals);
123         s.append("OperandStack:\n");
124         s.append(stack);
125         return s.toString();
126     }
127 }