    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 *  Unless required by applicable law or agreed to in writing, software
    012 *  distributed under the License is distributed on an "AS IS" BASIS,
    013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 *  See the License for the specific language governing permissions and
    015 *  limitations under the License.
    016 *
    017 */
    018package org.apache.bcel.verifier.structurals;
    019
    020/**
    021 * This class represents a JVM execution frame; that means, a local variable array and an operand stack.
    022 *
    023 */
    024
    025public class Frame {
    026
    027    /**
    028     * For instance initialization methods, it is important to remember which instance it is that is not initialized yet. It
    029     * will be initialized invoking another constructor later. NULL means the instance already *is* initialized.
    030     *
    031     * @deprecated Use the getter/setter to access the field as it may be made private in a later release
    032     */
    033    @Deprecated
    034    protected static UninitializedObjectType _this;
    035
    036    /**
    037     * @return the _this
    038     * @since 6.0
    039     */
    040    public static UninitializedObjectType getThis() {
    041        return _this;
    042    }
    043
    044    /**
    045     * @param _this the _this to set
    046     * @since 6.0
    047     */
    048    public static void setThis(final UninitializedObjectType _this) {
    049        Frame._this = _this;
    050    }
    051
    052    /**
    053     *
    054     */
    055    private final LocalVariables locals;
    056
    057    /**
    058     *
    059     */
    060    private final OperandStack stack;
    061
    062    /**
    063     *
    064     */
    065    public Frame(final int maxLocals, final int maxStack) {
    066        locals = new LocalVariables(maxLocals);
    067        stack = new OperandStack(maxStack);
    068    }
    069
    070    /**
    071     *
    072     */
    073    public Frame(final LocalVariables locals, final OperandStack stack) {
    074        this.locals = locals;
    075        this.stack = stack;
    076    }
    077
    078    /**
    079     *
    080     */
    081    @Override
    082    protected Object clone() {
    083        return new Frame(locals.getClone(), stack.getClone());
    084    }
    085
    086    /**
    087     *
    088     */
    089    @Override
    090    public boolean equals(final Object o) {
    091        if (!(o instanceof Frame)) {
    092            return false; // implies "null" is non-equal.
    093        }
    094        final Frame f = (Frame) o;
    095        return this.stack.equals(f.stack) && this.locals.equals(f.locals);
    096    }
    097
    098    /**
    099     *
    100     */
    101    public Frame getClone() {
    102        return (Frame) clone();
    103    }
    104
    105    /**
    106     *
    107     */
    108    public LocalVariables getLocals() {
    109        return locals;
    110    }
    111
    112    /**
    113     *
    114     */
    115    public OperandStack getStack() {
    116        return stack;
    117    }
    118
    119    /**
    120     * @return a hash code value for the object.
    121     */
    122    @Override
    123    public int hashCode() {
    124        return stack.hashCode() ^ locals.hashCode();
    125    }
    126
    127    /**
    128     * Returns a String representation of the Frame instance.
    129     */
    130    @Override
    131    public String toString() {
    132        String s = "Local Variables:\n";
    133        s += locals;
    134        s += "OperandStack:\n";
    135        s += stack;
    136        return s;
    137    }
    138}