Frame xref

View Javadoc

    1   /*
    2    * Copyright  2000-2004 The Apache Software Foundation
    3    *
    4    *  Licensed under the Apache License, Version 2.0 (the "License");
    5    *  you may not use this file except in compliance with the License.
    6    *  You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   *  Unless required by applicable law or agreed to in writing, software
    11   *  distributed under the License is distributed on an "AS IS" BASIS,
    12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *  See the License for the specific language governing permissions and
    14   *  limitations under the License.
    15   *
    16   */
    17  package org.apache.bcel.verifier.structurals;
    18
    19
    20
    21  /***
    22   * This class represents a JVM execution frame; that means,
    23   * a local variable array and an operand stack.
    24   *
    25   * @version $Id: Frame.java 386056 2006-03-15 11:31:56Z tcurdt $
    26   * @author Enver Haase
    27   */
    28
    29  public class Frame{
    30
    31  	/***
    32  	 * For instance initialization methods, it is important to remember
    33  	 * which instance it is that is not initialized yet. It will be
    34  	 * initialized invoking another constructor later.
    35  	 * NULL means the instance already *is* initialized.
    36  	 */
    37  	protected static UninitializedObjectType _this;
    38
    39  	/***
    40  	 *
    41  	 */
    42  	private LocalVariables locals;
    43
    44  	/***
    45  	 *
    46  	 */
    47  	private OperandStack stack;
    48
    49  	/***
    50  	 *
    51  	 */
    52  	public Frame(int maxLocals, int maxStack){
    53  		locals = new LocalVariables(maxLocals);
    54  		stack = new OperandStack(maxStack);
    55  	}
    56
    57  	/***
    58  	 *
    59  	 */
    60  	public Frame(LocalVariables locals, OperandStack stack){
    61  		this.locals = locals;
    62  		this.stack = stack;
    63  	}
    64
    65  	/***
    66  	 *
    67  	 */
    68  	protected Object clone(){
    69  		Frame f = new Frame(locals.getClone(), stack.getClone());
    70  		return f;
    71  	}
    72
    73  	/***
    74  	 *
    75  	 */
    76  	public Frame getClone(){
    77  		return (Frame) clone();
    78  	}
    79
    80  	/***
    81  	 *
    82  	 */
    83  	public LocalVariables getLocals(){
    84  		return locals;
    85  	}
    86
    87  	/***
    88  	 *
    89  	 */
    90  	public OperandStack getStack(){
    91  		return stack;
    92  	}
    93
    94  	/*** @return a hash code value for the object.
    95       */
    96  	public int hashCode() { return stack.hashCode() ^ locals.hashCode(); }
    97
    98  	/***
    99  	 *
    100 	 */
    101 	public boolean equals(Object o){
    102 		if (!(o instanceof Frame)) {
    103             return false; // implies "null" is non-equal.
    104         }
    105 		Frame f = (Frame) o;
    106 		return this.stack.equals(f.stack) && this.locals.equals(f.locals);
    107 	}
    108
    109 	/***
    110 	 * Returns a String representation of the Frame instance.
    111 	 */
    112 	public String toString(){
    113 		String s="Local Variables:\n";
    114 		s += locals;
    115 		s += "OperandStack:\n";
    116 		s += stack;
    117 		return s;
    118 	}
    119 }