ptolemy.codegen.kernel
Class CodeStream

java.lang.Object
  extended by ptolemy.codegen.kernel.CodeStream

public class CodeStream
extends java.lang.Object

Read and process code blocks from the adaptor .[target] file. Adaptor code template files contain c code blocks for the associated java adaptor actor. A proper code block should have the following grammar:

     _BLOCKSTART CodeBlockName [(Parameter1, Parameter2), ...] _HEADEREND
         CodeBlockBody
     _BLOCKEND
 
Parameterized code blocks can contain parameters which the user can specify. Parameter substitution syntax is straight-forward string pattern substitution, so the user is responsible for declaring unique parameter names. For example, a code block is declared to be the following:
     /*** initBlock ($arg) ***/
         if ($ref(input) != $arg) {
             $ref(output) = $arg;
         }
     /**/
 
If the user invoke the appendCodeBlock() method with a single argument, which is the integer 3,
     LinkedList args = new LinkedList();
     args.add(Integer.toString(3));
     appendCodeBlock("initBlock", args);
 
then after parameter substitution, the code block would become:
     if ($ref(input) != 3) {
         $ref(output) = 3;
     }
 
Parameter substitution takes place before macro substitution processed by the codegen kernel. CodeStream supports overriding superclass code blocks. It also supports overloading code blocks with different number of parameters.

Since:
Ptolemy II 6.0
Version:
$Id: CodeStream.java 55293 2009-07-28 02:08:23Z cxh $
Author:
Man-Kit Leung
Accepted Rating:
Yellow (mankit)
Proposed Rating:
Yellow (mankit)

Nested Class Summary
private  class CodeStream.CodeBlockTable
          The code block table class.
static class CodeStream.Signature
          Inner class for representing a code block signature.
 
Field Summary
private  CodeGeneratorHelper _adaptor
          The adaptor associated with this code stream.
private static java.lang.String _BLOCKEND
          String pattern which represents the end of a code block.
private static java.lang.String _BLOCKSTART
          String pattern which represents the start of a code block.
private  java.lang.String _codeBlocks
           
protected  CodeGenerator _codeGenerator
          The code generator associated with this code stream.
private  CodeStream.CodeBlockTable _declarations
          The code block table that stores the code blocks information, like the code body (StringBuffer), signatures, adaptor class associated with the code blocks.
private  boolean _doParsing
           
private static java.lang.String _eol
          End of line character.
private  java.lang.String _filePath
          The path of the current code template file being parsed.
private static java.lang.String _HEADEREND
          String pattern which represents the end of a code block header.
private static int _indentLevel
          The indent level.
private  java.lang.String _originalFilePath
          Original value of _filePath, used for error messages.
private  int _parseIndex
          Index pointer that indicates the current location within the code template file to be parsed.
private  java.lang.StringBuffer _stream
          The content of this CodeStream.
private  java.util.List _templateArguments
           
private  java.util.List _templateParameters
           
 
Constructor Summary
CodeStream(CodeGeneratorHelper adaptor)
          Construct a new code stream associated with the given adaptor.
CodeStream(java.util.List templateArguments, CodeGeneratorHelper adaptor)
          Construct a new code stream associated with the given java actor adaptor.
CodeStream(java.lang.String path, CodeGenerator generator)
          Construct a new code stream, given a specified file path of the adaptor .
 
Method Summary
private static void _assert(boolean invariant)
           
private static java.lang.String _checkArgumentName(java.lang.String name)
           
private static java.lang.String _checkCodeBlockName(java.lang.String name)
          Type check the given name and return a well-formed code block name.
private static java.lang.String _checkParameterName(java.lang.String name)
          Type check the parameter name.
private  void _constructCodeTable(boolean mayNotExist)
          Read the code blocks associated with this adaptor and construct the code block and parameter table.
private  void _constructCodeTableHelper(boolean mayNotExist)
           
private  java.lang.String _getPath(java.lang.Class adaptorClass)
          Get the file path for the adaptor .
private  boolean _needLineInfo()
          Return true if the generated source code is bound to the line number and file of the adaptor templates.
private  java.lang.StringBuffer _parseBody(java.lang.StringBuffer codeInFile)
          Parse from the _parseIndex and return the next code block body from the given StringBuffer.
private  CodeStream.Signature _parseCodeBlock(java.lang.StringBuffer codeInFile)
          Parse from the _parseIndex for the next single code block and return the code block name.
