ptolemy.domains.giotto.kernel
Class GiottoCodeGenerator

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.util.Attribute
          extended byptolemy.domains.giotto.kernel.GiottoCodeGenerator
All Implemented Interfaces:
Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable

public class GiottoCodeGenerator
extends Attribute

This attribute is a visible attribute that when configured (by double clicking on it or by invoking Configure in the context menu) it generates Giotto code and displays it a text editor. It is up to the user to save the Giotto code in an appropriate file, if necessary.

Since:
Ptolemy II 2.0
Version:
$Id: GiottoCodeGenerator.java,v 1.31.2.1 2004/06/18 00:49:11 cxh Exp $
Author:
Edward A. Lee, Steve Neuendorffer, Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Nested Class Summary
protected  class GiottoCodeGenerator.GiottoEditorFactory
           
 
Nested classes inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
protected  java.lang.String _endLine
           
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
GiottoCodeGenerator()
          Construct a factory with the default workspace and "" as name.
GiottoCodeGenerator(NamedObj container, java.lang.String name)
          Construct a factory with the specified container and name.
 
Method Summary
protected  java.lang.String _actuatorCode(TypedCompositeActor model)
          Generate code for the actuator.
protected  void _checkGiottoID(java.lang.String string)
          Throw an exception if the given string is a valid giotto reserved word, which prevents it from being used as an identifier.
protected  java.lang.String _driverCode(TypedCompositeActor model, Actor actor)
          Generate code for the driver.
protected  java.lang.String _driversCode(TypedCompositeActor model)
          Generate code for the drivers.
protected  java.lang.String _getTypeString(TypedIOPort port)
          Return the correct Giotto type string for the given port.
protected  boolean _initialize(TypedCompositeActor model)
          Topology analysis and initialization.
protected  void _instantiateEditorFactoryClass()
          Method to instantiate the Editor Factory class called from the constructor.
protected  java.lang.String _modeCode(TypedCompositeActor model)
          Generate code for the modes.
protected  boolean _needsInputDriver(Actor actor)
          Return true if the given actor has at least one connected input port, which requires it to have an input driver.
protected  java.lang.String _outputCode(TypedCompositeActor model)
          Generate code for the output ports.
protected  java.lang.String _sensorCode(TypedCompositeActor model)
          Generate code for the sensors.
protected  java.lang.String _taskCode(TypedCompositeActor model, Actor actor)
          Generate code for the task.
protected  java.lang.String _tasksCode(TypedCompositeActor model)
          Generate code for the tasks.
 java.lang.String generateGiottoCode(TypedCompositeActor model)
          Generate Giotto code for the given model.
 
Methods inherited from class ptolemy.kernel.util.Attribute
_getContainedObject, _propagateExistence, clone, getContainer, setContainer, setName
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_endLine

protected java.lang.String _endLine
Constructor Detail

GiottoCodeGenerator

public GiottoCodeGenerator()
                    throws IllegalActionException,
                           NameDuplicationException
Construct a factory with the default workspace and "" as name.

Throws:
IllegalActionException - If the factory is not of an acceptable attribute for the container.
NameDuplicationException - If the name coincides with an attribute already in the container.

GiottoCodeGenerator

public GiottoCodeGenerator(NamedObj container,
                           java.lang.String name)
                    throws IllegalActionException,
                           NameDuplicationException
Construct a factory with the specified container and name.

Parameters:
container - The container.
name - The name of the factory.
Throws:
IllegalActionException - If the factory is not of an acceptable attribute for the container.
NameDuplicationException - If the name coincides with an attribute already in the container.
Method Detail

generateGiottoCode

public java.lang.String generateGiottoCode(TypedCompositeActor model)
                                    throws IllegalActionException
Generate Giotto code for the given model.

Returns:
The Giotto code.
Throws:
IllegalActionException

_instantiateEditorFactoryClass

protected void _instantiateEditorFactoryClass()
                                       throws IllegalActionException,
                                              NameDuplicationException
Method to instantiate the Editor Factory class called from the constructor. The reason for having this is that it can be overridden by subclasses

Throws:
IllegalActionException
NameDuplicationException

_checkGiottoID

protected void _checkGiottoID(java.lang.String string)
                       throws IllegalActionException
Throw an exception if the given string is a valid giotto reserved word, which prevents it from being used as an identifier.

Throws:
IllegalActionException

_getTypeString

protected java.lang.String _getTypeString(TypedIOPort port)
Return the correct Giotto type string for the given port.


_initialize

protected boolean _initialize(TypedCompositeActor model)
                       throws IllegalActionException
Topology analysis and initialization.

Returns:
True if in giotto domain, False if in other domains.
Throws:
IllegalActionException

_sensorCode

protected java.lang.String _sensorCode(TypedCompositeActor model)
                                throws IllegalActionException
Generate code for the sensors.

Returns:
The sensors code.
Throws:
IllegalActionException

_actuatorCode

protected java.lang.String _actuatorCode(TypedCompositeActor model)
                                  throws IllegalActionException
Generate code for the actuator. Usually, there is only one actuator.

Returns:
The actuator code.
Throws:
IllegalActionException

_outputCode

protected java.lang.String _outputCode(TypedCompositeActor model)
                                throws IllegalActionException
Generate code for the output ports. In Giotto, the situation that one port has several inputs is illegal. From the output ports, it is easy to trace to get receivers for output delivery.

Returns:
The output code.
Throws:
IllegalActionException

_taskCode

protected java.lang.String _taskCode(TypedCompositeActor model,
                                     Actor actor)
                              throws IllegalActionException
Generate code for the task.

Returns:
The task code.
Throws:
IllegalActionException

_tasksCode

protected java.lang.String _tasksCode(TypedCompositeActor model)
                               throws IllegalActionException
Generate code for the tasks.

Returns:
The task code.
Throws:
IllegalActionException

_driverCode

protected java.lang.String _driverCode(TypedCompositeActor model,
                                       Actor actor)
                                throws IllegalActionException
Generate code for the driver.

Returns:
The driver code.
Throws:
IllegalActionException

_driversCode

protected java.lang.String _driversCode(TypedCompositeActor model)
                                 throws IllegalActionException
Generate code for the drivers. The order of ports in model has effect on the order of driver input parameters

Returns:
The drivers code.
Throws:
IllegalActionException

_modeCode

protected java.lang.String _modeCode(TypedCompositeActor model)
                              throws IllegalActionException
Generate code for the modes.

Returns:
The modes code.
Throws:
IllegalActionException

_needsInputDriver

protected boolean _needsInputDriver(Actor actor)
Return true if the given actor has at least one connected input port, which requires it to have an input driver.