ptolemy.codegen.rtmaude.kernel
Class RTMaudeAdaptor

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.codegen.kernel.CodeGeneratorHelper
          extended by ptolemy.codegen.rtmaude.kernel.RTMaudeAdaptor
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
AbstractActionsAttribute, Entity, IOPort, IORelation, Transition, Variable

public class RTMaudeAdaptor
extends CodeGeneratorHelper

Generate RTMaude code in DE domain. Every adaptor (helper) class for RTMaude should extend this class.

Since:
Ptolemy II 8.0
Version:
$Id: RTMaudeAdaptor.java 59203 2010-09-23 21:41:27Z cxh $
Author:
Kyungmin Bae
See Also:
CodeGeneratorHelper, Serialized Form
Accepted Rating:
Red (kquine)
Proposed Rating:
Red (kquine)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
CodeGeneratorHelper.Channel, CodeGeneratorHelper.VariableScope
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
protected  java.lang.String defaultTermBlock
          The default name of the block for the term template.
(package private)  java.util.List<java.lang.String> formalIncludes
           
(package private)  java.util.Map<java.lang.String,java.lang.String> RTMmodule
           
(package private)  java.util.List<java.lang.String> semanticsIncludes
           
 
Fields inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_codeGenerator, _codeStream, _eol, _INDENT1, _INDENT2, _parseTreeCodeGenerator, _portConversions, _referencedParameters
 
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
RTMaudeAdaptor(NamedObj component)
          Constructs a RTMaude code generator adaptor.
 
Method Summary
protected  java.lang.String _generateBlockCode(java.lang.String blockName, java.lang.String... args)
          Given a block name, generate code for that block.