private  CodeStream.Signature _parseHeader(java.lang.StringBuffer codeInFile)
          Parse the header of the code block.
private static java.util.List _parseParameterList(java.lang.StringBuffer codeInFile, int start, int end)
           
private static java.util.List _parseParameterList(java.lang.StringBuffer codeInFile, int start, int end, java.lang.String startSymbol, java.lang.String endSymbol)
          Return a list of parameter expression contains in the given string buffer.
private static java.lang.StringBuffer _substituteParameters(java.lang.StringBuffer codeBlock, java.util.List parameters, java.util.List arguments)
          Substitute parameters.
 void append(java.lang.String codeBlock)
          Append the contents of the given String to this code stream.
 void appendCodeBlock(java.lang.String blockName)
          Append the code block specified the given block name.
 void appendCodeBlock(java.lang.String blockName, boolean mayNotExist)
          Append the code block specified the given block name.
 void appendCodeBlock(java.lang.String blockName, boolean mayNotExist, int indentLevel)
          Append the code block specified the given block name.
 void appendCodeBlock(java.lang.String blockName, java.util.List arguments)
          Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list.
 void appendCodeBlock(java.lang.String blockName, java.util.List arguments, boolean mayNotExist)
          Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list.
 void appendCodeBlock(java.lang.String blockName, java.util.List arguments, boolean mayNotExist, int indentLevel)
          Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list.
 void appendCodeBlock(java.lang.String blockName, java.util.List arguments, int indentLevel)
          Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list.
 void appendCodeBlocks(java.lang.String nameExpression)
          Append multiple code blocks whose names match the given regular expression.
 void clear()
          Clear the contents of this code stream.
 java.lang.String description()
          Return a String that contains all the code block names and bodies from the associated adaptor .
 java.util.List<java.lang.String> getAllCodeBlockNames()
          Return a list of code block names contained by this CodeStream.
 java.util.Set<CodeStream.Signature> getAllCodeBlockSignatures()
          Return a set of code block signatures contained by this CodeStream.
 java.lang.String getCodeBlock(java.lang.String name)
          Given a code block name, return the corresponding code block.
 java.lang.String getCodeBlock(java.lang.String blockName, java.util.List arguments)
          Return a codeBlock with a given name and substitute in the given arguments.
 java.lang.String getCodeBlock(java.lang.String blockName, java.util.List arguments, boolean mayNotExist)
          Return a codeBlock with a given name and substitute in the given arguments.
 java.lang.String getCodeBlockTemplate(java.lang.Object signature)
          Given a code block signature, return the corresponding code block template.
static java.lang.String indent(int indentLevel, java.lang.String inputString)
          Indent the string to the specified indent level.
static java.lang.String indent(java.lang.String inputString)
          Indent the string to the default indent level.
 void insert(int offset, java.lang.String code)
          Insert the contents of the given String to this code stream at the given position.
 boolean isEmpty()
          return a boolean indicating if this stream is empty.
static void main(java.lang.String[] args)
          Simple stand alone test method.
 void parse(java.lang.String filePath)
          Parse additional code blocks from the file specified by the given file path.
 void parse(java.lang.String filePath, boolean mayNotExist)
          Parse additional code blocks from the file specified by the given file path.
 void reset()
          Reset this CodeStream object so that its code table will be re-constructed when needed.
static void selfTest()
          Perform a self test.
 void setCodeBlocks(java.lang.String codeBlocks)
          Set the code blocks which will be parsed instead of code template file.
static void setIndentLevel(int indentLevel)
          Set the indent level.
 java.lang.String toString()
          Return the string representation of the code stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_doParsing

private boolean _doParsing

_BLOCKEND

private static final java.lang.String _BLOCKEND
String pattern which represents the end of a code block. Both _BLOCKSTART and _BLOCKEND cannot be the prefix of the other.

See Also:
Constant Field Values

_BLOCKSTART

private static final java.lang.String _BLOCKSTART
String pattern which represents the start of a code block.

See Also:
Constant Field Values

_HEADEREND

private static final java.lang.String _HEADEREND
String pattern which represents the end of a code block header.

See Also:
Constant Field Values

_indentLevel

private static int _indentLevel
The indent level.


_codeGenerator

protected CodeGenerator _codeGenerator
The code generator associated with this code stream.


_codeBlocks

private java.lang.String _codeBlocks

_declarations

