Class DEDirector

  • All Implemented Interfaces:
    java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    PtidesDirector

    public class DEDirector
    extends PortDirector
    Code generator adapter associated with the DEDirector class. This adapter is highly experimental since it changes a lot of behaviors of the code generation process. This class is also associated with a code generator.
    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    William Lucas based on SDFDirector.java by Ye Zhou, Gang Zhou
    Pt.AcceptedRating:
    red (wlc)
    Pt.ProposedRating:
    red (wlc)
    • Field Detail

      • _referencedParameters

        protected java.util.HashMap<NamedProgramCodeGeneratorAdapter,​java.util.HashSet<Parameter>> _referencedParameters
        A hashmap that keeps track of parameters that are referenced for the associated actor.
    • Constructor Detail

      • DEDirector

        public DEDirector​(DEDirector deDirector)
        Construct the code generator adapter associated with the given DEDirector.
        Parameters:
        deDirector - The associated ptolemy.domains.de.kernel.DEDirector
    • Method Detail

      • allowDynamicMultiportReference

        public final java.lang.Boolean allowDynamicMultiportReference()
                                                               throws IllegalActionException
        Return whether the channels in multiports can be dynamically referenced using the $ref macro.
        Specified by:
        allowDynamicMultiportReference in class PortDirector
        Returns:
        True when the channels in multiports can be dynamically referenced using the $ref macro.
        Throws:
        IllegalActionException - If the expression cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.
      • generateConstructorCode

        public java.lang.String generateConstructorCode()
                                                 throws IllegalActionException
        Generate the constructor code for the specified director. In this class we initialize the director with its internal parameters and fields as well as with the depths of the actors.
        Overrides:
        generateConstructorCode in class Director
        Returns:
        The generated constructor code
        Throws:
        IllegalActionException - Not thrown in this base class.
      • generateFunctionsDeclaration

        public java.lang.String generateFunctionsDeclaration()
                                                      throws IllegalActionException
        Generate The functions' declaration code for this director.
        Returns:
        The functions' declaration function code.
        Throws:
        IllegalActionException - If thrown while generating code.
      • generateFireAtFunctionCode

        public java.lang.String generateFireAtFunctionCode()
                                                    throws IllegalActionException
        Generate The _fireAt function code. This method is the direct transposition of the _fireAt function of the director in C.
        Returns:
        The _fireAt function code.
        Throws:
        IllegalActionException - If thrown while generating fire code.
      • generateFireFunctionCode

        public java.lang.String generateFireFunctionCode()
                                                  throws IllegalActionException
        Generate The fire function code. This method calls fire() for in a loop This method is the direct transposition of the Fire function of the director in C.
        Overrides:
        generateFireFunctionCode in class Director
        Returns:
        The fire function code.
        Throws:
        IllegalActionException - If thrown while generating fire code.
      • generateFirePrivateFunctionCode

        public java.lang.String generateFirePrivateFunctionCode()
                                                         throws IllegalActionException
        Generate The _fire function code. This method is the direct transposition of the _fire function of the director in C.
        Returns:
        The _fire function code.
        Throws:
        IllegalActionException - If thrown while generating fire code.
      • generateInitializeFunctionCode

        public java.lang.String generateInitializeFunctionCode()
                                                        throws IllegalActionException
        Generate the initialize code for the associated DE director.
        Returns:
        The generated initialize code.
        Throws:
        IllegalActionException - If the adapter associated with an actor throws it while generating initialize code for the actor.
      • generateNextActorToFireFunctionCode

        public java.lang.String generateNextActorToFireFunctionCode()
                                                             throws IllegalActionException
        Generate The _NextActorToFire function code. This method is the direct transposition of the _NextActorToFire function of the director in C.
        Returns:
        The _fireAt function code.
        Throws:
        IllegalActionException - If thrown while generating fire code.
      • generatePortName

        public java.lang.String generatePortName​(TypedIOPort port)
                                          throws IllegalActionException
        Generate sanitized name for the given named object. Remove all underscores to avoid conflicts with systems functions.
        Specified by:
        generatePortName in class PortDirector
        Parameters:
        port - The port for which the name is generated.
        Returns:
        The sanitized name.
        Throws:
        IllegalActionException - If the variablesAsArrays parameter cannot be read or if the buffer size of the port cannot be read.
      • generatePostFireFunctionCode

        public java.lang.String generatePostFireFunctionCode()
                                                      throws IllegalActionException
        Generate The postfire function code.
        Returns:
        The postfire function code.
        Throws:
        IllegalActionException - If thrown while generating fire code.
      • generatePreFireFunctionCode

        public java.lang.String generatePreFireFunctionCode()
                                                     throws IllegalActionException
        Generate The prefire function code.
        Returns:
        The prefire function code.
        Throws:
        IllegalActionException - If thrown while generating fire code.
      • generatePreinitializeCode

        public java.lang.String generatePreinitializeCode()
                                                   throws IllegalActionException
        Generate the preinitialize code for this director.
        Overrides:
        generatePreinitializeCode in class Director
        Returns:
        The generated preinitialize code.
        Throws:
        IllegalActionException - If getting the adapter fails, or if generating the preinitialize code for a adapter fails, or if there is a problem getting the buffer size of a port.
      • generatePreinitializeMethodBodyCode

        public java.lang.String generatePreinitializeMethodBodyCode()
                                                             throws IllegalActionException
        Generate the preinitialize code for this director. The preinitialize code for the director is generated by appending the preinitialize code for each actor.
        Overrides:
        generatePreinitializeMethodBodyCode in class Director
        Returns:
        The generated preinitialize code.
        Throws:
        IllegalActionException - If getting the adapter fails, or if generating the preinitialize code for a adapter fails, or if there is a problem getting the buffer size of a port.
      • generateVariableDeclaration

        public java.lang.String generateVariableDeclaration()
                                                     throws IllegalActionException
        Generate the variable declaration.

        We override the super method, because in DE the declaration of the variables are in the actor's files.

        Overrides:
        generateVariableDeclaration in class Director
        Returns:
        code The generated code.
        Throws:
        IllegalActionException - If the adapter class for the model director cannot be found.
      • getHeaderFiles

        public java.util.Set<java.lang.String> getHeaderFiles()
                                                       throws IllegalActionException
        Get the files needed by the code generated from this adapter class. Basically here, we include the "standard" C-written declaration of the DECQEventQueue
        Overrides:
        getHeaderFiles in class NamedProgramCodeGeneratorAdapter
        Returns:
        A set of strings that are header files needed by the code generated from this adapter class.
        Throws:
        IllegalActionException - If something goes wrong.
      • padBuffers

        public final java.lang.Boolean padBuffers()
                                           throws IllegalActionException
        Return whether we need to pad buffers or not.
        Specified by:
        padBuffers in class PortDirector
        Returns:
        True when we need to pad buffers.
        Throws:
        IllegalActionException - If the expression cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.
      • _generateVariableDeclaration

        protected java.lang.String _generateVariableDeclaration​(NamedProgramCodeGeneratorAdapter target)
                                                         throws IllegalActionException
        Generate variable declarations for inputs and outputs and parameters. Append the declarations to the given string buffer.
        Overrides:
        _generateVariableDeclaration in class Director
        Parameters:
        target - The ProgramCodeGeneratorAdapter for which code needs to be generated.
        Returns:
        code The generated code.
        Throws:
        IllegalActionException - If the adapter class for the model director cannot be found.
      • _getParameter

        protected java.lang.String _getParameter​(NamedProgramCodeGeneratorAdapter target,
                                                 Attribute attribute,
                                                 java.lang.String[] channelAndOffset)
                                          throws IllegalActionException
        Return an unique label for the given attribute referenced by the given adapter.
        Overrides:
        _getParameter in class Director
        Parameters:
        target - The ProgramCodeGeneratorAdapter for which code needs to be generated.
        attribute - The given attribute.
        channelAndOffset - The given channel and offset.
        Returns:
        an unique label for the given attribute.
        Throws:
        IllegalActionException - If the adapter throws it while generating the label.