package accrue.analysis.preciseExceptions;

import java.util.HashMap;
import java.util.Map;

import polyglot.frontend.ExtensionInfo;
import accrue.AccrueExtensionInfo;
import accrue.analysis.goals.RegisterProceduresGoal;
import accrue.analysis.interprocanalysis.InterProcAnalysisPass;
import accrue.analysis.interprocanalysis.Registrar;

public class PreciseExPass extends InterProcAnalysisPass<PreciseExAbsVal> {

    static private Map<ExtensionInfo, Map<Integer, PreciseExPass>> singletons =
            new HashMap<ExtensionInfo, Map<Integer, PreciseExPass>>();

    static public PreciseExPass singleton(AccrueExtensionInfo extInfo, int i) {
        Map<Integer, PreciseExPass> m = singletons.get(extInfo);
        if (m == null) {
            m = new HashMap<Integer, PreciseExPass>();
            singletons.put(extInfo, m);
        }
        PreciseExPass singleton = m.get(i);
        if (singleton == null) {
            singleton =
                    new PreciseExPass(extInfo,
                                      RegisterProceduresGoal.registrar(extInfo),
                                      new PreciseExAnalysisFactory(extInfo),
                                      i);
            m.put(i, singleton);
        }
        return singleton;
    }

    private PreciseExPass(ExtensionInfo extInfo, Registrar registrar,
            PreciseExAnalysisFactory analysisFactory, int i) {
        super(extInfo,
              PreciseExGoal.singleton(extInfo, i),
              registrar,
              analysisFactory);
    }

}
