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
020import java.util.ArrayList;
021
022import org.apache.bcel.generic.InstructionHandle;
023
024/**
025 * An InstructionContext offers convenient access to information like control flow successors and such.
026 *
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     *
039     * @see ControlFlowGraph
040     * @see ExecutionVisitor
041     * @see #getOutFrame(ArrayList)
042     * @return true - if and only if the "outgoing" frame situation changed from the one before execute()ing.
043     */
044    boolean execute(Frame inFrame, ArrayList<InstructionContext> executionPredecessors, InstConstraintVisitor icv, ExecutionVisitor ev);
045
046    /**
047     * Returns the exception handlers that protect this instruction. They are special control flow successors.
048     */
049    ExceptionHandler[] getExceptionHandlers();
050
051    Frame getInFrame();
052
053    /**
054     * Returns the InstructionHandle this InstructionContext is wrapped around.
055     *
056     * @return The InstructionHandle this InstructionContext is wrapped around.
057     */
058    InstructionHandle getInstruction();
059
060    /**
061     * This method returns the outgoing execution frame situation; therefore <B>it has to be calculated by execute(Frame,
062     * ArrayList) first.</B>
063     *
064     * @see #execute(Frame, ArrayList, InstConstraintVisitor, ExecutionVisitor)
065     */
066    Frame getOutFrame(ArrayList<InstructionContext> executionPredecessors);
067
068    /**
069     * Returns the usual control flow successors.
070     *
071     * @see #getExceptionHandlers()
072     */
073    InstructionContext[] getSuccessors();
074
075    /**
076     * The getTag and setTag methods may be used for temporary flagging, such as graph colouring. Nothing in the
077     * InstructionContext object depends on the value of the tag. JustIce does not use it.
078     *
079     * @see #setTag(int tag)
080     */
081    int getTag();
082
083    /**
084     * The getTag and setTag methods may be used for temporary flagging, such as graph colouring. Nothing in the
085     * InstructionContext object depends on the value of the tag. JustIce does not use it.
086     *
087     * @see #getTag()
088     */
089    void setTag(int tag);
090}