Package ptolemy.cg.kernel.generic
Class RunnableCodeGenerator
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.cg.kernel.generic.GenericCodeGenerator
-
- ptolemy.cg.kernel.generic.RunnableCodeGenerator
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Decorator
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
AccessorCodeGenerator
,ProgramCodeGenerator
public class RunnableCodeGenerator extends GenericCodeGenerator
Code generate a runnable code that does not require compilation.- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Christopher Brooks. Based on ProgramCodeGenerator by Bert Rodiers
- Pt.AcceptedRating:
- red (rodiers)
- Pt.ProposedRating:
- red (rodiers)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description 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.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.-
Fields inherited from class ptolemy.cg.kernel.generic.GenericCodeGenerator
_codeFileName, _eol, _executeCommands, _generateInSubdirectory, _model, _sanitizedModelName, codeDirectory, generateInSubdirectory, generatorPackage, generatorPackageList, INDENT1, INDENT2, INDENT3, overwriteFiles
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description RunnableCodeGenerator(NamedObj container, java.lang.String name, java.lang.String outputFileExtension)
Create a new instance of the ProgramCodeGenerator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
_executeCommands()
Execute the compile and run commands in the codeDirectory directory.protected void
_reset()
Reset the code generator.protected java.lang.String
_runCommand()
Return the command to run the generated code.protected java.util.List<java.lang.String>
_setupCommands()
Return a list of setup commands to be invoked before the run command.protected void
_updateSubstituteMap()
Update the substitute map for the setup and run commands In this base class, @codeDirectory@, @modelName@ and @PTII@ are added to the map.java.lang.Object
clone(Workspace workspace)
Clone the attribute into the specified workspace.java.lang.String[][]
updateCommandOptions()
Return an updated array of command line options.-
Methods inherited from class ptolemy.cg.kernel.generic.GenericCodeGenerator
_copyCFilesTosrc, _copyCFileTosrc, _generateCode, _getAdapter, _getAdapterClassFilter, _getAutoGeneratedAdapter, _getOutputFilename, _instantiateAdapter, _isTopLevel, _printTimeAndMemory, _resetAll, _writeCode, _writeCodeFileName, attributeChanged, comment, createDecoratorAttributes, decoratedObjects, generateCode, generateCode, generateCode, generateCopyright, getAdapter, getCodeFileName, getComponent, getExecuteCommands, getMethodExceptionString, getMethodVisibilityString, isGlobalDecorator, main, setCodeGenerator, setContainer, setExecuteCommands
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_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
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
run
public Parameter run
If true, then run the generated code. The default value is a parameter with the value true.
-
runCommand
public StringParameter runCommand
The command to use to run the generated code if the useMake parameter is false. The initial default value is "make -f @modelName@.mk run". Various '@' delimited key/value pairs will be automatically substituted. In the default case @modelName@ will be replaced with a sanitized (Java-safe) version of the model name.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.
-
_runCommandDefault
protected static final java.lang.String _runCommandDefault
The initial default value of the runCommand parameter. The constructor of a derived class may compare the value of runCommand and this variable and decide to override the value of the runCommand parameter with a new value.- See Also:
- Constant Field Values
-
_substituteMap
protected java.util.Map<java.lang.String,java.lang.String> _substituteMap
Map of '@' delimited keys to values.
-
-
Constructor Detail
-
RunnableCodeGenerator
public RunnableCodeGenerator(NamedObj container, java.lang.String name, java.lang.String outputFileExtension) throws IllegalActionException, NameDuplicationException
Create a new instance of the ProgramCodeGenerator.- Parameters:
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)- Throws:
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
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the attribute into the specified workspace.- Overrides:
clone
in classGenericCodeGenerator
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new attribute.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class contains an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
_reset
protected void _reset() throws IllegalActionException
Reset the code generator.- Overrides:
_reset
in classGenericCodeGenerator
- Throws:
IllegalActionException
- Not thrown in this base class, thrown by the parent if the container of the model cannot be set to null.
-
updateCommandOptions
public java.lang.String[][] updateCommandOptions()
Return an updated array of command line options.- Overrides:
updateCommandOptions
in classGenericCodeGenerator
- Returns:
- An array of updated command line options.
-
_executeCommands
protected int _executeCommands() throws IllegalActionException
Execute the compile and run commands in the codeDirectory directory.- Overrides:
_executeCommands
in classGenericCodeGenerator
- Returns:
- The return value of the last subprocess that was executed or -1 if no commands were executed.
- Throws:
IllegalActionException
- If there are problems reading parameters or executing the commands.
-
_runCommand
protected java.lang.String _runCommand() throws IllegalActionException
Return the command to run the generated code. Derived classes typically extend_updateSubstituteMap()
.- Returns:
- The command to run the generated code.
- Throws:
IllegalActionException
- If the there is a problem substituting the @...@ tags.
-
_setupCommands
protected java.util.List<java.lang.String> _setupCommands() throws IllegalActionException
Return a list of setup commands to be invoked before the run command.- Returns:
- The list of commands.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
_updateSubstituteMap
protected void _updateSubstituteMap() throws IllegalActionException
Update the substitute map for the setup and run commands In this base class, @codeDirectory@, @modelName@ and @PTII@ are added to the map.- Throws:
IllegalActionException
- Not thrown in this base class, Derived classes should throw it if there is a problem parsing a value.
-
-