ptolemy.codegen.kernel
Class CodeGeneratorHelper

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.codegen.kernel.CodeGeneratorHelper
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
CCodeGeneratorHelper, Director, JavaCodeGeneratorHelper, RTMaudeAdaptor, TestCodeGeneratorHelper, TypedCompositeActor, TypedCompositeActor

public class CodeGeneratorHelper
extends NamedObj
implements ActorCodeGenerator

Base class for code generator helper.

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 6.0
Version:
$Id: CodeGeneratorHelper.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Ye Zhou, Gang Zhou, Edward A. Lee, Contributors: Christopher Brooks, Teale Fristoe
See Also:
Serialized Form
Accepted Rating:
Yellow (eal)
Proposed Rating:
Yellow (eal)

Nested Class Summary
static class CodeGeneratorHelper.Channel
          A class that defines a channel object.
protected  class CodeGeneratorHelper.VariableScope
          This class implements a scope, which is used to generate the parsed expressions in target language.
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
protected  CodeGenerator _codeGenerator
          The code generator that contains this helper class.
protected  CodeStream _codeStream
          The code stream associated with this helper.
private static java.lang.String[] _defaultBlocks
          The code block table that stores the code block body (StringBuffer) with the code block name (String) as key.
protected static java.lang.String _eol
          End of line character.
private  java.lang.String _fireCode
           
protected static java.lang.String _INDENT1
          Indent string for indent level 1.
protected static java.lang.String _INDENT2
          Indent string for indent level 2.
private  java.lang.Object _object
          The associated object.
protected  ParseTreeCodeGenerator _parseTreeCodeGenerator
          The parse tree to use with expressions.
protected  java.util.Hashtable _portConversions
          A HashMap that contains mapping for ports and their conversion method.
protected  java.util.HashSet _referencedParameters
          A hashset that keeps track of parameters that are referenced for the associated actor.
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
CodeGeneratorHelper()
          Construct a code generator helper.
CodeGeneratorHelper(NamedObj component)
          Construct the code generator helper associated with the given component.
CodeGeneratorHelper(NamedObj component, java.lang.String name)
          Construct the code generator helper associated with the given component.
CodeGeneratorHelper(java.lang.Object object)
          Construct a code generator helper.
 
Method Summary
protected  void _createBufferSizeAndOffsetMap()
          Create the buffer size and offset maps for each input port, which is associated with this helper object.
protected  void _createInputBufferSizeAndOffsetMap()
          Create the input buffer and offset map.
protected static int _findClosedParen(java.lang.String string, int pos)
          Find the paired close parenthesis given a string and an index which is the position of an open parenthesis.
private  java.lang.String _generateBlockByName(java.lang.String blockName)
          Generate code for a given block.
protected  java.lang.String _generateBlockCode(java.lang.String blockName)
          Given a block name, generate code for that block.
protected  java.lang.String _generateBlockCode(java.lang.String blockName, java.util.List args)
          Given a block name, generate code for that block.
protected  java.lang.String _generateFireCode()
          Generate the fire code.
private static java.lang.String _generateFireInvocation(NamedObj component)
          Generate the invocation of the fire function of the given component.
protected  java.lang.String _generateTypeConvertMethod(java.lang.String expression, java.lang.String castType, java.lang.String refType)
          Generate expression that evaluates to a result of equivalent value with the cast type.
protected  java.lang.String _generateTypeConvertStatement(CodeGeneratorHelper.Channel source, CodeGeneratorHelper.Channel sink, int offset)
          Generate the type conversion statement for the particular offset of the two given channels.
protected  java.lang.String _generateTypeConvertStatements(CodeGeneratorHelper.Channel source, CodeGeneratorHelper.Channel sink)
          Generate the type conversion statements for the two given channels.
private  CodeStream _getActualCodeStream()
          Return the actual CodeStream for this Helper.
private static CodeStream _getActualCodeStream(NamedObj namedObj, CodeGenerator codeGenerator)
          Return the actual CodeStream associated with the given Actor and CodeGenerator.
protected  java.lang.String _getCastType(java.lang.String name)
          Get the cast type of a name.
protected  java.lang.String[] _getChannelAndOffset(java.lang.String name)
          Return the channel and offset given in a string.
protected  java.lang.String _getFireFunctionArguments()
          Return the prototype for fire functions.
protected  ComponentCodeGenerator _getHelper(NamedObj component)
          Get the code generator helper associated with the given component.
protected  java.lang.Object _getHelper(java.lang.Object object)
          Get the code generator helper associated with the given object.
protected static java.lang.String _getIndentPrefix(int level)
          Return a number of spaces that is proportional to the argument.
private  int _getMacroStartIndex(java.lang.String code, int from)
          Return the position of the first occurence of the "&" sign in the given code string, starting from the given from position.
protected  java.lang.String _getReference(java.lang.String name, boolean isWrite)
          Return the reference to the specified parameter or port of the associated actor.
protected  java.util.List<CodeGeneratorHelper.Channel> _getReferenceChannels(TypedIOPort port, int channelNumber, boolean isWrite)
          Return the list of corresponding reference channel.
private  java.lang.String _getRefName(java.lang.String name)
           
