Ejemplo n.º 1
0
  /**
   * Run all jobs in the work list (and any children they have) to completion. This method returns
   * <code>true</code> if all jobs were successfully completed. If all jobs were successfully
   * completed, then the worklist will be empty.
   *
   * <p>The scheduling of <code>Job</code>s uses two methods to maintain scheduling invariants:
   * <code>selectJobFromWorklist</code> selects a <code>SourceJob</code> from <code>worklist</code>
   * (a list of jobs that still need to be processed); <code>enforceInvariants</code> is called
   * before a pass is performed on a <code>SourceJob</code> and is responsible for ensuring all
   * dependencies are satisfied before the pass proceeds, i.e. enforcing any scheduling invariants.
   */
  public boolean runToCompletion() {
    boolean okay = true;

    while (okay && !worklist.isEmpty()) {
      SourceJob job = selectJobFromWorklist();

      if (Report.should_report(Report.frontend, 1)) {
        Report.report(1, "Running job " + job);
      }

      okay &= runAllPasses(job);

      if (job.completed()) {
        // the job has finished. Let's remove it from the map so it
        // can be garbage collected, and free up the AST.
        jobs.put(job.source(), COMPLETED_JOB);

        if (Report.should_report(Report.frontend, 1)) {
          Report.report(1, "Completed job " + job);
        }
      } else {
        // the job is not yet completed (although, it really
        // should be...)
        if (Report.should_report(Report.frontend, 1)) {
          Report.report(1, "Failed to complete job " + job);
        }
        worklist.add(job);
      }
    }

    if (Report.should_report(Report.frontend, 1))
      Report.report(1, "Finished all passes -- " + (okay ? "okay" : "failed"));

    return okay;
  }