public class ProceduralCodeGenerator extends ProgramCodeGenerator
red (rodiers) |
red (rodiers) |
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
_compileCommandDefault
The initial default value of the compileCommand parameter.
|
protected java.util.Set<java.lang.String> |
_includes
Set of include command line arguments where each element is
a string, for example "-I/usr/local/include".
|
protected java.util.List<java.lang.String> |
_libraries
List of library command line arguments where each element is
a string, for example "-L/usr/local/lib".
|
Parameter |
compile
If true, then compile the generated code.
|
StringParameter |
compileCommand
The command to use to compile the generated code if the
useMake parameter is false.
|
Parameter |
generateEmbeddedCode
If true, then generate code for that uses the reflection for Java
and JNI for C and is embedded within the model
The default value is false and this parameter is not usually
editable by the user.
|
_modifiedVariables, _newTypesUsed, _portTypeMap, _portTypeMap2, _portTypeMap3, _portTypeMaxIndex, _portTypeMaxIndex2, _portTypeMaxIndex3, _primitiveTypes, _runCommandDefault, _substituteMap, _tokenFuncUsed, _typeFuncUsed, _variablesAsArrays, generateComment, inline, maximumLinesPerBlock, measureTime, run, runCommand, useMake, variablesAsArrays, verbosity
_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 |
---|
ProceduralCodeGenerator(NamedObj container,
java.lang.String name,
java.lang.String outputFileExtension,
java.lang.String templateExtension)
Create a new instance of the ProceduralCodeGenerator.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
_concatenateElements(java.util.Collection<java.lang.String> 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 void |
_reset()
Reset the code generator.
|
protected void |
_writeMakefile(CompositeEntity container,
java.lang.String currentDirectory)
Read in a template makefile, substitute variables and write
the resulting makefile.
|
void |
addInclude(java.lang.String includeCommand)
Add an include command line argument the compile command.
|
void |
addLibrary(java.lang.String libraryCommand)
Add a library command line argument the compile command.
|
void |
addLibraryIfNecessary(java.lang.String libraryCommand)
If the compile command does not yet containe a library,
add a library command line argument the compile command.
|
java.lang.Object |
clone(Workspace workspace)
Clone the object into the specified workspace.
|
void |
markFunctionCalled(java.lang.String name,
ProceduralTemplateParser templateParser)
Add called functions to the set of overloaded functions for
later use.
|
_addActorIncludeDirectories, _addActorLibraries, _analyzeTypeConversions, _codeDirectoryAsFile, _finalPassOverCode, _formatComment, _generateBodyCode, _generateCode, _generateIncludeFiles, _generatePreinitializeCode, _generatePreinitializeMethodBodyCode, _generatePreinitializeMethodEntryCode, _generatePreinitializeMethodExitCode, _generatePreinitializeMethodProcedureName, _generateSharedCode, _getFireFunctionArguments, _instantiateAdapter, _printExecutionTime, _recordStartTime, _setupAdapter, _splitBody, _splitVariableDeclaration, _templateParserClass, _writeVariableDeclarations, addModifiedVariables, attributeChanged, codeGenType, comment, comment, containsCode, generateClosingEntryCode, generateClosingExitCode, generateConstantDefinition, generateFireFunctionCode, generateFireFunctionCompositeEnd, generateFireFunctionCompositeStart, generateFireFunctionMethodInvocation, generateFireFunctionMethodName, generateFireFunctionVariableAndMethodName, generateFireFunctionVariableDeclaration, generateInitializeCode, generateInitializeEntryCode, generateInitializeExitCode, generateInitializeProcedureName, generateLineInfo, generateMainEntryCode, generateMainExitCode, generatePackageStatement, generatePortName, generatePostfireCode, generatePostfireEntryCode, generatePostfireExitCode, generatePostfireProcedureName, generatePtIOPortName, generatePtIOPortSize, generatePtTypedCompositeActorName, generatePtTypedCompositeActorSize, generateTypeConvertCode, generateVariableDeclaration, generateVariableInitialization, generateVariableName, generateWrapupCode, generateWrapupEntryCode, generateWrapupExitCode, generateWrapupProcedureName, getModifiedVariables, getTemplateExtension, isPrimitive, isPrimitive, ptolemyType, setModifiedVariables, splitLongBody, splitVariableDeclaration, targetType, updateCommandOptions
_copyCFilesTosrc, _copyCFileTosrc, _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 compile
public StringParameter compileCommand
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 generateEmbeddedCode
protected java.util.Set<java.lang.String> _includes
protected java.util.List<java.lang.String> _libraries
protected static final java.lang.String _compileCommandDefault
public ProceduralCodeGenerator(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 ProceduralCodeGenerator.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 void addInclude(java.lang.String includeCommand)
includeCommand
- The include command, for example
"-I/usr/local/include".public void addLibrary(java.lang.String libraryCommand)
libraryCommand
- The library command, for example
"-L/usr/local/lib".addLibraryIfNecessary(String)
public void addLibraryIfNecessary(java.lang.String libraryCommand)
libraryCommand
- The library command, for example
"-L/usr/local/lib".addLibrary(String)
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class ProgramCodeGenerator
workspace
- The workspace for the new object.java.lang.CloneNotSupportedException
- If any of the attributes
cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void markFunctionCalled(java.lang.String name, ProceduralTemplateParser templateParser) throws IllegalActionException
name
- The name of the function, for example "Double_equals"templateParser
- The corresponding templateParser that contains the
codeBlock.IllegalActionException
- If there is a problem adding
a function to the set of overloaded functions.protected java.lang.String _concatenateElements(java.util.Collection<java.lang.String> collection)
collection
- The Collection of Strings.protected void _reset() throws IllegalActionException
_reset
in class ProgramCodeGenerator
IllegalActionException
- Not thrown in this base
class, thrown by the parent if the container of the model
cannot be set to null.protected int _executeCommands() throws IllegalActionException
_executeCommands
in class GenericCodeGenerator
IllegalActionException
- If there are problems reading
parameters or executing the commands.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
.
See the parent class
ProgramCodeGenerator._writeMakefile(CompositeEntity, String)
for variable that are substituted by the parent class.
This class substitutes the following variables:
@PTCGIncludes@
addInclude(String)
, where each
element is separated by a space.
_writeMakefile
in class ProgramCodeGenerator
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.