private  java.lang.String _getRefType(Attribute attribute)
           
private  Typeable _getTypeable(java.lang.String objectName)
          If the object name is a Port or Variable, return its Port or Variable, otherwise return null.
protected  java.util.Set _getTypeConvertChannels()
          Get the set of channels that need to be type converted.
protected  java.lang.String _getTypeConvertReference(CodeGeneratorHelper.Channel channel)
          Generate a variable reference for the given channel.
private  java.util.List _getTypeConvertSinkChannels(CodeGeneratorHelper.Channel source)
          Get the list of sink channels that the given source channel needs to be type converted to.
private  Variable _getVariable(java.lang.String refName)
          Return a variable that matches the given label.
static int _indexOf(java.lang.String ch, java.lang.String string, int fromIndex)
          Return the index of a specific character in the string starting from the given index.
private  void _markTypeConvert(CodeGeneratorHelper.Channel source, CodeGeneratorHelper.Channel sink)
          Mark the given connection between the source and the sink channels as type conversion required.
private  java.lang.String _replaceGetMacro(java.lang.String parameter)
           
protected  java.lang.String _replaceMacro(java.lang.String macro, java.lang.String parameter)
          Return the replacement string of the given macro.
private  java.lang.String _replaceSendMacro(java.lang.String parameter)
           
 void addFunctionUsed(java.lang.String functionName)
          Add a functiom to the Set of functions used thus far.
 void addNewTypeUsed(java.lang.String typeName)
          Add a type to the Set of types used thus far.
 void analyzeTypeConvert()
          Find out each output port that needs to be converted for the actor associated with this helper.
 boolean checkLocal(boolean forComposite, IOPort port)
          Return true if the port is a local port.
 boolean checkRemote(boolean forComposite, IOPort port)
          Return true if the port is a remote port.
 java.lang.String codeGenType(Type ptType)
          Get the corresponding type in code generation from the given Ptolemy type.
static long copyFilesToCodeDirectory(NamedObj namedObj, CodeGenerator codeGenerator)
          Copy files to the code directory.
 java.lang.String createOffsetVariablesIfNeeded()
          Generate code for declaring read and write offset variables if needed.
static java.lang.String generateChannelOffset(IOPort port, boolean isWrite, java.lang.String channelString)
          Generate a string that represents the offset for a dynamically determined channel of a multiport.
 java.lang.String generateFireCode()
          Generate the fire code.
 java.lang.String generateFireFunctionCode()
          Generate The fire function code.
 java.lang.String generateFireFunctionCode2()
          Generate The fire function code.
 java.lang.String generateInitializeCode()
          Generate the initialize code.
 void generateModeTransitionCode(java.lang.StringBuffer code)
          Generate mode transition code.
static java.lang.String generateName(NamedObj namedObj)
          Generate sanitized name for the given named object.
 java.lang.String generateOffset(java.lang.String offsetString, IOPort port, int channel, boolean isWrite)
          Generate the expression that represents the offset in the generated code.
static java.lang.String generatePortReference(IOPort port, java.lang.String[] channelAndOffset, boolean isWrite)
          Return a reference to the port.
 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.
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 generateVariableName(NamedObj namedObj)
          Generate a variable name for the NamedObj.
 java.lang.String generateWrapupCode()
          Generate the wrapup code.
 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.
 CodeGenerator getCodeGenerator()
          Get the code generator associated with this helper class.
 NamedObj getComponent()
          Get the component associated with this helper.
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.
 Director getDirector()
          Return the executive director.
 Director getDirectorHelper()
          Return the helper of the director.
 java.lang.String getFunctionInvocation(java.lang.String functionString, boolean isStatic)
          Return the translated token instance function invocation string.
 java.util.Set getHeaderFiles()
          Get the files needed by the code generated from this helper class.
 java.util.Set getIncludeDirectories()
          Return a set of directories to include for the generated code.
 java.util.Set getLibraries()
          Return a set of libraries to link in the generated code.
 java.util.Set getLibraryDirectories()
          Return a set of directories to find libraries in.
 java.util.Set getModifiedVariables()
          Return a set of parameters that will be modified during the execution of the model.
 java.lang.String getNewInvocation(java.lang.String constructorString)
          Return the translated new constructor invocation string.
 NamedObj getObject()
          Get the object associated with this helper.
 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.
 ParseTreeCodeGenerator getParseTreeCodeGenerator()
          Return the parse tree to use with expressions.
 TypedIOPort getPort(java.lang.String refName)
          Get the port that has the given name.
 int[][] getRates()
          Return the associated actor's rates for all configurations of this actor.
 java.lang.Object getReadOffset(IOPort inputPort, int channelNumber)
          Get the read offset in the buffer of a given channel from which a token should be read.
 java.lang.String getReference(Attribute attribute, java.lang.String[] channelAndOffset)
          Return a reference to the attribute.
 java.lang.String getReference(java.lang.String name)
          Return the reference to the specified parameter or port of the associated actor.
 java.lang.String getReference(java.lang.String name, boolean isWrite)
          Return a reference.
 java.lang.String getReference(TypedIOPort port, java.lang.String[] channelAndOffset, boolean forComposite, boolean isWrite)
          Return a reference to the port.
 java.util.Set getSharedCode()
          Generate the shared code.
