package accrue.analysis.ast;

import java.util.Collections;
import java.util.List;

import polyglot.ast.Call_c;
import polyglot.ast.Expr;
import polyglot.ast.Id;
import polyglot.ast.Receiver;
import polyglot.util.Position;
import polyglot.util.SerialVersionUID;
import polyglot.visit.CFGBuilder;
import accrue.analysis.ext.AccrueExt_c;
import accrue.analysis.ext.ExtCall;
import accrue.analysis.interprocanalysis.PreciseDataFlow;

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

    public AccrueCall_c(Position pos, Receiver target, Id name,
            List<Expr> arguments) {
        super(pos, target, name, arguments);
    }

    @Override
    public <T> List<T> acceptCFG(CFGBuilder<?> v, List<T> succs) {
        List<T> l = super.acceptCFG(v, succs);
        if (v instanceof PreciseDataFlow.PreciseCFGBuilder) {
            PreciseDataFlow<?> pdf = (PreciseDataFlow<?>) v.dataflow();
            ExtCall ec = (ExtCall) AccrueExt_c.ext(this);
            if (!ec.canTerminateNormally(pdf.currentContext())) {
                // call cannot terminate normally.
                return Collections.emptyList();
            }
        }
        return l;
    }
}