protected  java.lang.String _generateTypeConvertMethod(java.lang.String ref, 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 _replaceMacro(java.lang.String macro, java.lang.String parameter)
          Return the replacement string of the given macro.
 java.lang.String generateEntryCode()
          Generates the entry code for RTMaude model, whose template is defined in "mainEntry" block.
 java.lang.String generateExitCode()
          Generates the exit code for the RTMaude model, whose template is defined in "mainExit" block.
 java.lang.String generateFireCode()
          Generate the fire code.
 java.lang.String generateFireFunctionCode()
          Generate The fire function code.
 java.lang.String generateTermCode()
          Generate a Real-time Maude term representation of given component.
 java.util.List<java.lang.String> getBlockCodeList(java.lang.String blockName, java.lang.String... args)
          Given a block name, generate a list of codes for that block.
protected  java.lang.String getInfo(java.lang.String name, java.util.List<java.lang.String> parameters)
          Returns some information of the component.
 java.util.List<java.lang.String> getModuleCode(java.lang.String header)
          Generates code for RTMaude module with the given template indicated by the header of the block.
 ParseTreeCodeGenerator getParseTreeCodeGenerator()
          Return a new parse tree code generator to use with expressions.
 java.util.Map<java.lang.String,java.lang.String> getRTMmodule()
          Returns the RTMmodule value.
 java.util.Set getSharedCode()
          Generate the shared code.
protected  java.lang.String getTranslatedExpression(java.lang.String expression)
          Get the translanted expression.
 
Methods inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_createBufferSizeAndOffsetMap, _createInputBufferSizeAndOffsetMap, _findClosedParen, _generateBlockCode, _generateBlockCode, _generateFireCode, _generateTypeConvertStatement, _generateTypeConvertStatements, _getCastType, _getChannelAndOffset, _getFireFunctionArguments, _getHelper, _getHelper, _getIndentPrefix, _getReference, _getReferenceChannels, _getTypeConvertChannels, _getTypeConvertReference, _indexOf, addFunctionUsed, addNewTypeUsed, analyzeTypeConvert, checkLocal, checkRemote, codeGenType, copyFilesToCodeDirectory, createOffsetVariablesIfNeeded, generateChannelOffset, generateFireFunctionCode2, generateInitializeCode, generateModeTransitionCode, generateName, generateOffset, generatePortReference, generatePostfireCode, generatePrefireCode, generatePreinitializeCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableDeclaration, generateVariableInitialization, generateVariableName, generateWrapupCode, getBufferSize, getBufferSize, getCodeGenerator, getComponent, getDefaultBlocks, getDirector, getDirectorHelper, getFunctionInvocation, getHeaderFiles, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getNewInvocation, getObject, getParameterValue, getPort, getRates, getReadOffset, getReference, getReference, getReference, getReference, getSinkChannels, getSize, getSourceChannel, getWCET, getWriteOffset, isPrimitive, isPrimitive, parseList, processCode, resetInputPortsOffset, setBufferSize, setCodeGenerator, setReadOffset, setWriteOffset, targetType, toString
 
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

defaultTermBlock

protected java.lang.String defaultTermBlock
The default name of the block for the term template.


RTMmodule

java.util.Map<java.lang.String,java.lang.String> RTMmodule

semanticsIncludes

java.util.List<java.lang.String> semanticsIncludes

formalIncludes

java.util.List<java.lang.String> formalIncludes
Constructor Detail

RTMaudeAdaptor

public RTMaudeAdaptor(NamedObj component)
Constructs a RTMaude code generator adaptor.

Parameters:
component - The associated component
Method Detail

getBlockCodeList

public java.util.List<java.lang.String> getBlockCodeList(java.lang.String blockName,
                                                         java.lang.String... args)
                                                  throws IllegalActionException
Given a block name, generate a list of codes for that block. (For Composite Actor and Director)

Parameters:
blockName - The name of the block.
args - The arguments for the block.
Returns:
The list of the block codes
Throws:
IllegalActionException

generateFireCode

public java.lang.String generateFireCode()
                                  throws IllegalActionException
Description copied from class: CodeGeneratorHelper
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
Overrides:
generateFireCode in class CodeGeneratorHelper
Returns:
The generated code.
Throws:
IllegalActionException - Not thrown in this base class.

generateFireFunctionCode

public java.lang.String generateFireFunctionCode()
                                          throws IllegalActionException
Description copied from class: CodeGeneratorHelper
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
Overrides:
generateFireFunctionCode in class CodeGeneratorHelper
Returns:
The fire function code.
Throws:
IllegalActionException - If thrown while generating fire code.

generateTermCode

public java.lang.String generateTermCode()
                                  throws IllegalActionException
Generate a Real-time Maude term representation of given component.

Returns:
the term representation of a component
Throws:
IllegalActionException

getSharedCode

public java.util.Set getSharedCode()
                            throws IllegalActionException
Description copied from class: CodeGeneratorHelper
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
Overrides:
getSharedCode in class CodeGeneratorHelper
Returns:
An empty set in this base class.
Throws:
IllegalActionException - Not thrown in this base class.

getModuleCode

public java.util.List<java.lang.String> getModuleCode(java.lang.String header)
                                               throws IllegalActionException
Generates code for RTMaude module with the given template indicated by the header of the block. The name of the template block will be "header_Class".

Parameters:
header - The header of the template block
Returns:
The RTMaude module code
Throws:
IllegalActionException

generateEntryCode

public java.lang.String generateEntryCode()
                                   throws IllegalActionException
Generates the entry code for RTMaude model, whose template is defined in "mainEntry" block.

Returns:
The entry code
Throws:
IllegalActionException

generateExitCode

public java.lang.String generateExitCode()
                                  throws IllegalActionException
Generates the exit code for the RTMaude model, whose template is defined in "mainExit" block.

Returns:
The exit code
Throws:
IllegalActionException

getParseTreeCodeGenerator

public ParseTreeCodeGenerator getParseTreeCodeGenerator()
Return a new parse tree code generator to use with expressions.

Overrides:
getParseTreeCodeGenerator in class CodeGeneratorHelper
Returns:
the parse tree code generator to use with expressions.

getRTMmodule

public java.util.Map<java.lang.String,java.lang.String> getRTMmodule()
Returns the RTMmodule value.

Returns:
a Map object representing the RTMmodule value

getInfo

protected java.lang.String getInfo(java.lang.String name,
                                   java.util.List<java.lang.String> parameters)
                            throws IllegalActionException
Returns some information of the component. Subclasses may override this method to define more specific information.

Parameters:
name - The name of the desired information
parameters - The parameters for the information
Returns:
The information indicated by the given name.
Throws:
IllegalActionException

_generateBlockCode

protected java.lang.String _generateBlockCode(java.lang.String blockName,
                                              java.lang.String... args)
                                       throws IllegalActionException
Given a block name, generate code for that block.

Parameters:
blockName - The name of the block.
args - The arguments for the block.
Returns:
The block code
Throws:
IllegalActionException

_generateTypeConvertMethod

protected java.lang.String _generateTypeConvertMethod(java.lang.String ref,
                                                      java.lang.String castType,
                                                      java.lang.String refType)
                                               throws IllegalActionException
Description copied from class: CodeGeneratorHelper
Generate expression that evaluates to a result of equivalent value with the cast type.

Overrides:
_generateTypeConvertMethod in class CodeGeneratorHelper
Parameters:
ref - 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

_replaceMacro

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

Overrides:
_replaceMacro in class CodeGeneratorHelper
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.

getTranslatedExpression

protected java.lang.String getTranslatedExpression(java.lang.String expression)
                                            throws IllegalActionException
Get the translanted expression.

Parameters:
expression - The expression to be parsed and translated.
Returns:
the translated expression.
Throws:
IllegalActionException - If thrown by the parser.