package accrue.analysis.domination;

import polyglot.ast.ProcedureDecl;
import polyglot.types.SemanticException;
import polyglot.util.InternalCompilerError;
import accrue.AccrueExtensionInfo;
import accrue.analysis.AnalysisTopics;
import accrue.analysis.interprocanalysis.AnalysisFactory;
import accrue.analysis.interprocanalysis.AnalysisUnit;
import accrue.analysis.interprocanalysis.AnalysisUtil;
import accrue.analysis.interprocanalysis.Unit;
import accrue.analysis.interprocanalysis.WorkQueue;

public class DominationAnalysisFactory extends AnalysisFactory<Unit> {
    private final DominationPass.Kind kind;

    public DominationAnalysisFactory(DominationPass.Kind kind,
            AccrueExtensionInfo extInfo) {
        super(extInfo);
        this.kind = kind;
    }

    @Override
    public String analysisName() {
        return "accrue.analysis.domination";
    }

    @Override
    public String analysisReportName() {
        switch (kind) {
        case POSTDOMINATION:
        case NONFATALPOSTDOMINATION:
            return AnalysisTopics.POST_DOMINATOR;
        case DOMINATION:
            return AnalysisTopics.DOMINATOR;
        }
        throw new InternalCompilerError("Unknown kind: " + kind);
    }

    public Unit bottomValDFI() {
        return Unit.UNIT;
    }

    @Override
    public Unit startItem(AnalysisUtil<Unit> autil, ProcedureDecl startProc)
            throws SemanticException {
        // the DFIContext for main(String[] args)
        return Unit.UNIT;
    }

    @Override
    public AnalysisUtil<Unit> analysisUtil(WorkQueue<Unit> wq,
            AnalysisUnit aunit) {
        return new DominationAnalysisUtil(wq, aunit, extInfo, kind);
    }

}
