ptolemy.actor.ptalon
Class AbstractPtalonEvaluator.IfTree

java.lang.Object
  extended by ptolemy.actor.ptalon.NamedTree<AbstractPtalonEvaluator.IfTree>
      extended by ptolemy.actor.ptalon.AbstractPtalonEvaluator.IfTree
Enclosing class:
AbstractPtalonEvaluator

protected class AbstractPtalonEvaluator.IfTree
extends NamedTree<AbstractPtalonEvaluator.IfTree>

This is a representation of an if/else construct in Ptalon. The true branch and/or the false branch can point to a set of IfTrees. This class is used when the keyword "if" apears in the Ptalon source code. There are no dangling "if"s in Ptalon, so this class always knows when to use the true or false branch in the representation.


Field Summary
private  java.lang.Boolean _activeBranch
          This is true when the active branch for this if statement is true, false when it is false, and null when it is unknown.
private  java.util.Hashtable<java.lang.String,java.lang.Integer> _createdIteration
          The number of iterations (number of times the if/for block has been entered) for each symbol created.
private  boolean _currentBranch
          This is true if we are in the main scope or the true part of a true branch.
private  java.util.Hashtable<java.lang.String,java.lang.String> _falseNameMappings
          Each symbol gets mapped to its unique name in the Ptalon Actor.
private  java.util.Hashtable<java.lang.String,java.lang.Boolean> _falseSetStatus
          A symbol maps to false if it has been set to some value or false otherwise.
private  java.util.Hashtable<java.lang.String,java.lang.String> _falseSymbols
          The symbol table for this level of the if hierarchy.
private  boolean _inNewWhileIteration
          This is true if in a new iteration of a while block.
private  java.util.Hashtable<java.lang.String,java.lang.String> _trueNameMappings
          Each symbol gets mapped to its unique name in the Ptalon Actor.
private  java.util.Hashtable<java.lang.String,java.lang.Boolean> _trueSetStatus
          A symbol maps to true if it has been set to some value or false otherwise.
private  java.util.Hashtable<java.lang.String,java.lang.String> _trueSymbols
          The symbol table for this level of the if hierarchy.
 int entered
          The number of times the if/for tree has been entered.
 PtalonAST forBlock
          This is the AST for this for block, if this is a for block.
 java.lang.String initExpr
          This is the initially expression for the for statement, if this is a for statement.
 boolean isForStatement
          This is true if this if statement is actually used to represent a for statement.
 java.lang.String nextExpr
          This is the next expression for the for statement, if this is a for statement.
 PtalonPopulator populator
          This is the PtalonPopulator that accesses this for statement, if this is a for statement.
 java.lang.String satExpr
          This is the satisfies expression for the for statement, if this is a for statement.
 java.lang.String variable
          This is the variable for the for statement, if this is a for statement.
 
Fields inherited from class ptolemy.actor.ptalon.NamedTree
_children, _name, _parent
 
Constructor Summary
AbstractPtalonEvaluator.IfTree(AbstractPtalonEvaluator.IfTree parent, java.lang.String name)
          Create a new if tree.
 
Method Summary
 AbstractPtalonEvaluator.IfTree addChild(java.lang.String name)
          Create a new child tree to this tree with the specified name and return it.
 void addSymbol(java.lang.String symbol, java.lang.String type)
          Add a symbol to the scope of this if statement.
 void addSymbol(java.lang.String symbol, java.lang.String type, boolean status, java.lang.String uniqueName)
          Add a symbol to the scope of this if statement.
 void evaluateForScope()
          Evaluate this for block, assuming this is a for block.
 java.lang.Boolean getActiveBranch()
          Return the active branch, which may be null if it has not yet been set.
 java.util.List<AbstractPtalonEvaluator.IfTree> getAncestors()
          Return the ancestors of this tree, including this tree.
 boolean getCurrentBranch()
          Return true if we are in the main scope or the true part of a true branch.
 java.lang.String getDeepMappedName(java.lang.String symbol)
          Get the unique name for the symbol in the PtalonActor, looking deep into for loops for potential matches.
 java.lang.String getDeepType(java.lang.String symbol)
          Return the type associated with the given symbol, looking deep into for loops that might add symbols to this scope.
 int getEnteredIteration(java.lang.String symbol)
          Get the iteration (number of times this if/for block has been entered) in which this symbol is created.
 java.lang.String getMappedName(java.lang.String symbol)
          Get the unique name for the symbol in the PtalonActor.
 java.util.Set<java.lang.String> getSymbols()
          Return a set of strings representing all symbols in the scope of the if-block.
 java.lang.String getType(java.lang.String symbol)
          Return the type associated with the given symbol.
 boolean inDeepScope(java.lang.String symbol)
          Return true if the given symbol is in this scope, or deeply in this scope through some for loop.
 boolean inNewWhileIteration()
          Return true if in a new iteration of a while block.
 boolean isCreated(java.lang.String symbol)
          Return true if an entity was created in PtalonActor for the given symbol.
 boolean isFullyAssigned()
          Return true if all the symbols in this if block have been assigned a value.
 void mapName(java.lang.String symbol, java.lang.String uniqueName)
          Map a name of a symbol from a Ptalon program to a name in the PtalonActor which creates it.
 void setActiveBranch(boolean branch)
          Set the active branch to true or false.
 void setCurrentBranch(boolean branch)
          Set the current branch that's being walked.
 void setEnteredIteration(java.lang.String symbol, int iteration)
          Set the iteration (number of times this if/for block has been entered) in which this symbol is created.
 void setStatus(java.lang.String symbol, boolean status)
          Set the status of the symbol to true, if the symbol is ready, and false otherwise.
 java.lang.String toString()
          Enumerate the info from this scope.
 
