package accrue.analysis.ast;

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

import polyglot.ast.ConstructorCall_c;
import polyglot.ast.Expr;
import polyglot.util.Position;
import polyglot.util.SerialVersionUID;
import polyglot.visit.CFGBuilder;
import accrue.analysis.ext.ExtConstructorCall;
import accrue.analysis.ext.AccrueExt_c;
import accrue.analysis.interprocanalysis.PreciseDataFlow;

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

    public AccrueConstructorCall_c(Position pos, Kind kind, Expr qualifier,
            List<? extends Expr> arguments) {
        super(pos, kind, qualifier, 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();
            ExtConstructorCall ec = (ExtConstructorCall) AccrueExt_c.ext(this);
            if (!ec.canTerminateNormally(pdf.currentContext())) {
                // call cannot terminate normally.
                return Collections.emptyList();
            }
        }
        return l;
    }
}
