Class PortDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.cg.kernel.generic.CodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
-
- ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director
-
- ptolemy.cg.adapter.generic.adapters.ptolemy.actor.PortDirector
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
DEDirector
,StaticSchedulingDirector
public abstract class PortDirector extends Director
A Director that use Ports and PortInfo.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Christopher Brooks
- See Also:
GenericCodeGenerator
- Pt.AcceptedRating:
- Yellow (zhouye)
- Pt.ProposedRating:
- Yellow (zhouye)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
NamedProgramCodeGeneratorAdapter.VariableScope
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
ProgramCodeGeneratorAdapter.Channel
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
_sanitizedDirectorName
The name of the director in a format suitable to be used as a variable name.Ports
ports
The meta information about the ports in the container.-
Fields inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_component, _defaultBlocks, _eol, _templateParser
-
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 PortDirector(Director director)
Construct the code generator adapter associated with the given director.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static boolean
_checkLocal(boolean forComposite, IOPort port)
Return true if the port is a local port.protected static boolean
_checkRemote(boolean forComposite, IOPort port)
Return true if the port is a remote port.protected java.lang.String
_generateChannelOffset(TypedIOPort port, boolean isWrite, java.lang.String channelString)
Generate a string that represents the offset for a dynamically determined channel of a multiport.protected java.lang.String
_generatePortReference(TypedIOPort port, java.lang.String[] channelAndOffset, boolean isWrite)
Generate a string that represents the reference for an IOPort.protected java.lang.String
_getCastType(java.lang.String name)
Get the cast type.protected java.lang.String[]
_getChannelAndOffset(java.lang.String name)
Return the channel and offset given in a string.protected java.lang.String
_getRefName(java.lang.String name)
Generate a string that represents the reference to a parameter or a port named "name".protected java.lang.String
_getRefType(Attribute attribute)
Generate a string that represents the type of an attribute (only if it is a parameter).abstract java.lang.Boolean
allowDynamicMultiportReference()
Return whether the channels in multiports can be dynamically referenced using the $ref macro.abstract java.lang.String
generatePortName(TypedIOPort port)
Generate sanitized name for the given named object.java.lang.String
getReference(java.lang.String name, boolean isWrite, NamedProgramCodeGeneratorAdapter target)
Return the reference to the specified parameter or port of the associated actor.java.lang.String
getReference(TypedIOPort port, java.lang.String[] channelAndOffset, boolean forComposite, boolean isWrite, NamedProgramCodeGeneratorAdapter target)
Return an unique label for the given port channel referenced by the given adapter.java.lang.String
getSanitizedDirectorName()
Return the sanitized name of this director adapter.abstract java.lang.Boolean
padBuffers()
Return whether we need to pad buffers or not.-
Methods inherited from class ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director
_ceilToPowerOfTwo, _generateVariableDeclaration, _generateVariableInitialization, _getParameter, generateCodeForGet, generateCodeForSend, generateConstructorCode, generateFireCode, generateFireFunctionCode, generateInitializeCode, generateModeTransitionCode, generatePostfireCode, generatePreinitializeCode, generatePreinitializeMethodBodyCode, generateTransferInputsCode, generateTransferInputsCode, generateTransferOutputsCode, generateTransferOutputsCode, generateVariableDeclaration, generateVariableDeclaration, generateVariableInitialization, generateVariableInitialization, generateWrapupCode, getComponent, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getParameter
-
Methods inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
_generateFireCode, _generateTypeConvertStatement, analyzeTypeConvert, copyFilesToCodeDirectory, generateMainLoop, generatePrefireCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, getAddTimeString, getBufferSize, getBufferSize, getDeclareSharedCode, getDefaultBlocks, getFireFunctionParameters, getHeaderFiles, getName, getParameterValue, getReference, getReference, getSharedCode, getSinkChannels, getSourceTimeString, getTimeSourcePortName, getTypeConvertChannels, getTypeConvertReference, getTypeConvertSinkChannels, setupAdapter, targetType
-
Methods inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_generateBlockByName, getAdapter, getCodeGenerator, getTemplateParser, processCode, setCodeGenerator, setTemplateParser, toString
-
Methods inherited from class ptolemy.cg.kernel.generic.CodeGeneratorAdapter
createDecoratorAttributes, generateName
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateExistence, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, decorators, 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, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
-
-
-
-
Field Detail
-
ports
public Ports ports
The meta information about the ports in the container.
-
_sanitizedDirectorName
protected java.lang.String _sanitizedDirectorName
The name of the director in a format suitable to be used as a variable name.
-
-
Constructor Detail
-
PortDirector
public PortDirector(Director director)
Construct the code generator adapter associated with the given director. Note before calling the generate*() methods, you must also call setCodeGenerator(GenericCodeGenerator).- Parameters:
director
- The associated director.
-
-
Method Detail
-
allowDynamicMultiportReference
public abstract java.lang.Boolean allowDynamicMultiportReference() throws IllegalActionException
Return whether the channels in multiports can be dynamically referenced using the $ref macro.- Returns:
- True when the channels in multiports can be dynamically referenced using the $ref macro.
- Throws:
IllegalActionException
- If the expression cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.
-
generatePortName
public abstract java.lang.String generatePortName(TypedIOPort port) throws IllegalActionException
Generate sanitized name for the given named object. Remove all underscores to avoid conflicts with systems functions.- Parameters:
port
- The port for which the name is generated.- Returns:
- The sanitized name.
- Throws:
IllegalActionException
- If the variablesAsArrays parameter cannot be read or if the buffer size of the port cannot be read.
-
getReference
public java.lang.String getReference(java.lang.String name, boolean isWrite, NamedProgramCodeGeneratorAdapter target) throws IllegalActionException
Return the reference to the specified parameter or port of the associated actor. For a parameter, the returned string is in the form "fullName_parameterName". For a port, the returned string is in the form "fullName_portName[channelNumber][offset]", if any channel number or offset is given.Usually given the name of an input port, getReference(String name) returns a target language variable name representing the input port. Given the name of an output port, getReference(String name) returns variable names representing the input ports connected to the output port. However, if the name of an input port starts with '@', getReference(String name) returns variable names representing the input ports connected to the given input port on the inside. If the name of an output port starts with '@', getReference(String name) returns variable name representing the the given output port which has inside receivers. The special use of '@' is for composite actor when tokens are transferred into or out of the composite actor.
- Overrides:
getReference
in classDirector
- Parameters:
name
- The name of the parameter or portisWrite
- Whether to generate the write or read offset.target
- The ProgramCodeGeneratorAdapter for which code needs to be generated.- Returns:
- The reference to that parameter or port (a variable name, for example).
- Throws:
IllegalActionException
- If the parameter or port does not exist or does not have a value.
-
getReference
public java.lang.String getReference(TypedIOPort port, java.lang.String[] channelAndOffset, boolean forComposite, boolean isWrite, NamedProgramCodeGeneratorAdapter target) throws IllegalActionException
Return an unique label for the given port channel referenced by the given adapter. By default, this delegates to the adapter to generate the reference. Subclass may override this method to generate the desire label according to the given parameters.- Parameters:
port
- The given port.channelAndOffset
- The given channel and offset.forComposite
- Whether the given adapter is associated with a CompositeActorisWrite
- The type of the reference. True if this is a write reference; otherwise, this is a read reference.target
- The ProgramCodeGeneratorAdapter for which code needs to be generated.- Returns:
- an unique reference label for the given port channel.
- Throws:
IllegalActionException
- If the adapter throws it while generating the label.
-
getSanitizedDirectorName
public java.lang.String getSanitizedDirectorName()
Return the sanitized name of this director adapter.- Returns:
- The name of the director
-
padBuffers
public abstract java.lang.Boolean padBuffers() throws IllegalActionException
Return whether we need to pad buffers or not.- Returns:
- True when we need to pad buffers.
- Throws:
IllegalActionException
- If the expression cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.
-
_checkLocal
protected static boolean _checkLocal(boolean forComposite, IOPort port)
Return true if the port is a local port.- Parameters:
forComposite
- True if we are checking for a compositeport
- The port to be checked.- Returns:
- A boolean true when the port is local.
-
_checkRemote
protected static boolean _checkRemote(boolean forComposite, IOPort port)
Return true if the port is a remote port.- Parameters:
forComposite
- True if this for a composite.port
- The port to check.- Returns:
- True if the port is an output and not a composite or the port is an input and this is for a composite.
-
_generateChannelOffset
protected java.lang.String _generateChannelOffset(TypedIOPort port, boolean isWrite, java.lang.String channelString) throws IllegalActionException
Generate a string that represents the offset for a dynamically determined channel of a multiport.- Parameters:
port
- The referenced port.isWrite
- Whether to generate the write or read offset.channelString
- The string that will determine the channel.- Returns:
- The expression that represents the offset for a channel determined dynamically in the generated code.
- Throws:
IllegalActionException
- If thrown while generating the port name.
-
_generatePortReference
protected java.lang.String _generatePortReference(TypedIOPort port, java.lang.String[] channelAndOffset, boolean isWrite) throws IllegalActionException
Generate a string that represents the reference for an IOPort.- Parameters:
port
- The port to get the reference.isWrite
- Whether to generate the write or read offset.channelAndOffset
- The string[] that will determine the channel and the offset.- Returns:
- The expression that represents the reference for the port
- Throws:
IllegalActionException
- If thrown while generating the channel offsite or generating the port name.
-
_getCastType
protected java.lang.String _getCastType(java.lang.String name) throws IllegalActionException
Get the cast type.- Parameters:
name
- The name with # syntax.- Returns:
- The cast type
- Throws:
IllegalActionException
- If there are more than two # in the name, indicating an invalid cast type.
-
_getChannelAndOffset
protected java.lang.String[] _getChannelAndOffset(java.lang.String name) throws IllegalActionException
Return the channel and offset given in a string. The result is an string array of length 2. The first element indicates the channel index, and the second the offset. If either element is an empty string, it means that channel/offset is not specified.- Parameters:
name
- The given string.- Returns:
- An string array of length 2, containing expressions of the channel index and offset.
- Throws:
IllegalActionException
- If the channel index or offset specified in the given string is illegal.
-
_getRefName
protected java.lang.String _getRefName(java.lang.String name) throws IllegalActionException
Generate a string that represents the reference to a parameter or a port named "name".- Parameters:
name
- The name.- Returns:
- The string which represents the reference
- Throws:
IllegalActionException
- If the reference cannot be found or is an invalid cast type.
-
_getRefType
protected java.lang.String _getRefType(Attribute attribute)
Generate a string that represents the type of an attribute (only if it is a parameter).- Parameters:
attribute
- The attribute, which is typically a Parameter.- Returns:
- the code generation type if the attribute is a parameter, otherwise, null.
-
-