ptolemy.actor.ptalon
Class PtalonEvaluator

java.lang.Object
  extended by ptolemy.actor.ptalon.AbstractPtalonEvaluator
      extended by ptolemy.actor.ptalon.PtalonEvaluator
Direct Known Subclasses:
TransformationEvaluator

public class PtalonEvaluator
extends AbstractPtalonEvaluator

A code manager that manages the extra complexity of dealing with parsing Ptalon actors or values and setting them to parameters of PtalonActors (ones declared in a Ptalon file). FIXME: This implementation could be improved by investigating ways to better address partial evaluation. A lot of memory gets eaten up by IfTrees, and it would be better to keep only the minimum subset in order to free up memory.

Since:
Ptolemy II 6.1
Version:
$Id: PtalonEvaluator.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Adam Cataldo, Elaine Cheong
Accepted Rating:
Yellow (celaine)
Proposed Rating:
Yellow (celaine)

Nested Class Summary
private  class PtalonEvaluator.ActorTree
          This class is a tree whose structure mimics that of a nested actor declaration.
 
Nested classes/interfaces inherited from class ptolemy.actor.ptalon.AbstractPtalonEvaluator
AbstractPtalonEvaluator.IfTree, AbstractPtalonEvaluator.PtalonExpressionScope
 
Field Summary
private  PtalonEvaluator.ActorTree _currentActorTree
          This represents the current point in the scope of a nested actor declaration.
private  boolean _danglingPortsOkay
          If this is true, then dangling, or unconnected ports of actors contained in the PtalonActor should be left alone.
private  java.util.Map<java.lang.String,java.lang.Integer> _instanceNumbers
          This map gives the number for the next instance of the specified symbol.
private  java.util.List<PtalonEvaluator.ActorTree> _trees
          Each tree in this list represents a nested actor declaration, like Foo(a := Foo(a: = Bar(), b := Bar()), b := Bar())
 
Fields inherited from class ptolemy.actor.ptalon.AbstractPtalonEvaluator
_actor, _currentIfTree, _imports, _scope, _transparentRelations
 
Constructor Summary
PtalonEvaluator(PtalonActor actor)
          Create a new PtalonEvaluator.
 
Method Summary
private  java.lang.String _parameterToImport(java.lang.String expression)
          The reverse of _importToParameter
private  java.lang.String[] _parseActorExpression(java.lang.String expression)
          Break an expression like: a(x := <1/>, y := <2/>)(z := b(y := <2/>, z := <2/>)) into an array of expressions like: a x <1/> y <2/> z b(y : = <2/>, z := <2/>)
private  java.lang.String _uniqueSymbol(java.lang.String symbol)
          Return a unique symbol for the given symbol.
 void addActor(java.lang.String name)
          Add an actor to the PtalonActor.
 void addParameterAssign(java.lang.String parameterName, java.lang.String expression)
          Add an assignment of the specified parameter of this actor declaration to the specified actor declaration.
 void addPortAssign(java.lang.String portName, java.lang.String connectPoint)
          Add an assignment of the specified port of this actor declaration to the containing Ptalon actor connection point, which is either a port or a relation.
 void addPortAssign(java.lang.String portName, java.lang.String connectPointPrefix, java.lang.String connectPointExpression)
          Add an assignment of the specified port of this actor declaration to the containing Ptalon actor connection point, which is either a port or a relation.
 void addSymbol(java.lang.String name, java.lang.String type)
          Add a symbol with the given name and type to the symbol table at the current level of the if-tree hierarchy.
 void addUnknownLeftSide(java.lang.String prefix, java.lang.String expression)
          Add the unknown left side to this actor declaration.
 void enterActorDeclaration(java.lang.String name)
          Enter the named actor declaration.
 void exitActorDeclaration()
          Exit the current actor declaration.
 boolean isActorReady()
          Returns true if the current actor declaration is ready to be created.
 java.lang.String popActorDeclaration()
          Pop an actor off of the current tree and return the name.
 void pushActorDeclaration(java.lang.String actorName)
          Push an actor name onto the current tree, or create a new tree if entering a new nested actor declaration.
 void setActorParameter(java.lang.String paramName)
          Set the parameter name for the current actor declaration, if any, to the given parameter name.
 void setActorSymbol(java.lang.String symbol)
          Set the symbol in the PtalonCode which represents this AbstractPtalonEvaluator's actor.
 void setDanglingPortsOkay(boolean value)
          Set whether or not dangling ports are okay.
 void startAtTop()
          Prepare the compiler to start at the outermost scope of the Ptalon program during run time.
 
