|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.codegen.kernel.CodeGeneratorHelper
public class CodeGeneratorHelper
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()));
Yellow (eal) |
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 java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected CodeGenerator _codeGenerator
protected CodeStream _codeStream
protected static final java.lang.String _eol
protected ParseTreeCodeGenerator _parseTreeCodeGenerator
protected java.util.Hashtable _portConversions
protected java.util.HashSet _referencedParameters
protected static final java.lang.String _INDENT1
StringUtilities.getIndentPrefix(int)
protected static final java.lang.String _INDENT2
StringUtilities.getIndentPrefix(int)
private final java.lang.Object _object
private static final java.lang.String[] _defaultBlocks
private java.lang.String _fireCode
Constructor Detail |
---|
public CodeGeneratorHelper()
public CodeGeneratorHelper(NamedObj component)
component
- The associated component.public CodeGeneratorHelper(NamedObj component, java.lang.String name)
component
- The associated component.name
- The name of helper. All periods are replaced with
underscores.public CodeGeneratorHelper(java.lang.Object object)
object
- The object for which the code generator should be constructed.Method Detail |
---|
public void addNewTypeUsed(java.lang.String typeName)
typeName
- A string naming the type, for example "Boolean" or
"String".public void addFunctionUsed(java.lang.String functionName)
functionName
- A string naming a function, for example "new".public void analyzeTypeConvert() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public boolean checkLocal(boolean forComposite, IOPort port) throws IllegalActionException
forComposite
- True if this check is for a compositeport
- The port to be checked.
IllegalActionException
- If thrown while queryint the port.public boolean checkRemote(boolean forComposite, IOPort port)
forComposite
- True if this check is for a compositeport
- The port to be checked.
public java.lang.String codeGenType(Type ptType)
ptType
- The given Ptolemy type.
IllegalActionException
- Thrown if the given ptolemy cannot be
resolved.public java.lang.String createOffsetVariablesIfNeeded() throws IllegalActionException
createOffsetVariablesIfNeeded
in interface ActorCodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateFireCode() throws IllegalActionException
generateFireCode
in interface ActorCodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateFireFunctionCode() throws IllegalActionException
generateFireFunctionCode
in interface ActorCodeGenerator
IllegalActionException
- If thrown while generating fire code.public java.lang.String generateFireFunctionCode2() throws IllegalActionException
IllegalActionException
- If thrown while generating fire code.public java.lang.String generateInitializeCode() throws IllegalActionException
generateInitializeCode
in interface ComponentCodeGenerator
IllegalActionException
- If thrown while appending to the the
block or processing the macros.public void generateModeTransitionCode(java.lang.StringBuffer code) throws IllegalActionException
generateModeTransitionCode
in interface ActorCodeGenerator
code
- The string buffer that the generated code is appended to.
IllegalActionException
- Not thrown in this base class.public java.lang.String generateOffset(java.lang.String offsetString, IOPort port, int channel, boolean isWrite) throws IllegalActionException
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.
IllegalActionException
- If there is problems getting the port
buffer size or the offset in the channel and offset map.public java.lang.String generatePostfireCode() throws IllegalActionException
generatePostfireCode
in interface ActorCodeGenerator
IllegalActionException
- If thrown while appending to the the
block or processing the macros.public java.lang.String generatePrefireCode() throws IllegalActionException
ActorCodeGenerator
generatePrefireCode
in interface ActorCodeGenerator
IllegalActionException
- If the helper associated with
an actor throws it while generating the prefire code for the actor.public java.lang.String generatePreinitializeCode() throws IllegalActionException
generatePreinitializeCode
in interface ActorCodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String generateTypeConvertFireCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.public java.lang.String generateTypeConvertFireCode(boolean forComposite) throws IllegalActionException
forComposite
- True if we are generating code for a composite.
IllegalActionException
- Not thrown in this base class.public java.lang.String generateVariableDeclaration() throws IllegalActionException
generateVariableDeclaration
in interface ActorCodeGenerator
IllegalActionException
- If the helper class for the model
director cannot be found.public java.lang.String generateVariableInitialization() throws IllegalActionException
generateVariableInitialization
in interface ActorCodeGenerator
IllegalActionException
- If the helper class for the model
director cannot be found.public java.lang.String generateVariableName(NamedObj namedObj)
namedObj
- The NamedObj to generate variable name for.
CodeGenerator.generateVariableName(NamedObj)
public java.lang.String generateWrapupCode() throws IllegalActionException
generateWrapupCode
in interface ComponentCodeGenerator
IllegalActionException
- If thrown while appending to the the
block or processing the macros.public int getBufferSize(IOPort port) throws IllegalActionException
port
- The given port.
IllegalActionException
- If the
getBufferSize(IOPort, int)
method throws it.setBufferSize(IOPort, int, int)
public int getBufferSize(IOPort port, int channelNumber) throws IllegalActionException
port
- The given port.channelNumber
- The given channel.
IllegalActionException
- If the getBufferSize() method of the
actor helper class throws it.setBufferSize(IOPort, int, int)
public CodeGenerator getCodeGenerator()
setCodeGenerator(CodeGenerator)
public NamedObj getComponent()
getComponent
in interface ComponentCodeGenerator
public Director getDirector()
public Director getDirectorHelper() throws IllegalActionException
IllegalActionException
- If thrown while getting the helper
of the director.public java.lang.String getFunctionInvocation(java.lang.String functionString, boolean isStatic) throws IllegalActionException
functionString
- The string within the $tokenFunc() macro.isStatic
- True if the method is static.
IllegalActionException
- The given function string is not
well-formed.public java.util.Set getHeaderFiles() throws IllegalActionException
getHeaderFiles
in interface ActorCodeGenerator
IllegalActionException
- Not Thrown in this base class.public java.util.Set getIncludeDirectories() throws IllegalActionException
getIncludeDirectories
in interface ActorCodeGenerator
IllegalActionException
- If thrown when getting or reading the
CodeStream.public java.util.Set getLibraries() throws IllegalActionException
getLibraries
in interface ActorCodeGenerator
IllegalActionException
- If thrown when getting or reading the
CodeStream.public java.util.Set getLibraryDirectories() throws IllegalActionException
getLibraryDirectories
in interface ActorCodeGenerator
IllegalActionException
- If thrown when getting or reading the
CodeStream.public java.util.Set getModifiedVariables() throws IllegalActionException
getModifiedVariables
in interface ActorCodeGenerator
IllegalActionException
- If an actor throws it while getting
modified variables.public java.lang.String getNewInvocation(java.lang.String constructorString) throws IllegalActionException
constructorString
- The string within the $new() macro.
IllegalActionException
- The given constructor string is not
well-formed.public NamedObj getObject()
public java.lang.String getParameterValue(java.lang.String name, NamedObj container) throws IllegalActionException
name
- The name of the parameter.container
- The container to search upwards from.
IllegalActionException
- If the parameter does not exist or does
not have a value.public ParseTreeCodeGenerator getParseTreeCodeGenerator()
public TypedIOPort getPort(java.lang.String refName)
refName
- The given name.
public int[][] getRates()
public java.lang.Object getReadOffset(IOPort inputPort, int channelNumber) throws IllegalActionException
inputPort
- The given port.channelNumber
- The given channel number.
IllegalActionException
- Thrown if the helper class cannot be
found.setReadOffset(IOPort, int, Object)
public java.lang.String getReference(java.lang.String name) throws IllegalActionException
name
- The name of the parameter or port
IllegalActionException
- If the parameter or port does not exist
or does not have a value.public java.util.Set getSharedCode() throws IllegalActionException
getSharedCode
in interface ActorCodeGenerator
IllegalActionException
- Not thrown in this base class.public java.lang.String getSize(java.lang.String name) throws IllegalActionException
name
- The name of the parameter.
IllegalActionException
- If no port or parameter of the given
name is found.public double getWCET() throws IllegalActionException
IllegalActionException
- If there is a problem determining
the WCET or a problem accessing the model. Not thrown in this
base class.public java.lang.Object getWriteOffset(IOPort port, int channelNumber) throws IllegalActionException
port
- The given port.channelNumber
- The given channel number.
IllegalActionException
- Thrown if the helper class cannot be
found.setWriteOffset(IOPort, int, Object)
public boolean isPrimitive(java.lang.String cgType)
cgType
- The given codegen type.
public boolean isPrimitive(Type ptType)
ptType
- The given ptolemy type.
public java.lang.String processCode(java.lang.String code) throws IllegalActionException
code
- The code to process.
IllegalActionException
- If illegal macro names are found.public java.lang.String resetInputPortsOffset() throws IllegalActionException
IllegalActionException
- If thrown while getting or setting the
offset.public void setBufferSize(IOPort port, int channelNumber, int bufferSize) throws IllegalActionException
port
- The given port.channelNumber
- The given channel.bufferSize
- The buffer size to be set to that port and channel.
IllegalActionException
getBufferSize(IOPort)
public void setCodeGenerator(CodeGenerator codeGenerator)
setCodeGenerator
in interface ComponentCodeGenerator
codeGenerator
- The code generator associated with this helper
class.getCodeGenerator()
public void setReadOffset(IOPort port, int channelNumber, java.lang.Object readOffset) throws IllegalActionException
port
- The given port.channelNumber
- The given channel.readOffset
- The offset to be set to the buffer of that channel.
IllegalActionException
- Thrown if the helper class cannot be
found.getReadOffset(IOPort, int)
public void setWriteOffset(IOPort port, int channelNumber, java.lang.Object writeOffset) throws IllegalActionException
port
- The given port.channelNumber
- The given channel.writeOffset
- The offset to be set to the buffer of that channel.
IllegalActionException
- If
setWriteOffset(IOPort, int, Object)
method throws it.getWriteOffset(IOPort, int)
public java.lang.String targetType(Type ptType)
ptType
- The given Ptolemy type.
public java.lang.String toString()
NamedObj
toString
in class NamedObj
public static int _indexOf(java.lang.String ch, java.lang.String string, int fromIndex)
ch
- The character to search for.string
- The given string to search from.fromIndex
- The index to start the search.
public static java.util.List<java.lang.String> parseList(java.lang.String parameters)
parameters
- A comma separate list of parameters.
public static long copyFilesToCodeDirectory(NamedObj namedObj, CodeGenerator codeGenerator) throws java.io.IOException, IllegalActionException
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.
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.
java.io.IOException
- If there is a problem reading the codeDirectory
parameter.
IllegalActionException
- If there is a problem reading the
codeDirectory parameter.public static java.lang.String generateChannelOffset(IOPort port, boolean isWrite, java.lang.String channelString)
port
- The referenced port.isWrite
- Whether to generate the write or read offset.channelString
- The string that will determine the channel.
public static java.lang.String generateName(NamedObj namedObj)
namedObj
- The named object for which the name is generated.
public static java.lang.String generateSimpleName(NamedObj namedObj)
namedObj
- The named object for which the name is generated.
public static java.lang.String generatePortReference(IOPort port, java.lang.String[] channelAndOffset, boolean isWrite)
port
- The port.channelAndOffset
- The given channel and offset.isWrite
- True if the port is to be written to.
getReference(TypedIOPort, String[], boolean, boolean)
public static java.lang.String[] getDefaultBlocks()
public java.lang.String getReference(Attribute attribute, java.lang.String[] channelAndOffset) throws IllegalActionException
attribute
- The attribute.channelAndOffset
- The given channel and offset.
IllegalActionException
- If the attribute does not
exist or does not have a value.public java.lang.String getReference(java.lang.String name, boolean isWrite) throws IllegalActionException
name
- The reference to be parsed. The format is
assumed to be "xxx#(yyy)", where "yyy" will be returnedisWrite
- True if the reference is to be written to.
IllegalActionException
- If the attribute does not
exist or does not have a value.public java.lang.String getReference(TypedIOPort port, java.lang.String[] channelAndOffset, boolean forComposite, boolean isWrite) throws IllegalActionException
port
- The port.channelAndOffset
- The given channel and offset.forComposite
- True if this check is for a compositeisWrite
- True if the reference is to be written to.
IllegalActionException
- If the attribute does not
exist or does not have a value.generatePortReference(IOPort, String[], boolean)
public static java.util.List<CodeGeneratorHelper.Channel> getSinkChannels(IOPort port, int channelNumber) throws IllegalActionException
port
- The given output port.channelNumber
- The given channel number.
IllegalActionException
public static CodeGeneratorHelper.Channel getSourceChannel(IOPort port, int channelNumber) throws IllegalActionException
port
- The port.channelNumber
- The channel number of the port.
IllegalActionException
- If there is a problem getting
information about the receivers or constructing the new Channel.protected java.lang.String _generateFireCode() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.protected void _createBufferSizeAndOffsetMap() throws IllegalActionException
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.protected void _createInputBufferSizeAndOffsetMap() throws IllegalActionException
IllegalActionException
- If thrown while getting port
information.protected java.lang.String _generateBlockCode(java.lang.String blockName) throws IllegalActionException
blockName
- The name of the block.
IllegalActionException
- If illegal macro names are found, or if
there is a problem parsing the code block from the helper .c file.protected java.lang.String _generateBlockCode(java.lang.String blockName, java.util.List args) throws IllegalActionException
blockName
- The name of the block.args
- The arguments for the block.
IllegalActionException
- If illegal macro names are found, or if
there is a problem parsing the code block from the helper .c file.protected java.lang.String _generateTypeConvertMethod(java.lang.String expression, java.lang.String castType, java.lang.String refType) throws IllegalActionException
expression
- The given variable expression.castType
- The given cast type.refType
- The given type of the variable.
IllegalActionException
protected java.lang.String _generateTypeConvertStatement(CodeGeneratorHelper.Channel source, CodeGeneratorHelper.Channel sink, int offset) throws IllegalActionException
source
- The given source channel.sink
- The given sink channel.offset
- The given offset.
IllegalActionException
- If there is a problem getting the
helpers for the ports or if the conversion cannot be handled.protected java.lang.String _generateTypeConvertStatements(CodeGeneratorHelper.Channel source, CodeGeneratorHelper.Channel sink) throws IllegalActionException
source
- The given source channel.sink
- The given sink channel.
IllegalActionException
- If there is a problem getting the
helpers for the ports or if the conversion cannot be handled.protected java.lang.String _getCastType(java.lang.String name) throws IllegalActionException
name
- The given name. The name must have a "#" in it.
IllegalActionException
- If the cast type is invalid.protected java.lang.String[] _getChannelAndOffset(java.lang.String name) throws IllegalActionException
name
- The given string.
IllegalActionException
- If the channel index or offset
specified in the given string is illegal.protected java.lang.String _getFireFunctionArguments()
protected ComponentCodeGenerator _getHelper(NamedObj component) throws IllegalActionException
component
- The given component.
IllegalActionException
- If the helper class cannot be found.protected java.lang.Object _getHelper(java.lang.Object object) throws IllegalActionException
object
- The given object.
IllegalActionException
- If the helper class cannot be found.protected java.lang.String _getReference(java.lang.String name, boolean isWrite) throws IllegalActionException
name
- The name of the parameter or portisWrite
- Whether to generate the write or read offset.
IllegalActionException
- If the parameter or port does not exist
or does not have a value.protected java.util.List<CodeGeneratorHelper.Channel> _getReferenceChannels(TypedIOPort port, int channelNumber, boolean isWrite) throws IllegalActionException
port
- The specified port.channelNumber
- The specified channel number.isWrite
- Whether this is a write or read access.
IllegalActionException
protected java.util.Set _getTypeConvertChannels()
protected java.lang.String _getTypeConvertReference(CodeGeneratorHelper.Channel channel)
channel
- The given source channel.
protected java.lang.String _replaceMacro(java.lang.String macro, java.lang.String parameter) throws IllegalActionException
macro
- The given macro.parameter
- The given parameter to the macro.
IllegalActionException
- Thrown if the given macro or parameter
is not valid.protected static int _findClosedParen(java.lang.String string, int pos) throws IllegalActionException
string
- The given string.pos
- The given index.
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.protected static java.lang.String _getIndentPrefix(int level)
level
- The level of indenting represented by the spaces.
private java.lang.String _generateBlockByName(java.lang.String blockName) throws IllegalActionException
blockName
- The name of the block, which usually ends with the
string "Block".
IllegalActionException
- If thrown while appending to the the
block or processing the macros.private static java.lang.String _generateFireInvocation(NamedObj component)
component
- The given component.
private CodeStream _getActualCodeStream() throws IllegalActionException
IllegalActionException
- If thrown by a called method.private int _getMacroStartIndex(java.lang.String code, int from)
code
- The given code string.from
- The given position to start searching from.
private java.lang.String _getRefName(java.lang.String name) throws IllegalActionException
IllegalActionException
private java.lang.String _getRefType(Attribute attribute)
private Typeable _getTypeable(java.lang.String objectName)
objectName
- The object name
private java.util.List _getTypeConvertSinkChannels(CodeGeneratorHelper.Channel source)
source
- The given source channel.
private Variable _getVariable(java.lang.String refName)
refName
- The given label.
private void _markTypeConvert(CodeGeneratorHelper.Channel source, CodeGeneratorHelper.Channel sink)
source
- The given source channel.sink
- The given input channel.private java.lang.String _replaceGetMacro(java.lang.String parameter) throws IllegalActionException
IllegalActionException
private java.lang.String _replaceSendMacro(java.lang.String parameter) throws IllegalActionException
IllegalActionException
private static CodeStream _getActualCodeStream(NamedObj namedObj, CodeGenerator codeGenerator) throws IllegalActionException
namedObj
- The actor whose code to return.codeGenerator
- The actor's CodeGenerator.
IllegalActionException
- If thrown when getting the actor's
helper.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |