polyglot.frontend
Class AbstractExtensionInfo

java.lang.Object
  extended by polyglot.frontend.AbstractExtensionInfo
All Implemented Interfaces:
ExtensionInfo
Direct Known Subclasses:
ExtensionInfo

public abstract class AbstractExtensionInfo
extends java.lang.Object
implements ExtensionInfo

This is an abstract ExtensionInfo.


Field Summary
protected  Compiler compiler
           
protected static java.lang.Object COMPLETED_JOB
           
protected  Job currentJob
          The currently running job, or null if no job is running.
protected  java.util.Map jobs
          A map from Sources to SourceJobs or to the COMPLETED_JOB object if the SourceJob previously existed but has now finished.
protected  NodeFactory nf
           
protected  SourceLoader source_loader
           
protected  Stats stats
           
protected  TargetFactory target_factory
           
protected  TypeSystem ts
           
protected  java.util.LinkedList worklist
          A list of all active (that is, uncompleted) SourceJobs.
 
Constructor Summary
AbstractExtensionInfo()
           
 
Method Summary
 void addDependencyToCurrentJob(Source s)
          Adds a dependency from the current job to the given Source.
 SourceJob addJob(Source source)
          Add a new SourceJob for the Source source.
 SourceJob addJob(Source source, Node ast)
          Add a new SourceJob for the Source source, with AST ast.
 void afterPass(java.util.List passes, Pass.ID id, java.util.List newPasses)
          Insert the list of newPasses into passes immediately after the pass named id.
 void afterPass(java.util.List passes, Pass.ID id, Pass pass)
          Insert the pass pass into passes immediately after the pass named id.
 void beforePass(java.util.List passes, Pass.ID id, java.util.List newPasses)
          Insert the list of newPasses into passes immediately before the pass named id.
 void beforePass(java.util.List passes, Pass.ID id, Pass pass)
          Insert the pass pass into passes immediately before the pass named id.
 Compiler compiler()
           
 ClassFile createClassFile(java.io.File classFileSource, byte[] code)
          Create class file
protected  Job createJob(Node ast, Context context, Job outer, Pass.ID begin, Pass.ID end)
          Create a new non-SourceJob Job, for the given AST.
protected abstract  NodeFactory createNodeFactory()
          Create the node factory for this extension.
protected  Options createOptions()
           
protected  SourceJob createSourceJob(Source source, Node ast)
          Create a new SourceJob for the given source and AST.
protected abstract  TypeSystem createTypeSystem()
          Create the type system for this extension.
 java.lang.String[] defaultFileExtensions()
          Get the default list of file extensions.
protected  void enforceInvariants(Job job, Pass pass)
          Before running Pass pass on SourceJob job make sure that all appropriate scheduling invariants are satisfied, to ensure that all passes of other jobs that job depends on will have already been done.
 java.lang.String[] fileExtensions()
          Get the file name extension of source files.
 Options getOptions()
          Return an Options object, which will be given the command line to parse.
 Stats getStats()
          Return a Stats object to accumulate and report statistics.
 void initCompiler(Compiler compiler)
          Initialize the extension with a particular compiler.
protected abstract  void initTypeSystem()
           
 JobExt jobExt()
          Get the job extension for this language extension.
 NodeFactory nodeFactory()
          Get the AST node factory for this extension.
abstract  Parser parser(java.io.Reader reader, FileSource source, ErrorQueue eq)
          Get the parser for this language extension.
abstract  java.util.List passes(Job job)
          Get the complete list of passes for the job.
 java.util.List passes(Job job, Pass.ID begin, Pass.ID end)
          Get the sub-list of passes for the job between passes begin and end, inclusive.
 boolean readSource(FileSource source)
          Read a source file and compile it up to the the current job's last barrier.
 void removePass(java.util.List passes, Pass.ID id)
          Remove the pass named id from passes.
 void replacePass(java.util.List passes, Pass.ID id, java.util.List newPasses)
          Replace the pass named id in passes with the list of newPasses.
 void replacePass(java.util.List passes, Pass.ID id, Pass pass)
          Replace the pass named id in passes with the pass pass.
 boolean runAllPasses(Job job)
          Run all pending passes on job.
protected  void runPass(Job job, Pass pass)
          Run the pass pass on the job.
 boolean runToCompletion()
          Run all jobs in the work list (and any children they have) to completion.
 boolean runToPass(Job job, Pass.ID goal)
          Run a job until the goal pass completes.
 boolean runToPass(Job job, Pass goal)
          Run a job up to the goal pass.
