Class PortDirector

    • Field Detail

      • ports

        public Ports ports
        The meta information about the ports in the container.
      • _sanitizedDirectorName

        protected java.lang.String _sanitizedDirectorName
        The name of the director in a format suitable to be used as a variable name.
    • Constructor Detail

      • PortDirector

        public PortDirector​(Director director)
        Construct the code generator adapter associated with the given director. Note before calling the generate*() methods, you must also call setCodeGenerator(GenericCodeGenerator).
        Parameters:
        director - The associated director.
    • Method Detail

      • allowDynamicMultiportReference

        public abstract java.lang.Boolean allowDynamicMultiportReference()
                                                                  throws IllegalActionException
        Return whether the channels in multiports can be dynamically referenced using the $ref macro.
        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.
      • generatePortName

        public abstract 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.
        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.
      • getReference

        public java.lang.String getReference​(java.lang.String name,
                                             boolean isWrite,
                                             NamedProgramCodeGeneratorAdapter target)
                                      throws IllegalActionException
        Return the reference to the specified parameter or port of the associated actor. For a parameter, the returned string is in the form "fullName_parameterName". For a port, the returned string is in the form "fullName_portName[channelNumber][offset]", if any channel number or offset is given.

        Usually given the name of an input port, getReference(String name) returns a target language variable name representing the input port. Given the name of an output port, getReference(String name) returns variable names representing the input ports connected to the output port. However, if the name of an input port starts with '@', getReference(String name) returns variable names representing the input ports connected to the given input port on the inside. If the name of an output port starts with '@', getReference(String name) returns variable name representing the the given output port which has inside receivers. The special use of '@' is for composite actor when tokens are transferred into or out of the composite actor.

        Overrides:
        getReference in class Director
        Parameters:
        name - The name of the parameter or port
        isWrite - Whether to generate the write or read offset.
        target - The ProgramCodeGeneratorAdapter for which code needs to be generated.
        Returns:
        The reference to that parameter or port (a variable name, for example).
        Throws:
        IllegalActionException - If the parameter or port does not exist or does not have a value.
      • getReference

        public java.lang.String getReference​(TypedIOPort port,
                                             java.lang.String[] channelAndOffset,
                                             boolean forComposite,
                                             boolean isWrite,
                                             NamedProgramCodeGeneratorAdapter target)
                                      throws IllegalActionException
        Return an unique label for the given port channel referenced by the given adapter. By default, this delegates to the adapter to generate the reference. Subclass may override this method to generate the desire label according to the given parameters.
        Parameters:
        port - The given port.
        channelAndOffset - The given channel and offset.
        forComposite - Whether the given adapter is associated with a CompositeActor
        isWrite - The type of the reference. True if this is a write reference; otherwise, this is a read reference.
        target - The ProgramCodeGeneratorAdapter for which code needs to be generated.
        Returns:
        an unique reference label for the given port channel.
        Throws:
        IllegalActionException - If the adapter throws it while generating the label.
      • getSanitizedDirectorName

        public java.lang.String getSanitizedDirectorName()
        Return the sanitized name of this director adapter.
        Returns:
        The name of the director
      • padBuffers

        public abstract java.lang.Boolean padBuffers()
                                              throws IllegalActionException
        Return whether we need to pad buffers or not.
        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.
      • _checkLocal

        protected static boolean _checkLocal​(boolean forComposite,
                                             IOPort port)
        Return true if the port is a local port.
        Parameters:
        forComposite - True if we are checking for a composite
        port - The port to be checked.
        Returns:
        A boolean true when the port is local.
      • _checkRemote

        protected static boolean _checkRemote​(boolean forComposite,
                                              IOPort port)
        Return true if the port is a remote port.
        Parameters:
        forComposite - True if this for a composite.
        port - The port to check.
        Returns:
        True if the port is an output and not a composite or the port is an input and this is for a composite.
      • _generateChannelOffset

        protected java.lang.String _generateChannelOffset​(TypedIOPort port,
                                                          boolean isWrite,
                                                          java.lang.String channelString)
                                                   throws IllegalActionException
        Generate a string that represents the offset for a dynamically determined channel of a multiport.
        Parameters:
        port - The referenced port.
        isWrite - Whether to generate the write or read offset.
        channelString - The string that will determine the channel.
        Returns:
        The expression that represents the offset for a channel determined dynamically in the generated code.
        Throws:
        IllegalActionException - If thrown while generating the port name.
      • _generatePortReference

        protected java.lang.String _generatePortReference​(TypedIOPort port,
                                                          java.lang.String[] channelAndOffset,
                                                          boolean isWrite)
                                                   throws IllegalActionException
        Generate a string that represents the reference for an IOPort.
        Parameters:
        port - The port to get the reference.
        isWrite - Whether to generate the write or read offset.
        channelAndOffset - The string[] that will determine the channel and the offset.
        Returns:
        The expression that represents the reference for the port
        Throws:
        IllegalActionException - If thrown while generating the channel offsite or generating the port name.
      • _getCastType

        protected java.lang.String _getCastType​(java.lang.String name)
                                         throws IllegalActionException
        Get the cast type.
        Parameters:
        name - The name with # syntax.
        Returns:
        The cast type
        Throws:
        IllegalActionException - If there are more than two # in the name, indicating an invalid cast type.
      • _getChannelAndOffset

        protected java.lang.String[] _getChannelAndOffset​(java.lang.String name)
                                                   throws IllegalActionException
        Return the channel and offset given in a string. The result is an string array of length 2. The first element indicates the channel index, and the second the offset. If either element is an empty string, it means that channel/offset is not specified.
        Parameters:
        name - The given string.
        Returns:
        An string array of length 2, containing expressions of the channel index and offset.
        Throws:
        IllegalActionException - If the channel index or offset specified in the given string is illegal.
      • _getRefName

        protected java.lang.String _getRefName​(java.lang.String name)
                                        throws IllegalActionException
        Generate a string that represents the reference to a parameter or a port named "name".
        Parameters:
        name - The name.
        Returns:
        The string which represents the reference
        Throws:
        IllegalActionException - If the reference cannot be found or is an invalid cast type.
      • _getRefType

        protected java.lang.String _getRefType​(Attribute attribute)
        Generate a string that represents the type of an attribute (only if it is a parameter).
        Parameters:
        attribute - The attribute, which is typically a Parameter.
        Returns:
        the code generation type if the attribute is a parameter, otherwise, null.