private CodeStream.CodeBlockTable _declarations
The code block table that stores the code blocks information, like the code body (StringBuffer), signatures, adaptor class associated with the code blocks. It uses code block Signature as keys.


_eol

private static java.lang.String _eol
End of line character. Under Unix: "\n", under Windows: "\n\r". We use a end of line charactor so that the files we generate have the proper end of line character for use by other native tools.


_filePath

private java.lang.String _filePath
The path of the current code template file being parsed.


_adaptor

private CodeGeneratorHelper _adaptor
The adaptor associated with this code stream.


_originalFilePath

private java.lang.String _originalFilePath
Original value of _filePath, used for error messages.


_parseIndex

private int _parseIndex
Index pointer that indicates the current location within the code template file to be parsed.


_stream

private java.lang.StringBuffer _stream
The content of this CodeStream.


_templateArguments

private java.util.List _templateArguments

_templateParameters

private java.util.List _templateParameters
Constructor Detail

CodeStream

public CodeStream(CodeGeneratorHelper adaptor)
Construct a new code stream associated with the given adaptor. Each actor should have its own codestream during code generation.

Parameters:
adaptor - The adaptor associated with this code stream, which is currently ignored.

CodeStream

public CodeStream(java.util.List templateArguments,
                  CodeGeneratorHelper adaptor)
Construct a new code stream associated with the given java actor adaptor. Each actor should have its own codestream during code generation.

Parameters:
templateArguments - Template arguments to be substituted in the code. Template arguments begin with "<" and end with ">".
adaptor - The actor adaptor associated with this code stream, which is currently ignored.

CodeStream

public CodeStream(java.lang.String path,
                  CodeGenerator generator)
Construct a new code stream, given a specified file path of the adaptor .[target] file as a URL suitable for FileUtilities.openForReading(String, URI, ClassLoader), for example "file:./test/testCodeBlock.c".

Parameters:
path - The given file path.
generator - The generator associated with this CodeStream.
Method Detail

append

public void append(java.lang.String codeBlock)
Append the contents of the given String to this code stream.

Parameters:
codeBlock - The given string.

appendCodeBlock

public void appendCodeBlock(java.lang.String blockName)
                     throws IllegalActionException
Append the code block specified the given block name. This method invokes appendCodeBlock(String, LinkedList) with no arguments by passing an empty array list of argments. The requested code block is required to exist.

Parameters:
blockName - The given code block name.
Throws:
IllegalActionException - If appendCodeBlock(String, List, boolean) throws the exception.
See Also:
appendCodeBlock(String, List, boolean)

appendCodeBlock

public void appendCodeBlock(java.lang.String blockName,
                            boolean mayNotExist)
                     throws IllegalActionException
Append the code block specified the given block name. This method invokes appendCodeBlock(String, LinkedList) with no arguments by passing an empty array list of argments. The requested code block is required to exist.

Parameters:
blockName - The given code block name.
mayNotExist - Indicate if it is okay not to find the code block. if the code block has parameters.
Throws:
IllegalActionException - If appendCodeBlock(String, List, boolean) throws the exception.
See Also:
appendCodeBlock(String, List, boolean)

appendCodeBlock

public void appendCodeBlock(java.lang.String blockName,
                            boolean mayNotExist,
                            int indentLevel)
                     throws IllegalActionException
Append the code block specified the given block name. This method invokes appendCodeBlock(String, LinkedList) with no arguments by passing an empty array list of argments. The requested code block is required to exist.

Parameters:
blockName - The given code block name.
mayNotExist - Indicate if it is okay not to find the code block. if the code block has parameters.
indentLevel - The level of indention.
Throws:
IllegalActionException - If appendCodeBlock(String, List, boolean) throws the exception.
See Also:
appendCodeBlock(String, List, boolean)

appendCodeBlock

public void appendCodeBlock(java.lang.String blockName,
                            java.util.List arguments)
                     throws IllegalActionException
Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list. The requested code block is required to exist.

Parameters:
blockName - The name of the code block.
arguments - The user-specified arguments for the code block, if the code block has parameters.
Throws:
IllegalActionException - If appendCodeBlock(String, List, boolean) throws the exception.
See Also:
appendCodeBlock(String, List, boolean)

appendCodeBlock

public void appendCodeBlock(java.lang.String blockName,
                            java.util.List arguments,
                            int indentLevel)
                     throws IllegalActionException
Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list. The requested code block is required to exist.