static java.util.List<CodeGeneratorHelper.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 getSize(java.lang.String name)
          Get the size of a parameter.
static CodeGeneratorHelper.Channel getSourceChannel(IOPort port, int channelNumber)
          Given a port and channel number, create a Channel that sends data to the specified port and channel number.
 double getWCET()
          Return the worst case execution time (WCET) seen by this component.
 java.lang.Object getWriteOffset(IOPort port, int channelNumber)
          Get the write offset in the buffer of a given channel to which a token should be put.
 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 java.util.List<java.lang.String> parseList(java.lang.String parameters)
          Parse the list of comma separted parameters.
 java.lang.String processCode(java.lang.String code)
          Process the specified code, replacing macros with their values.
 java.lang.String resetInputPortsOffset()
          Reset the offsets of all channels of all input ports of the associated actor to the default value of 0.
 void setBufferSize(IOPort port, int channelNumber, int bufferSize)
          Set the buffer size of a given port.
 void setCodeGenerator(CodeGenerator codeGenerator)
          Set the code generator associated with this helper class.
 void setReadOffset(IOPort port, int channelNumber, java.lang.Object readOffset)
          Set the read offset in a buffer of a given channel from which a token should be read.
 void setWriteOffset(IOPort port, int channelNumber, java.lang.Object writeOffset)
          Set the write offset in a buffer of a given channel to which a token should be put.
 java.lang.String targetType(Type ptType)
          Get the corresponding type in C from the given Ptolemy type.
 java.lang.String toString()
          Return the class name and the full name of the object, with syntax "className {fullName}".
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getContainedObject, _isMoMLSuppressed, _markContentsDerived, _propagateExistence, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, 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, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_codeGenerator

protected CodeGenerator _codeGenerator
The code generator that contains this helper class.


_codeStream

protected CodeStream _codeStream
The code stream associated with this helper.


_eol

protected static final java.lang.String _eol
End of line character. Under Unix: "\n", under Windows: "\n\r". We use a end of line charactor so that the files we generate have the proper end of line character for use by other native tools.


_parseTreeCodeGenerator

protected ParseTreeCodeGenerator _parseTreeCodeGenerator
The parse tree to use with expressions.


_portConversions

protected java.util.Hashtable _portConversions
A HashMap that contains mapping for ports and their conversion method. Ports that does not need to be converted do NOT have record in this map. The codegen kernel record this mapping during the first pass over the model. This map is used later in the code generation phase.


_referencedParameters

protected java.util.HashSet _referencedParameters
A hashset that keeps track of parameters that are referenced for the associated actor.


_INDENT1

protected static final java.lang.String _INDENT1
Indent string for indent level 1.

See Also:
StringUtilities.getIndentPrefix(int)

_INDENT2

protected static final java.lang.String _INDENT2
Indent string for indent level 2.

See Also:
StringUtilities.getIndentPrefix(int)

_object

private final java.lang.Object _object
The associated object.


_defaultBlocks

private static final java.lang.String[] _defaultBlocks
The code block table that stores the code block body (StringBuffer) with the code block name (String) as key.


_fireCode

private java.lang.String _fireCode
Constructor Detail

CodeGeneratorHelper

public CodeGeneratorHelper()
Construct a code generator helper.


CodeGeneratorHelper

public CodeGeneratorHelper(NamedObj component)
Construct the code generator helper associated with the given component.

Parameters:
component - The associated component.

CodeGeneratorHelper

public CodeGeneratorHelper(NamedObj component,
                           java.lang.String name)
Construct the code generator helper associated with the given component.

Parameters:
component - The associated component.
name - The name of helper. All periods are replaced with underscores.

CodeGeneratorHelper

public CodeGeneratorHelper(java.lang.Object object)
Construct a code generator helper.

Parameters:
object - The object for which the code generator should be constructed.
Method Detail

addNewTypeUsed

public void addNewTypeUsed(java.lang.String typeName)
Add a type to the Set of types used thus far.

Parameters:
typeName - A string naming the type, for example "Boolean" or "String".

addFunctionUsed

public void addFunctionUsed(java.lang.String functionName)
Add a functiom to the Set of functions used thus far.

Parameters:
functionName - A string naming a function, for example "new".

analyzeTypeConvert

public void analyzeTypeConvert()
                        throws IllegalActionException
Find out each output port that needs to be converted for the actor associated with this helper. Then, mark these ports along with the sink ports (connection).

Throws:
IllegalActionException - Not thrown in this base class.

checkLocal

public boolean checkLocal(boolean forComposite,
                          IOPort port)
                   throws IllegalActionException
Return true if the port is a local port.

Parameters:
forComposite - True if this check is for a composite
port - The port to be checked.
Returns:
true if the port is a local port.
Throws:
IllegalActionException - If thrown while queryint the port.

checkRemote

public boolean checkRemote(boolean forComposite,
                           IOPort port)
Return true if the port is a remote port.

Parameters:
forComposite - True if this check is for a composite
port - The port to be checked.
Returns:
true if the port is a remote port.

