Package ptolemy.actor.ptalon
Class AbstractPtalonEvaluator.IfTree
- java.lang.Object
-
- ptolemy.actor.ptalon.NamedTree<AbstractPtalonEvaluator.IfTree>
-
- 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" appears 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
Fields Modifier and Type Field Description 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.
-
Constructor Summary
Constructors Constructor Description IfTree(AbstractPtalonEvaluator.IfTree parent, java.lang.String name)
Create a new if tree.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
-
-
-
-
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.
-
-
Constructor Detail
-
IfTree
public 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 classNamedTree<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 classjava.lang.Object
-
-