Parameters:
blockName - The name of the code block.
arguments - The user-specified arguments for the code block, if the code block has parameters.
indentLevel - The level of indention.
Throws:
IllegalActionException - If appendCodeBlock(String, List, boolean) throws the exception.
See Also:
appendCodeBlock(String, List, boolean)

appendCodeBlock

public void appendCodeBlock(java.lang.String blockName,
                            java.util.List arguments,
                            boolean mayNotExist)
                     throws IllegalActionException
Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list. The initial default level of indention is 0. To change the the level of indentation, call setIndentLevel(int).

Parameters:
blockName - The name of the code block.
arguments - The user-specified arguments for the code block,
mayNotExist - Indicate if it is okay not to find the code block. if the code block has parameters.
Throws:
IllegalActionException - If _constructCodeTable() throws the exception, or if the requested code block is required but cannot be found, or if the numbers of arguments and parameters do not match.

appendCodeBlock

public void appendCodeBlock(java.lang.String blockName,
                            java.util.List arguments,
                            boolean mayNotExist,
                            int indentLevel)
                     throws IllegalActionException
Append the specific code block with an array of arguments and substitute each argument with the parameters of the code block in the order listed in the given arguments array list.

Parameters:
blockName - The name of the code block.
arguments - The user-specified arguments for the code block,
mayNotExist - Indicate if it is okay not to find the code block. if the code block has parameters.
indentLevel - The level of indention.
Throws:
IllegalActionException - If _constructCodeTable() throws the exception, or if the requested code block is required but cannot be found, or if the numbers of arguments and parameters do not match.

getCodeBlock

public java.lang.String getCodeBlock(java.lang.String blockName,
                                     java.util.List arguments)
                              throws IllegalActionException
Return a codeBlock with a given name and substitute in the given arguments. The codeBlock must exist or an exception is thrown.

Parameters:
blockName - The given name that identifies the code block.
arguments - The list of arguments to substitute in the code block.
Returns:
The content contained by the code block with the given name.
Throws:
IllegalActionException - Thrown if getCodeBlock(String, List, boolean) throws it.

getCodeBlock

public java.lang.String getCodeBlock(java.lang.String blockName,
                                     java.util.List arguments,
                                     boolean mayNotExist)
                              throws IllegalActionException
Return a codeBlock with a given name and substitute in the given arguments.

Parameters:
blockName - The given name that identifies the code block.
arguments - The list of arguments to substitute in the code block.
mayNotExist - False to require the codeblock to exist.
Returns:
The content contained by the code block with the given name.
Throws:
IllegalActionException - Thrown if a problem occurs in constructing the code block table, or the given code block name is required to exist but does not.

appendCodeBlocks

public void appendCodeBlocks(java.lang.String nameExpression)
                      throws IllegalActionException
Append multiple code blocks whose names match the given regular expression.

Parameters:
nameExpression - The given regular expression for the block names.
Throws:
IllegalActionException - If _constructCodeTable() throws the exception, or if the requested code block is required but cannot be found, or if the numbers of arguments and parameters do not match.

clear

public void clear()
Clear the contents of this code stream.


description

public java.lang.String description()
                             throws IllegalActionException
Return a String that contains all the code block names and bodies from the associated adaptor .[target] file.

Returns:
The content from parsing the adaptor .[target] file.
Throws:
IllegalActionException - If an error occurs during parsing.

getAllCodeBlockNames

public java.util.List<java.lang.String> getAllCodeBlockNames()
                                                      throws IllegalActionException
Return a list of code block names contained by this CodeStream.

Returns:
The list of code block names contained by this CodeStream.
Throws:
IllegalActionException - If there is a problem when parsing the code adaptor .[target] file.

getAllCodeBlockSignatures

public java.util.Set<CodeStream.Signature> getAllCodeBlockSignatures()
                                                              throws IllegalActionException
Return a set of code block signatures contained by this CodeStream.

Returns:
The set of code block signatures contained by this CodeStream.
Throws:
IllegalActionException - If there is a problem when parsing the code adaptor .[target] file.

getCodeBlock

public java.lang.String getCodeBlock(java.lang.String name)
                              throws IllegalActionException
Given a code block name, return the corresponding code block.

Parameters:
name - The name of the code block.
Returns:
The code block with the name.
Throws:
IllegalActionException - If a code block by that name cannot be found.

getCodeBlockTemplate

public java.lang.String getCodeBlockTemplate(java.lang.Object signature)
                                      throws IllegalActionException
Given a code block signature, return the corresponding code block template.

