EntitySootClass theClass, HashMap objectNameToCreatorName) {
//Entity classObject = (Entity) _findDeferredInstance(entity);
// This local is used to store the return from the getPort
// method, before it is stored in a type-specific local variable.
Local tempPortLocal = Jimple.v().newLocal("tempPort",
RefType.v(PtolemyUtilities.componentPortClass));
body.getLocals().add(tempPortLocal);
for (Iterator ports = entity.portList().iterator(); ports.hasNext();) {
Port port = (Port) ports.next();
// System.out.println("ModelTransformer: port: " + port);
String className = port.getClass().getName();
// FIXME: what about subclasses of TypedIOPort?
//String portName = port.getName(context);
String fieldName = getFieldNameForPort(port, context);
RefType portType = RefType.v(className);
Local portLocal = Jimple.v().newLocal("port", portType);
body.getLocals().add(portLocal);
// Deal with ParameterPorts specially, since they are
// created by the PortParameter. Just use the
// portParameter to get a reference to the ParameterPort.
if (port instanceof ParameterPort) {
updateCreatedSet(entity.getFullName() + "." + port.getName(),
port, port, objectNameToCreatorName);
PortParameter parameter = ((ParameterPort) port).getParameter();
Local parameterLocal = Jimple.v().newLocal("parameter",
RefType.v(PtolemyUtilities.portParameterClass));
body.getLocals().add(parameterLocal);
body.getUnits().add(
Jimple.v().newAssignStmt(
parameterLocal,
Jimple.v().newVirtualInvokeExpr(
contextLocal,
PtolemyUtilities.getAttributeMethod
.makeRef(),
StringConstant.v(parameter
.getName(context)))));
// If the class for the object already creates the
// port, then get a reference to the existing port.
// First assign to temp
body
.getUnits()
.add(
Jimple
.v()
.newAssignStmt(
portLocal,
Jimple
.v()
.newVirtualInvokeExpr(
parameterLocal,
PtolemyUtilities.portParameterGetPortMethod
.makeRef())));
} else if (objectNameToCreatorName.keySet().contains(
port.getFullName())) {
// System.out.println("already created!");
// If the class for the object already creates the
// port, then get a reference to the existing port.
// First assign to temp
body.getUnits().add(
Jimple.v().newAssignStmt(
tempPortLocal,
Jimple.v().newVirtualInvokeExpr(
entityLocal,
PtolemyUtilities.getPortMethod
.makeRef(),
StringConstant.v(port.getName()))));
// and then cast to portLocal
body.getUnits().add(
Jimple.v()
.newAssignStmt(
portLocal,
Jimple.v().newCastExpr(tempPortLocal,
portType)));
} else {
// System.out.println("Creating new!");
// If the class does not create the port
// then create a new port with the right name.
Local local = PtolemyUtilities.createNamedObjAndLocal(body,
className, entityLocal, port.getName());
// Record the name of the created port.
// NOTE: we assume that this is only a TypedIOPort, which
// contains no other objects!
// Port classPort =
// (Port)_findDeferredInstance(port);
// updateCreatedSet(entity.getFullName() + "."
// + port.getName(),
// classPort, classPort, objectNameToCreatorName);
String name = entity.getFullName() + "." + port.getName();
objectNameToCreatorName.put(name, name);
// Then assign to portLocal.
body.getUnits().add(Jimple.v().newAssignStmt(portLocal, local));
}
if (port instanceof TypedIOPort) {
TypedIOPort ioport = (TypedIOPort) port;
Local ioportLocal = Jimple.v().newLocal(
"typed_" + port.getName(), PtolemyUtilities.ioportType);
body.getLocals().add(ioportLocal);
Stmt castStmt = Jimple.v().newAssignStmt(
ioportLocal,
Jimple.v().newCastExpr(portLocal,
PtolemyUtilities.ioportType));
body.getUnits().add(castStmt);
if (ioport.isInput()) {
body.getUnits().add(
Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(
ioportLocal,
PtolemyUtilities.setInputMethod
.makeRef(),
IntConstant.v(1))));
}
if (ioport.isOutput()) {
body.getUnits().add(
Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(
ioportLocal,
PtolemyUtilities.setOutputMethod
.makeRef(),
IntConstant.v(1))));
}
if (ioport.isMultiport()) {
body.getUnits().add(
Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(
ioportLocal,
PtolemyUtilities.setMultiportMethod
.makeRef(),
IntConstant.v(1))));
}
// Set the port's type.
Local typeLocal = PtolemyUtilities.buildConstantTypeLocal(body,
castStmt, ioport.getType());
body.getUnits().add(
Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(
ioportLocal,