Methods inherited from class ptolemy.actor.ptalon.AbstractPtalonEvaluator
_getIndentPrefix, _getTimesEntered, _getType, _getTypeForScope, _inNewWhileIteration, _isPreservingTransformation, _processAttributes, _resetParameters, _setPreservingTransformation, addActorParameter, addActorParameter, addInPort, addOutPort, addParameter, addParameter, addPort, addRelation, addTransparentRelation, assignInternalParameters, enterForScope, enterIfScope, enterTransformation, evaluateBoolean, evaluateExpression, evaluateForScope, evaluateString, exitForScope, exitIfScope, exitTransformation, getMappedName, hasUnassignedParameters, inScope, isCreated, isForReady, isIfReady, isReady, negateObject, optionalObject, popForStatement, popIfStatement, preserveObject, pushForStatement, pushIfStatement, removeObject, setActiveBranch, setCurrentBranch, setNextExpression
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_currentActorTree

private PtalonEvaluator.ActorTree _currentActorTree
This represents the current point in the scope of a nested actor declaration. It is null when not inside an actor declaration.


_danglingPortsOkay

private boolean _danglingPortsOkay
If this is true, then dangling, or unconnected ports of actors contained in the PtalonActor should be left alone. This is false by default, which means that unconnected ports will be "brought to the outside" of the PtalonActor.


_instanceNumbers

private java.util.Map<java.lang.String,java.lang.Integer> _instanceNumbers
This map gives the number for the next instance of the specified symbol. As an example, if no instance of the parameter Foo has been created, and it has created, then _instanceNumbers.get("Foo") returns 0. If it is created again, then _instanceNumbers.get("Foo") returns 1.


_trees

private java.util.List<PtalonEvaluator.ActorTree> _trees
Each tree in this list represents a nested actor declaration, like Foo(a := Foo(a: = Bar(), b := Bar()), b := Bar())

Constructor Detail

PtalonEvaluator

public PtalonEvaluator(PtalonActor actor)
Create a new PtalonEvaluator.

Parameters:
actor - The ptalon actor for this manager.
Method Detail

addActor

public void addActor(java.lang.String name)
              throws PtalonRuntimeException
Add an actor to the PtalonActor. In the case of an actor specified by an import statement, the actor will be a PtalonActor. In the case of an actor specified by a parameter, the actor will be arbitrary.

Parameters:
name - The unique name of the actor declaration.
Throws:
PtalonRuntimeException - If there is any trouble loading the actor.

addParameterAssign

public void addParameterAssign(java.lang.String parameterName,
                               java.lang.String expression)
                        throws PtalonScopeException
Add an assignment of the specified parameter of this actor declaration to the specified actor declaration. This is not allowed in nested actor declarations, only top-level declarations. For instance: Foo(port := containing) port is okay, but not Bar(a := Foo(port := containing))

Parameters:
parameterName - The name of the parameter.
expression - The expression to be assigned to the parameter.
Throws:
PtalonScopeException - If this is not a top-level actor declaration with respect to the assignment, or if connectPoint is not a port or relation.

addPortAssign

public void addPortAssign(java.lang.String portName,
                          java.lang.String connectPoint)
                   throws PtalonScopeException
Add an assignment of the specified port of this actor declaration to the containing Ptalon actor connection point, which is either a port or a relation. This is not allowed in nested actor declarations, only top-level declarations. For instance, Foo(port := containing) port is okay, but not Bar(a := Foo(port := containing))

Parameters:
portName - The name of the port in this
connectPoint - The name of the container's port or relation.
Throws:
PtalonScopeException - If this is not a top-level actor declaration with respect to the assignment, or if connectPoint is not a port or relation.

addPortAssign

public void addPortAssign(java.lang.String portName,
                          java.lang.String connectPointPrefix,
                          java.lang.String connectPointExpression)
                   throws PtalonScopeException
Add an assignment of the specified port of this actor declaration to the containing Ptalon actor connection point, which is either a port or a relation. This is not allowed in nested actor declarations, only top-level declarations. For instance, Foo(port := containing) port is okay, but not Bar(a := Foo(port := containing))

Parameters:
portName - The name of the port in this
connectPointPrefix - The prefix of the name of the container's port or relation.
connectPointExpression - The variable suffix of the name of the container's port or relation.
Throws:
PtalonScopeException - If this is not a top-level actor declaration with respect to the assignment, or if connectPoint is not a port or relation.