protected  SourceJob selectJobFromWorklist()
          Select and remove a SourceJob from the non-empty worklist.
 SourceLoader sourceLoader()
          Get the source file loader object for this extension.
 Job spawnJob(Context c, Node ast, Job outerJob, Pass.ID begin, Pass.ID end)
          Spawn a new job.
 TargetFactory targetFactory()
          Get the target factory object for this extension.
 java.lang.String toString()
           
 TypeSystem typeSystem()
          Get the type system for this extension.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface polyglot.frontend.ExtensionInfo
compilerName, defaultFileExtension, version
 

Field Detail

compiler

protected Compiler compiler

ts

protected TypeSystem ts

nf

protected NodeFactory nf

source_loader

protected SourceLoader source_loader

target_factory

protected TargetFactory target_factory

stats

protected Stats stats

worklist

protected java.util.LinkedList worklist
A list of all active (that is, uncompleted) SourceJobs.


jobs

protected java.util.Map jobs
A map from Sources to SourceJobs or to the COMPLETED_JOB object if the SourceJob previously existed but has now finished. The map contains entries for all Sources that have had Jobs added for them.


COMPLETED_JOB

protected static final java.lang.Object COMPLETED_JOB

currentJob

protected Job currentJob
The currently running job, or null if no job is running.

Constructor Detail

AbstractExtensionInfo

public AbstractExtensionInfo()
Method Detail

getOptions

public Options getOptions()
Description copied from interface: ExtensionInfo
Return an Options object, which will be given the command line to parse.

Specified by:
getOptions in interface ExtensionInfo

createOptions

protected Options createOptions()

getStats

public Stats getStats()
Return a Stats object to accumulate and report statistics.

Specified by:
getStats in interface ExtensionInfo

compiler

public Compiler compiler()
Specified by:
compiler in interface ExtensionInfo

initCompiler

public void initCompiler(Compiler compiler)
Description copied from interface: ExtensionInfo
Initialize the extension with a particular compiler. This must be called after the compiler is initialized, but before the compiler starts work.

Specified by:
initCompiler in interface ExtensionInfo

initTypeSystem

protected abstract void initTypeSystem()

runToCompletion

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

Specified by:
runToCompletion in interface ExtensionInfo

selectJobFromWorklist

protected SourceJob selectJobFromWorklist()
Select and remove a SourceJob from the non-empty worklist. Return the selected SourceJob which will be scheduled to run all of its remaining passes.


readSource

public boolean readSource(FileSource source)
Read a source file and compile it up to the the current job's last barrier.

Specified by:
readSource in interface ExtensionInfo

runAllPasses

public boolean runAllPasses(Job job)
Run all pending passes on job.

Specified by:
runAllPasses in interface ExtensionInfo

runToPass

public boolean runToPass(Job job,
                         Pass.ID goal)
Run a job until the goal pass completes.

Specified by:
runToPass in interface ExtensionInfo

runToPass

public boolean runToPass(Job job,
                         Pass goal)
Run a job up to the goal pass.


runPass

protected void runPass(Job job,
                       Pass pass)
                throws CyclicDependencyException
Run the pass pass on the job. Before running the pass on the job, if the job is a SourceJob, then this method will ensure that the scheduling invariants are enforced by calling enforceInvariants.

Throws:
CyclicDependencyException

enforceInvariants

protected void enforceInvariants(Job job,
                                 Pass pass)
                          throws CyclicDependencyException
Before running Pass pass on SourceJob job make sure that all appropriate scheduling invariants are satisfied, to ensure that all passes of other jobs that job depends on will have already been done.

Throws:
CyclicDependencyException

fileExtensions

public java.lang.String[] fileExtensions()
Get the file name extension of source files. This is either the language extension's default file name extension or the string passed in with the "-sx" command-line option.

Specified by:
fileExtensions in interface ExtensionInfo

defaultFileExtensions

public java.lang.String[] defaultFileExtensions()
Get the default list of file extensions.

Specified by:
defaultFileExtensions in interface ExtensionInfo

sourceLoader

public SourceLoader sourceLoader()
Get the source file loader object for this extension.

Specified by:
sourceLoader in interface ExtensionInfo

targetFactory

public TargetFactory targetFactory()
Get the target factory object for this extension.

Specified by:
targetFactory in interface ExtensionInfo

createTypeSystem

