polyglot.visit
Class Translator

java.lang.Object
  extended by polyglot.visit.PrettyPrinter
      extended by polyglot.visit.Translator
All Implemented Interfaces:
java.lang.Cloneable, Copy
Direct Known Subclasses:
TypedTranslator

public class Translator
extends PrettyPrinter
implements Copy

A Translator generates output code from the processed AST. Output is sent to one or more java file in the directory Options.output_directory. Each SourceFile in the AST is output to exactly one java file. The name of that file is determined as follows:

To use:
     new Translator(job, ts, nf, tf).translate(ast);
 
The ast must be either a SourceFile or a SourceCollection.


Field Summary
protected  Context context
          The current typing context, or null if type information is unavailable in this subtree of the AST.
protected  Job job
           
protected  NodeFactory nf
           
protected  TargetFactory tf
           
protected  TypeSystem ts
           
 
Fields inherited from class polyglot.visit.PrettyPrinter
appendSemicolon, printType
 
Constructor Summary
Translator(Job job, TypeSystem ts, NodeFactory nf, TargetFactory tf)
          Create a Translator.
 
Method Summary
 Context context()
          Get the current typing context, or null.
 Translator context(Context c)
          Create a new Translator identical to this but with new context c
 java.lang.Object copy()
          Copy the translator.
protected  java.util.List exports(SourceFile sfn)
          Get the list of public top-level classes declared in the source file.
 Job job()
          Return the job associated with this Translator.
 NodeFactory nodeFactory()
          Get the extension's node factory.
 void print(Node parent, Node child, CodeWriter w)
          Print an ast node using the given code writer.
 java.lang.String toString()
           
 boolean translate(Node ast)
          Translate the entire AST.
protected  boolean translateSource(SourceFile sfn)
          Translate a single SourceFile node
protected  void translateTopLevelDecl(CodeWriter w, SourceFile source, TopLevelDecl decl)
          Translate a top-level declaration decl of source file source.
 TypeSystem typeSystem()
          Get the extension's type system.
protected  void writeHeader(SourceFile sfn, CodeWriter w)
          Write the package and import declarations for a source file.
 
Methods inherited from class polyglot.visit.PrettyPrinter
appendSemicolon, appendSemicolon, printAst, printType, printType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

job

protected Job job

nf

protected NodeFactory nf

tf

protected TargetFactory tf

ts

protected TypeSystem ts

context

protected Context context
The current typing context, or null if type information is unavailable in this subtree of the AST.

Constructor Detail

Translator

public Translator(Job job,
                  TypeSystem ts,
                  NodeFactory nf,
                  TargetFactory tf)
Create a Translator. The output of the visitor is a collection of files whose names are added to the collection outputFiles.

Method Detail

job

public Job job()
Return the job associated with this Translator.


copy

public java.lang.Object copy()
Copy the translator.

Specified by:
copy in interface Copy

typeSystem

public TypeSystem typeSystem()
Get the extension's type system.


nodeFactory

public NodeFactory nodeFactory()
Get the extension's node factory.


context

public Context context()
Get the current typing context, or null.


context

public Translator context(Context c)
Create a new Translator identical to this but with new context c


print

public void print(Node parent,
                  Node child,
                  CodeWriter w)
Print an ast node using the given code writer. This method should not be called directly to translate a source file AST; use translate(Node) instead. This method should only be called by nodes to print their children.

Overrides:
print in class PrettyPrinter

translate

public boolean translate(Node ast)
Translate the entire AST.


translateSource

protected boolean translateSource(SourceFile sfn)
Translate a single SourceFile node


translateTopLevelDecl

protected void translateTopLevelDecl(CodeWriter w,
                                     SourceFile source,
                                     TopLevelDecl decl)
Translate a top-level declaration decl of source file source.

Parameters:
w -
source -
decl -

writeHeader

protected void writeHeader(SourceFile sfn,
                           CodeWriter w)
Write the package and import declarations for a source file.


exports

protected java.util.List exports(SourceFile sfn)
Get the list of public top-level classes declared in the source file.


toString

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