Class CTemplateParser


  • public class CTemplateParser
    extends ProceduralTemplateParser
    A class that allows to parse macros of templates in a code generator perspective.
    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Bert Rodiers
    Pt.AcceptedRating:
    Red (rodiers)
    Pt.ProposedRating:
    Red (rodiers)
    • Constructor Detail

      • CTemplateParser

        public CTemplateParser()
        Construct the CTemplateParser associated with the given component and the given adapter.
    • Method Detail

      • generateTypeConvertStatement

        public java.lang.String generateTypeConvertStatement​(ProgramCodeGeneratorAdapter.Channel source,
                                                             ProgramCodeGeneratorAdapter.Channel sink,
                                                             int offset,
                                                             java.lang.String alternativeSourceRef)
                                                      throws IllegalActionException
        Generate the type conversion statement for the particular offset of the two given channels. This assumes that the offset is the same for both channel. Advancing the offset of one has to advance the offset of the other.
        Overrides:
        generateTypeConvertStatement in class TemplateParser
        Parameters:
        source - The given source channel.
        sink - The given sink channel.
        offset - The given offset.
        alternativeSourceRef - The alternative source reference for the port. If alternativeSourceRef is null, then the adapter for the port of the source channel is used.z
        Returns:
        The type convert statement for assigning the converted source variable to the sink variable with the given offset.
        Throws:
        IllegalActionException - If there is a problem getting the adapters for the ports or if the conversion cannot be handled.
      • getFunctionInvocation

        public java.lang.String getFunctionInvocation​(java.lang.String functionString,
                                                      boolean isStatic)
                                               throws IllegalActionException
        Return the translated token instance function invocation string.
        Overrides:
        getFunctionInvocation in class TemplateParser
        Parameters:
        functionString - The string within the $tokenFunc() macro.
        isStatic - True if the method is static.
        Returns:
        The translated type function invocation string.
        Throws:
        IllegalActionException - The given function string is not well-formed.
      • _replaceMacro

        protected java.lang.String _replaceMacro​(java.lang.String macro,
                                                 java.lang.String parameter)
                                          throws IllegalActionException
        Return the replacement string of the given macro. Subclass of GenericCodeGenerator may overriding this method to extend or support a different set of macros.
        Overrides:
        _replaceMacro in class TemplateParser
        Parameters:
        macro - The given macro.
        parameter - The given parameter to the macro.
        Returns:
        The replacement string of the given macro.
        Throws:
        IllegalActionException - Thrown if the given macro or parameter is not valid.