Class NamedProgramCodeGeneratorAdapter
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.cg.kernel.generic.CodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
AbsoluteValue
,Accelerometer
,Accumulator
,AddSubtract
,AutoAdapter
,BooleanMultiplexor
,BooleanSwitch
,BooleanToAnything
,BootstrapSampleDelay
,CC3000Control
,CC3000Module
,ColtRandomSource
,Commutator
,Comparator
,ComplexToCartesian
,CurrentMicrostep
,CurrentTime
,DB
,Differential
,Director
,Discard
,DiscreteClock
,Display
,Distributor
,DownSample
,ElementsToArray
,EmbeddedCodeActor.EmbeddedActor
,EmbeddedCodeActor.EmbeddedActor
,Expression
,Expression
,FFT
,FMIMACodeGeneratorAdapter
,FMUImport
,FSMActor
,GestureRecognition
,GPIOWriter
,HSBtoRGB
,IFFT
,InputDevice
,IOPort
,JavaScript
,JopReadPort
,JopSerialRead
,JopSerialWrite
,JopWatchDog
,JopWritePort
,JSAccessor
,LEDCubeUpdate
,LEDMatrix
,LimitedFiringSource
,Limiter
,LogicFunction
,Maximum
,Merge
,Minimum
,ModalController
,MostRecent
,MostRecent
,MovingAverage
,MultiplyDivide
,NeoPixelLEDStrip
,OutputDevice
,PacketToSensorData
,PID
,PID
,PoissonClock
,Previous
,Publisher
,PublisherTest
,Pulse
,Ramp
,RandomSource
,Recorder
,Register
,Remainder
,Repeat
,Round
,SampleDelay
,Scale
,SensorDataCalibration
,Sequence
,SequencePlotter
,SingleEvent
,SongWrapper
,State
,StringCompare
,StringConst
,StringLength
,Subscriber
,SubscriptionAggregator
,Synchronizer
,Test
,TimeCompare
,TimeDelay
,TimeGap
,TokenToExpression
,TopLevelCurrentTime
,TrigFunction
,TrueGate
,TypedCompositeActor
,UnaryMathFunction
,UpSample
,VariableDelay
,VectorAssembler
,VectorDisassembler
public class NamedProgramCodeGeneratorAdapter extends ProgramCodeGeneratorAdapter
Base class for code generator adapter. Actor adapters extend this class.Subclasses should override generateFireCode(), generateInitializeCode() generatePostfireCode(), generatePreinitializeCode(), and generateWrapupCode() methods by appending a corresponding code block.
Subclasses should be sure to properly indent the code by either using the code block functionality in methods like _generateBlockCode(String) or by calling
CodeStream.indent(String)
, for example:StringBuffer code = new StringBuffer(); code.append(super.generateWrapupCode()); code.append("// Local wrapup code"); return processCode(CodeStream.indent(code.toString()));
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Ye Zhou, Gang Zhou, Edward A. Lee, Bert Rodiers Contributors: Christopher Brooks, Teale Fristoe
- Pt.AcceptedRating:
- Yellow (eal)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
NamedProgramCodeGeneratorAdapter.VariableScope
This class implements a scope, which is used to generate the parsed expressions in target language.-
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 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 NamedProgramCodeGeneratorAdapter(NamedObj component)
Construct the code generator adapter associated with the given component.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
_generateFireCode()
Generate the fire code.protected java.lang.String
_generateTypeConvertStatement(ProgramCodeGeneratorAdapter.Channel source, ProgramCodeGeneratorAdapter.Channel sink, int offset)
Generate the type conversion statement for the particular offset of the two given channels.void
analyzeTypeConvert()
Find out each output port that needs to be converted for the actor associated with this adapter.static long
copyFilesToCodeDirectory(NamedObj namedObj, ProgramCodeGenerator codeGenerator)
Copy files to the code directory.java.lang.String
generateFireCode()
Generate the fire code.java.lang.String
generateFireFunctionCode()
Generate The fire function code.java.lang.String
generateInitializeCode()
Generate the initialize code.java.lang.String
generateMainLoop()
Generate a main loop for an execution under the control of a director.void
generateModeTransitionCode(java.lang.StringBuffer code)
Generate mode transition code.java.lang.String
generatePostfireCode()
Generate the postfire code.java.lang.String
generatePrefireCode()
Generate the prefire code of the associated composite actor.java.lang.String
generatePreinitializeCode()
Generate the preinitialize code.java.lang.String
generatePreinitializeMethodBodyCode()
Generate the preinitialization method body.static java.lang.String
generateSimpleName(NamedObj namedObj)
Generate sanitized name for the given named object.java.lang.String
generateTypeConvertFireCode()
Generate the type conversion fire code.java.lang.String
generateTypeConvertFireCode(boolean forComposite)
Generate the type conversion fire 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
generateWrapupCode()
Generate the wrapup code.java.lang.String
getAddTimeString()
Return a string that represents the additional time.int
getBufferSize(IOPort port)
Return the buffer size of a given port, which is the maximum of the bufferSizes of all channels of the given port.int
getBufferSize(IOPort port, int channelNumber)
Get the buffer size of the given port of this actor.NamedObj
getComponent()
Get the component associated with this adapter.java.util.Set<java.lang.String>
getDeclareSharedCode()
Generate the declaration of the shared code (only for C code) At run time of the generated code, the code generated by this method is run first, so any initialization of variables of this adapter should be done in this method.static java.lang.String[]
getDefaultBlocks()
Return an array of strings that are regular expressions of all the code blocks that are appended automatically by default.java.lang.String
getFireFunctionParameters()
Return the parameters for the fire function.java.util.Set<java.lang.String>
getHeaderFiles()
Get the files needed by the code generated from this adapter class.java.util.Set<java.lang.String>
getIncludeDirectories()
Return a set of directories to include for the generated code.java.util.Set<java.lang.String>
getLibraries()
Return a set of libraries to link in the generated code.java.util.Set<java.lang.String>
getLibraryDirectories()
Return a set of directories to find libraries in.java.util.Set<Parameter>
getModifiedVariables()
Return a set of parameters that will be modified during the execution of the model.java.lang.String
getName()
Return the name of the object.java.lang.String
getParameterValue(java.lang.String name, NamedObj container)
Return the value or an expression in the target language for the specified parameter of the associated actor.java.lang.String
getReference(java.lang.String name, boolean executive)
Return the reference to the specified parameter or port of the associated actor.java.lang.String
getReference(java.lang.String name, boolean isWrite, boolean executive)
Return the reference to the specified parameter or port of the associated actor.java.util.Set<java.lang.String>
getSharedCode()
Generate the shared code.static java.util.List<ProgramCodeGeneratorAdapter.Channel>
getSinkChannels(IOPort port, int channelNumber)
Return a list of channel objects that are the sink input ports given a port and channel.java.lang.String
getSourceTimeString(java.lang.String timeVariable)
Return a string that represents the source time.java.lang.String
getTimeSourcePortName()
Return the name of the port that is the time source.java.util.Set<ProgramCodeGeneratorAdapter.Channel>
getTypeConvertChannels()
Get the set of channels that need to be type converted.static java.lang.String
getTypeConvertReference(ProgramCodeGeneratorAdapter.Channel channel)
Generate a variable reference for the given channel.java.util.List<ProgramCodeGeneratorAdapter.Channel>
getTypeConvertSinkChannels(ProgramCodeGeneratorAdapter.Channel source)
Get the list of sink channels that the given source channel needs to be type converted to.void
setupAdapter()
Perform any setup or initialization of the adapter.java.lang.String
targetType(Type ptType)
Get the corresponding type in the target language from the given Ptolemy type.-
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
-
-
-
-
Constructor Detail
-
NamedProgramCodeGeneratorAdapter
public NamedProgramCodeGeneratorAdapter(NamedObj component)
Construct the code generator adapter associated with the given component.- Parameters:
component
- The associated component.
-
-
Method Detail
-
analyzeTypeConvert
public void analyzeTypeConvert() throws IllegalActionException
Find out each output port that needs to be converted for the actor associated with this adapter. Then, mark these ports along with the sink ports (connection).- Throws:
IllegalActionException
- Not thrown in this base class.
-
copyFilesToCodeDirectory
public static long copyFilesToCodeDirectory(NamedObj namedObj, ProgramCodeGenerator codeGenerator) throws java.io.IOException, IllegalActionException
Copy files to the code directory. The optionalfileDependencies
codeBlock consists of one or more lines where each line names a file that should be copied to the directory named by the codeDirectory parameter of the code generator. The file is only copied if a file by that name does not exist in codeDirectory or if the source file was more recently modified than the destination file.Using the
fileDependencies
code block allows actor writers to refer to code defined in other files.- Parameters:
namedObj
- If this argument is an instance of ptolemy.actor.lib.jni.EmbeddedCActor, then the code blocks from EmbeddedCActor's embeddedCCode parameter are used.codeGenerator
- The code generator from which the codeDirectory parameter is read.- Returns:
- The modification time of the most recent file.
- Throws:
java.io.IOException
- If there is a problem reading the codeDirectory parameter.IllegalActionException
- If there is a problem reading the codeDirectory parameter.
-
getComponent
public NamedObj getComponent()
Get the component associated with this adapter.- Overrides:
getComponent
in classProgramCodeGeneratorAdapter
- Returns:
- The associated component.
-
getDefaultBlocks
public static java.lang.String[] getDefaultBlocks()
Return an array of strings that are regular expressions of all the code blocks that are appended automatically by default. Since the content of the array are regex, users should use matches() instead of equals() to compare their strings.- Returns:
- Array of string regular expressions of names of code blocks that are appended by default.
-
getAddTimeString
public java.lang.String getAddTimeString() throws IllegalActionException
Return a string that represents the additional time.- Returns:
- In this base class, return the empty string. derived classes may want to return the value of the delay parameter in the target language.
- Throws:
IllegalActionException
- Not thrown in this baseclass. Derived classes may throw it if there is a problem accessing ports or parameters in the associated actor.
-
getSourceTimeString
public java.lang.String getSourceTimeString(java.lang.String timeVariable) throws IllegalActionException
Return a string that represents the source time.- Parameters:
timeVariable
- The variable to be set in the generated code.- Returns:
- In this base class, return the empty string. Derived classes may want to return code that sets the time variable to the time stamp.
- Throws:
IllegalActionException
- Not thrown in this baseclass. Derived classes may throw it if there is a problem accessing ports or parameters in the associated actor.
-
getTimeSourcePortName
public java.lang.String getTimeSourcePortName()
Return the name of the port that is the time source.- Returns:
- In this base class, return the empty string. Derived classes should return the name of the port that is the time source.
-
getFireFunctionParameters
public java.lang.String getFireFunctionParameters()
Return the parameters for the fire function.- Returns:
- In this base class, return the empty string.
-
generateFireCode
public java.lang.String generateFireCode() throws IllegalActionException
Generate the fire code. In this base class, add the name of the associated component in the comment. It checks the inline parameter of the code generator. If the value is true, it generates the actor fire code and the necessary type conversion code. Otherwise, it generate an invocation to the actor function that is generated by generateFireFunctionCode.- Returns:
- The generated code.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateFireFunctionCode
public java.lang.String generateFireFunctionCode() throws IllegalActionException
Generate The fire function code. This method is called when the firing code of each actor is not inlined. Each actor's firing code is in a function with the same name as that of the actor.- Returns:
- The fire function code.
- Throws:
IllegalActionException
- If thrown while generating fire code.
-
generateMainLoop
public java.lang.String generateMainLoop() throws IllegalActionException
Generate a main loop for an execution under the control of a director. In this base class, this simply delegates to generateFireCode() and generatePostfireCOde().- Returns:
- Whatever generateFireCode() returns.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateTypeConvertFireCode
public java.lang.String generateTypeConvertFireCode() throws IllegalActionException
Generate the type conversion fire code. This method is called by the Director to append necessary fire code to handle type conversion.- Returns:
- The generated code.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateInitializeCode
public java.lang.String generateInitializeCode() throws IllegalActionException
Generate the initialize code. In this base class, return empty string. Subclasses may extend this method to generate initialize code of the associated component and append the code to the given string buffer.- Returns:
- The initialize code of the containing composite actor.
- Throws:
IllegalActionException
- If thrown while appending to the the block or processing the macros.
-
generateModeTransitionCode
public void generateModeTransitionCode(java.lang.StringBuffer code) throws IllegalActionException
Generate mode transition code. The mode transition code generated in this method is executed after each global iteration, e.g., in HDF model. Do nothing in this base class.- Parameters:
code
- The string buffer that the generated code is appended to.- Throws:
IllegalActionException
- Not thrown in this base class.
-
generatePostfireCode
public java.lang.String generatePostfireCode() throws IllegalActionException
Generate the postfire code. In this base class, do nothing. Subclasses may extend this method to generate the postfire code of the associated component and append the code to the given string buffer.- Returns:
- The generated postfire code.
- Throws:
IllegalActionException
- If thrown while appending to the the block or processing the macros.
-
generatePrefireCode
public java.lang.String generatePrefireCode() throws IllegalActionException
Generate the prefire code of the associated composite actor.- Returns:
- The prefire code of the associated composite actor.
- Throws:
IllegalActionException
- If illegal macro names are found.
-
generatePreinitializeCode
public java.lang.String generatePreinitializeCode() throws IllegalActionException
Generate the preinitialize code. In this base class, return an empty string. This method generally does not generate any execution code and returns an empty string. Subclasses may generate code for variable declaration, defining constants, etc.- Returns:
- A string of the preinitialize code for the adapter.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generatePreinitializeMethodBodyCode
public java.lang.String generatePreinitializeMethodBodyCode() throws IllegalActionException
Generate the preinitialization method body.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.
- Returns:
- a string for the preinitialization method body. In this base class, return the empty string.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateSimpleName
public static final java.lang.String generateSimpleName(NamedObj namedObj)
Generate sanitized name for the given named object. Remove all underscores to avoid conflicts with systems functions.- Parameters:
namedObj
- The named object for which the name is generated.- Returns:
- The sanitized name.
- See Also:
CodeGeneratorAdapter.generateName(NamedObj)
-
generateTypeConvertFireCode
public java.lang.String generateTypeConvertFireCode(boolean forComposite) throws IllegalActionException
Generate the type conversion fire code. This method is called by the Director to append necessary fire code to handle type conversion.- Parameters:
forComposite
- True if we are generating code for a composite.- Returns:
- The generated code.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateVariableDeclaration
public java.lang.String generateVariableDeclaration() throws IllegalActionException
Generate variable declarations for inputs and outputs and parameters. Append the declarations to the given string buffer.- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
generateVariableInitialization
public java.lang.String generateVariableInitialization() throws IllegalActionException
Generate variable initialization for the referenced parameters.- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
generateWrapupCode
public java.lang.String generateWrapupCode() throws IllegalActionException
Generate the wrapup code. In this base class, do nothing. Subclasses may extend this method to generate the wrapup code of the associated component and append the code to the given string buffer.- Returns:
- The generated wrapup code.
- Throws:
IllegalActionException
- If thrown while appending to the the block or processing the macros.
-
getHeaderFiles
public java.util.Set<java.lang.String> getHeaderFiles() throws IllegalActionException
Get the files needed by the code generated from this adapter class. This base class returns an empty set. Typically, the "includeFiles" block is used to set list of files needed. SeeTemplateParser.getHeaderFiles()
.- Returns:
- A set of strings that are header files needed by the code generated from this adapter class.
- Throws:
IllegalActionException
- Not Thrown in this base class.
-
getIncludeDirectories
public java.util.Set<java.lang.String> getIncludeDirectories() throws IllegalActionException
Return a set of directories to include for the generated code.- Returns:
- A Set containing the contents of the actor's "includeDirectories" block in its template.
- Throws:
IllegalActionException
- If thrown when getting or reading the CodeStream.
-
getBufferSize
public int getBufferSize(IOPort port) throws IllegalActionException
Return the buffer size of a given port, which is the maximum of the bufferSizes of all channels of the given port.- Parameters:
port
- The given port.- Returns:
- The buffer size of the given port.
- Throws:
IllegalActionException
- If thegetBufferSize(IOPort, int)
method throws it.
-
getBufferSize
public int getBufferSize(IOPort port, int channelNumber) throws IllegalActionException
Get the buffer size of the given port of this actor.- Parameters:
port
- The given port.channelNumber
- The given channel.- Returns:
- The buffer size of the given port and channel.
- Throws:
IllegalActionException
- If the getBufferSize() method of the actor helper class throws it.
-
getLibraries
public java.util.Set<java.lang.String> getLibraries() throws IllegalActionException
Return a set of libraries to link in the generated code.- Returns:
- A Set containing the libraries in the actor's "libraries" block in its template.
- Throws:
IllegalActionException
- If thrown when getting or reading the CodeStream.
-
getLibraryDirectories
public java.util.Set<java.lang.String> getLibraryDirectories() throws IllegalActionException
Return a set of directories to find libraries in.- Returns:
- A Set containing the directories in the actor's "libraryDirectories" block in its template.
- Throws:
IllegalActionException
- If thrown when getting or reading the CodeStream.
-
getName
public java.lang.String getName()
Return the name of the object.- Specified by:
getName
in interfaceNameable
- Overrides:
getName
in classNamedObj
- Returns:
- The name of the object.
- See Also:
NamedObj.setName(String)
-
getModifiedVariables
public java.util.Set<Parameter> getModifiedVariables() throws IllegalActionException
Return a set of parameters that will be modified during the execution of the model. The actor gets those variables if it implements ExplicitChangeContext interface or it contains PortParameters.- Returns:
- a set of parameters that will be modified.
- Throws:
IllegalActionException
- If an actor throws it while getting modified variables.
-
getParameterValue
public final java.lang.String getParameterValue(java.lang.String name, NamedObj container) throws IllegalActionException
Return the value or an expression in the target language for the specified parameter of the associated actor. If the parameter is specified by an expression, then the expression will be parsed. If any parameter referenced in that expression is specified by another expression, the parsing continues recursively until either a parameter is directly specified by a constant or a parameter can be directly modified during execution in which case a reference to the parameter is generated.- Parameters:
name
- The name of the parameter.container
- The container to search upwards from.- Returns:
- The value or expression as a string.
- Throws:
IllegalActionException
- If the parameter does not exist or does not have a value.
-
getReference
public final java.lang.String getReference(java.lang.String name, boolean executive) 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. FIXME: need documentation on the input string format.- Parameters:
name
- The name of the parameter or portexecutive
- If true, then look for the reference in the executive director (the director of the container).- 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(java.lang.String name, boolean isWrite, boolean executive) 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. FIXME: need documentation on the input string format.- Parameters:
name
- The name of the parameter or portisWrite
- Whether to generate the write or read offset.executive
- If true, then look for the reference in the executive director (the director of the container).- 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.
-
getDeclareSharedCode
public java.util.Set<java.lang.String> getDeclareSharedCode() throws IllegalActionException
Generate the declaration of the shared code (only for C code) At run time of the generated code, the code generated by this method is run first, so any initialization of variables of this adapter should be done in this method. Note that at code generation time,setupAdapter()
is run before this method. In this base class, return an empty set. Subclasses may generate code for variable declaration, defining constants, etc.- Returns:
- An empty set in this base class.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
getSharedCode
public java.util.Set<java.lang.String> getSharedCode() throws IllegalActionException
Generate the shared code. At run time of the generated code, the code generated by this method is run first, so any initialization of variables of this adapter should be done in this method. Note that at code generation time,setupAdapter()
is run before this method. In this base class, return an empty set. Subclasses may generate code for variable declaration, defining constants, etc.- Returns:
- An empty set in this base class.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
getSinkChannels
public static java.util.List<ProgramCodeGeneratorAdapter.Channel> getSinkChannels(IOPort port, int channelNumber) throws IllegalActionException
Return a list of channel objects that are the sink input ports given a port and channel. Note the returned channels are newly created objects and therefore not associated with the adapter class.- Parameters:
port
- The given output port.channelNumber
- The given channel number.- Returns:
- The list of channel objects that are the sink channels of the given output channel.
- Throws:
IllegalActionException
- If thrown while getting the remote or deep receivers.
-
getTypeConvertChannels
public java.util.Set<ProgramCodeGeneratorAdapter.Channel> getTypeConvertChannels()
Get the set of channels that need to be type converted.- Returns:
- Set of channels that need to be type converted.
-
getTypeConvertReference
public static java.lang.String getTypeConvertReference(ProgramCodeGeneratorAdapter.Channel channel)
Generate a variable reference for the given channel. This variable reference is needed for type conversion. The source adapter get this reference instead of using the sink reference directly. This method assumes the given channel is a source (output) channel.- Parameters:
channel
- The given source channel.- Returns:
- The variable reference for the given channel.
-
getTypeConvertSinkChannels
public java.util.List<ProgramCodeGeneratorAdapter.Channel> getTypeConvertSinkChannels(ProgramCodeGeneratorAdapter.Channel source)
Get the list of sink channels that the given source channel needs to be type converted to.- Parameters:
source
- The given source channel.- Returns:
- List of sink channels that the given source channel needs to be type converted to.
-
setupAdapter
public void setupAdapter() throws IllegalActionException
Perform any setup or initialization of the adapter. Note that this is not the Ptolemy initialize() method, this method merely sets up any codegen-time variables in the adapters. In this base class, nothing is done.- Throws:
IllegalActionException
- If an error occurrs while initializing an adapter.
-
targetType
public final java.lang.String targetType(Type ptType)
Get the corresponding type in the target language from the given Ptolemy type.- Parameters:
ptType
- The given Ptolemy type.- Returns:
- The target language data type.
-
_generateFireCode
protected java.lang.String _generateFireCode() throws IllegalActionException
Generate the fire code. In this base class, add the name of the associated component in the comment. It checks the inline parameter of the code generator. If the value is true, it generates the actor fire code and the necessary type conversion code. Otherwise, it generate an invocation to the actor function that is generated by generateFireFunctionCode.- Returns:
- The generated code.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
_generateTypeConvertStatement
protected java.lang.String _generateTypeConvertStatement(ProgramCodeGeneratorAdapter.Channel source, ProgramCodeGeneratorAdapter.Channel sink, int offset) throws IllegalActionException
Generate the type conversion statement for the particular offset of the two given channels. This assumes that the offset is the same for both channel. Advancing the offset of one has to advance the offset of the other.- Parameters:
source
- The given source channel.sink
- The given sink channel.offset
- The given offset.- Returns:
- The type convert statement for assigning the converted source variable to the sink variable with the given offset.
- Throws:
IllegalActionException
- If there is a problem getting the adapters for the ports or if the conversion cannot be handled.
-
-