codeGenType

public java.lang.String codeGenType(Type ptType)
Get the corresponding type in code generation from the given Ptolemy type.

Parameters:
ptType - The given Ptolemy type.
Returns:
The code generation type.
Throws:
IllegalActionException - Thrown if the given ptolemy cannot be resolved.

createOffsetVariablesIfNeeded

public java.lang.String createOffsetVariablesIfNeeded()
                                               throws IllegalActionException
Generate code for declaring read and write offset variables if needed. Return empty string in this base class.

Specified by:
createOffsetVariablesIfNeeded in interface ActorCodeGenerator
Returns:
The empty string.
Throws:
IllegalActionException - Not thrown in this base class.

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.

Specified by:
generateFireCode in interface ActorCodeGenerator
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.

Specified by:
generateFireFunctionCode in interface ActorCodeGenerator
Returns:
The fire function code.
Throws:
IllegalActionException - If thrown while generating fire code.

generateFireFunctionCode2

public java.lang.String generateFireFunctionCode2()
                                           throws IllegalActionException
Generate The fire function code. This method is called when generating code for a Giotto director. Produce the fire code but do not transfer generate any type conversion code that sends this actors output to another actor's input. The typeConversion and moving from an output to an input should be taken care of in a driver method not the fire method. This works under that assumption that _generateFireCode() also generates the code for postfire. If later we generate postfire code in a different method please add that method call to this method

Returns:
The fire function code.
Throws:
IllegalActionException - If thrown while generating fire code.

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.

Specified by:
generateInitializeCode in interface ComponentCodeGenerator
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.

Specified by:
generateModeTransitionCode in interface ActorCodeGenerator
Parameters:
code - The string buffer that the generated code is appended to.
Throws:
IllegalActionException - Not thrown in this base class.

generateOffset

public java.lang.String generateOffset(java.lang.String offsetString,
                                       IOPort port,
                                       int channel,
                                       boolean isWrite)
                                throws IllegalActionException
Generate the expression that represents the offset in the generated code.

Parameters:
offsetString - The specified offset from the user.
port - The referenced port.
channel - The referenced port channel.
isWrite - Whether to generate the write or read offset.
Returns:
The expression that represents the offset in the generated code.
Throws:
IllegalActionException - If there is problems getting the port buffer size or the offset in the channel and offset map.

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.

Specified by:
generatePostfireCode in interface ActorCodeGenerator
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
Description copied from interface: ActorCodeGenerator
Generate the prefire code of the associated composite actor.

Specified by:
generatePrefireCode in interface ActorCodeGenerator
Returns:
The prefire code of the associated composite actor.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating the prefire code for the actor.

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.

Specified by:
generatePreinitializeCode in interface ActorCodeGenerator
Returns:
A string of the preinitialize code for the helper.
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.

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.

Specified by:
generateVariableDeclaration in interface ActorCodeGenerator
Returns:
code The generated code.
Throws:
IllegalActionException - If the helper class for the model director cannot be found.

generateVariableInitialization

public java.lang.String generateVariableInitialization()
                                                throws IllegalActionException
Generate variable initialization for the referenced parameters.

Specified by:
generateVariableInitialization in interface ActorCodeGenerator
Returns:
code The generated code.
Throws:
IllegalActionException - If the helper class for the model director cannot be found.

generateVariableName

public java.lang.String generateVariableName(NamedObj namedObj)
Generate a variable name for the NamedObj.

Parameters:
namedObj - The NamedObj to generate variable name for.
Returns:
The variable name for the NamedObj.
See Also:
CodeGenerator.generateVariableName(NamedObj)

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.

Specified by:
generateWrapupCode in interface ComponentCodeGenerator
Returns:
The generated wrapup code.
Throws:
IllegalActionException - If thrown while appending to the the block or processing the macros.

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 the getBufferSize(IOPort, int) method throws it.
See Also:
setBufferSize(IOPort, int, int)

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.
See Also:
setBufferSize(IOPort, int, int)

getCodeGenerator

public CodeGenerator getCodeGenerator()
Get the code generator associated with this helper class.

Returns:
The code generator associated with this helper class.
See Also:
setCodeGenerator(CodeGenerator)

getComponent

public NamedObj getComponent()
Get the component associated with this helper.

Specified by:
getComponent in interface ComponentCodeGenerator
Returns:
The associated component.

getDirector

public Director getDirector()
Return the executive director. If there is no executive director, then return the director associated with the object passed in to the constructor.

Returns:
the executive director or the director of the actor.

getDirectorHelper

public Director getDirectorHelper()
                           throws IllegalActionException
Return the helper of the director.

Returns:
Return the helper of the director.
Throws:
IllegalActionException - If thrown while getting the helper of the director.

getFunctionInvocation

public java.lang.String getFunctionInvocation(java.lang.String functionString,
                                              boolean isStatic)
                                       throws IllegalActionException
Return the translated token instance function invocation string.

Parameters:
functionString - The string within the $tokenFunc() macro.
isStatic - True if the method is static.
Returns:
The translated type function invocation string.
Throws:
IllegalActionException - The given function string is not well-formed.

