ptolemy.copernicus.java
Class ModelTransformer

java.lang.Object
  extended by soot.Transformer
      extended by soot.SceneTransformer
          extended by ptolemy.copernicus.java.ModelTransformer
All Implemented Interfaces:
soot.HasPhaseOptions

public class ModelTransformer
extends soot.SceneTransformer
implements soot.HasPhaseOptions

A transformer that creates a class to represent the model specified in the constructor. This transformer creates instance classes for each actor in the model, and generates code for composite actors that instantiates singleton instances of those classes. Additionally code is generated in composite actor classes to create links and relations between actors.

The class generates code for composite actors itself. For atomic actors, it defers to various implementations of the AtomicActorCreator class. This allows customized code to be generated for various atomic actors. By default, this class defers to a GenericAtomicActorCreator. That creator simply copies the existing actor specification code and specializes it.

Since:
Ptolemy II 2.0
Version:
$Id: ModelTransformer.java,v 1.156 2008/01/24 02:07:31 cxh Exp $
Author:
Stephen Neuendorffer, Christopher Hylands
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Method Summary
static NamedObj _findDeferredInstance(NamedObj object)
          Return an instance that represents the class that the given object defers to.
static boolean _isIgnorableAttribute(Attribute attribute)
           
static java.util.List actorClassList()
          Return the list of classes that correspond to actors.
static void addActorForClass(soot.SootClass theClass, Entity entity)
          Associate the given class, which has been created, with the given attribute.
static void addAttributeForClass(soot.SootClass theClass, Attribute attribute)
          Associate the given class, which has been created, with the given attribute.
static void addFieldForEntity(soot.SootField field, Entity entity)
          Assert that the given field always points to the given entity.
static void addFieldForObject(soot.SootField field, NamedObj object)
          Assert that the given field always points to the given object.
static java.util.List attributeClassList()
          Return the list of classes that correspond to attributes.
static void computeAttributesBefore(soot.jimple.JimpleBody body, soot.jimple.Stmt insertPoint, NamedObj context, soot.Local contextLocal, NamedObj namedObj, soot.Local namedObjLocal, soot.SootClass theClass, java.util.List attributeList)
          Generate code in the given body of the given class before the given statement to compute the values of the given list of attributes.
static void createAttributeComputationFunctions(NamedObj context, NamedObj namedObj, soot.SootClass theClass, ConstVariableModelAnalysis constAnalysis)
          Create a method in the given class for each variables or settable attributes in the given namedObj that will compute the value of the variables and settable attributes and set the token for the associated parameter.
static void createAttributes(soot.jimple.JimpleBody body, NamedObj context, soot.Local contextLocal, NamedObj namedObj, soot.Local namedObjLocal, soot.SootClass theClass, java.util.HashMap objectNameToCreatorName)
          Generate code in the given body of the given class to create attributes contained by the given named object.
static void createPorts(soot.jimple.JimpleBody body, soot.Local contextLocal, Entity context, soot.Local entityLocal, Entity entity, EntitySootClass theClass, java.util.HashMap objectNameToCreatorName)
          Generate code in the given body of the given class to create ports contained by the given entity.
static Entity getActorForClass(soot.SootClass theClass)
          Return the entity for the given class if the given class is a class being generated, or null if not.
static java.lang.String getAttributeComputationFunctionName(Attribute attribute, NamedObj context)
          Return the name of the method that is created to compute the current value of a variable.
static Attribute getAttributeForClass(soot.SootClass theClass)
           
static soot.SootClass getClassForActor(Entity entity)
          Return the entity for the given class if the given class is a class being generated, or null if not.
static soot.SootClass getClassForObject(NamedObj object)
          Return the entity for the given class if the given class is a class being generated, or null if not.
static java.lang.String getContainerFieldName()
          Return the name of the field that references the container of a generated class.
 java.lang.String getDeclaredOptions()
           
 java.lang.String getDefaultOptions()
           
