createAttributeComputationFunctions(entity, entity,
entityInstanceClass, _constAnalysis);
{
// create a new body for the initialization method.
SootMethod initMethod = entityInstanceClass.getInitMethod();
JimpleBody body = Jimple.v().newBody(initMethod);
initMethod.setActiveBody(body);
body.insertIdentityStmts();
Chain units = body.getUnits();
Local thisLocal = body.getThisLocal();
// Create a new class for each actor in the model.
_createActorsIn(entity, tempCreatedMap, "modelTransformer",
_constAnalysis, options);
// Create code in the model class to instantiate the ports
// and parameters of the model.
createAttributes(body, entity, thisLocal, entity, thisLocal,
entityInstanceClass, tempCreatedMap);
_ports(body, thisLocal, entity, thisLocal, entity,
entityInstanceClass, tempCreatedMap, true);
// Excess initialization, but necessary for -actor???
Stmt insertPoint = Jimple.v().newNopStmt();
body.getUnits().add(insertPoint);
// InitializeAttributes of the ports and parameters.
initializeAttributesBefore(body, insertPoint, entity, thisLocal,
entity, thisLocal, entityInstanceClass);
// Create code in the model class to instantiate all
// actors and relations, and connect the relations
// to the ports.
_entities(body, thisLocal, entity, thisLocal, entity,
entityInstanceClass, tempCreatedMap, options);
_relations(body, thisLocal, entity, entityInstanceClass);
_links(body, entity);
_linksOnPortsContainedByContainedEntities(body, entity);
// return void
units.add(Jimple.v().newReturnVoidStmt());
}
implementExecutableInterface(entityInstanceClass);
// Reinitialize the hierarchy, since we've added classes.
Scene.v().setActiveHierarchy(new Hierarchy());
Scene.v().setFastHierarchy(new FastHierarchy());
{
Set locallyModifiedAttributeSet = _constAnalysis
.getVariablesWithChangeContext(entity);
// Filter out any attribute that is independent (and might
// be modified).
for (Iterator i = locallyModifiedAttributeSet.iterator(); i
.hasNext();) {
if (_constAnalysis.isIndependent((Variable) i.next())) {
i.remove();
}
}
// Sort according to dependencies.
List locallyModifiedAttributeList;
try {
DirectedGraph graph = _constAnalysis.getDependencyGraph();
locallyModifiedAttributeList = Arrays.asList(Graph
.weightArray(graph.topologicalSort(graph
.nodes(locallyModifiedAttributeSet))));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
System.out.println("locallyModifiedAttributeList of " + entity
+ " = " + locallyModifiedAttributeList);
// Add code to the beginning of the prefire method that
// computes the attribute values of anything that is not a
// constant.
SootMethod method = entityInstanceClass.getMethodByName("prefire");
System.out.println("method = " + method);
JimpleBody body = (JimpleBody) method.getActiveBody();
Stmt insertPoint = body.getFirstNonIdentityStmt();
Local containerLocal = Jimple.v().newLocal("entity",
PtolemyUtilities.componentEntityType);
body.getLocals().add(containerLocal);
// Invoke the method to compute each attribute, in order.
for (Iterator attributes = locallyModifiedAttributeList.iterator(); attributes
.hasNext();) {
Attribute attribute = (Attribute) attributes.next();
Entity attributeContainer = FieldsForEntitiesTransformer
.getEntityContainerOfObject(attribute);
SootClass containerClass = (SootClass) _objectToClassMap
.get(attributeContainer);
SootMethod computeMethod = containerClass
.getMethodByName(getAttributeComputationFunctionName(
attribute, attributeContainer));
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
containerLocal,
Jimple.v().newVirtualInvokeExpr(
body.getThisLocal(),
PtolemyUtilities.getEntityMethod
.makeRef(),
StringConstant.v(attributeContainer
.getName(entity)))),
insertPoint);
// and then cast
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
containerLocal,
Jimple.v().newCastExpr(containerLocal,
RefType.v(containerClass))),
insertPoint);
body.getUnits().insertBefore(
Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(containerLocal,
computeMethod.makeRef())), insertPoint);
}
// ModelTransformer.computeAttributesBefore(body, insertPoint,
// entity, body.getThisLocal(),
// entity, body.getThisLocal(),