/**
 * 
 */
package accrue.analysis.ctldep;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import polyglot.frontend.ExtensionInfo;
import polyglot.frontend.Pass;
import polyglot.frontend.Scheduler;
import polyglot.frontend.goals.AbstractGoal;
import polyglot.frontend.goals.Goal;
import polyglot.util.InternalCompilerError;
import accrue.AccrueExtensionInfo;
import accrue.AccrueScheduler;

public class CtlDepGoal extends AbstractGoal {
    public static Goal singleton(ExtensionInfo extInfo) {
        Scheduler scheduler = extInfo.scheduler();
        return scheduler.internGoal(new CtlDepGoal());
    }

    protected CtlDepGoal() {
        super(null, "CtlDepGoal");
    }

    @Override
    public Collection<Goal> prerequisiteGoals(Scheduler scheduler) {
        List<Goal> l = new ArrayList<Goal>();
        l.add(((AccrueScheduler) scheduler).helper()
                                           .PreciseExceptionAnalysis(1));
        l.add(((AccrueScheduler) scheduler).helper().PreciseCallGraph());
        l.add(((AccrueScheduler) scheduler).helper().DefUseAnalysis());
        l.add(((AccrueScheduler) scheduler).helper().NonFatalPostDominator());
        l.add(((AccrueScheduler) scheduler).helper().RegisterExpressions());
        l.addAll(super.prerequisiteGoals(scheduler));
        return l;
    }

    @Override
    public Pass createPass(ExtensionInfo extInfo) {
        if (extInfo instanceof AccrueExtensionInfo)
            return CtlDepPass.singleton((AccrueExtensionInfo) extInfo);
        throw new InternalCompilerError(getClass()
                + " requires an AccrueExtensionInfo extension.");
    }
}