static Entity getEntityForField(soot.SootField field)
          Given an entity that we are generating code for, return a reference to the instance field created for that entity.
static java.lang.String getFieldNameForAttribute(Attribute attribute, NamedObj context)
          Return the name of the field that is created for the given entity.
static java.lang.String getFieldNameForEntity(Entity entity, NamedObj context)
          Return the name of the field that is created for the given entity.
static java.lang.String getFieldNameForPort(Port port, NamedObj context)
          Return the name of the field that is created for the given entity.
static java.lang.String getFieldNameForRelation(Relation relation, NamedObj context)
          Return the name of the field that is created for the given entity.
static java.lang.String getInstanceClassName(NamedObj object, java.util.Map options)
          Return the name of the class that is generated for the given named object.
static soot.SootClass getModelClass()
          Return the model class created during the most recent execution of this transformer.
static java.lang.String getModelClassName(CompositeActor model, java.util.Map options)
          Return the name of the class that will be created for the given model.
static NamedObj getObjectForClass(soot.SootClass theClass)
          Return the object that the given class was generated for.
 java.lang.String getPhaseName()
           
static void implementExecutableInterface(soot.SootClass theClass)
          Transform the given class so that it properly implements the ptolemy Executable interface.
static void initializeAttributesBefore(soot.jimple.JimpleBody body, soot.jimple.Stmt insertPoint, NamedObj context, soot.Local contextLocal, NamedObj namedObj, soot.Local namedObjLocal, soot.SootClass theClass)
          Generate code in the given body of the given class before the given statement to set the values of variables and settable attributes contained by the given named object.
static void inlineLocalCalls(soot.SootClass theClass)
          Inline invocation sites from methods in the given class to another method in the given class that are problematic.
protected  void internalTransform(java.lang.String phaseName, java.util.Map options)
           
static boolean isActorClass(soot.SootClass theClass)
          Return true if the given class was generated for an actor in the model
static void updateCreatedSet(java.lang.String prefix, NamedObj context, NamedObj object, java.util.HashMap objectNameToCreatorName)
          Add the full names of all named objects contained in the given object to the given set, assuming that the object is contained within the given context.
static ModelTransformer v(CompositeActor model)
          Return an instance of this transformer that will operate on the given model.
 
Methods inherited from class soot.SceneTransformer
transform, transform, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

v

public static ModelTransformer v(CompositeActor model)
Return an instance of this transformer that will operate on the given model. The model is assumed to already have been properly initialized so that resolved types and other static properties of the model can be inspected.


computeAttributesBefore

public static void computeAttributesBefore(soot.jimple.JimpleBody body,
                                           soot.jimple.Stmt insertPoint,
                                           NamedObj context,
                                           soot.Local contextLocal,
                                           NamedObj namedObj,
                                           soot.Local namedObjLocal,
                                           soot.SootClass theClass,
                                           java.util.List attributeList)
Generate code in the given body of the given class before the given statement to compute the values of the given list of attributes. The value of the variable will be computed using generated code, and then set into the variable. The given class is assumed to be associated with the given context.

Parameters:
body - The body to generate code in.
insertPoint - A statement in the given body.
context - The named object corresponding to the class in which code is being generated.
contextLocal - A local in the given body that points to an instance of the given class.
namedObj - The named object that contains attributes.
namedObjLocal - A local in the given body. Attributes will be created using this local as the container.
theClass - The soot class being modified.
attributeList - The list of attributes.

createAttributes

public static void createAttributes(soot.jimple.JimpleBody body,
                                    NamedObj context,
                                    soot.Local contextLocal,
                                    NamedObj namedObj,
                                    soot.Local namedObjLocal,
                                    soot.SootClass theClass,
                                    java.util.HashMap objectNameToCreatorName)
Generate code in the given body of the given class to create attributes contained by the given named object. The given class is assumed to be associated with the given context. Attributes whose full names are already keys in objectNameToCreatorName are not created. The given objectNameToCreatorName map is updated with the full names of all the created attributes.