addSymbol

public void addSymbol(java.lang.String name,
                      java.lang.String type)
               throws PtalonScopeException
Add a symbol with the given name and type to the symbol table at the current level of the if-tree hierarchy.

Overrides:
addSymbol in class AbstractPtalonEvaluator
Parameters:
name - The symbol name.
type - The symbol type.
Throws:
PtalonScopeException - If a symbol with this name has already been added somewhere in the current scope.

addUnknownLeftSide

public void addUnknownLeftSide(java.lang.String prefix,
                               java.lang.String expression)
Add the unknown left side to this actor declaration.

Parameters:
prefix - The prefix for the unknown left side.
expression - The suffix expression for the unknown left side.

enterActorDeclaration

public void enterActorDeclaration(java.lang.String name)
                           throws PtalonRuntimeException
Enter the named actor declaration.

Parameters:
name - The name of the actor declaration.
Throws:
PtalonRuntimeException - If such an actor declaration does not exist.

exitActorDeclaration

public void exitActorDeclaration()
                          throws PtalonRuntimeException
Exit the current actor declaration.

Throws:
PtalonRuntimeException - If already at the top-level if scope.

isActorReady

public boolean isActorReady()
                     throws PtalonRuntimeException
Returns true if the current actor declaration is ready to be created.

Returns:
true If the current actor declaration is ready to be created.
Throws:
PtalonRuntimeException - If thrown trying to access a parameter, or if there is no actor declaration to create.

popActorDeclaration

public java.lang.String popActorDeclaration()
                                     throws PtalonScopeException
Pop an actor off of the current tree and return the name.

Returns:
The unique name of the actor declaration being popped from.
Throws:
PtalonScopeException - If not inside an actor declaration.

pushActorDeclaration

public void pushActorDeclaration(java.lang.String actorName)
                          throws PtalonScopeException
Push an actor name onto the current tree, or create a new tree if entering a new nested actor declaration.

Parameters:
actorName - The name of the actor.
Throws:
PtalonScopeException - If actorName is not a valid parameter or import in the current scope.

setActorParameter

public void setActorParameter(java.lang.String paramName)
                       throws PtalonScopeException
Set the parameter name for the current actor declaration, if any, to the given parameter name.

Parameters:
paramName - The name of the parameter.
Throws:
PtalonScopeException - If not inside the scope of an actor declaration.

setActorSymbol

public void setActorSymbol(java.lang.String symbol)
                    throws PtalonScopeException
Set the symbol in the PtalonCode which represents this AbstractPtalonEvaluator's actor.

Overrides:
setActorSymbol in class AbstractPtalonEvaluator
Parameters:
symbol - The name of this actor in the Ptalon file.
Throws:
PtalonScopeException - If the symbol has been added already, or if there is some problem accessing its associated file.

setDanglingPortsOkay

public void setDanglingPortsOkay(boolean value)
Set whether or not dangling ports are okay. If this input is false, then dangling ports will be connected to the outside of this PtalonActor, the default behavior. Setting this to true means that this is not desired.

Parameters:
value - true if dangling ports should be left alone.

startAtTop

public void startAtTop()
Prepare the compiler to start at the outermost scope of the Ptalon program during run time.

Overrides:
startAtTop in class AbstractPtalonEvaluator

_parameterToImport

private java.lang.String _parameterToImport(java.lang.String expression)
The reverse of _importToParameter

Parameters:
expression - The expression to convert.
Returns:
The converted expression.

_parseActorExpression

private java.lang.String[] _parseActorExpression(java.lang.String expression)
Break an expression like:

a(x := <1/>, y := <2/>)(z := b(y := <2/>, z := <2/>))

into an array of expressions like:

a

x

<1/>

y

<2/>

z

b(y : = <2/>, z := <2/>)

Parameters:
expression - The expression to split.
Returns:
The array of expression components.

_uniqueSymbol

private java.lang.String _uniqueSymbol(java.lang.String symbol)
                                throws PtalonScopeException
Return a unique symbol for the given symbol. The symbol will always end with a whole number. For instance _uniqueSymbol("Foo") may return "Foo0", "Foo1", or "Foo2". The input symbol is assumed to refer to a previously declared parameter or import statement.

Parameters:
symbol - The symbol from which to derive the unique symbol.
Returns:
A unique name.
Throws:
PtalonScopeException - If the symbol does not refer to a parameter or import valid in the current scope.