protected abstract TypeSystem createTypeSystem()
Create the type system for this extension.


typeSystem

public TypeSystem typeSystem()
Get the type system for this extension.

Specified by:
typeSystem in interface ExtensionInfo

createNodeFactory

protected abstract NodeFactory createNodeFactory()
Create the node factory for this extension.


nodeFactory

public NodeFactory nodeFactory()
Get the AST node factory for this extension.

Specified by:
nodeFactory in interface ExtensionInfo

jobExt

public JobExt jobExt()
Get the job extension for this language extension. The job extension is used to extend the Job class without subtyping.


addDependencyToCurrentJob

public void addDependencyToCurrentJob(Source s)
Adds a dependency from the current job to the given Source.

Specified by:
addDependencyToCurrentJob in interface ExtensionInfo

addJob

public SourceJob addJob(Source source)
Add a new SourceJob for the Source source. A new job will be created if needed. If the Source source has already been processed, and its job discarded to release resources, then null will be returned.

Specified by:
addJob in interface ExtensionInfo

addJob

public SourceJob addJob(Source source,
                        Node ast)
Add a new SourceJob for the Source source, with AST ast. A new job will be created if needed. If the Source source has already been processed, and its job discarded to release resources, then null will be returned.

Specified by:
addJob in interface ExtensionInfo

createSourceJob

protected SourceJob createSourceJob(Source source,
                                    Node ast)
Create a new SourceJob for the given source and AST. In general, this method should only be called by addJob.


createJob

protected Job createJob(Node ast,
                        Context context,
                        Job outer,
                        Pass.ID begin,
                        Pass.ID end)
Create a new non-SourceJob Job, for the given AST. In general this method should only be called by spawnJob.

Parameters:
ast - the AST the new Job is for.
context - the context that the AST occurs in
outer - the Job that spawned this job.
begin - the first pass to perform for this job.
end - the last pass to perform for this job.

spawnJob

public Job spawnJob(Context c,
                    Node ast,
                    Job outerJob,
                    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.

Specified by:
spawnJob in interface ExtensionInfo
Parameters:
c - the context that the AST occurs in
ast - the AST the new Job is for.
outerJob - the Job that spawned this job.
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().

parser

public abstract Parser parser(java.io.Reader reader,
                              FileSource source,
                              ErrorQueue eq)
Get the parser for this language extension.

Specified by:
parser in interface ExtensionInfo

replacePass

public void replacePass(java.util.List passes,
                        Pass.ID id,
                        java.util.List newPasses)
Replace the pass named id in passes with the list of newPasses.

Specified by:
replacePass in interface ExtensionInfo

removePass

public void removePass(java.util.List passes,
                       Pass.ID id)
Remove the pass named id from passes.

Specified by:
removePass in interface ExtensionInfo

beforePass

public void beforePass(java.util.List passes,
                       Pass.ID id,
                       java.util.List newPasses)
Insert the list of newPasses into passes immediately before the pass named id.

Specified by:
beforePass in interface ExtensionInfo

afterPass

public void afterPass(java.util.List passes,
                      Pass.ID id,
                      java.util.List newPasses)
Insert the list of newPasses into passes immediately after the pass named id.

Specified by:
afterPass in interface ExtensionInfo

replacePass

public void replacePass(java.util.List passes,
                        Pass.ID id,
                        Pass pass)
Replace the pass named id in passes with the pass pass.

Specified by:
replacePass in interface ExtensionInfo

beforePass

public void beforePass(java.util.List passes,
                       Pass.ID id,
                       Pass pass)
Insert the pass pass into passes immediately before the pass named id.

Specified by:
beforePass in interface ExtensionInfo

afterPass

public void afterPass(java.util.List passes,
                      Pass.ID id,
                      Pass pass)
Insert the pass pass into passes immediately after the pass named id.

Specified by:
afterPass in interface ExtensionInfo

passes

public abstract java.util.List passes(Job job)
Get the complete list of passes for the job.

Specified by:
passes in interface ExtensionInfo

passes

public java.util.List passes(Job job,
                             Pass.ID begin,
                             Pass.ID end)
Get the sub-list of passes for the job between passes begin and end, inclusive.

Specified by:
passes in interface ExtensionInfo

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createClassFile

public ClassFile createClassFile(java.io.File classFileSource,
                                 byte[] code)
Description copied from interface: ExtensionInfo
Create class file

Specified by:
createClassFile in interface ExtensionInfo