polyglot.frontend
Class Job

java.lang.Object
  extended by polyglot.frontend.Job
Direct Known Subclasses:
InnerJob, SourceJob

public abstract class Job
extends java.lang.Object

A Job encapsulates work done by the compiler. Jobs are typically associated either with a nested class (InnerJobs) or a source file (SourceJobs). A Job contains all information carried between phases of the compiler. A Job consists of a set of scheduled passes over the associated code.


Field Summary
protected  Node ast
          The AST constructed from the source file.
protected  JobExt ext
          Field used for storing extension-specific information.
protected  int initialErrorCount
          Initial count of errors before running the job.
protected  ExtensionInfo lang
          The language extension used for this job.
protected  int nextPass
          Index of the next pass to run.
protected  java.util.ArrayList passes
          List of passes to be run on this job.
protected  java.util.Map passMap
          Map from pass id to pass.
protected  boolean reportedErrors
          True if the the job has reported an error.
protected  Pass runningPass
          The currently running pass, or null.
protected  boolean status
          True if all passes run so far have been successful.
 
Constructor Summary
Job(ExtensionInfo lang, JobExt ext, Node ast)
           
 
Method Summary
 Node ast()
          Get the state's AST.
 void ast(Node ast)
          Set the state's AST.
 Compiler compiler()
           
 boolean completed()
          Return true if all of the passes been completed.
 boolean completed(Pass.ID id)
          Return true if the pass id has been completed.
 java.util.List completedPasses()
          Return a list of passes that have been completed so far.
 Context context()
          By default, a Job does not have a context associated with it.
 void dump(CodeWriter cw)
           
 JobExt ext()
           
 ExtensionInfo extensionInfo()
           
 void finishPass(Pass p, boolean okay)
          Inform this Job that pass p has finished.
protected abstract  java.util.List getPasses()
          Get the initial list of passes that this Job should go through.
 Pass getPreviousTo(Pass.ID id)
          Return the pass immediately before the pass identified by id.
protected  void init()
          Initialize the passes field and the passMap field.
 boolean isRunning()
           
 BarrierPass lastBarrier()
          Return the last BarrierPass that this job completed; return null if no BarrierPasses have yet been completed
 Pass nextPass()
          Return the next pass to be performed.
 Pass passByID(Pass.ID id)
          Get the pass identified by id.
 java.util.List passes()
          Get the list of passes that this Job needs to go through.
 boolean pending(Pass.ID id)
          Return true if the pass id is still pending.
 java.util.List pendingPasses()
          Return a list of passes that still have to be performed.
 boolean reportedErrors()
          True if some pass reported an error.
 Pass runningPass()
           
 void setRunningPass(Pass pass)
           
 Source source()
          Return the Source associated with the SourceJob returned by sourceJob.
abstract  SourceJob sourceJob()
          Get the SourceJob associated with this Job.
 Job spawn(Context c, Node ast, Pass.ID begin, Pass.ID end)
          Spawn a new job.
 boolean status()
           
 boolean userSpecified()
          Returns whether the source for this job was explicitly specified by the user, or if it was drawn into the compilation process due to some dependency.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ext

protected JobExt ext
Field used for storing extension-specific information.


lang

protected ExtensionInfo lang
The language extension used for this job.


ast

protected Node ast
The AST constructed from the source file.


passes

protected java.util.ArrayList passes
List of passes to be run on this job.


nextPass

protected int nextPass
Index of the next pass to run.


runningPass

protected Pass runningPass
The currently running pass, or null.


status

protected boolean status
True if all passes run so far have been successful.


passMap

protected java.util.Map passMap
Map from pass id to pass.


initialErrorCount

protected int initialErrorCount
Initial count of errors before running the job.


reportedErrors

protected boolean reportedErrors
True if the the job has reported an error.

Constructor Detail

Job

public Job(ExtensionInfo lang,
           JobExt ext,
           Node ast)
Method Detail

ext

public JobExt ext()

lastBarrier

public BarrierPass lastBarrier()
Return the last BarrierPass that this job completed; return null if no BarrierPasses have yet been completed


setRunningPass

public void setRunningPass(Pass pass)

isRunning

public boolean isRunning()

runningPass

public Pass runningPass()

ast

public Node ast()
Get the state's AST.


ast

public void ast(Node ast)
Set the state's AST.


reportedErrors

public boolean reportedErrors()
True if some pass reported an error.


dump

public void dump(CodeWriter cw)

context

public Context context()
By default, a Job does not have a context associated with it. Subclasses may override this method.


sourceJob

public abstract SourceJob sourceJob()
Get the SourceJob associated with this Job. If this Job is a SourceJob, then this object should be returned; otherwise the most suitable SourceJob should be returned. See subclasses' documentation for more details of what the most suitable SourceJob is.


source

public Source source()
Return the Source associated with the SourceJob returned by sourceJob.


userSpecified

public boolean userSpecified()
Returns whether the source for this job was explicitly specified by the user, or if it was drawn into the compilation process due to some dependency.


getPasses

protected abstract java.util.List getPasses()
Get the initial list of passes that this Job should go through. This method is called only once, from init.


passes

public final java.util.List passes()
Get the list of passes that this Job needs to go through. This list is initialized with the list returned by getPasses.


init

protected void init()
Initialize the passes field and the passMap field.


completed

public boolean completed()
Return true if all of the passes been completed.


completedPasses

public java.util.List completedPasses()
Return a list of passes that have been completed so far. The list returned by completedPasses concatenated with the list returned by pendingPasses should be equivalent to the list returned by passes.


pendingPasses

public java.util.List pendingPasses()
Return a list of passes that still have to be performed. The list returned by completedPasses concatenated with the list returned by pendingPasses should be equivalent to the list returned by passes.


completed

public boolean completed(Pass.ID id)
Return true if the pass id has been completed.


pending

public boolean pending(Pass.ID id)
Return true if the pass id is still pending.


passByID

public Pass passByID(Pass.ID id)
Get the pass identified by id.


getPreviousTo

public Pass getPreviousTo(Pass.ID id)
Return the pass immediately before the pass identified by id. Return null if no such pass exists.


nextPass

public Pass nextPass()
Return the next pass to be performed. Return null if there are no passes left to be performed.


status

public boolean status()

finishPass

public void finishPass(Pass p,
                       boolean okay)
Inform this Job that pass p has finished. If okay is true, then the pass was completed successfully; if it is false the pass was not completed successfully. Pass p may be any pending pass.


extensionInfo

public ExtensionInfo extensionInfo()

compiler

public Compiler compiler()

spawn

public Job spawn(Context c,
                 Node ast,
                 Pass.ID begin,
                 Pass.ID end)
Spawn a new job. All passes between the pass begin and end inclusive will be performed immediately on the AST ast, and the resulting AST returned. Spawn a new job. All passes between the pass begin and end inclusive will be performed immediately on the AST ast.

Parameters:
c - the context that the AST occurs in
ast - the AST the new Job is for.
begin - the first pass to perform for this job.
end - the last pass to perform for this job.
Returns:
the new job. The caller can check the result with j.status() and get the ast with j.ast().