ptolemy.domains.tdl.kernel
Class TDLCodeGeneratorUtilities

java.lang.Object
  extended by ptolemy.domains.tdl.kernel.TDLCodeGeneratorUtilities

public class TDLCodeGeneratorUtilities
extends java.lang.Object

Utilities for generating TDL code.

Since:
Ptolemy II 8.0
Version:
$Id: TDLCodeGeneratorUtilities.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Patricia Derler

Field Summary
private static java.util.List _modules
          All TDL modules in the model.
private static java.util.Set _portsConnectedToModuleOutputPorts
          Input ports of a module that are connected to another TDL module's output ports.
 
Constructor Summary
private TDLCodeGeneratorUtilities()
          Instances of this class cannot be created.
 
Method Summary
protected static void _actuatorCode(java.lang.StringBuffer sb, TDLModule module)
          Generate code for the actuator.
private static java.util.List _getModes(TDLModule module)
          Get all modes of a module.
private static void _getModules(TypedCompositeActor model)
          Add all modules to the global list of modules.
private static java.lang.String _getRefinementPortParameter(IOPort port, java.lang.String paramName)
          for whatever reason, the parameter specified at the modalport is not stored there but at the refinement port one level inside modalport.insideReceivers[0][0].getParameter("getter") returns the correct value.
protected static java.lang.String _getTypeString(IOPort port)
          Get the datatype of a port.
protected static void _headerCode(java.lang.StringBuffer sb, TypedCompositeActor model)
          Generate header code for the file.
protected static boolean _initialize(TypedCompositeActor model)
          Initialize the code generation process by checking whether the given model is a TDL model.
protected static void _modeCode(java.lang.StringBuffer sb, State state, TDLModule module)
          Generate code for the modes.
private static java.lang.StringBuffer _portList(java.lang.StringBuffer sb, Actor actor, java.lang.String type)
          Generate code for the ports.
protected static void _sensorCode(java.lang.StringBuffer sb, TDLModule module)
          Generate code for the sensors.
protected static void _tasksCode(java.lang.StringBuffer sb, TDLModule module)
          Generate code for the tasks.
static void checkTDLID(java.lang.String string)
          Throw an exception if the given string is a valid TDL reserved word, which prevents it from being used as an identifier.
static java.lang.String generateTDLCode(TypedCompositeActor model)
          Generate TDL code for the given TDL model.
static void main(java.lang.String[] args)
          Create an instance of a model and generate TDL code for it The TDL code is printed on standard out.
static 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_modules

private static java.util.List _modules
All TDL modules in the model.


_portsConnectedToModuleOutputPorts

private static java.util.Set _portsConnectedToModuleOutputPorts
Input ports of a module that are connected to another TDL module's output ports. This is required to find the difference between actuators and module output ports.

Constructor Detail

TDLCodeGeneratorUtilities

private TDLCodeGeneratorUtilities()
Instances of this class cannot be created.

Method Detail

checkTDLID

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

Parameters:
string - A string to be used in TDL program.
Throws:
IllegalActionException - If the string can not be used.

generateTDLCode

public static java.lang.String generateTDLCode(TypedCompositeActor model)
                                        throws IllegalActionException
Generate TDL code for the given TDL model.

Parameters:
model - The given TDL model.
Returns:
The TDL code.
Throws:
IllegalActionException - If code can not be generated.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Create an instance of a model and generate TDL code for it The TDL code is printed on standard out.

Parameters:
args - The command-line arguments naming the .xml or .moml file to run
Throws:
java.lang.Throwable - If there is a problem reading the model or generating code.

needsInputDriver

public static boolean needsInputDriver(Actor actor)
                                throws IllegalActionException
Return true if the given actor has at least one connected input port, which requires it to have an input driver.

Parameters:
actor - The actor to test.
Returns:
True if the given actor has at least on connected input port.
Throws:
IllegalActionException

_actuatorCode

protected static void _actuatorCode(java.lang.StringBuffer sb,
                                    TDLModule module)
                             throws IllegalActionException
Generate code for the actuator. Usually, there is only one actuator.

Parameters:
sb - Buffer used store the parts of the generated code.
module - The module.
Throws:
IllegalActionException - If there is a problem accessing the ports.

_getTypeString

protected static java.lang.String _getTypeString(IOPort port)
                                          throws IllegalActionException
Get the datatype of a port. Default type is double.

Parameters:
port - An IO port.
Returns:
A string containing the type of the port.
Throws:
IllegalActionException

_headerCode

protected static void _headerCode(java.lang.StringBuffer sb,
                                  TypedCompositeActor model)
                           throws IllegalActionException
Generate header code for the file. Usually, there is only one header.

Parameters:
sb - Buffer used store the parts of the generated code.
model - The model
Throws:
IllegalActionException - If there is a problem getting the model name.

_initialize

protected static boolean _initialize(TypedCompositeActor model)
Initialize the code generation process by checking whether the given model is a TDL model. Return false if it is not.

Parameters:
model - A model to generate TDL code from.
Returns:
True if in the given model is a tdl model.

_modeCode

protected static void _modeCode(java.lang.StringBuffer sb,
                                State state,
                                TDLModule module)
                         throws IllegalActionException
Generate code for the modes.

Parameters:
sb - Buffer used store the parts of the generated code.
state - The state
module - The module
Throws:
IllegalActionException - If there is a problem getting the director or accessing the ports.

_sensorCode

protected static void _sensorCode(java.lang.StringBuffer sb,
                                  TDLModule module)
                           throws IllegalActionException
Generate code for the sensors.

Parameters:
sb - Buffer used store the parts of the generated code.
module - The model from which we generate code.
Throws:
IllegalActionException - If there is a problem iterating over the actors.

_tasksCode

protected static void _tasksCode(java.lang.StringBuffer sb,
                                 TDLModule module)
                          throws IllegalActionException
Generate code for the tasks.

Parameters:
sb - Buffer used store the parts of the generated code.
module - The model from which we generate code.
Throws:
IllegalActionException - If there is a problem iterating over the actors.

_getRefinementPortParameter

private static java.lang.String _getRefinementPortParameter(IOPort port,
                                                            java.lang.String paramName)
for whatever reason, the parameter specified at the modalport is not stored there but at the refinement port one level inside modalport.insideReceivers[0][0].getParameter("getter") returns the correct value.

Parameters:
port - refinement port.
Returns:
the code generated for the refinementPort.

_portList

private static java.lang.StringBuffer _portList(java.lang.StringBuffer sb,
                                                Actor actor,
                                                java.lang.String type)
                                         throws IllegalActionException
Generate code for the ports.

Parameters:
sb - Buffer used store the parts of the generated code.
actor - Actor containing the ports that code should be generated for.
type - Input or output port.
Returns:
Code generated for the ports.
Throws:
IllegalActionException - Thrown if port type could not be defined.

_getModules

private static void _getModules(TypedCompositeActor model)
Add all modules to the global list of modules.

Parameters:
model - Model containing TDL modules.

_getModes

private static java.util.List _getModes(TDLModule module)
                                 throws IllegalActionException
Get all modes of a module.

Parameters:
module - TDL module.
Returns:
list of all modes of a module.
Throws:
IllegalActionException - if controller of module could not be retrieved.