Class CTemplateParser
- java.lang.Object
-
- ptolemy.cg.kernel.generic.program.TemplateParser
-
- ptolemy.cg.kernel.generic.program.procedural.ProceduralTemplateParser
-
- ptolemy.cg.kernel.generic.program.procedural.c.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)
-
-
Field Summary
-
Fields inherited from class ptolemy.cg.kernel.generic.program.procedural.ProceduralTemplateParser
_includeFiles
-
Fields inherited from class ptolemy.cg.kernel.generic.program.TemplateParser
_codeGenerator, _component, _parseTreeCodeGenerator
-
-
Constructor Summary
Constructors Constructor Description CTemplateParser()
Construct the CTemplateParser associated with the given component and the given adapter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CCodeGenerator
_getCodeGenerator()
Get the code generator associated with this adapter class.protected java.lang.String
_replaceMacro(java.lang.String macro, java.lang.String parameter)
Return the replacement string of the given macro.java.lang.String
generateTypeConvertStatement(ProgramCodeGeneratorAdapter.Channel source, ProgramCodeGeneratorAdapter.Channel sink, int offset, java.lang.String alternativeSourceRef)
Generate the type conversion statement for the particular offset of the two given channels.java.lang.String
getFunctionInvocation(java.lang.String functionString, boolean isStatic)
Return the translated token instance function invocation string.ParseTreeCodeGenerator
getParseTreeCodeGenerator()
Return a new parse tree code generator to use with expressions.-
Methods inherited from class ptolemy.cg.kernel.generic.program.procedural.ProceduralTemplateParser
generateFireCode, getHeaderFiles, init
-
Methods inherited from class ptolemy.cg.kernel.generic.program.TemplateParser
_findClosedParen, addFunctionUsed, addNewTypesUsed, escapeName, escapePortName, generateBlockCode, generateTypeConvertMethod, getCodeStream, getNewInvocation, getParameterValue, getPort, getSize, indexOf, parseList, processCode, setCodeGenerator, unescapeName, unescapePortName
-
-
-
-
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 classTemplateParser
- 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 classTemplateParser
- 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.
-
getParseTreeCodeGenerator
public ParseTreeCodeGenerator getParseTreeCodeGenerator()
Return a new parse tree code generator to use with expressions.- Overrides:
getParseTreeCodeGenerator
in classProceduralTemplateParser
- Returns:
- the parse tree code generator to use with expressions.
-
_getCodeGenerator
protected CCodeGenerator _getCodeGenerator()
Get the code generator associated with this adapter class.- Overrides:
_getCodeGenerator
in classTemplateParser
- Returns:
- The code generator associated with this adapter class.
- See Also:
TemplateParser.setCodeGenerator(ProgramCodeGenerator)
-
_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 classTemplateParser
- 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.
-
-