getHeaderFiles

public java.util.Set getHeaderFiles()
                             throws IllegalActionException
Get the files needed by the code generated from this helper class. This base class returns an empty set.

Specified by:
getHeaderFiles in interface ActorCodeGenerator
Returns:
A set of strings that are header files needed by the code generated from this helper class.
Throws:
IllegalActionException - Not Thrown in this base class.

getIncludeDirectories

public java.util.Set getIncludeDirectories()
                                    throws IllegalActionException
Return a set of directories to include for the generated code.

Specified by:
getIncludeDirectories in interface ActorCodeGenerator
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.

getLibraries

public java.util.Set getLibraries()
                           throws IllegalActionException
Return a set of libraries to link in the generated code.

Specified by:
getLibraries in interface ActorCodeGenerator
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 getLibraryDirectories()
                                    throws IllegalActionException
Return a set of directories to find libraries in.

Specified by:
getLibraryDirectories in interface ActorCodeGenerator
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.

getModifiedVariables

public java.util.Set 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.

Specified by:
getModifiedVariables in interface ActorCodeGenerator
Returns:
a set of parameters that will be modified.
Throws:
IllegalActionException - If an actor throws it while getting modified variables.

getNewInvocation

public java.lang.String getNewInvocation(java.lang.String constructorString)
                                  throws IllegalActionException
Return the translated new constructor invocation string. Keep the types referenced in the info table of this helper. The kernel will retrieve this information to determine the total number of referenced types in the model.

Parameters:
constructorString - The string within the $new() macro.
Returns:
The translated new constructor invocation string.
Throws:
IllegalActionException - The given constructor string is not well-formed.

getObject

public NamedObj getObject()
Get the object associated with this helper.

Returns:
The associated object.

getParameterValue

public 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.

getParseTreeCodeGenerator

public ParseTreeCodeGenerator getParseTreeCodeGenerator()
Return the parse tree to use with expressions.

Returns:
the parse tree to use with expressions.

getPort

public TypedIOPort getPort(java.lang.String refName)
Get the port that has the given name.

Parameters:
refName - The given name.
Returns:
The port that has the given name.

getRates

public int[][] getRates()
Return the associated actor's rates for all configurations of this actor. In this base class, return null.

Returns:
null

getReadOffset

public java.lang.Object getReadOffset(IOPort inputPort,
                                      int channelNumber)
                               throws IllegalActionException
Get the read offset in the buffer of a given channel from which a token should be read. The channel is given by its containing port and the channel number in that port.

Parameters:
inputPort - The given port.
channelNumber - The given channel number.
Returns:
The offset in the buffer of a given channel from which a token should be read.
Throws:
IllegalActionException - Thrown if the helper class cannot be found.
See Also:
setReadOffset(IOPort, int, Object)

getReference

public java.lang.String getReference(java.lang.String name)
                              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 port
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.

getSharedCode

public java.util.Set getSharedCode()
                            throws IllegalActionException
Generate the shared code. This is the first generate method invoked out of all, so any initialization of variables of this helper should be done in this method. In this base class, return an empty set. Subclasses may generate code for variable declaration, defining constants, etc.

Specified by:
getSharedCode in interface ActorCodeGenerator
Returns:
An empty set in this base class.
Throws:
IllegalActionException - Not thrown in this base class.

getSize

public java.lang.String getSize(java.lang.String name)
                         throws IllegalActionException
Get the size of a parameter. The size of a parameter is the length of its array if the parameter's type is array, and 1 otherwise.

Parameters:
name - The name of the parameter.
Returns:
The expression that represents the size of a parameter or port.
Throws:
IllegalActionException - If no port or parameter of the given name is found.

getWCET

public double getWCET()
               throws IllegalActionException
Return the worst case execution time (WCET) seen by this component.

Returns:
The Worst Case Execution Time (WCET), in this base class, the default value of 500.0 is returned.
Throws:
IllegalActionException - If there is a problem determining the WCET or a problem accessing the model. Not thrown in this base class.

getWriteOffset

public java.lang.Object getWriteOffset(IOPort port,
                                       int channelNumber)
                                throws IllegalActionException
Get the write offset in the buffer of a given channel to which a token should be put. The channel is given by its containing port and the channel number in that port.

Parameters:
port - The given port.
channelNumber - The given channel number.
Returns:
The offset in the buffer of a given channel to which a token should be put.
Throws:
IllegalActionException - Thrown if the helper class cannot be found.
See Also:
setWriteOffset(IOPort, int, Object)

isPrimitive

public boolean isPrimitive(java.lang.String cgType)
Determine if the given type is primitive.

Parameters:
cgType - The given codegen type.
Returns:
true if the given type is primitive, otherwise false.

isPrimitive

public boolean isPrimitive(Type ptType)
Determine if the given type is primitive.

Parameters:
ptType - The given ptolemy type.
Returns:
true if the given type is primitive, otherwise false.

processCode

public java.lang.String processCode(java.lang.String code)
                             throws IllegalActionException
Process the specified code, replacing macros with their values.

Parameters:
code - The code to process.
Returns:
The processed code.
Throws:
IllegalActionException - If illegal macro names are found.

