/**
 * 
 */
package accrue.analysis.readwritesets;

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

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

/**
 * Goal for the analysis that gathers the set of locations read an written by a 
 * procedure
 */
public class ReadWriteSetsGoal extends AbstractGoal {

    /**
     * Create a singleton goal
     * 
     * @param extInfo
     *          Accrue extension information
     *          
     * @return singleton goal
     */
    public static Goal singleton(ExtensionInfo extInfo) {
        Scheduler scheduler = extInfo.scheduler();
        return scheduler.internGoal(new ReadWriteSetsGoal());
    }

    /**
     * Create a new goal object with a null {@link Job}
     */
    protected ReadWriteSetsGoal() {
        super(null, "ReadWriteSetsGoal");

    }

    @Override
    public Collection<Goal> prerequisiteGoals(Scheduler scheduler) {
        List<Goal> l = new ArrayList<Goal>();
        l.add(((AccrueScheduler) scheduler).helper().RegisterProceduresDone());
        l.add(((AccrueScheduler) scheduler).helper().PointerAnalysis());
        l.addAll(super.prerequisiteGoals(scheduler));
        return l;
    }

    @Override
    public Pass createPass(ExtensionInfo extInfo) {
        return ReadWriteSetsPass.singleton((AccrueExtensionInfo) extInfo, this);
    }
}
