ptolemy.codegen.java.kernel
Class JavaCodeGeneratorHelper

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.codegen.kernel.CodeGeneratorHelper
          extended by ptolemy.codegen.java.kernel.JavaCodeGeneratorHelper
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
Accumulator, AddSubtract, BooleanMultiplexor, ColtRandomSource, Commutator, Comparator, Const, CurrentTime, Discard, Display, Distributor, ElementsToArray, EmbeddedJavaActor.EmbeddedActor, Expression, FSMActor, IOPort, JopReadPort, JopSerialRead, JopSerialWrite, JopWatchDog, JopWritePort, Limiter, LogicFunction, Minimum, MovingAverage, MultiplyDivide, Publisher, PublisherTest, Pulse, Ramp, RandomSource, Repeat, Round, SampleDelay, Scale, Sequence, SequencePlotter, StringConst, StringLength, Subscriber, SubscriptionAggregator, Test, TokenToExpression, TrigFunction, TypedCompositeActor, UnaryMathFunction, VectorAssembler, VectorDisassembler

public class JavaCodeGeneratorHelper
extends CodeGeneratorHelper

Base class for C code generator helper.

Actor helpers extend this class and optionally define the generateFireCode(), generateInitializeCode(), generatePrefireCode(), generatePostfireCode(), generatePreinitializeCode(), and generateWrapupCode() methods.

In derived classes, these methods, if present, make actor specific changes to the corresponding code. If these methods are not present, then the parent class will automatically read the corresponding .c file and subsitute in the corresponding code block. For example, generateInitializeCode() reads the initBlock, processes the macros and adds the resulting code block to the output.

For a complete list of methods to define, see CodeGeneratorHelper.

For further details, see $PTII/ptolemy/codegen/README.html

Since:
Ptolemy II 8.0 o @Pt.ProposedRating Yellow (cxh)
Version:
$Id: JavaCodeGeneratorHelper.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Christopher Brooks, Edward Lee, Man-Kit Leung, Gang Zhou, Ye Zhou
See Also:
Serialized Form
Accepted Rating:
Red (cxh)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
CodeGeneratorHelper.Channel, CodeGeneratorHelper.VariableScope
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  java.util.Set _includeFiles
          The set of header files that needed to be included.
private  boolean _printedJVMWarning
          True if we have printed the JVM warning.
 
Fields inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_codeGenerator, _codeStream, _eol, _INDENT1, _INDENT2, _parseTreeCodeGenerator, _portConversions, _referencedParameters
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
JavaCodeGeneratorHelper(NamedObj component)
          Create a new instance of the C code generator helper.
 
Method Summary
protected  java.lang.String _generateInputVariableDeclaration()
          Generate input variable declarations.
protected  java.lang.String _generateOutputVariableDeclaration()
          Generate output variable declarations.
protected  java.lang.String _generateReferencedParameterDeclaration()
          Generate referenced parameter declarations.
protected  java.lang.String _generateTypeConvertVariableDeclaration()
          Generate type convert variable declarations.
private  void _portVariableDeclaration(java.lang.StringBuffer code, TypedIOPort port)
           
protected  java.lang.String _replaceMacro(java.lang.String macro, java.lang.String parameter)
          Return the replacement string of the given macro.
 java.lang.String generateVariableDeclaration()
          Generate variable declarations for inputs and outputs and parameters.
 JavaCodeGenerator getCodeGenerator()
          Get the code generator associated with this helper class.
 java.lang.String getFunctionInvocation(java.lang.String functionString, boolean isStatic)
          Return the translated token instance function invocation string.
 java.util.Set getHeaderFiles()
          Get the files needed by the code generated from this helper class.
 java.util.Set getJVMHeaderFiles()
          Get the header files needed to compile with the jvm library.
 java.lang.String getNewInvocation(java.lang.String constructorString)
          Return the translated new constructor invocation string.
 ParseTreeCodeGenerator getParseTreeCodeGenerator()
          Return a new parse tree code generator to use with expressions.
 java.lang.String getReference(Attribute attribute, java.lang.String[] channelAndOffset)
          Return a reference to the attribute.
 
Methods inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_createBufferSizeAndOffsetMap, _createInputBufferSizeAndOffsetMap, _findClosedParen, _generateBlockCode, _generateBlockCode, _generateFireCode, _generateTypeConvertMethod, _generateTypeConvertStatement, _generateTypeConvertStatements, _getCastType, _getChannelAndOffset, _getFireFunctionArguments, _getHelper, _getHelper, _getIndentPrefix, _getReference, _getReferenceChannels, _getTypeConvertChannels, _getTypeConvertReference, _indexOf, addFunctionUsed, addNewTypeUsed, analyzeTypeConvert, checkLocal, checkRemote, codeGenType, copyFilesToCodeDirectory, createOffsetVariablesIfNeeded, generateChannelOffset, generateFireCode, generateFireFunctionCode, generateFireFunctionCode2, generateInitializeCode, generateModeTransitionCode, generateName, generateOffset, generatePortReference, generatePostfireCode, generatePrefireCode, generatePreinitializeCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableInitialization, generateVariableName, generateWrapupCode, getBufferSize, getBufferSize, getComponent, getDefaultBlocks, getDirector, getDirectorHelper, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getObject, getParameterValue, getPort, getRates, getReadOffset, getReference, getReference, getReference, getSharedCode, getSinkChannels, getSize, getSourceChannel, getWCET, getWriteOffset, isPrimitive, isPrimitive, parseList, processCode, resetInputPortsOffset, setBufferSize, setCodeGenerator, setReadOffset, setWriteOffset, targetType, toString
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getContainedObject, _isMoMLSuppressed, _markContentsDerived, _propagateExistence, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_includeFiles