resetInputPortsOffset

public java.lang.String resetInputPortsOffset()
                                       throws IllegalActionException
Reset the offsets of all channels of all input ports of the associated actor to the default value of 0.

Returns:
The reset code of the associated actor.
Throws:
IllegalActionException - If thrown while getting or setting the offset.

setBufferSize

public void setBufferSize(IOPort port,
                          int channelNumber,
                          int bufferSize)
                   throws IllegalActionException
Set the buffer size of a given port.

Parameters:
port - The given port.
channelNumber - The given channel.
bufferSize - The buffer size to be set to that port and channel.
Throws:
IllegalActionException
See Also:
getBufferSize(IOPort)

setCodeGenerator

public void setCodeGenerator(CodeGenerator codeGenerator)
Set the code generator associated with this helper class.

Specified by:
setCodeGenerator in interface ComponentCodeGenerator
Parameters:
codeGenerator - The code generator associated with this helper class.
See Also:
getCodeGenerator()

setReadOffset

public void setReadOffset(IOPort port,
                          int channelNumber,
                          java.lang.Object readOffset)
                   throws IllegalActionException
Set the read offset in a buffer of a given channel from which a token should be read.

Parameters:
port - The given port.
channelNumber - The given channel.
readOffset - The offset to be set to the buffer of that channel.
Throws:
IllegalActionException - Thrown if the helper class cannot be found.
See Also:
getReadOffset(IOPort, int)

setWriteOffset

public void setWriteOffset(IOPort port,
                           int channelNumber,
                           java.lang.Object writeOffset)
                    throws IllegalActionException
Set the write offset in a buffer of a given channel to which a token should be put.

Parameters:
port - The given port.
channelNumber - The given channel.
writeOffset - The offset to be set to the buffer of that channel.
Throws:
IllegalActionException - If setWriteOffset(IOPort, int, Object) method throws it.
See Also:
getWriteOffset(IOPort, int)

targetType

public java.lang.String targetType(Type ptType)
Get the corresponding type in C from the given Ptolemy type.

Parameters:
ptType - The given Ptolemy type.
Returns:
The C data type.

toString

public java.lang.String toString()
Description copied from class: NamedObj
Return the class name and the full name of the object, with syntax "className {fullName}".

Overrides:
toString in class NamedObj
Returns:
The class name and the full name.

_indexOf

public static int _indexOf(java.lang.String ch,
                           java.lang.String string,
                           int fromIndex)
Return the index of a specific character in the string starting from the given index. It find the first occurence of the character that is not embedded inside parentheses "()".

Parameters:
ch - The character to search for.
string - The given string to search from.
fromIndex - The index to start the search.
Returns:
The first occurence of the character in the string that is not embedded in parentheses.

parseList

public static java.util.List<java.lang.String> parseList(java.lang.String parameters)
Parse the list of comma separted parameters.

Parameters:
parameters - A comma separate list of parameters.
Returns:
A list of parameters.

copyFilesToCodeDirectory

public static long copyFilesToCodeDirectory(NamedObj namedObj,
                                            CodeGenerator codeGenerator)
                                     throws java.io.IOException,
                                            IllegalActionException
Copy files to the code directory. The optional fileDependencies 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.

generateChannelOffset

public static java.lang.String generateChannelOffset(IOPort port,
                                                     boolean isWrite,
                                                     java.lang.String channelString)
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.

generateName

public static java.lang.String generateName(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.

generateSimpleName

public static 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.

generatePortReference

public static java.lang.String generatePortReference(IOPort port,
                                                     java.lang.String[] channelAndOffset,
                                                     boolean isWrite)
Return a reference to the port.

Parameters:
port - The port.
channelAndOffset - The given channel and offset.
isWrite - True if the port is to be written to.
Returns:
The reference to the port.
See Also:
getReference(TypedIOPort, String[], boolean, boolean)

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.

getReference

public java.lang.String getReference(Attribute attribute,
                                     java.lang.String[] channelAndOffset)
                              throws IllegalActionException
Return a reference to the attribute.

Parameters:
attribute - The attribute.
channelAndOffset - The given channel and offset.
Returns:
The reference.
Throws:
IllegalActionException - If the attribute does not exist or does not have a value.

getReference

public java.lang.String getReference(java.lang.String name,
                                     boolean isWrite)
                              throws IllegalActionException
Return a reference.

Parameters:
name - The reference to be parsed. The format is assumed to be "xxx#(yyy)", where "yyy" will be returned
isWrite - True if the reference is to be written to.
Returns:
The reference.
Throws:
IllegalActionException - If the attribute 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)
                              throws IllegalActionException
Return a reference to the port.

Parameters:
port - The port.
channelAndOffset - The given channel and offset.
forComposite - True if this check is for a composite
isWrite - True if the reference is to be written to.
Returns:
the reference.
Throws:
IllegalActionException - If the attribute does not exist or does not have a value.
See Also:
generatePortReference(IOPort, String[], boolean)

getSinkChannels

public static java.util.List<CodeGeneratorHelper.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 helper 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

getSourceChannel

public static CodeGeneratorHelper.Channel getSourceChannel(IOPort port,
                                                           int channelNumber)
                                                    throws IllegalActionException
