package accrue.analysis.ext;

import java.util.Map;

import polyglot.ast.Special;
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.AnalysisContext;
import accrue.analysis.interprocanalysis.DataFlowDispatch;
import accrue.analysis.pointer.RegisterPointerStmtsVisitor;
import accrue.analysis.pointer.StmtRegistrar;

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

    @Override
    public void registerPointerStmts(StmtRegistrar registrar,
            RegisterPointerStmtsVisitor v) {

        if (v.currentCode() == null) {
            throw new InternalCompilerError(this.node().position(),
                                            "No current code for special");
        }
        if (v.currentCode().thisNode == null) {
            throw new InternalCompilerError("Null thisNode");
        }

        this.setReferenceVariable(v.currentCode().thisNode, v.constructorContext());
    }

    @Override
    public int numArgumentsOnResultStack() {
        return 0;
    }

    @Override
    public boolean mayBeNull(AnalysisContext context) {
        return false;
    }

    @Override
    public <DFItem extends DataFlow.Item> Map<EdgeKey, DFItem> flowDispatch(
            DataFlowDispatch<DFItem> d, DFItem dfIn, FlowGraph<DFItem> graph,
            Peer<DFItem> peer) {
        Special n = (Special) this.node();
        return d.flowSpecial(n, dfIn, graph, peer);
    }

}
