    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
    022/**
    023 * This class represents a JVM execution frame; that means,
    024 * a local variable array and an operand stack.
    025 *
    026 */
    027
    028public class Frame{
    029
    030    /**
    031     * For instance initialization methods, it is important to remember
    032     * which instance it is that is not initialized yet. It will be
    033     * initialized invoking another constructor later.
    034     * NULL means the instance already *is* initialized.
    035     * @deprecated Use the getter/setter to access the field as it may
    036     * be made private in a later release
    037     */
    038    @Deprecated
    039    protected static UninitializedObjectType _this;
    040
    041    /**
    042     *
    043     */
    044    private final LocalVariables locals;
    045
    046    /**
    047     *
    048     */
    049    private final OperandStack stack;
    050
    051    /**
    052     *
    053     */
    054    public Frame(final int maxLocals, final int maxStack) {
    055        locals = new LocalVariables(maxLocals);
    056        stack = new OperandStack(maxStack);
    057    }
    058
    059    /**
    060     *
    061     */
    062    public Frame(final LocalVariables locals, final OperandStack stack) {
    063        this.locals = locals;
    064        this.stack = stack;
    065    }
    066
    067    /**
    068     *
    069     */
    070    @Override
    071    protected Object clone() {
    072        final Frame f = new Frame(locals.getClone(), stack.getClone());
    073        return f;
    074    }
    075
    076    /**
    077     *
    078     */
    079    public Frame getClone() {
    080        return (Frame) clone();
    081    }
    082
    083    /**
    084     *
    085     */
    086    public LocalVariables getLocals() {
    087        return locals;
    088    }
    089
    090    /**
    091     *
    092     */
    093    public OperandStack getStack() {
    094        return stack;
    095    }
    096
    097    /** @return a hash code value for the object.
    098     */
    099    @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 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}