Methods inherited from class ptolemy.actor.ptalon.NamedTree
getChild, getChildren, getName, getParent, getProperAncestors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

entered

public int entered
The number of times the if/for tree has been entered.


forBlock

public PtalonAST forBlock
This is the AST for this for block, if this is a for block.


initExpr

public java.lang.String initExpr
This is the initially expression for the for statement, if this is a for statement.


isForStatement

public boolean isForStatement
This is true if this if statement is actually used to represent a for statement.


nextExpr

public java.lang.String nextExpr
This is the next expression for the for statement, if this is a for statement.


populator

public PtalonPopulator populator
This is the PtalonPopulator that accesses this for statement, if this is a for statement.


satExpr

public java.lang.String satExpr
This is the satisfies expression for the for statement, if this is a for statement.


variable

public java.lang.String variable
This is the variable for the for statement, if this is a for statement.


_activeBranch

private java.lang.Boolean _activeBranch
This is true when the active branch for this if statement is true, false when it is false, and null when it is unknown.


_createdIteration

private java.util.Hashtable<java.lang.String,java.lang.Integer> _createdIteration
The number of iterations (number of times the if/for block has been entered) for each symbol created.


_currentBranch

private boolean _currentBranch
This is true if we are in the main scope or the true part of a true branch.


_falseNameMappings

private java.util.Hashtable<java.lang.String,java.lang.String> _falseNameMappings
Each symbol gets mapped to its unique name in the Ptalon Actor. This is for the false branch of this if tree.


_falseSetStatus

private java.util.Hashtable<java.lang.String,java.lang.Boolean> _falseSetStatus
A symbol maps to false if it has been set to some value or false otherwise. This is for the false branch of this if tree.


_falseSymbols

private java.util.Hashtable<java.lang.String,java.lang.String> _falseSymbols
The symbol table for this level of the if hierarchy. This is for the false branch of this if tree.


_inNewWhileIteration

private boolean _inNewWhileIteration
This is true if in a new iteration of a while block.


_trueNameMappings

private java.util.Hashtable<java.lang.String,java.lang.String> _trueNameMappings
Each symbol gets mapped to its unique name in the Ptalon Actor. This is for the true branch of this if tree.


_trueSetStatus

private java.util.Hashtable<java.lang.String,java.lang.Boolean> _trueSetStatus
A symbol maps to true if it has been set to some value or false otherwise. This is for the true branch of this if tree.


_trueSymbols

private java.util.Hashtable<java.lang.String,java.lang.String> _trueSymbols
The symbol table for this level of the if hierarchy. This is for the true branch of this if tree.

Constructor Detail

AbstractPtalonEvaluator.IfTree

public AbstractPtalonEvaluator.IfTree(AbstractPtalonEvaluator.IfTree parent,
                                      java.lang.String name)
Create a new if tree.

Parameters:
name - The name to give this if tree.
parent - The parent to this tree, which may be null if this is the root of a tree.
Method Detail

addChild

public AbstractPtalonEvaluator.IfTree addChild(java.lang.String name)
Create a new child tree to this tree with the specified name and return it. Subclasses should override this if it's not the case.

Specified by:
addChild in class NamedTree<AbstractPtalonEvaluator.IfTree>
Parameters:
name - The name of the child.
Returns:
The child IfTree.

addSymbol

public void addSymbol(java.lang.String symbol,
                      java.lang.String type)
Add a symbol to the scope of this if statement.

Parameters:
symbol - The symbol to add.
type - Its corresponding type.

addSymbol

public void addSymbol(java.lang.String symbol,
                      java.lang.String type,
                      boolean status,
                      java.lang.String uniqueName)
Add a symbol to the scope of this if statement.

Parameters:
symbol - The symbol to add.
type - Its corresponding type.
status - Whether the if statement has been loaded or not.
uniqueName - The unique name of this if statement.

evaluateForScope

public void evaluateForScope()
                      throws PtalonRuntimeException
Evaluate this for block, assuming this is a for block.

Throws:
PtalonRuntimeException - If there is any trouble evaluating this for block.

getActiveBranch

public java.lang.Boolean getActiveBranch()
Return the active branch, which may be null if it has not yet been set.