private java.util.Set _includeFiles
The set of header files that needed to be included.


_printedJVMWarning

private boolean _printedJVMWarning
True if we have printed the JVM warning.

Constructor Detail

JavaCodeGeneratorHelper

public JavaCodeGeneratorHelper(NamedObj component)
Create a new instance of the C code generator helper.

Parameters:
component - The actor object for this helper.
Method Detail

getNewInvocation

public java.lang.String getNewInvocation(java.lang.String constructorString)
                                  throws IllegalActionException
Return the translated new constructor invocation string. Keep the types referenced in the info table of this helper. The kernel will retrieve this information to determine the total number of referenced types in the model.

Overrides:
getNewInvocation in class CodeGeneratorHelper
Parameters:
constructorString - The string within the $new() macro.
Returns:
The translated new constructor invocation string.
Throws:
IllegalActionException - The given constructor string is not well-formed.

getParseTreeCodeGenerator

public ParseTreeCodeGenerator getParseTreeCodeGenerator()
Return a new parse tree code generator to use with expressions.

Overrides:
getParseTreeCodeGenerator in class CodeGeneratorHelper
Returns:
the parse tree code generator to use with expressions.

generateVariableDeclaration

public java.lang.String generateVariableDeclaration()
                                             throws IllegalActionException
Generate variable declarations for inputs and outputs and parameters. Append the declarations to the given string buffer.

Specified by:
generateVariableDeclaration in interface ActorCodeGenerator
Overrides:
generateVariableDeclaration in class CodeGeneratorHelper
Returns:
code The generated code.
Throws:
IllegalActionException - If the helper class for the model director cannot be found.

getCodeGenerator

public JavaCodeGenerator getCodeGenerator()
Get the code generator associated with this helper class.

Overrides:
getCodeGenerator in class CodeGeneratorHelper
Returns:
The code generator associated with this helper class.
See Also:
CodeGeneratorHelper.setCodeGenerator(CodeGenerator)

getFunctionInvocation

public java.lang.String getFunctionInvocation(java.lang.String functionString,
                                              boolean isStatic)
                                       throws IllegalActionException
Return the translated token instance function invocation string.

Overrides:
getFunctionInvocation in class CodeGeneratorHelper
Parameters:
functionString - The string within the $tokenFunc() macro.
isStatic - True if the method is static.
Returns:
The translated type function invocation string.
Throws:
IllegalActionException - The given function string is not well-formed.

getHeaderFiles

public java.util.Set getHeaderFiles()
                             throws IllegalActionException
Get the files needed by the code generated from this helper class. This base class returns an empty set.

Specified by:
getHeaderFiles in interface ActorCodeGenerator
Overrides:
getHeaderFiles in class CodeGeneratorHelper
Returns:
A set of strings that are header files needed by the code generated from this helper class.
Throws:
IllegalActionException - Not Thrown in this base class.

getJVMHeaderFiles

public java.util.Set getJVMHeaderFiles()
                                throws IllegalActionException
Get the header files needed to compile with the jvm library.

Returns:
A set of strings that are names of the header files needed by the code generated for jvm library
Throws:
IllegalActionException - Not Thrown in this subclass.

_generateInputVariableDeclaration

protected java.lang.String _generateInputVariableDeclaration()
                                                      throws IllegalActionException
Generate input variable declarations.

Returns:
a String that declares input variables.
Throws:
IllegalActionException - If thrown while getting port information.

_generateOutputVariableDeclaration

protected java.lang.String _generateOutputVariableDeclaration()
                                                       throws IllegalActionException
Generate output variable declarations.

Returns:
a String that declares output variables.
Throws:
IllegalActionException - If thrown while getting port information.

_generateReferencedParameterDeclaration

protected java.lang.String _generateReferencedParameterDeclaration()
                                                            throws IllegalActionException
Generate referenced parameter declarations.

Returns:
a String that declares referenced parameters.
Throws:
IllegalActionException - If thrown while getting modified variable information.

_generateTypeConvertVariableDeclaration

protected java.lang.String _generateTypeConvertVariableDeclaration()
                                                            throws IllegalActionException
Generate type convert variable declarations.

Returns:
a String that declares type convert variables.
Throws:
IllegalActionException - If thrown while getting port information.

getReference

public java.lang.String getReference(Attribute attribute,
                                     java.lang.String[] channelAndOffset)
                              throws IllegalActionException
Description copied from class: CodeGeneratorHelper
Return a reference to the attribute.

Overrides:
getReference in class CodeGeneratorHelper
Parameters:
attribute - The attribute.
channelAndOffset - The given channel and offset.
Returns:
The reference.
Throws:
IllegalActionException - If the attribute does not exist or does not have a value.

_replaceMacro

protected java.lang.String _replaceMacro(java.lang.String macro,
                                         java.lang.String parameter)
                                  throws IllegalActionException
Description copied from class: CodeGeneratorHelper
Return the replacement string of the given macro. Subclass of CodeGenerator may overriding this method to extend or support a different set of macros.

Overrides:
_replaceMacro in class CodeGeneratorHelper
Parameters:
macro - The given macro.
parameter - The given parameter to the macro.
Returns:
The replacement string of the given macro.
Throws:
IllegalActionException - Thrown if the given macro or parameter is not valid.

_portVariableDeclaration

private void _portVariableDeclaration(java.lang.StringBuffer code,
                                      TypedIOPort port)
                               throws IllegalActionException
Throws:
IllegalActionException