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