public class ProgramCodeGenerator extends GenericCodeGenerator
This base class contains parameters and methods common to all programming languages.
red (rodiers) |
red (rodiers) |
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected java.util.Set<Parameter> |
_modifiedVariables
A set that contains all variables in the model whose values can be
changed during execution.
|
protected java.util.HashSet<java.lang.String> |
_newTypesUsed
A HashSet that contains all codegen types referenced in the model.
|
protected java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> |
_portTypeMap
A map from String type name to a HashMap of port name to an
array index.
|
protected java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> |
_portTypeMap2
A map from String type name to a HashMap of multiport or port
to an array index.
|
protected java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> |
_portTypeMap3
A map from String type name to a HashMap of multiports to an
array index.
|
protected java.util.HashMap<java.lang.String,java.lang.Integer> |
_portTypeMaxIndex
A map from String type name to a HashMap of port name to Array
Index.
|
protected java.util.HashMap<java.lang.String,java.lang.Integer> |
_portTypeMaxIndex2
A map from String type name to a HashMap of multiport or port
to the maximum number in the corresponding array.
|
protected java.util.HashMap<java.lang.String,java.lang.Integer> |
_portTypeMaxIndex3
A map from String type name to a HashMap of multiports to an
to the maximum number in the corresponding array.
|
protected static java.util.List<java.lang.String> |
_primitiveTypes
A list of the primitive types supported by the code generator.
|
protected static java.lang.String |
_runCommandDefault
The initial default value of the runCommand parameter.
|
protected java.util.Map<java.lang.String,java.lang.String> |
_substituteMap
Map of '@' delimited keys to values.
|
protected java.util.Set<java.lang.String> |
_tokenFuncUsed
A set that contains all token functions referenced in the model.
|
protected java.util.Set<java.lang.String> |
_typeFuncUsed
A set that contains all type-specific functions referenced in the model.
|
protected boolean |
_variablesAsArrays
The value of the variableAsArrays parameter.
|
Parameter |
generateComment
If true, generate comments in the output code; otherwise,
no comments is generated.
|
Parameter |
inline
If true, generate file with no functions.
|
Parameter |
maximumLinesPerBlock
The maximum number of lines per block.
|
Parameter |
measureTime
If true, generate code to measure the execution time.
|
Parameter |
run
If true, then run the generated code.
|
StringParameter |
runCommand
The command to use to run the generated code if the
useMake parameter is false.
|
Parameter |
useMake
If true, then use the 'make' command to compile and run
the generated code.
|
Parameter |
variablesAsArrays
If true, then generate code that puts variables into arrays;
otherwise, use standalone variables.
|
Parameter |
verbosity
Level of verbosity in comments and other output.
|
_codeFileName, _eol, _executeCommands, _generateInSubdirectory, _model, _sanitizedModelName, codeDirectory, generateInSubdirectory, generatorPackage, generatorPackageList, INDENT1, INDENT2, INDENT3, overwriteFiles
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
Constructor and Description |
---|
ProgramCodeGenerator(NamedObj container,
java.lang.String name,
java.lang.String outputFileExtension,
java.lang.String templateExtension)
Create a new instance of the ProgramCodeGenerator.
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected java.io.File |
_codeDirectoryAsFile()
Return the value of the codeDirectory parameter.
|
protected java.lang.StringBuffer |
_finalPassOverCode(java.lang.StringBuffer code)
Make a final pass over the generated code.
|
protected java.lang.String |
_formatComment(java.lang.String comment)
Return a formatted comment containing the specified string.
|
protected java.lang.String |
_generateBodyCode()
Generate the body code that lies between variable declaration
and wrapup.
|
protected int |
_generateCode(java.lang.StringBuffer code)
Generate code and append it to the given string buffer.
|
protected java.lang.String |
_generateIncludeFiles()
Generate include files.
|
protected java.lang.String |
_generatePreinitializeCode()
Generate preinitialize code (if there is any).
|
protected java.lang.String |
_generatePreinitializeMethodBodyCode()
Generate the preinitialization method body.
|
protected java.lang.String |
_generatePreinitializeMethodEntryCode()
Generate the preinitialization procedure entry point.
|
protected java.lang.String |
_generatePreinitializeMethodExitCode()
Generate the preinitialization procedure exit point.
|
protected java.lang.String |
_generatePreinitializeMethodProcedureName()
Generate the preinitialization procedure name.
|
protected java.lang.String |
_generateSharedCode()
Generate code shared by actors, including globally defined
data struct types and static methods or variables shared by multiple
instances of the same actor type.
|
protected java.lang.String |
_getFireFunctionArguments()
Return the prototype for fire functions.
|
protected CodeGeneratorAdapter |
_instantiateAdapter(java.lang.Object component,
java.lang.Class<?> componentClass,
java.lang.String adapterClassName)
Instantiate the given code generator adapter.
|
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 |
_reset()
Reset the code generator.
|
protected void |
_setupAdapter()
Perform any setup or initialization of the adapter.
|
java.lang.String[] |
_splitBody(java.lang.String prefix,
java.lang.String code)
Split the code.
|
protected java.util.List<java.lang.String> |
_splitVariableDeclaration(java.lang.String suffix,
java.lang.String code)
Split the variable declaration into possibly two sections.
|
protected java.lang.Class<? extends TemplateParser> |
_templateParserClass()
Return the class of the templateParser class.
|
protected void |
_writeMakefile(CompositeEntity container,
java.lang.String currentDirectory)
Read in a template makefile, substitute variables and write
the resulting makefile.
|
protected java.lang.String |
_writeVariableDeclarations(java.util.List<java.lang.String> variableDeclarations)
Write the variable declaration code.
|
void |
addModifiedVariables(Parameter variable)
Add a modified variable.
|
void |
attributeChanged(Attribute attribute)
If the attribute is the verbosity attribute, then if
its value is 1, set a debug listener on the code generator.
|
java.lang.Object |
clone(Workspace workspace)
Clone the attribute into the specified workspace.
|
java.lang.String |
codeGenType(Type ptType)
Get the corresponding type in code generation from the given Ptolemy
type.
|
java.lang.String |
comment(int indentLevel,
java.lang.String comment)
Return a formatted comment containing the
specified string with a specified indent level.
|
java.lang.String |
comment(java.lang.String comment)
Return a formatted comment containing the
specified string.
|
static boolean |
containsCode(java.lang.String code)
Return true if the input contains code.
|
java.lang.String |
generateClosingEntryCode()
Return the closing entry code, if any.
|
java.lang.String |
generateClosingExitCode()
Return the closing exit code, if any.
|
java.lang.String |
generateConstantDefinition(java.lang.String constant,
java.lang.String type,
java.lang.String value)
Generate code that defines a constant.
|
java.lang.String |
generateFireFunctionCode()
Generate The fire function code.
|
java.lang.String |
generateFireFunctionCompositeEnd()
Generate the closing code for a group of fire functions common
to a Composite Actor.
|
java.lang.String |
generateFireFunctionCompositeStart(java.lang.String className)
Generate the initial code for a group of fire functions common
to a Composite Actor.
|
java.lang.String |
generateFireFunctionMethodInvocation(NamedObj namedObj)
Generate the fire function method invocation.
|
java.lang.String |
generateFireFunctionMethodName(NamedObj namedObj)
Generate the fire function method name.
|
java.lang.String[] |
generateFireFunctionVariableAndMethodName(NamedObj namedObj)
Generate the fire function variable name and method
name.
|
java.lang.String |
generateFireFunctionVariableDeclaration(NamedObj namedObj)
Generate the fire function variable declaration.
|
java.lang.String |
generateInitializeCode()
Return the code associated with initialization of the containing
composite actor.
|
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 and file name information.
|
java.lang.String |
generateMainEntryCode()
Generate the main entry point.
|
java.lang.String |
generateMainExitCode()
Generate the main exit point.
|
java.lang.String |
generatePackageStatement()
Generate the package statement, if any.
|
java.lang.String |
generatePortName(TypedIOPort port,
java.lang.String portName,
int bufferSize)
Generate sanitized name for the given port.
|
java.lang.String |
generatePostfireCode()
Generate into the specified code stream the code associated with
postfiring up the container composite actor.
|
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 |
generatePtIOPortName(NamedObj container,
java.lang.String portName)
Generate sanitized name for the given Ptolemy IOPort.
|
int |
generatePtIOPortSize()
Return the size of the ioPortMap.
|
java.lang.String |
generatePtTypedCompositeActorName(NamedObj container,
java.lang.String actorName)
Generate sanitized name for the given TypedCompositeActor
This method is used when the
variablesAsArrays
parameter is true. |
int |
generatePtTypedCompositeActorSize()
Return the size of the TypedCompositeActor Map.
|
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 |
generateVariableName(NamedObj attribute)
Generate variable name for the given attribute.
|
java.lang.String |
generateWrapupCode()
Generate into the specified code stream the code associated with
wrapping up the container composite actor.
|
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.
|
java.util.Set<Parameter> |
getModifiedVariables()
Return the set of modified variables.
|
java.lang.String |
getTemplateExtension()
Return The extension of the template files.
|
boolean |
isPrimitive(java.lang.String cgType)
Determine if the given type is primitive.
|
boolean |
isPrimitive(Type ptType)
Determine if the given type is primitive.
|
static Type |
ptolemyType(java.lang.String cgType)
Return the Ptolemy type that corresponds to the type named by
the argument.
|
void |
setModifiedVariables(java.util.Set<Parameter> modifiedVariables)
Sets the set of modified variables.
|
java.lang.String[] |
splitLongBody(int linesPerMethod,
java.lang.String prefix,
java.lang.String code)
Split a long function body into multiple functions.
|
java.util.List<java.lang.String> |
splitVariableDeclaration(int linesPerMethod,
java.lang.String prefix,
java.lang.String code)
Split a long variable declaration body into multiple blocks
or files.
|
java.lang.String |
targetType(Type ptType)
Get the corresponding type in C from the given Ptolemy type.
|
java.lang.String[][] |
updateCommandOptions()
Return an updated array of command line options.
|
_copyCFilesTosrc, _copyCFileTosrc, _executeCommands, _getAdapter, _getAdapterClassFilter, _getAutoGeneratedAdapter, _getOutputFilename, _isTopLevel, _printTimeAndMemory, _resetAll, _writeCode, _writeCodeFileName, createDecoratorAttributes, decoratedObjects, generateCode, generateCode, generateCode, generateCopyright, getAdapter, getCodeFileName, getComponent, getExecuteCommands, getMethodExceptionString, getMethodVisibilityString, isGlobalDecorator, main, setCodeGenerator, setContainer, setExecuteCommands
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
description, getContainer, getDisplayName, getFullName, getName, getName, setName
public Parameter generateComment
public Parameter inline
public Parameter maximumLinesPerBlock
public Parameter measureTime
public Parameter run
public StringParameter runCommand
If the string "@help:all@" appears, then all the key/value pairs are echoed at run time, though this may not result in a syntactically correct command.
If useMake is true, then the value of this parameter is ignored.
public Parameter useMake
public Parameter variablesAsArrays
public Parameter verbosity
protected java.util.Set<Parameter> _modifiedVariables
protected java.util.HashSet<java.lang.String> _newTypesUsed
protected java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> _portTypeMap
variablesAsArrays
parameter enables use of
this map to reduce the number of variables generated.protected java.util.HashMap<java.lang.String,java.lang.Integer> _portTypeMaxIndex
variablesAsArrays
parameter enables use of
this map to reduce the number of variables generated.protected java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> _portTypeMap2
variablesAsArrays
parameter enables use of
this map to reduce the number of variables generated.protected java.util.HashMap<java.lang.String,java.lang.Integer> _portTypeMaxIndex2
variablesAsArrays
parameter enables use of
this map to reduce the number of variables generated.protected java.util.HashMap<java.lang.String,java.util.HashMap<java.lang.String,java.lang.Integer>> _portTypeMap3
variablesAsArrays
parameter enables use of
this map to reduce the number of variables generated.protected java.util.HashMap<java.lang.String,java.lang.Integer> _portTypeMaxIndex3
variablesAsArrays
parameter enables use of
this map to reduce the number of variables generated.protected static java.util.List<java.lang.String> _primitiveTypes
protected static final java.lang.String _runCommandDefault
protected java.util.Map<java.lang.String,java.lang.String> _substituteMap
protected java.util.Set<java.lang.String> _tokenFuncUsed
protected java.util.Set<java.lang.String> _typeFuncUsed
protected boolean _variablesAsArrays
public ProgramCodeGenerator(NamedObj container, java.lang.String name, java.lang.String outputFileExtension, java.lang.String templateExtension) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the ProgramCodeGenerator.outputFileExtension
- The extension of the output file.
(for example c in case of C and java in case of Java)templateExtension
- The extension of the template files.
(for example c in case of C and j in case of Java).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.public final void addModifiedVariables(Parameter variable) throws IllegalActionException
variable
- The variable to add to the SetIllegalActionException
- Not thrown in this base class.getModifiedVariables()
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class GenericCodeGenerator
attribute
- The attribute that changed.IllegalActionException
- If the change is not acceptable
to this container.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class GenericCodeGenerator
workspace
- The workspace for the new object.java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public java.lang.String codeGenType(Type ptType)
ptType
- The given Ptolemy type.ptolemyType(String)
public java.lang.String comment(int indentLevel, java.lang.String comment)
comment
- The string to put in the comment.indentLevel
- The indentation level.public java.lang.String comment(java.lang.String comment)
comment
in class GenericCodeGenerator
comment
- The string to put in the comment.public java.lang.String generateConstantDefinition(java.lang.String constant, java.lang.String type, java.lang.String value)
constant
- The name of the constant to be definedtype
- A string representing the type. In C, this
parameter is ignored.value
- The value of the constant.public java.lang.String generateFireFunctionCode() throws IllegalActionException
generateFireFunctionMethodName(NamedObj)
. Derived
classes such as JavaCodeGenerator may put the fire functions
in inner classes so as to reduce the Java file size.IllegalActionException
- If thrown while generating fire code.public java.lang.String generateFireFunctionCompositeEnd()
public java.lang.String generateFireFunctionCompositeStart(java.lang.String className)
className
- The name of the class to include in the
initial code.public java.lang.String generateFireFunctionMethodInvocation(NamedObj namedObj) throws IllegalActionException
namedObj
- The named object for which the name is generated.IllegalActionException
- Not thrown in this base class.
Derived classes should throw this exception if there are problems
accessing the name or generating the name.public java.lang.String generateFireFunctionMethodName(NamedObj namedObj) throws IllegalActionException
namedObj
- The named object for which the name is generated.IllegalActionException
- Not thrown in this base class.
Derived classes should throw this exception if there are problems
accessing the name or generating the name.public java.lang.String[] generateFireFunctionVariableAndMethodName(NamedObj namedObj) throws IllegalActionException
namedObj
- The named object for which the name is generated.IllegalActionException
- If thrown while generating fire code.public java.lang.String generateFireFunctionVariableDeclaration(NamedObj namedObj) throws IllegalActionException
The purpose of this method is to allow derived generators to generate code in inner classes and thus allow the compilation of large models.
namedObj
- The named object for which the name is generated.IllegalActionException
- Not thrown in this base class.
Derived classes should throw this exception if there are problems
accessing the name or generating the name.public static boolean containsCode(java.lang.String code)
code
- The string to check for code.public java.lang.String generateInitializeCode() throws IllegalActionException
IllegalActionException
- If the adapter class for the model
director cannot be found or if an error occurs when the director
adapter generates initialize code.public java.lang.String generateClosingEntryCode()
public java.lang.String generateClosingExitCode()
public java.lang.String generateInitializeEntryCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generateInitializeExitCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generateInitializeProcedureName() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generateLineInfo(int lineNumber, java.lang.String filename)
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
IllegalActionException
- Not thrown in this base class.public java.lang.String generateMainExitCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generatePackageStatement() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generatePortName(TypedIOPort port, java.lang.String portName, int bufferSize)
variablesAsArrays
parameter is true, then
a reference into an array of the appropriate type (ports_int[],
ports_double[] etc.) is returned. Otherwise, the name of
the port with any underscores converted to periods is returned.
See SDFDirector.generateInitializeCode()
for where the arrays are initialized.port
- The port for which the name is generated.portName
- The sanitized name of the port.bufferSize
- The size of the port buffer.public java.lang.String generatePtIOPortName(NamedObj container, java.lang.String portName)
variablesAsArrays
parameter is true.container
- The actor that contains the port, which may be null.portName
- The sanitized name of the portpublic int generatePtIOPortSize()
public java.lang.String generatePtTypedCompositeActorName(NamedObj container, java.lang.String actorName) throws IllegalActionException
variablesAsArrays
parameter is true.container
- The container of the actor.actorName
- The sanitized name of the actor.IllegalActionException
- If the variablesAsArrays parameter
of the code generator cannot be read.public int generatePtTypedCompositeActorSize()
public java.lang.String generatePostfireCode() throws IllegalActionException
IllegalActionException
- If the adapter class for the model
director cannot be found.public java.lang.String generatePostfireEntryCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generatePostfireExitCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generatePostfireProcedureName() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generateTypeConvertCode() throws IllegalActionException
IllegalActionException
- If an error occurrs when generating
the type conversion code, or if the adapter class for the model
director cannot be found, or if an error occurs when the adapter
actor generates the type conversion code.public java.lang.String generateVariableDeclaration() throws IllegalActionException
IllegalActionException
- If the adapter class for the model
director cannot be found.public java.lang.String generateVariableInitialization() throws IllegalActionException
IllegalActionException
- If the adapter class for the model
director cannot be found.public java.lang.String generateVariableName(NamedObj attribute)
attribute
- The attribute to for which to generate a variable name.public java.lang.String generateWrapupCode() throws IllegalActionException
IllegalActionException
- If the adapter class for the model
director cannot be found.public java.lang.String generateWrapupEntryCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generateWrapupExitCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generateWrapupProcedureName() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public final java.util.Set<Parameter> getModifiedVariables() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.setModifiedVariables(Set)
public final java.lang.String getTemplateExtension()
public final boolean isPrimitive(java.lang.String cgType)
cgType
- The given codegen type.public final boolean isPrimitive(Type ptType)
ptType
- The given ptolemy type.public static Type ptolemyType(java.lang.String cgType)
cgType
- A String naming a type.codeGenType(Type)
public final void setModifiedVariables(java.util.Set<Parameter> modifiedVariables) throws IllegalActionException
modifiedVariables
- The set of modified variables to be savedIllegalActionException
- Not thrown in this base class.getModifiedVariables()
public java.lang.String[] splitLongBody(int linesPerMethod, java.lang.String prefix, java.lang.String code) throws java.io.IOException
In this base class, since we don't know what the target language will be, the first element is the empty string, the second element is the code argument.
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 while reading the code.public java.util.List<java.lang.String> splitVariableDeclaration(int linesPerMethod, java.lang.String prefix, java.lang.String code) throws java.io.IOException
In this base class, since we don't know what the target language will be, the first element is the empty string, the second element is the code argument.
linesPerMethod
- The number of lines that should go into
each method.prefix
- The prefix to use when naming functions that
are createdcode
- The variable declarations to be split.java.io.IOException
- If thrown while reading the code.public java.lang.String targetType(Type ptType)
ptType
- The given Ptolemy type.public java.lang.String[][] updateCommandOptions()
updateCommandOptions
in class GenericCodeGenerator
protected void _addActorIncludeDirectories() throws IllegalActionException
IllegalActionException
- Never in this base class.protected void _addActorLibraries() throws IllegalActionException
IllegalActionException
- Never in this base class.protected void _analyzeTypeConversions() throws IllegalActionException
IllegalActionException
- If the adapter of the
top composite actor is unavailable.protected java.io.File _codeDirectoryAsFile() throws java.io.IOException, IllegalActionException
GenericCodeGenerator.codeDirectory
parameter.java.io.IOException
- If the codeDirectory parameter
names a file or a directory cannot be created.IllegalActionException
- If thrown while reading the
codeDirectory parameter.protected java.lang.StringBuffer _finalPassOverCode(java.lang.StringBuffer code) throws IllegalActionException
code
- The given code to be processed.IllegalActionException
- If #getOutputFilename() throws it.protected java.lang.String _formatComment(java.lang.String comment)
comment
- The string to put in the comment.protected java.lang.String _generateBodyCode() throws IllegalActionException
IllegalActionException
- If there is no director.protected java.lang.String _generateIncludeFiles() throws IllegalActionException
IllegalActionException
- If the adapter class for some actor
cannot be found.protected java.lang.String _generateSharedCode() throws IllegalActionException
IllegalActionException
- If an error occurrs when generating
the globally shared code, or if the adapter class for the model
director cannot be found, or if an error occurs when the adapter
actor generates the shared code.protected int _generateCode(java.lang.StringBuffer code) throws KernelException
$HOME
, the name of the
model is Foo
and the generatorPackage
is ptolemy.codegen.c
, then the file that is
written will be $HOME/Foo.c
This method is the main entry point._generateCode
in class GenericCodeGenerator
code
- The given string buffer.KernelException
- If the target file cannot be overwritten
or write-to-file throw any exception.protected java.lang.String _generatePreinitializeCode() throws IllegalActionException
IllegalActionException
- If the adapter class for the model
director cannot be found, or if an error occurs when the director
adapter generates preinitialize code.protected java.lang.String _generatePreinitializeMethodBodyCode() throws IllegalActionException
Typically, the preinitialize code consists of variable declarations. However, AutoAdapter generates method calls that instantiate wrapper TypedCompositeActors, so we need to invoke those method calls.
IllegalActionException
- Not thrown in this base class.protected java.lang.String _generatePreinitializeMethodEntryCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.protected java.lang.String _generatePreinitializeMethodExitCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.protected java.lang.String _generatePreinitializeMethodProcedureName() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.protected CodeGeneratorAdapter _instantiateAdapter(java.lang.Object component, java.lang.Class<?> componentClass, java.lang.String adapterClassName) throws IllegalActionException
_instantiateAdapter
in class GenericCodeGenerator
component
- The given component.componentClass
- The class of the component to be instantiated.
The constructor for class named by the adapterClassName argument
must take an argument of the class componentClass.adapterClassName
- The dot separated name of the adapter.IllegalActionException
- If the adapter class cannot be found.protected java.lang.String _getFireFunctionArguments()
protected java.lang.String _printExecutionTime()
protected java.lang.String _recordStartTime()
protected void _reset() throws IllegalActionException
_reset
in class GenericCodeGenerator
IllegalActionException
- Not thrown in this base class,
thrown by the parent if the container of the model
cannot be set to null.protected void _setupAdapter() throws IllegalActionException
IllegalActionException
- If an error occurrs while
initializing an adapter.protected java.util.List<java.lang.String> _splitVariableDeclaration(java.lang.String suffix, java.lang.String code)
suffix
- The suffix to use when naming functions that
are created.code
- The variable declarations to be split.protected java.lang.Class<? extends TemplateParser> _templateParserClass()
protected void _writeMakefile(CompositeEntity container, java.lang.String currentDirectory) 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 resource "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.
@CLASSPATHSEPARATOR@
@PTJNI_NO_CYGWIN@
,
@PTJNI_SHAREDLIBRARY_CFLAG@
,
@PTJNI_SHAREDLIBRARY_LDFLAG@
,
@PTJNI_SHAREDLIBRARY_PREFIX@
@PTJNI_SHAREDLIBRARY_SUFFIX@
@PTJavaCompiler@
javac
container
- The composite actor for which we generate the makefilecurrentDirectory
- The director in which the makefile is to be written.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.public java.lang.String[] _splitBody(java.lang.String prefix, java.lang.String code)
prefix
- The prefix to use when naming functions that
are createdcode
- The method body to be split.protected java.lang.String _writeVariableDeclarations(java.util.List<java.lang.String> variableDeclarations) throws IllegalActionException
variableDeclarations
- A List of two or more elements. If
the first element is the empty String, then the second element
contains all of the variable declarations. If the first element
is not empty, then it contains the language specific declarations
for the variable declarations. For example, in C, the first element
would consist of one or more "#include" statements. In Java, the
first element would consist of one or more "import" statements. The
second and successive elements contain the code to be written
to separate files or to be returned as one String.IllegalActionException
- Not thrown in this base class. Derived
classes should throw this if there is a problem writing the file(s).