package accrue.analysis.ext;

import java.util.Map;

import polyglot.ast.Expr;
import polyglot.ast.Local;
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;
import accrue.analysis.pointer.RegisterPointerStmtsVisitor;
import accrue.analysis.pointer.StmtRegistrar;

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

    @Override
    public void registerPointerStmts(StmtRegistrar registrar,
            RegisterPointerStmtsVisitor v) {
        Expr e = (Expr) this.node();
        if (!e.type().isReference()) return;

        registrar.updateReferenceVariable((Local) this.node(),
                              v.currentCode(),
                              v.constructorContext());
    }

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

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

}