Parameters:
body - The body to generate code in.
context - The named object corresponding to the class in which code is being generated.
contextLocal - A local in the given body that points to an instance of the given class.
namedObj - The named object that contains attributes.
namedObjLocal - A local in the given body. Attributes will be created using this local as the container.
theClass - The soot class being modified.
objectNameToCreatorName - A map from full names of objects to the full name of the object that created that object.

createPorts

public static void createPorts(soot.jimple.JimpleBody body,
                               soot.Local contextLocal,
                               Entity context,
                               soot.Local entityLocal,
                               Entity entity,
                               EntitySootClass theClass,
                               java.util.HashMap objectNameToCreatorName)
Generate code in the given body of the given class to create ports contained by the given entity. The given class is assumed to be associated with the given context. Ports whose full names are already keys in objectNameToCreatorName are not created. The given objectNameToCreatorName map is updated with the full names of all the created ports.

Parameters:
body - The body to generate code in.
context - The named object corresponding to the class in which code is being generated.
contextLocal - A local in the given body that points to an instance of the given class.
entity - The entity that contains ports.
entityLocal - A local in the given body. Ports will be created using this local as the container.
theClass - The soot class being modified.
objectNameToCreatorName - A map from full names of objects to the full name of the object that created that object.

createAttributeComputationFunctions

public static void createAttributeComputationFunctions(NamedObj context,
                                                       NamedObj namedObj,
                                                       soot.SootClass theClass,
                                                       ConstVariableModelAnalysis constAnalysis)
Create a method in the given class for each variables or settable attributes in the given namedObj that will compute the value of the variables and settable attributes and set the token for the associated parameter. The given class is assumed to be associated with the given context.

Parameters:
context - The named object corresponding to the class in which code is being generated.
namedObj - The named object that contains attributes.
theClass - The soot class being modified.
constAnalysis - Analysis that is used to determine parameter dependencies.

initializeAttributesBefore

public static void initializeAttributesBefore(soot.jimple.JimpleBody body,
                                              soot.jimple.Stmt insertPoint,
                                              NamedObj context,
                                              soot.Local contextLocal,
                                              NamedObj namedObj,
                                              soot.Local namedObjLocal,
                                              soot.SootClass theClass)
Generate code in the given body of the given class before the given statement to set the values of variables and settable attributes contained by the given named object. The given class is assumed to be associated with the given context.

Parameters:
body - The body to generate code in.
insertPoint - A statement in the given body.
context - The named object corresponding to the class in which code is being generated.
contextLocal - A local in the given body that points to an instance of the given class.
namedObj - The named object that contains attributes.
namedObjLocal - A local in the given body. Attributes will be created using this local as the container.
theClass - The soot class being modified.

getPhaseName

public java.lang.String getPhaseName()
Specified by:
getPhaseName in interface soot.HasPhaseOptions

getDefaultOptions

public java.lang.String getDefaultOptions()
Specified by:
getDefaultOptions in interface soot.HasPhaseOptions

getDeclaredOptions

public java.lang.String getDeclaredOptions()
Specified by:
getDeclaredOptions in interface soot.HasPhaseOptions

getAttributeComputationFunctionName

public static java.lang.String getAttributeComputationFunctionName(Attribute attribute,
                                                                   NamedObj context)
Return the name of the method that is created to compute the current value of a variable.


getFieldNameForAttribute

public static java.lang.String getFieldNameForAttribute(Attribute attribute,
                                                        NamedObj context)
Return the name of the field that is created for the given entity.


getFieldNameForEntity

public static java.lang.String getFieldNameForEntity(Entity entity,
                                                     NamedObj context)
Return the name of the field that is created for the given entity.


getEntityForField

public static Entity getEntityForField(soot.SootField field)
Given an entity that we are generating code for, return a reference to the instance field created for that entity.

Throws:
java.lang.RuntimeException - If no field was created for the given entity.

addFieldForEntity

public static void addFieldForEntity(soot.SootField field,
                                     Entity entity)
Assert that the given field always points to the given entity.