Given a port and channel number, create a Channel that sends data to the specified port and channel number.

Parameters:
port - The port.
channelNumber - The channel number of the port.
Returns:
the source channel.
Throws:
IllegalActionException - If there is a problem getting information about the receivers or constructing the new Channel.

_generateFireCode

protected java.lang.String _generateFireCode()
                                      throws IllegalActionException
Generate the fire code. This method is intended to be overwritten by sub-classes to generate actor-specific code.

Returns:
The generated code.
Throws:
IllegalActionException - Not thrown in this base class.

_createBufferSizeAndOffsetMap

protected void _createBufferSizeAndOffsetMap()
                                      throws IllegalActionException
Create the buffer size and offset maps for each input port, which is associated with this helper object. A key of the map is an IOPort of the actor. The corresponding value is an array of channel objects. The i-th channel object corresponds to the i-th channel of that IOPort. This method is used to maintain a internal HashMap of channels of the actor. The channel objects in the map are used to keep track of the buffer sizes or offsets in their buffer.

Throws:
IllegalActionException - If the director helper or executive director is not found, or if setReadOffset(IOPort, int, Object) method throws it, or if setWriteOffset(IOPort, int, Object) method throws it.

_createInputBufferSizeAndOffsetMap

protected void _createInputBufferSizeAndOffsetMap()
                                           throws IllegalActionException
Create the input buffer and offset map.

Throws:
IllegalActionException - If thrown while getting port information.

_generateBlockCode

protected java.lang.String _generateBlockCode(java.lang.String blockName)
                                       throws IllegalActionException
Given a block name, generate code for that block. This method is called by actors helpers that have simple blocks that do not take parameters or have widths.

Parameters:
blockName - The name of the block.
Returns:
The code for the given block.
Throws:
IllegalActionException - If illegal macro names are found, or if there is a problem parsing the code block from the helper .c file.

_generateBlockCode

protected java.lang.String _generateBlockCode(java.lang.String blockName,
                                              java.util.List args)
                                       throws IllegalActionException
Given a block name, generate code for that block. This method is called by actors helpers that have simple blocks that do not take parameters or have widths.

Parameters:
blockName - The name of the block.
args - The arguments for the block.
Returns:
The code for the given block.
Throws:
IllegalActionException - If illegal macro names are found, or if there is a problem parsing the code block from the helper .c file.

_generateTypeConvertMethod

protected java.lang.String _generateTypeConvertMethod(java.lang.String expression,
                                                      java.lang.String castType,
                                                      java.lang.String refType)
                                               throws IllegalActionException
Generate expression that evaluates to a result of equivalent value with the cast type.

Parameters:
expression - The given variable expression.
castType - The given cast type.
refType - The given type of the variable.
Returns:
The variable expression that evaluates to a result of equivalent value with the cast type.
Throws:
IllegalActionException

_generateTypeConvertStatement

