ptolemy.codegen.kernel
Class CodeStream.CodeBlockTable

java.lang.Object
  extended by ptolemy.codegen.kernel.CodeStream.CodeBlockTable
Enclosing class:
CodeStream

private class CodeStream.CodeBlockTable
extends java.lang.Object

The code block table class. A code block table contains code objects, which consists of the file path of the code block, the code block content, and the parameter list. The table is represented using a LinkedList of scopes, where the first element is scope for the left child class and each latter element is parent scope of the prior.


Field Summary
private  java.util.LinkedList<java.util.LinkedHashMap> _codeTableList
          LinkedList of LinkedHashMap of code blocks.
 
Constructor Summary
CodeStream.CodeBlockTable()
          Constructor for a code block table.
 
Method Summary
private  java.lang.StringBuffer _getCode(CodeStream.Signature signature, java.util.List arguments, java.util.List scopeList)
          Return the code block content of the given signature and substitute parameters with the given list of arguments.
private  java.lang.String _getHeader(CodeStream.Signature signature, java.util.List scopeList)
           
private  java.util.List _getParameters(CodeStream.Signature signature, java.util.List scopeList)
          Get the parameters for the code block with the given signature.
private  int _indexOfMacro(java.lang.StringBuffer codeBlock, java.lang.String macro, int start, boolean allowDot)
           
private  java.lang.StringBuffer _substituteSuperAndThis(CodeStream.Signature signature, java.util.List scopeList, java.lang.Object[] codeObject, java.lang.StringBuffer codeBlock)
           
 void addScope()
          Add a new scope to the code block table.
 java.lang.StringBuffer getCode(CodeStream.Signature signature, java.util.List arguments)
          Return the code block content of the given signature and substitute parameters with the given list of arguments.
 java.util.List getParameters(CodeStream.Signature signature)
          Get the list of parameters for the code block with the given signature.
 java.lang.StringBuffer getTemplateCode(CodeStream.Signature signature)
          Return the code block content of the given signature without substituting parameters.
private  java.util.Iterator keys()
          Return all contained signature keys.
private  java.util.Set keySet()
          Return all the keys contained in this code block table.
 void putCode(CodeStream.Signature signature, java.lang.String filePath, java.lang.StringBuffer code)
          Put the given file path and code content into the current scope using the given signature as the key.
 void putParameters(CodeStream.Signature signature, java.util.List parameters)
          Put the given list parameters into the current scope using the given signature as the key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_codeTableList

private java.util.LinkedList<java.util.LinkedHashMap> _codeTableList
LinkedList of LinkedHashMap of code blocks. Each index of the LinkedList represents a separate adaptor code template file.

Constructor Detail

CodeStream.CodeBlockTable

public CodeStream.CodeBlockTable()
Constructor for a code block table.

Method Detail

addScope

public void addScope()
Add a new scope to the code block table. This assumes parent scope is being added always add to the end of the list.


getCode

public java.lang.StringBuffer getCode(CodeStream.Signature signature,
                                      java.util.List arguments)
                               throws IllegalActionException
Return the code block content of the given signature and substitute parameters with the given list of arguments. This searches from the all scopes from the code block table.

Parameters:
signature - The given code block signature.
arguments - The given list of arguments.
Returns:
The code block content.
Throws:
IllegalActionException - Thrown if getCode(Signature, List, List) throws it.

getTemplateCode

public java.lang.StringBuffer getTemplateCode(CodeStream.Signature signature)
                                       throws IllegalActionException
Return the code block content of the given signature without substituting parameters. This searches from the all scopes from the code block table.

Parameters:
signature - The given code block signature.
Returns:
The code block content.
Throws:
IllegalActionException - Thrown if getCode(Signature, List, List) throws it.

getParameters

public java.util.List getParameters(CodeStream.Signature signature)
Get the list of parameters for the code block with the given signature. This searches the code block from the entire list of scopes.

Parameters:
signature - The given code block signature.
Returns:
The list of parameters strings.

putCode

public void putCode(CodeStream.Signature signature,
                    java.lang.String filePath,
                    java.lang.StringBuffer code)
Put the given file path and code content into the current scope using the given signature as the key. It assumes the given signature already exists in the current scope.

Parameters:
signature - The given signature.
filePath - The given file path.
code - The given code content.

putParameters

public void putParameters(CodeStream.Signature signature,
                          java.util.List parameters)
                   throws IllegalActionException
Put the given list parameters into the current scope using the given signature as the key.

Parameters:
signature - The given signature.
parameters - The given list of parameters.
Throws:
IllegalActionException - Thrown if the given signature already exists in the current scope.

_getCode

private java.lang.StringBuffer _getCode(CodeStream.Signature signature,
                                        java.util.List arguments,
                                        java.util.List scopeList)
                                 throws IllegalActionException
Return the code block content of the given signature and substitute parameters with the given list of arguments. This searches from the specified list of scopes.

Parameters:
signature - The given signature.
arguments - The given list of arguments.
scopeList - The given list of scopes.
Returns:
The code block content of the given signature.
Throws:
IllegalActionException - Thrown if the code block for a super call cannot be found, or if substituteParameters( StringBuffer, List, List) throws it.

_getHeader

private java.lang.String _getHeader(CodeStream.Signature signature,
                                    java.util.List scopeList)
                             throws IllegalActionException
Throws:
IllegalActionException

_substituteSuperAndThis

private java.lang.StringBuffer _substituteSuperAndThis(CodeStream.Signature signature,
                                                       java.util.List scopeList,
                                                       java.lang.Object[] codeObject,
                                                       java.lang.StringBuffer codeBlock)
                                                throws IllegalActionException
Throws:
IllegalActionException

_indexOfMacro

private int _indexOfMacro(java.lang.StringBuffer codeBlock,
                          java.lang.String macro,
                          int start,
                          boolean allowDot)

_getParameters

private java.util.List _getParameters(CodeStream.Signature signature,
                                      java.util.List scopeList)
Get the parameters for the code block with the given signature. It search the code block from the given list of scopes.

Parameters:
signature - The given signature.
scopeList - The given list of scopes.
Returns:
The list of parameter strings.

keySet

private java.util.Set keySet()
Return all the keys contained in this code block table.

Returns:
The set of keys contained in this code block table.

keys

private java.util.Iterator keys()
Return all contained signature keys. This method is used for testing purposes.

Returns:
A Iterator of all contained signature keys.