addFieldForObject

public static void addFieldForObject(soot.SootField field,
                                     NamedObj object)
Assert that the given field always points to the given object.


getFieldNameForPort

public static java.lang.String getFieldNameForPort(Port port,
                                                   NamedObj context)
Return the name of the field that is created for the given entity.


getFieldNameForRelation

public static java.lang.String getFieldNameForRelation(Relation relation,
                                                       NamedObj context)
Return the name of the field that is created for the given entity.


getActorForClass

public static Entity getActorForClass(soot.SootClass theClass)
Return the entity for the given class if the given class is a class being generated, or null if not.


getClassForActor

public static soot.SootClass getClassForActor(Entity entity)
Return the entity for the given class if the given class is a class being generated, or null if not.


getClassForObject

public static soot.SootClass getClassForObject(NamedObj object)
Return the entity for the given class if the given class is a class being generated, or null if not.


isActorClass

public static boolean isActorClass(soot.SootClass theClass)
Return true if the given class was generated for an actor in the model


addAttributeForClass

public static void addAttributeForClass(soot.SootClass theClass,
                                        Attribute attribute)
Associate the given class, which has been created, with the given attribute. This allows references to the given class to be resolved as references to the given attribute.


addActorForClass

public static void addActorForClass(soot.SootClass theClass,
                                    Entity entity)
Associate the given class, which has been created, with the given attribute. This allows references to the given class to be resolved as references to the given attribute.


actorClassList

public static java.util.List actorClassList()
Return the list of classes that correspond to actors.


attributeClassList

public static java.util.List attributeClassList()
Return the list of classes that correspond to attributes.


getObjectForClass

public static NamedObj getObjectForClass(soot.SootClass theClass)
Return the object that the given class was generated for.


getAttributeForClass

public static Attribute getAttributeForClass(soot.SootClass theClass)
Throws:
java.lang.RuntimeException - If no field was created for the given attribute.

getInstanceClassName

public static java.lang.String getInstanceClassName(NamedObj object,
                                                    java.util.Map options)
Return the name of the class that is generated for the given named object. This name is guaranteed to be unique among the classes being generated.


getModelClass

public static soot.SootClass getModelClass()
Return the model class created during the most recent execution of this transformer.


getModelClassName

public static java.lang.String getModelClassName(CompositeActor model,
                                                 java.util.Map options)
Return the name of the class that will be created for the given model.


getContainerFieldName

public static java.lang.String getContainerFieldName()
Return the name of the field that references the container of a generated class.


implementExecutableInterface

public static void implementExecutableInterface(soot.SootClass theClass)
Transform the given class so that it properly implements the ptolemy Executable interface. If any of those methods not implemented directly by the given class, then they are created and given minimal bodies. The generated prefire() and postfire() methods return true.

Parameters:
theClass - The class to transform.

inlineLocalCalls

public static void inlineLocalCalls(soot.SootClass theClass)
Inline invocation sites from methods in the given class to another method in the given class that are problematic. This primarily includes any method that takes or returns a NamedObj.

Parameters:
theClass - The class to transform.

updateCreatedSet

public static void updateCreatedSet(java.lang.String prefix,
                                    NamedObj context,
                                    NamedObj object,
                                    java.util.HashMap objectNameToCreatorName)
Add the full names of all named objects contained in the given object to the given set, assuming that the object is contained within the given context. Additionally, record the name of the object that created the given object in the given map.

Parameters:
prefix - The full name of the context in the model.
context - The context.
object - The object being recorded.
objectNameToCreatorName - A map from full names of objects to the full name of the object that created that object.

internalTransform

protected void internalTransform(java.lang.String phaseName,
                                 java.util.Map options)
Specified by:
internalTransform in class soot.SceneTransformer

_findDeferredInstance

public static NamedObj _findDeferredInstance(NamedObj object)
Return an instance that represents the class that the given object defers to.


_isIgnorableAttribute

public static boolean _isIgnorableAttribute(Attribute attribute)