ptolemy.codegen.java.domains.modal.kernel
Class FSMActor

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.codegen.kernel.CodeGeneratorHelper
          extended by ptolemy.codegen.java.kernel.JavaCodeGeneratorHelper
              extended by ptolemy.codegen.java.domains.modal.kernel.FSMActor
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class FSMActor
extends JavaCodeGeneratorHelper

Code generator helper for FSMActor.

Since:
Ptolemy II 8.0
Version:
$Id: FSMActor.java 59203 2010-09-23 21:41:27Z cxh $
Author:
Gang Zhou
See Also:
Serialized Form
Accepted Rating:
Red (zgang)
Proposed Rating:
Red (zgang)

Nested Class Summary
protected  class FSMActor.PortScope
          This class implements a scope, which is used to generate the parsed expressions in target language.
static interface FSMActor.TransitionRetriever
          A class implementing this interface implements a method to retrieve transitions of a given state.
 
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  FSMActor.PortScope _scope
          The scope to generate code for guard expression, choice action and commit action.
 
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
FSMActor(FSMActor component)
          Construct the code generator helper associated with the given FSMActor.
 
Method Summary
protected  java.lang.String _generateFireCode()
          Generate the fire code of the associated FSMActor.
private  java.lang.Object _generateStateConstantLabel(State state)
           
protected  void _updateCurrentState(java.lang.StringBuffer codeBuffer, State state)
          Generate code for updating current state of this FSMActor.
 java.lang.String generateInitializeCode()
          Generate the initialize code of the associated FSMActor.
 java.lang.String generatePreinitializeCode()
          Generate the preinitialize code of the associated FSMActor.
 void generateTransitionCode(java.lang.StringBuffer code, FSMActor.TransitionRetriever transitionRetriever)
          Generate code for making transition.
 
Methods inherited from class ptolemy.codegen.java.kernel.JavaCodeGeneratorHelper
_generateInputVariableDeclaration, _generateOutputVariableDeclaration, _generateReferencedParameterDeclaration, _generateTypeConvertVariableDeclaration, _replaceMacro, generateVariableDeclaration, getCodeGenerator, getFunctionInvocation, getHeaderFiles, getJVMHeaderFiles, getNewInvocation, getParseTreeCodeGenerator, getReference
 
Methods inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_createBufferSizeAndOffsetMap, _createInputBufferSizeAndOffsetMap, _findClosedParen, _generateBlockCode, _generateBlockCode, _generateTypeConvertMethod, _generateTypeConvertStatement, _generateTypeConvertStatements, _getCastType, _getChannelAndOffset, _getFireFunctionArguments, _getHelper, _getHelper, _getIndentPrefix, _getReference, _getReferenceChannels, _getTypeConvertChannels, _getTypeConvertReference, _indexOf, addFunctionUsed, addNewTypeUsed, analyzeTypeConvert, checkLocal, checkRemote, codeGenType, copyFilesToCodeDirectory, createOffsetVariablesIfNeeded, generateChannelOffset, generateFireCode, generateFireFunctionCode, generateFireFunctionCode2, generateModeTransitionCode, generateName, generateOffset, generatePortReference, generatePostfireCode, generatePrefireCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableInitialization, generateVariableName, generateWrapupCode, getBufferSize, getBufferSize, getComponent, getDefaultBlocks, getDirector, getDirectorHelper, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getObject, getParameterValue, getPort, getRates, getReadOffset, getReference, getReference, getReference, getSharedCode, 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

_scope

protected FSMActor.PortScope _scope
The scope to generate code for guard expression, choice action and commit action.

Constructor Detail

FSMActor

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

Parameters:
component - The associated component.
Method Detail

_generateFireCode

protected java.lang.String _generateFireCode()
                                      throws IllegalActionException
Generate the fire code of the associated FSMActor. It provides generateTransitionCode(StringBuffer, TransitionRetriever) with an anonymous class implementing a method which returns an iterator of all outgoing transitions of the current state.

Overrides:
_generateFireCode in class CodeGeneratorHelper
Returns:
The generated fire code.
Throws:
IllegalActionException - If thrown while generating firing code.

generateInitializeCode

public java.lang.String generateInitializeCode()
                                        throws IllegalActionException
Generate the initialize code of the associated FSMActor. It generates code for initializing current state with initial state, and initializing current configuration of the container when it applies (i.e., when this FSMActor works as a modal controller for a MultirateFSMDirector).

Specified by:
generateInitializeCode in interface ComponentCodeGenerator
Overrides:
generateInitializeCode in class CodeGeneratorHelper
Returns:
The initialize code of the associated FSMActor.
Throws:
IllegalActionException - If initial state cannot be found, configuration number cannot be updated or code cannot be processed.

generatePreinitializeCode

public java.lang.String generatePreinitializeCode()
                                           throws IllegalActionException
Generate the preinitialize code of the associated FSMActor. It declares two variables for this actor: currentState and transitionFlag. currentState is an int representing this actor's current state. transitionFlag is an unsigned char to indicate if a preemptive transition is taken. It also defines a symbolic constant to each state.

Specified by:
generatePreinitializeCode in interface ActorCodeGenerator
Overrides:
generatePreinitializeCode in class CodeGeneratorHelper
Returns:
The preinitialize code of the associated FSMActor.
Throws:
IllegalActionException - If thrown when creating buffer size and offset map or processing code.

_generateStateConstantLabel

private java.lang.Object _generateStateConstantLabel(State state)

generateTransitionCode

public void generateTransitionCode(java.lang.StringBuffer code,
                                   FSMActor.TransitionRetriever transitionRetriever)
                            throws IllegalActionException
Generate code for making transition. It generates code for both choice action and commit action.

Parameters:
code - The string buffer that the generated code is appended to.
transitionRetriever - An instance of a class implementing a method. which returns an iterator of all, preemptive or non-preemptive transitions of the current state.
Throws:
IllegalActionException - If thrown while generating transition code.

_updateCurrentState

protected void _updateCurrentState(java.lang.StringBuffer codeBuffer,
                                   State state)
                            throws IllegalActionException
Generate code for updating current state of this FSMActor. The states are numbered according to the order in the list returned by entityList().

Parameters:
codeBuffer - The string buffer that the generated code is appended to.
state - The current state.
Throws:
IllegalActionException - Thrown if the corresponding code block cannot be fetched.