Parameters:
signature - The signature of the code block.
Returns:
The code block template that matches the signature, or the empty string if a code block with that signature cannot be found.
Throws:
IllegalActionException - If thrown whilegetting a code block template with the name of the signature.

indent

public static java.lang.String indent(java.lang.String inputString)
Indent the string to the default indent level.

Parameters:
inputString - The string to be indented.
Returns:
The indented string.

indent

public static java.lang.String indent(int indentLevel,
                                      java.lang.String inputString)
Indent the string to the specified indent level.

Parameters:
indentLevel - The level of indention.
inputString - The string to be indented
Returns:
The indented string.

insert

public void insert(int offset,
                   java.lang.String code)
Insert the contents of the given String to this code stream at the given position.

Parameters:
offset - The given position.
code - The given string.

isEmpty

public boolean isEmpty()
return a boolean indicating if this stream is empty.

Returns:
true if this stream is empty.

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        IllegalActionException
Simple stand alone test method. Parse a adaptor .[target] file, and print all the code blocks.

Parameters:
args - Command-line arguments, the first of which names a .[target] file as a URL , for example file:./test/testCodeBlock.c.
Throws:
java.io.IOException - If an error occurs when reading user inputs.
IllegalActionException - If an error occurs during parsing the adaptor .[target] file.

parse

public void parse(java.lang.String filePath)
           throws IllegalActionException
Parse additional code blocks from the file specified by the given file path. This assumes the given filePath points to an existing file. This is equivalent to calling parse(filePath, false). See parse(String, boolean).

Parameters:
filePath - The given file path.
Throws:
IllegalActionException - Thrown if an error occurs when parsing the code blocks in the file.

parse

public void parse(java.lang.String filePath,
                  boolean mayNotExist)
           throws IllegalActionException
Parse additional code blocks from the file specified by the given file path. The new code blocks will be put alongside and have higher precedence than the code blocks already contained by this CodeStream. Also, the specified file path may not be required to point to an existing file; otherwise, an exception is thrown.

Parameters:
filePath - The given file path.
mayNotExist - Whether to allow invalid filePath input. True if the given filePath may not exist (no exception thrown for invalid file path); false, otherwise.
Throws:
IllegalActionException - Thrown if an error occurs when parsing the code blocks in the file.

reset

public void reset()
Reset this CodeStream object so that its code table will be re-constructed when needed.


setCodeBlocks

public void setCodeBlocks(java.lang.String codeBlocks)
Set the code blocks which will be parsed instead of code template file.

Parameters:
codeBlocks - The code blocks to be parsed.

_assert

private static void _assert(boolean invariant)

selfTest

public static void selfTest()
Perform a self test.


setIndentLevel

public static void setIndentLevel(int indentLevel)
Set the indent level.

Parameters:
indentLevel - The indent level, where 0 means no indentation, 1 means indent one level (probably 4 spaces).

toString

public java.lang.String toString()
Return the string representation of the code stream.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of this code stream.

_checkCodeBlockName

private static java.lang.String _checkCodeBlockName(java.lang.String name)
                                             throws IllegalActionException
Type check the given name and return a well-formed code block name. This method assumes the code block name is short (that is why String is used instead of StringBuffer). This method returns a well-formed code block name, otherwise, it throws an exception.

Parameters:
name - The given code block name.
Returns:
The well-formed code block name after lexical checking.
Throws:
Thrown - if the given name is not well-formed.
IllegalActionException

_checkArgumentName

private static java.lang.String _checkArgumentName(java.lang.String name)
                                            throws IllegalActionException
Throws:
IllegalActionException

_checkParameterName

private static java.lang.String _checkParameterName(java.lang.String name)
                                             throws IllegalActionException
Type check the parameter name. Check if the given string starts with '$'. Insert '\' before '$'. '$' is a special charater in regular expression, and we are using this name string as regular expression to do text substitution. Requires the rest of the characters to be within the set [a-zA-Z_0-9]. Returns a well-formed parameter name, otherwise, throws an IllegalActionException.

Parameters:
name - The given parameter name.
Returns:
The well-formed parameter name after lexical checking.
Throws:
Thrown - if the given name is not well-formed.
IllegalActionException

_constructCodeTable

private void _constructCodeTable(boolean mayNotExist)
                          throws IllegalActionException
Read the code blocks associated with this adaptor and construct the code block and parameter table. If there is a pre-specified file path to read from, it only reads code block from the specified file only. Otherwise, it recursively searches code blocks from super classes' adaptors.

