|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.codegen.kernel.CodeGenerator
ptolemy.codegen.java.kernel.JavaCodeGenerator
public class JavaCodeGenerator
Base class for Java code generator.
red (zgang) |
red (zgang) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private CodeStream |
_overloadedFunctions
|
private java.util.Set<java.lang.String> |
_overloadedFunctionSet
|
private static java.util.Set |
_scalarDeleteTypes
Types that share the scalarDelete() method, which does nothing. |
private static java.util.Set |
_unsupportedTypeFunctions
Set of type/function combinations that are not supported. |
Fields inherited from class ptolemy.codegen.kernel.CodeGenerator |
---|
_codeFileName, _commandFlags, _commandOptions, _commandTemplate, _DEFAULT_TARGET, _eol, _executeCommands, _includes, _INDENT1, _INDENT2, _INDENT3, _libraries, _macros, _model, _modifiedVariables, _newTypesUsed, _postfireCode, _primitiveTypes, _sanitizedModelName, _tokenFuncUsed, _typeFuncUsed, allowDynamicMultiportReference, codeDirectory, compile, compileTarget, generateComment, generateCpp, generateEmbeddedCode, generatorPackage, inline, measureTime, overwriteFiles, padBuffers, run, sourceLineBinding, target |
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 | |
---|---|
JavaCodeGenerator(NamedObj container,
java.lang.String name)
Create a new instance of the Java code generator. |
Method Summary | |
---|---|
protected void |
_addActorIncludeDirectories()
Add include directories specified by the actors in this model. |
protected void |
_addActorLibraries()
Add libraries specified by the actors in this model. |
protected void |
_analyzeTypeConversions()
Analyze the model to find out what connections need to be type converted. |
private static java.lang.String |
_concatenateClasspath(java.util.Collection collection)
Given a Collection of Strings, return a string where each element of the Set is separated by $. |
private static java.lang.String |
_concatenateElements(java.util.Collection collection)
Given a Collection of Strings, return a string where each element of the Set is separated by a space. |
protected int |
_executeCommands()
Execute the compile and run commands in the codeDirectory directory. |
protected java.lang.StringBuffer |
_finalPassOverCode(java.lang.StringBuffer code)
Make a final pass over the generated code. |
protected java.lang.String |
_generateIncludeFiles()
Generate include files. |
private java.util.HashSet |
_getReferencedFunctions()
Return the set of referenced functions. |
private java.util.HashSet |
_getReferencedTypes(java.util.HashSet functions)
Return the new types used by the given set of functions. |
private int |
_iterations()
Return the value of the iterations parameter of the director, if any. |
protected java.lang.String |
_printExecutionTime()
Generate the code for printing the execution time since the code generated by _recordStartTime() was called. |
protected java.lang.String |
_recordStartTime()
Generate the code for recording the current time. |
protected void |
_writeMakefile()
Read in a template makefile, substitute variables and write the resulting makefile. |
java.lang.String |
codeGenType(Type type)
Get the corresponding type in code generation from the given Ptolemy type. |
java.lang.String |
generateClosingEntryCode()
Return the closing entry code, if any. |
java.lang.String |
generateClosingExitCode()
Return the closing exit code, if any. |
java.lang.Object |
generateFunctionTable(java.lang.Object[] types,
java.lang.Object[] functions)
Generate the function table. |
java.lang.String |
generateInitializeEntryCode()
Generate the initialization procedure entry point. |
java.lang.String |
generateInitializeExitCode()
Generate the initialization procedure exit point. |
java.lang.String |
generateInitializeProcedureName()
Generate the initialization procedure name. |
java.lang.String |
generateLineInfo(int lineNumber,
java.lang.String filename)
Generate line number information. |
java.lang.String |
generateMainEntryCode()
Generate the main entry point. |
java.lang.String |
generateMainExitCode()
Generate the main exit point. |
java.lang.String |
generatePostfireEntryCode()
Generate the postfire procedure entry point. |
java.lang.String |
generatePostfireExitCode()
Generate the postfire procedure exit point. |
java.lang.String |
generatePostfireProcedureName()
Generate the postfire procedure name. |
java.lang.String |
generateTypeConvertCode()
Generate type conversion code. |
java.lang.String |
generateVariableDeclaration()
Generate variable declarations for inputs and outputs and parameters. |
java.lang.String |
generateVariableInitialization()
Generate variable initialization for the referenced parameters. |
java.lang.String |
generateWrapupEntryCode()
Generate the wrapup procedure entry point. |
java.lang.String |
generateWrapupExitCode()
Generate the wrapup procedure exit point. |
java.lang.String |
generateWrapupProcedureName()
Generate the wrapup procedure name. |
void |
markFunctionCalled(java.lang.String name,
JavaCodeGeneratorHelper helper)
Add called functions to the set of overloaded functions for later use. |
java.lang.String |
processCode(java.lang.String code)
Process the specified code for the helper associated with the container. |
java.lang.String[] |
splitLongBody(int linesPerMethod,
java.lang.String prefix,
java.lang.String code)
Split a long function body into multiple functions. |
java.lang.String |
targetType(Type ptType)
Get the corresponding type in Java from the given Ptolemy type. |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private CodeStream _overloadedFunctions
private java.util.Set<java.lang.String> _overloadedFunctionSet
private static java.util.Set _unsupportedTypeFunctions
private static java.util.Set _scalarDeleteTypes
Constructor Detail |
---|
public JavaCodeGenerator(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the Java code generator.
IllegalActionException
- If the super class throws the
exception or error occurs when setting the file path.
NameDuplicationException
- If the super class throws the
exception or an error occurs when setting the file path.Method Detail |
---|
public java.lang.String codeGenType(Type type)
CodeGenerator
codeGenType
in class CodeGenerator
type
- The given Ptolemy type.
public java.lang.Object generateFunctionTable(java.lang.Object[] types, java.lang.Object[] functions)
generateFunctionTable
in class CodeGenerator
types
- An array of types.functions
- An array of functions.
public java.lang.String generateClosingEntryCode()
generateClosingEntryCode
in class CodeGenerator
public java.lang.String generateClosingExitCode()
generateClosingExitCode
in class CodeGenerator
public java.lang.String generateInitializeEntryCode() throws IllegalActionException
generateInitializeEntryCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateInitializeExitCode() throws IllegalActionException
generateInitializeExitCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateInitializeProcedureName() throws IllegalActionException
generateInitializeProcedureName
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateLineInfo(int lineNumber, java.lang.String filename)
#line lineNumber "filename"are generated for use by the C preprocessor.
generateLineInfo
in class CodeGenerator
lineNumber
- The line number of the source file or
file containing code blocks.filename
- The name of the source file or file containing
code blocks.
public java.lang.String generateMainEntryCode() throws IllegalActionException
generateMainEntryCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateMainExitCode() throws IllegalActionException
generateMainExitCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generatePostfireEntryCode() throws IllegalActionException
generatePostfireEntryCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generatePostfireExitCode() throws IllegalActionException
generatePostfireExitCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generatePostfireProcedureName() throws IllegalActionException
generatePostfireProcedureName
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateTypeConvertCode() throws IllegalActionException
generateTypeConvertCode
in class CodeGenerator
IllegalActionException
- If an error occurrs when generating
the type resolution code, or if the helper class for the model
director cannot be found, or if an error occurs when the helper
actor generates the type resolution code.public java.lang.String processCode(java.lang.String code) throws IllegalActionException
code
- The code to process.
IllegalActionException
- If illegal macro names are found.private java.util.HashSet _getReferencedFunctions()
private java.util.HashSet _getReferencedTypes(java.util.HashSet functions)
functions
- The set of functions used, such as "equals",
"isCloseTo", and "toString".
public java.lang.String generateVariableDeclaration() throws IllegalActionException
generateVariableDeclaration
in class CodeGenerator
IllegalActionException
- If the helper class for the model
director cannot be found.public java.lang.String generateVariableInitialization() throws IllegalActionException
generateVariableInitialization
in class CodeGenerator
IllegalActionException
- If the helper class for the model
director cannot be found.public java.lang.String generateWrapupEntryCode() throws IllegalActionException
generateWrapupEntryCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateWrapupExitCode() throws IllegalActionException
generateWrapupExitCode
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateWrapupProcedureName() throws IllegalActionException
generateWrapupProcedureName
in class CodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String[] splitLongBody(int linesPerMethod, java.lang.String prefix, java.lang.String code) throws java.io.IOException
splitLongBody
in class CodeGenerator
linesPerMethod
- The number of lines that should go into
each method.prefix
- The prefix to use when naming functions that
are createdcode
- The method body to be split.
java.io.IOException
- If thrown will reading the code.public java.lang.String targetType(Type ptType)
targetType
in class CodeGenerator
ptType
- The given Ptolemy type.
protected void _addActorIncludeDirectories() throws IllegalActionException
_addActorIncludeDirectories
in class CodeGenerator
IllegalActionException
- If thrown when getting an actor's
include directories.protected void _addActorLibraries() throws IllegalActionException
_addActorLibraries
in class CodeGenerator
IllegalActionException
- If thrown when getting an actor's
libraries.protected void _analyzeTypeConversions() throws IllegalActionException
_analyzeTypeConversions
in class CodeGenerator
IllegalActionException
- If the helper of the
top composite actor is unavailable.protected int _executeCommands() throws IllegalActionException
_executeCommands
in class CodeGenerator
IllegalActionException
- If there are problems reading
parameters or executing the commands.protected java.lang.StringBuffer _finalPassOverCode(java.lang.StringBuffer code) throws IllegalActionException
_finalPassOverCode
in class CodeGenerator
code
- The given code to be processed.
IllegalActionException
- If #getOutputFilename() throws it.protected java.lang.String _generateIncludeFiles() throws IllegalActionException
_generateIncludeFiles
in class CodeGenerator
IllegalActionException
- If the helper class for some actor
cannot be found.protected java.lang.String _printExecutionTime()
_printExecutionTime
in class CodeGenerator
protected java.lang.String _recordStartTime()
_recordStartTime
in class CodeGenerator
protected void _writeMakefile() throws IllegalActionException
If a .mk.in
file with the name of the sanitized model
name, then that file is used as a template. For example, if the
model name is Foo
and the file Foo.mk.in
exists, then the file Foo.mk.in
is used as a makefile
template.
If no .mk.in
file is found, then the makefile
template can be found by looking up a resource name
makefile.in in the package named by the
generatorPackage parameter. Thus, if the
generatorPackage has the value "ptolemy.codegen.c",
then we look for the resouce "ptolemy.codegen.c.makefile.in", which
is usually found as $PTII/ptolemy/codegen/c/makefile.in
.
The makefile is written to a directory named by the codeDirectory parameter, with a file name that is a sanitized version of the model name, and a ".mk" extension. Thus, for a model named "Foo", we might generate a makefile in "$HOME/codegen/Foo.mk".
Under Java under Windows, your $HOME
variable
is set to the value of the user.home
System property,
which is usually something like
C:\Documents and Settings\yourlogin
, thus
for user mrptolemy
the makefile would be
C:\Documents and Settings\mrptolemy\codegen\Foo.mk
.
The following variables are substituted
@modelName@
StringUtilities.sanitizeName(String)
on the model name.
@PTCGIncludes@
CodeGenerator.addInclude(String)
, where each
element is separated by a space.
@PTCGLibraries@
CodeGenerator.addLibrary(String)
, where each
element is separated by a space.
_writeMakefile
in class CodeGenerator
IllegalActionException
- If there is a problem reading
a parameter, if there is a problem creating the codeDirectory directory
or if there is a problem writing the code to a file.private static java.lang.String _concatenateClasspath(java.util.Collection collection)
collection
- The collection of elements.
private static java.lang.String _concatenateElements(java.util.Collection collection)
collection
- The collection of elements.
private int _iterations() throws IllegalActionException
IllegalActionException
public void markFunctionCalled(java.lang.String name, JavaCodeGeneratorHelper helper) throws IllegalActionException
name
- The name of the function, for example "Double_equals"helper
- The corresponding helper that contains the
codeBlock.
IllegalActionException
- If there is a problem adding
a function to the set of overloaded functions.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |