package accrue.analysis.ast;

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

import polyglot.ast.ClassBody;
import polyglot.ast.Expr;
import polyglot.ast.New_c;
import polyglot.ast.TypeNode;
import polyglot.util.Position;
import polyglot.util.SerialVersionUID;
import polyglot.visit.CFGBuilder;
import accrue.analysis.ext.ExtNew;
import accrue.analysis.ext.AccrueExt_c;
import accrue.analysis.interprocanalysis.PreciseDataFlow;

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

    public AccrueNew_c(Position pos, Expr qualifier, TypeNode tn,
            List<Expr> arguments, ClassBody body) {
        super(pos, qualifier, tn, arguments, body);
    }

    @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();
            ExtNew ec = (ExtNew) AccrueExt_c.ext(this);
            if (!ec.canTerminateNormally(pdf.currentContext())) {
                // call cannot terminate normally.
                return Collections.emptyList();
            }
        }
        return l;
    }
}
