polyglot.visit
Class CppTranslator

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

public class CppTranslator
extends TypedTranslator


Field Summary
protected  Context context
           
protected static java.util.HashMap createdFiles
           
 
Fields inherited from class polyglot.visit.Translator
job, nf, tf, ts
 
Fields inherited from class polyglot.visit.PrettyPrinter
appendSemicolon, printType
 
Constructor Summary
CppTranslator(Job job, TypeSystem ts, NodeFactory nf, TargetFactory tf)
           
 
Method Summary
protected static boolean cppBackend()
           
static java.lang.String cScope(java.lang.String s)
          Turns a package or class name from Java "x.y.z" format into a C-style scope ("x::y::z")
 java.lang.String cTypeString(Type type)
           
static java.util.HashMap getFileNames()
           
 HeaderTranslator headerContext(Context c)
          Create a new Translator identical to this, except: a) wrapped inside a HeaderTranslator object, and b) with a new context c
 void print(Node parent, Node child, CodeWriter w)
          Print an ast node using the given code writer.
protected  boolean translateSource(SourceFile sfn)
          Transate a single SourceFile node
protected  void writeFooter(SourceFile sfn, CodeWriter w)
          C++ files also require a footer terminal '}' because they need to close the namespace they're opening.
protected  void writeHeader(SourceFile sfn, CodeWriter w)
          Write the package and import declarations for a source file.
protected  void writeHFileFooter(SourceFile sfn, CodeWriter w)
          Write the footer of the .h file if we're in C++ mode
protected  void writeHFileHeader(SourceFile sfn, java.lang.String className, CodeWriter w)
          Write the opening lines of the header file for a given class
 
Methods inherited from class polyglot.visit.TypedTranslator
context, context, translateTopLevelDecl
 
Methods inherited from class polyglot.visit.Translator
copy, exports, job, macroEscape, nodeFactory, targetFactory, toString, translate, typeSystem
 
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

context

protected Context context

createdFiles

protected static java.util.HashMap createdFiles
Constructor Detail

CppTranslator

public CppTranslator(Job job,
                     TypeSystem ts,
                     NodeFactory nf,
                     TargetFactory tf)
Method Detail

cppBackend

protected static boolean cppBackend()

getFileNames

public static java.util.HashMap getFileNames()

headerContext

public HeaderTranslator headerContext(Context c)
Create a new Translator identical to this, except: a) wrapped inside a HeaderTranslator object, and b) with a new context c

Parameters:
c - - the new context to use
Returns:
- a header translator identical to this one, but with new context.

cScope

public static java.lang.String cScope(java.lang.String s)
Turns a package or class name from Java "x.y.z" format into a C-style scope ("x::y::z")

Parameters:
s - the input package or class name
Returns:
A c-scoped version of s

cTypeString

public java.lang.String cTypeString(Type type)

print

public void print(Node parent,
                  Node child,
                  CodeWriter w)
Description copied from class: Translator
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 TypedTranslator

translateSource

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

Overrides:
translateSource in class Translator

writeHFileHeader

protected void writeHFileHeader(SourceFile sfn,
                                java.lang.String className,
                                CodeWriter w)
Write the opening lines of the header file for a given class

Parameters:
sfn - - representation of the source file we're compiling; used for Imports.
className - - The name of the class we're describing
w - - The CodeWriter to write it all out to (the .h file)

writeHFileFooter

protected void writeHFileFooter(SourceFile sfn,
                                CodeWriter w)
Write the footer of the .h file if we're in C++ mode

Parameters:
w -

writeFooter

protected void writeFooter(SourceFile sfn,
                           CodeWriter w)
C++ files also require a footer terminal '}' because they need to close the namespace they're opening.


writeHeader

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

Overrides:
writeHeader in class Translator