Class FSMActor
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.cg.kernel.generic.CodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
-
- ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.domains.modal.kernel.FSMActor
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
FSMActor
public class FSMActor extends NamedProgramCodeGeneratorAdapter
Code generator helper for FSMActor.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Shanna-Shaye Forbes, Based on codegen FSMActor by Gang Zhou
- Pt.AcceptedRating:
- Red (zgang)
- Pt.ProposedRating:
- Red (zgang)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FSMActor.OutgoingRelations
The outgoing releations.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.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
NamedProgramCodeGeneratorAdapter.VariableScope
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
ProgramCodeGeneratorAdapter.Channel
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected FSMActor.PortScope
_scope
The scope to generate code for guard expression, choice action and commit action.-
Fields inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_component, _defaultBlocks, _eol, _templateParser
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
_generateFireCode()
Generate the fire code of the associated FSMActor.protected java.lang.Object
_generateStateConstantLabel(State state)
Generate a label for a state constant.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.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
_generateTypeConvertStatement, analyzeTypeConvert, copyFilesToCodeDirectory, generateFireCode, generateFireFunctionCode, generateMainLoop, generateModeTransitionCode, generatePostfireCode, generatePrefireCode, generatePreinitializeMethodBodyCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableDeclaration, generateVariableInitialization, generateWrapupCode, getAddTimeString, getBufferSize, getBufferSize, getComponent, getDeclareSharedCode, getDefaultBlocks, getFireFunctionParameters, getHeaderFiles, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getName, getParameterValue, getReference, getReference, getSharedCode, getSinkChannels, getSourceTimeString, getTimeSourcePortName, getTypeConvertChannels, getTypeConvertReference, getTypeConvertSinkChannels, setupAdapter, targetType
-
Methods inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_generateBlockByName, getAdapter, getCodeGenerator, getTemplateParser, processCode, setCodeGenerator, setTemplateParser, toString
-
Methods inherited from class ptolemy.cg.kernel.generic.CodeGeneratorAdapter
createDecoratorAttributes, generateName
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateExistence, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
-
-
-
-
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) throws NameDuplicationException, IllegalActionException
Construct the code generator helper associated with the given FSMActor.- Parameters:
component
- The associated component.- Throws:
NameDuplicationException
- If the container already contains a a code generator adapter for this particular FSMActor.IllegalActionException
- If the NamedProgramCodeGeneratorAdapter throws an IllegalActionException.
-
-
Method Detail
-
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).- Overrides:
generateInitializeCode
in classNamedProgramCodeGeneratorAdapter
- 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.- Overrides:
generatePreinitializeCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The preinitialize code of the associated FSMActor.
- Throws:
IllegalActionException
- If thrown when creating buffer size and offset map or processing code.
-
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.
-
_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 classNamedProgramCodeGeneratorAdapter
- Returns:
- The generated fire code.
- Throws:
IllegalActionException
- If thrown while generating firing 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.
-
_generateStateConstantLabel
protected java.lang.Object _generateStateConstantLabel(State state)
Generate a label for a state constant.- Parameters:
state
- The state.- Returns:
- The label.
-
-