Parameters:
mayNotExist - Indicate if the file is required to exist.
Throws:
IllegalActionException - If an error occurs when parsing the adaptor .[target] file.

_constructCodeTableHelper

private void _constructCodeTableHelper(boolean mayNotExist)
                                throws IllegalActionException
Parameters:
mayNotExist - Indicate if the file is required to exist.
Throws:
IllegalActionException

_needLineInfo

private boolean _needLineInfo()
                       throws IllegalActionException
Return true if the generated source code is bound to the line number and file of the adaptor templates.

Returns:
True if the generated source code is bound to the line number and file of the adaptor templates. Return false if the source is bound only to the output file, or if there is no CodeGenerator associated with this stream.
Throws:
IllegalActionException - If there is a problem reading the CodeGenerator.sourceLineBinding parameter.

_getPath

private java.lang.String _getPath(java.lang.Class adaptorClass)
Get the file path for the adaptor .[target] file associated with the given adaptor class. If the adaptor has no code generator, then the empty string is returned.

Parameters:
adaptorClass - The given adaptor class
Returns:
Path for the adaptor .[target] file.

_parseBody

private java.lang.StringBuffer _parseBody(java.lang.StringBuffer codeInFile)
                                   throws IllegalActionException
Parse from the _parseIndex and return the next code block body from the given StringBuffer. This method recursively parses within the code body for nested code blocks.

Parameters:
codeInFile - Code from the adaptor code template file.
Returns:
The code body within the current code block.
Throws:
IllegalActionException - If code block's close block pattern, _BLOCKEND, is missing.
See Also:
_parseIndex, _BLOCKEND

_parseCodeBlock

private CodeStream.Signature _parseCodeBlock(java.lang.StringBuffer codeInFile)
                                      throws IllegalActionException
Parse from the _parseIndex for the next single code block and return the code block name. This method puts the code block body (value) and the code block name (key) into the code block table. It calls the _parseHeader(StringBuffer) and _parseBody(StringBuffer) functions.

Parameters:
codeInFile - Code from the adaptor code template file.
Returns:
The name of the code block, or null if there is no more code blocks to be parsed.
Throws:
IllegalActionException - If an error occurs during parsing.
See Also:
_parseHeader(StringBuffer), _parseBody(StringBuffer)

_parseHeader

private CodeStream.Signature _parseHeader(java.lang.StringBuffer codeInFile)
                                   throws IllegalActionException
Parse the header of the code block. Usually code block header starts with the code block name followed by the list of parameters. Users can also overload the code block by giving different number of arguments, and/or specifying different types for the ports. appendCodeBlock would append the corresponding block by checking the number of given arguments. Parse from the _parseIndex for the next code block header and return the next code block name. This method parses for any parameter declarations and put the list of parameter(s) into the _declarations.

Parameters:
codeInFile - Code from the adaptor code template file.
Returns:
The name of the code block, or null if there is no more code blocks to be parsed.
Throws:
IllegalActionException - If the code block's close header pattern, _HEADEREND, is missing.
See Also:
_HEADEREND, _declarations

_parseParameterList

private static java.util.List _parseParameterList(java.lang.StringBuffer codeInFile,
                                                  int start,
                                                  int end)

_parseParameterList

private static java.util.List _parseParameterList(java.lang.StringBuffer codeInFile,
                                                  int start,
                                                  int end,
                                                  java.lang.String startSymbol,
                                                  java.lang.String endSymbol)
Return a list of parameter expression contains in the given string buffer. It parses comma-separated expressions and also understand nested parenthesis by matching open and close parenthesis pairs.

Parameters:
codeInFile - The given string buffer.
start - The given start index to start parsing.
end - The given end index to stop parsing.
Returns:
The list of parameter expressions.

_substituteParameters

private static java.lang.StringBuffer _substituteParameters(java.lang.StringBuffer codeBlock,
                                                            java.util.List parameters,
                                                            java.util.List arguments)
                                                     throws IllegalActionException
Substitute parameters. This method searches all occurences of each parameter expressions in the given code block content and replace each with the given arguments using straight-forward text substitution.

Parameters:
codeBlock - The given code block content.
parameters - The given list of parameters.
arguments - The given list of arguments.
Returns:
The code block content after parameter substitutions.
Throws:
IllegalActionException - Thrown if _checkParameterName(String) throws it.