    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.bcel.verifier.structurals;
    020
    021import java.util.ArrayList;
    022
    023import org.apache.bcel.generic.InstructionHandle;
    024
    025/**
    026 * An InstructionContext offers convenient access to information like control flow successors and such.
    027 */
    028public interface InstructionContext {
    029
    030    /**
    031     * This method symbolically executes the Instruction held in the InstructionContext. It "merges in" the incoming
    032     * execution frame situation (see The Java Virtual Machine Specification, 2nd edition, page 146). By so doing, the
    033     * outgoing execution frame situation is calculated.
    034     *
    035     * This method is JustIce-specific and is usually of no sense for users of the ControlFlowGraph class. They should use
    036     * getInstruction().accept(Visitor), possibly in conjunction with the ExecutionVisitor.
    037     *
    038     * @param inFrame the incoming frame.
    039     * @param executionPredecessors the execution predecessors.
    040     * @param icv the instruction constraint visitor.
    041     * @param ev the execution visitor.
    042     * @see ControlFlowGraph
    043     * @see ExecutionVisitor
    044     * @see #getOutFrame(ArrayList)
    045     * @return true - if and only if the "outgoing" frame situation changed from the one before execute()ing.
    046     */
    047    boolean execute(Frame inFrame, ArrayList<InstructionContext> executionPredecessors, InstConstraintVisitor icv, ExecutionVisitor ev);
    048
    049    /**
    050     * Returns the exception handlers that protect this instruction. They are special control flow successors.
    051     *
    052     * @return the exception handlers.
    053     */
    054    ExceptionHandler[] getExceptionHandlers();
    055
    056    /**
    057     * Gets the incoming frame.
    058     *
    059     * @return the incoming frame.
    060     */
    061    Frame getInFrame();
    062
    063    /**
    064     * Returns the InstructionHandle this InstructionContext is wrapped around.
    065     *
    066     * @return The InstructionHandle this InstructionContext is wrapped around.
    067     */
    068    InstructionHandle getInstruction();
    069
    070    /**
    071     * This method returns the outgoing execution frame situation; therefore <B>it has to be calculated by execute(Frame,
    072     * ArrayList) first.</B>
    073     *
    074     * @param executionPredecessors the execution predecessors.
    075     * @return the outgoing frame.
    076     * @see #execute(Frame, ArrayList, InstConstraintVisitor, ExecutionVisitor)
    077     */
    078    Frame getOutFrame(ArrayList<InstructionContext> executionPredecessors);
    079
    080    /**
    081     * Returns the usual control flow successors.
    082     *
    083     * @return the successors.
    084     * @see #getExceptionHandlers()
    085     */
    086    InstructionContext[] getSuccessors();
    087
    088    /**
    089     * The getTag and setTag methods may be used for temporary flagging, such as graph coloring. Nothing in the
    090     * InstructionContext object depends on the value of the tag. JustIce does not use it.
    091     *
    092     * @return the tag value.
    093     * @see #setTag(int tag)
    094     */
    095    int getTag();
    096
    097    /**
    098     * The getTag and setTag methods may be used for temporary flagging, such as graph coloring. Nothing in the
    099     * InstructionContext object depends on the value of the tag. JustIce does not use it.
    100     *
    101     * @param tag the tag value.
    102     * @see #getTag()
    103     */
    104    void setTag(int tag);
    105}