package accrue.analysis.callgraph;

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

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

public class PreciseCallGraphPass extends InterProcAnalysisPass<PCGAbsVal> {

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

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

    private PreciseCallGraphPass(ExtensionInfo extInfo, Registrar registrar,
            AnalysisFactory<PCGAbsVal> analysisFactory, int i) {
        super(extInfo,
              PreciseCallGraphGoal.singleton(extInfo, i),
              registrar,
              analysisFactory);
    }

}
