package accrue.analysis.ext;

import java.util.Map;

import polyglot.ast.Block;
import polyglot.util.InternalCompilerError;
import polyglot.util.SerialVersionUID;
import polyglot.visit.DataFlow;
import polyglot.visit.FlowGraph;
import polyglot.visit.FlowGraph.EdgeKey;
import polyglot.visit.FlowGraph.Peer;
import accrue.analysis.interprocanalysis.DataFlowDispatch;

public class ExtBlock extends ExtTerm {
    private static final long serialVersionUID = SerialVersionUID.generate();

    private Boolean isFinallyBlock = null;

    public boolean isFinallyBlock() {
        if (isFinallyBlock == null) {
            throw new InternalCompilerError("Finally block structure not computed yet");
        }
        return isFinallyBlock.booleanValue();
    }

    public void isFinallyBlock(boolean isFinallyBlock) {
        this.isFinallyBlock = Boolean.valueOf(isFinallyBlock);
    }

    @Override
    public <DFItem extends DataFlow.Item> Map<EdgeKey, DFItem> flowDispatch(
            DataFlowDispatch<DFItem> dataflow, DFItem dfIn,
            FlowGraph<DFItem> graph, Peer<DFItem> peer) {
        Block n = (Block) this.node();
        if (isFinallyBlock != null && isFinallyBlock.booleanValue()) {
            return dataflow.flowFinally(n, dfIn, graph, peer);
        }
        else {
            return dataflow.flowBlock(n, dfIn, graph, peer);
        }
    }

}