Returns:
The active branch
See Also:
setActiveBranch(boolean)

getAncestors

public java.util.List<AbstractPtalonEvaluator.IfTree> getAncestors()
Return the ancestors of this tree, including this tree.

Returns:
The ancestors of this tree, including this tree.

getCurrentBranch

public boolean getCurrentBranch()
Return true if we are in the main scope or the true part of a true branch.

Returns:
true If in main scope or true part of a true branch.
See Also:
setCurrentBranch(boolean)

getDeepMappedName

public java.lang.String getDeepMappedName(java.lang.String symbol)
                                   throws PtalonRuntimeException
Get the unique name for the symbol in the PtalonActor, looking deep into for loops for potential matches.

Parameters:
symbol - The symbol to test.
Returns:
The unique name.
Throws:
PtalonRuntimeException - If no such symbol exists.

getDeepType

public java.lang.String getDeepType(java.lang.String symbol)
                             throws PtalonScopeException
Return the type associated with the given symbol, looking deep into for loops that might add symbols to this scope.

Parameters:
symbol - The symbol under test.
Returns:
The type associated with the given symbol.
Throws:
PtalonScopeException - If the symbol is not in the scope of the if statement associated with this IfTree.

getEnteredIteration

public int getEnteredIteration(java.lang.String symbol)
Get the iteration (number of times this if/for block has been entered) in which this symbol is created.

Parameters:
symbol - The symbol created.
Returns:
The iteration number.
See Also:
setEnteredIteration(java.lang.String, int)

getMappedName

public java.lang.String getMappedName(java.lang.String symbol)
                               throws PtalonRuntimeException
Get the unique name for the symbol in the PtalonActor.

Parameters:
symbol - The symbol to test.
Returns:
The unique name.
Throws:
PtalonRuntimeException - If no such symbol exists.

getSymbols

public java.util.Set<java.lang.String> getSymbols()
Return a set of strings representing all symbols in the scope of the if-block.

Returns:
All symbols in the scope of the if-block.

getType

public java.lang.String getType(java.lang.String symbol)
                         throws PtalonScopeException
Return the type associated with the given symbol.

Parameters:
symbol - The symbol under test.
Returns:
The type associated with the given symbol.
Throws:
PtalonScopeException - If the symbol is not in the scope of the if statement associated with this IfTree.

inDeepScope

public boolean inDeepScope(java.lang.String symbol)
Return true if the given symbol is in this scope, or deeply in this scope through some for loop.

Parameters:
symbol - The symbol to test.
Returns:
true If symbol is in the right scope.

inNewWhileIteration

public boolean inNewWhileIteration()
Return true if in a new iteration of a while block.

Returns:
true If in a new iteration of a while block.

isCreated

public boolean isCreated(java.lang.String symbol)
                  throws PtalonRuntimeException
Return true if an entity was created in PtalonActor for the given symbol. This symbol is assumed to be in the current scope.

Parameters:
symbol - The symbol to test.
Returns:
true If an entity was created for this symbol.
Throws:
PtalonRuntimeException - If the symbol is not in the current scope.

isFullyAssigned

public boolean isFullyAssigned()
                        throws PtalonRuntimeException
Return true if all the symbols in this if block have been assigned a value. A symbol has been assigned a value if a corresponding entity for the symbol has been created in the PtalonActor, and in the case of parameters, that the user has provided a value for the parameter.

Returns:
true If all the symbols in this if block have been assigned a value.
Throws:
PtalonRuntimeException - If there is any problem accessing a parameter.

mapName

public void mapName(java.lang.String symbol,
                    java.lang.String uniqueName)
             throws PtalonRuntimeException
Map a name of a symbol from a Ptalon program to a name in the PtalonActor which creates it.

Parameters:
symbol - The name for the symbol in the Ptalon program.
uniqueName - The unique name for the symbol in the PtalonActor.
Throws:
PtalonRuntimeException - If the symbol does not exist.

setActiveBranch

public void setActiveBranch(boolean branch)
Set the active branch to true or false.

Parameters:
branch - The branch to set it to.
See Also:
getActiveBranch()

setCurrentBranch

public void setCurrentBranch(boolean branch)
Set the current branch that's being walked.

Parameters:
branch - True if the true branch is being walked.
See Also:
getCurrentBranch()

setEnteredIteration

public void setEnteredIteration(java.lang.String symbol,
                                int iteration)
Set the iteration (number of times this if/for block has been entered) in which this symbol is created.

Parameters:
symbol - The symbol created.
iteration - The iteration of the symbol.
See Also:
getEnteredIteration(java.lang.String)

setStatus

public void setStatus(java.lang.String symbol,
                      boolean status)
Set the status of the symbol to true, if the symbol is ready, and false otherwise.

Parameters:
symbol - The symbol.
status - The status.

toString

public java.lang.String toString()
Enumerate the info from this scope.

Overrides:
toString in class java.lang.Object