ptolemy.copernicus.c
Class CodeGenerator

java.lang.Object
  extended by ptolemy.copernicus.c.CodeGenerator
Direct Known Subclasses:
ClassStructureGenerator, CodeFileGenerator, HeaderFileGenerator, InstanceStructureGenerator, MainFileGenerator, StubFileGenerator

public abstract class CodeGenerator
extends java.lang.Object

A base class for C code generators in Ptolemy II.

Since:
Ptolemy II 2.0
Version:
$Id: CodeGenerator.java,v 1.43 2007/12/06 21:56:50 cxh Exp $
Author:
Shuvra S. Bhattacharyya
Accepted Rating:
Red (ssb)
Proposed Rating:
Red (ssb)

Field Summary
protected  Context _context
          Code generation context information.
protected  java.util.HashMap _requiredTypeMap
          Mapping from classes that the current class depends on to their include file names.
 
Constructor Summary
CodeGenerator()
          Construct a new code generator.
 
Method Summary
protected  java.lang.String _comment(java.lang.String text)
          Enclose a given string of text within appropriate delimiters to form a comment in the generated code.
protected  java.lang.String _generateArrayInstanceDeclarations()
          Generate code for typedef declaring array instances.
protected  java.lang.String _generateIncludeDirectives()
          Generate include directives for all types that are required for the class that we are generating code for.
protected  java.lang.String _generateMethodHeader(soot.SootMethod method)
          Generate header code for a method.
protected  java.lang.String _generateParameterTypeList(soot.SootMethod method)
          Generate code for the parameter type list of a method, excluding parentheses.
protected  java.util.Iterator _getRequiredIncludeFiles()
          Return an iterator over the include files required by the generated code.
protected  java.lang.String _indent(int level)
          Return a string that generates an indentation string (a sequence of spaces) for the given indentation level.
protected  void _removeRequiredType(soot.SootClass source)
          Remove a class from the list of required types (types whose associated include files must be imported) if the class exists in the list.
protected  void _updateRequiredTypes(soot.Type type)
          Register a type as a type that must be imported into the generated code through an #include directive.
protected  void _warn(java.lang.String message)
          Issue a warning message to standard error.
abstract  java.lang.String generate(soot.SootClass source)
          Given a class, return the code generated by this code generator for the class.
 void setSingleClassMode()
          Turn on (enable) single class mode translation (see Context.getSingleClassMode()).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_context

protected Context _context
Code generation context information.


_requiredTypeMap

protected java.util.HashMap _requiredTypeMap
Mapping from classes that the current class depends on to their include file names.

Constructor Detail

CodeGenerator

public CodeGenerator()
Construct a new code generator.

Method Detail

generate

public abstract java.lang.String generate(soot.SootClass source)
Given a class, return the code generated by this code generator for the class.

Parameters:
source - The class.
Returns:
The generated code.

setSingleClassMode

public void setSingleClassMode()
Turn on (enable) single class mode translation (see Context.getSingleClassMode()).


_comment

protected final java.lang.String _comment(java.lang.String text)
Enclose a given string of text within appropriate delimiters to form a comment in the generated code. Also, append a new line after the comment.

Parameters:
text - The text to place in the generated comment.
Returns:
The generated comment.

_generateArrayInstanceDeclarations

protected java.lang.String _generateArrayInstanceDeclarations()
Generate code for typedef declaring array instances.

Returns:
A newline character (\n) separated string of typdefs for the arrays needed.

_generateIncludeDirectives

protected java.lang.String _generateIncludeDirectives()
Generate include directives for all types that are required for the class that we are generating code for.

Returns:
The generated include directives.

_generateMethodHeader

protected java.lang.String _generateMethodHeader(soot.SootMethod method)
Generate header code for a method. Parameter names are not included in the generated code.

Parameters:
method - The method.
Returns:
The header code.

_generateParameterTypeList

protected java.lang.String _generateParameterTypeList(soot.SootMethod method)
Generate code for the parameter type list of a method, excluding parentheses.

Parameters:
method - The method.
Returns:
Code for the parameter type list.

_getRequiredIncludeFiles

protected java.util.Iterator _getRequiredIncludeFiles()
Return an iterator over the include files required by the generated code. Each element in the iterator is a String that gives the name of an include file.

Returns:
The names of the required include files.

_indent

protected java.lang.String _indent(int level)
Return a string that generates an indentation string (a sequence of spaces) for the given indentation level. Each indentation level unit is four characters wide.

Parameters:
level - The indentation level.
Returns:
The indentation string that corresponds to the given indentation level.

_removeRequiredType

protected void _removeRequiredType(soot.SootClass source)
Remove a class from the list of required types (types whose associated include files must be imported) if the class exists in the list.

Parameters:
source - The class.

_updateRequiredTypes

protected void _updateRequiredTypes(soot.Type type)
Register a type as a type that must be imported into the generated code through an #include directive. The request is processed only if the argument is a RefType, or if it is an ArrayType with a RefType as the base type. All other requests are ignored. Duplicate requests are also ignored.

Parameters:
type - The type.

_warn

protected void _warn(java.lang.String message)
Issue a warning message to standard error.

Parameters:
message - The warning message.