Local indexArrayLocal = Jimple.v().newLocal("indexArray",
ArrayType.v(IntType.v(), 1));
body.getLocals().add(indexArrayLocal);
// The first argument is always the channel.
Value channelValue = expr.getArg(0);
// We have to repeat for all of the remote types.
Set typeSet = _getConnectedTypeListInside(port);
for (Iterator types = typeSet.iterator(); types.hasNext();) {
ptolemy.data.type.Type type = (ptolemy.data.type.Type) types.next();
Local typeLocal = null;
if (_forceConversions || !port.getType().equals(type)) {
typeLocal = PtolemyUtilities.buildConstantTypeLocal(body, stmt,
type);
}
Value bufferSizeValue = _getBufferAndSize(body, stmt, port, type,
channelValue, bufferLocal,
_portToTypeNameToInsideBufferField, true);
_getCorrectIndex(body, stmt, port, indexLocal, indexArrayLocal,
channelValue, bufferSizeValue, _portToInsideIndexArrayField);
// A local of type token
Local tokenLocal = Jimple.v().newLocal("tokenLocal",
PtolemyUtilities.tokenType);
body.getLocals().add(tokenLocal);
// A local of the appropriate type to store in the
// buffer.
Local outputTokenLocal = Jimple.v().newLocal("outputTokenLocal",
PtolemyUtilities.getSootTypeForTokenType(type));
body.getLocals().add(outputTokenLocal);
// If we are calling with just a channel, then write the value.
if (expr.getArgCount() == 2) {
Local sendTokenLocal = (Local) expr.getArg(1);
// Replace the put() with an array write.
body.getUnits().insertBefore(
_createBufferStoreInstructions(bufferLocal, indexLocal,
sendTokenLocal, typeLocal, tokenLocal,
outputTokenLocal), stmt);
// increment the position in the buffer.
body.getUnits()
.insertBefore(
_createIndexUpdateInstructions(indexLocal,
indexArrayLocal, channelValue,
bufferSizeValue), stmt);
} else {
Local sendArrayLocal = (Local) expr.getArg(1);
/* Jimple.v().newLocal("sendArray",
ArrayType.v(PtolemyUtilities.tokenType, 1));
body.getLocals().add(sendArrayLocal);
// We must send an array of tokens.
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
sendArrayLocal,
expr.getArg(1)),
stmt);*/
Value countValue = expr.getArg(2);
Local sendTokenLocal = Jimple.v().newLocal("sendToken",
PtolemyUtilities.tokenType);
body.getLocals().add(sendTokenLocal);