protected java.lang.String _generateTypeConvertStatement(CodeGeneratorHelper.Channel source,
                                                         CodeGeneratorHelper.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 helpers for the ports or if the conversion cannot be handled.

_generateTypeConvertStatements

protected java.lang.String _generateTypeConvertStatements(CodeGeneratorHelper.Channel source,
                                                          CodeGeneratorHelper.Channel sink)
                                                   throws IllegalActionException
Generate the type conversion statements for the two given channels.

Parameters:
source - The given source channel.
sink - The given sink channel.
Returns:
The type convert statement for assigning the converted source variable to the sink variable.
Throws:
IllegalActionException - If there is a problem getting the helpers for the ports or if the conversion cannot be handled.

_getCastType

protected java.lang.String _getCastType(java.lang.String name)
                                 throws IllegalActionException
Get the cast type of a name.

Parameters:
name - The given name. The name must have a "#" in it.
Returns:
The string after the "#" and before the () is returned
Throws:
IllegalActionException - If the cast type is invalid.

_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.

_getFireFunctionArguments

protected java.lang.String _getFireFunctionArguments()
Return the prototype for fire functions.

Returns:
In this base class, return "()". Derived classes, such as the C code generator helper might return "(void)".

_getHelper

protected ComponentCodeGenerator _getHelper(NamedObj component)
                                     throws IllegalActionException
Get the code generator helper associated with the given component.

Parameters:
component - The given component.
Returns:
The code generator helper.
Throws:
IllegalActionException - If the helper class cannot be found.

_getHelper

protected java.lang.Object _getHelper(java.lang.Object object)
                               throws IllegalActionException
Get the code generator helper associated with the given object.

Parameters:
object - The given object.
Returns:
The code generator helper.
Throws:
IllegalActionException - If the helper class cannot be found.

_getReference

protected java.lang.String _getReference(java.lang.String name,
                                         boolean isWrite)
                                  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.

Parameters:
name - The name of the parameter or port
isWrite - Whether to generate the write or read offset.
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.

_getReferenceChannels

protected java.util.List<CodeGeneratorHelper.Channel> _getReferenceChannels(TypedIOPort port,
                                                                            int channelNumber,
                                                                            boolean isWrite)
                                                                     throws IllegalActionException
Return the list of corresponding reference channel. This is because a channel may map to multiple reference channels in the generated code. At the same time, multiple channels may map to the same reference channel (e.g. the input-output port pair of a connection).

Parameters:
port - The specified port.
channelNumber - The specified channel number.
isWrite - Whether this is a write or read access.
Returns:
The list of reference channel.
Throws:
IllegalActionException

_getTypeConvertChannels

protected java.util.Set _getTypeConvertChannels()
Get the set of channels that need to be type converted.

Returns:
Set of channels that need to be type converted.

_getTypeConvertReference

protected java.lang.String _getTypeConvertReference(CodeGeneratorHelper.Channel channel)
Generate a variable reference for the given channel. This varaible reference is needed for type conversion. The source helper 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.

_replaceMacro

protected java.lang.String _replaceMacro(java.lang.String macro,
                                         java.lang.String parameter)
                                  throws IllegalActionException
Return the replacement string of the given macro. Subclass of CodeGenerator may overriding this method to extend or support a different set of macros.

Parameters:
macro - The given macro.
parameter - The given parameter to the macro.
Returns:
The replacement string of the given macro.
Throws:
IllegalActionException - Thrown if the given macro or parameter is not valid.

_findClosedParen

protected static int _findClosedParen(java.lang.String string,
                                      int pos)
                               throws IllegalActionException
Find the paired close parenthesis given a string and an index which is the position of an open parenthesis. Return -1 if no paired close parenthesis is found.

Parameters:
string - The given string.
pos - The given index.
Returns:
The index which indicates the position of the paired close parenthesis of the string.
Throws:
IllegalActionException - If the character at the given position of the string is not an open parenthesis or if the index is less than 0 or past the end of the string.

_getIndentPrefix

protected static java.lang.String _getIndentPrefix(int level)
Return a number of spaces that is proportional to the argument. If the argument is negative or zero, return an empty string.

Parameters:
level - The level of indenting represented by the spaces.
Returns:
A string with zero or more spaces.

_generateBlockByName

private java.lang.String _generateBlockByName(java.lang.String blockName)
                                       throws IllegalActionException
Generate code for a given block. The comment includes the portion of the blockName parameter up until the string "Block".

Parameters:
blockName - The name of the block, which usually ends with the string "Block".
Returns:
The generated wrapup code.
Throws:
IllegalActionException - If thrown while appending to the the block or processing the macros.

_generateFireInvocation

private static java.lang.String _generateFireInvocation(NamedObj component)
Generate the invocation of the fire function of the given component.

Parameters:
component - The given component.
Returns:
The generated code.

_getActualCodeStream

private CodeStream _getActualCodeStream()
                                 throws IllegalActionException
Return the actual CodeStream for this Helper.

Returns:
The actual CodeStream.
Throws:
IllegalActionException - If thrown by a called method.

_getMacroStartIndex

private int _getMacroStartIndex(java.lang.String code,
                                int from)
Return the position of the first occurence of the "&" sign in the given code string, starting from the given from position. If the "&" sign found is escaped by "\\", it will be ignored.

Parameters:
code - The given code string.
from - The given position to start searching from.
Returns:
The next position of the "&" sign.

_getRefName

private java.lang.String _getRefName(java.lang.String name)
                              throws IllegalActionException
Throws:
IllegalActionException

_getRefType

private java.lang.String _getRefType(Attribute attribute)

_getTypeable

private Typeable _getTypeable(java.lang.String objectName)
If the object name is a Port or Variable, return its Port or Variable, otherwise return null.

Parameters:
objectName - The object name
Returns:
Either the Port, Variable or null.

_getTypeConvertSinkChannels

private java.util.List _getTypeConvertSinkChannels(CodeGeneratorHelper.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.

_getVariable

private Variable _getVariable(java.lang.String refName)
Return a variable that matches the given label. Null is returned, if no such variable cannot found.

Parameters:
refName - The given label.
Returns:
A variable that matches the given label, or null if no such variable is found.

_markTypeConvert

private void _markTypeConvert(CodeGeneratorHelper.Channel source,
                              CodeGeneratorHelper.Channel sink)
Mark the given connection between the source and the sink channels as type conversion required.

Parameters:
source - The given source channel.
sink - The given input channel.

_replaceGetMacro

private java.lang.String _replaceGetMacro(java.lang.String parameter)
                                   throws IllegalActionException
Throws:
IllegalActionException

_replaceSendMacro

private java.lang.String _replaceSendMacro(java.lang.String parameter)
                                    throws IllegalActionException
Throws:
IllegalActionException

_getActualCodeStream

private static CodeStream _getActualCodeStream(NamedObj namedObj,
                                               CodeGenerator codeGenerator)
                                        throws IllegalActionException
Return the actual CodeStream associated with the given Actor and CodeGenerator. Generally, this will come from the Actor's template file, but EmbeddedCActors get their code from the embeddedCCode parameter.

Parameters:
namedObj - The actor whose code to return.
codeGenerator - The actor's CodeGenerator.
Returns:
The actor's actual CodeStream.
Throws:
IllegalActionException - If thrown when getting the actor's helper.