package accrue.analysis.ext;

import java.util.Map;

import polyglot.ast.Return;
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 ExtReturn extends ExtTerm {
    private static final long serialVersionUID = SerialVersionUID.generate();

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

        Return ret = (Return) this.node();
        if (ret.expr() != null && ret.expr().type().isReference()) {
            registrar.addAssignment(v.currentCode().retValue,
                                    v.getReferenceVariable(ret.expr()),
                                    ret.position(),
                                    v.currentCode());
        }

    }

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

}
