Program: 73377
Project: 73377
Buggy source:
/** 
 * Generate code for putting tokens into the receiver.
 * @param sourcePort The port for which to generate the send code.
 * @param offset The offset in the array representation of the port.
 * @param token The token to be sent.
 * @return generate type conversion as well as put code.
 * @exception IllegalActionException If the receiver adapter isnot found or it encounters an error while generating the send code.
 */
public String generatePutCode(IOPort sourcePort,String offset,String token) throws IllegalActionException {
  TypedIOPort sinkPort=(TypedIOPort)getComponent().getContainer();
  if (sinkPort.isOutput()) {
    StringBuffer code=new StringBuffer();
    ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort portAdapter=(ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort)getAdapter(sinkPort);
    for (int channel=0; channel < sinkPort.getWidth(); channel++) {
      code.append(portAdapter.generatePutCode(Integer.toString(channel),offset,token));
    }
    return code.toString();
  }
  int sinkChannel=sinkPort.getChannelForReceiver(getComponent());
  Channel source=new Channel(sourcePort,0);
  Channel sink=new Channel(sinkPort,sinkChannel);
  token=((NamedProgramCodeGeneratorAdapter)getAdapter(getComponent().getContainer().getContainer())).getTemplateParser().generateTypeConvertStatement(source,sink,0,token);
  token=_removeSink(token);
  Actor actor=(Actor)sinkPort.getContainer();
  Director director=actor.getDirector();
  String depth=Integer.toString(((CausalityInterfaceForComposites)director.getCausalityInterface()).getDepthOfActor(actor));
  Parameter relativeDeadline=(Parameter)sinkPort.getAttribute("String_Node_Str");
  String deadlineSecsString=null;
  String deadlineNsecsString=null;
  if (relativeDeadline != null) {
    double value=((DoubleToken)relativeDeadline.getToken()).doubleValue();
    int intPart=(int)value;
    int fracPart=(int)((value - intPart) * 1000000000.0);
    deadlineSecsString=Integer.toString(intPart);
    deadlineNsecsString=Integer.toString(fracPart);
  }
 else {
    deadlineSecsString=new String("String_Node_Str");
    deadlineNsecsString=new String("String_Node_Str");
  }
  Parameter offsetTime=(Parameter)sinkPort.getAttribute("String_Node_Str");
  String offsetSecsString=null;
  String offsetNsecsString=null;
  if (offsetTime != null) {
    double value=((DoubleToken)((ArrayToken)offsetTime.getToken()).arrayValue()[sinkChannel]).doubleValue();
    int intPart=(int)value;
    int fracPart=(int)((value - intPart) * 1000000000.0);
    offsetSecsString=Integer.toString(intPart);
    offsetNsecsString=Integer.toString(fracPart);
  }
 else {
    throw new IllegalActionException(sinkPort,"String_Node_Str");
  }
  String sinkName=NamedProgramCodeGeneratorAdapter.generateName(sinkPort.getContainer());
  List args=new ArrayList();
  args.add(sinkPort.getType().toString());
  args.add(token);
  args.add(sinkName);
  args.add("String_Node_Str" + sinkName + "String_Node_Str"+ sinkPort.getName()+ "String_Node_Str"+ sinkPort.getChannelForReceiver(getComponent())+ "String_Node_Str");
  args.add(depth);
  args.add(deadlineSecsString);
  args.add(deadlineNsecsString);
  args.add(offsetSecsString);
  args.add(offsetNsecsString);
  return _templateParser.generateBlockCode("String_Node_Str",args);
}

Fixed version (ground truth):
/** 
 * Generate code for putting tokens into the receiver.
 * @param sourcePort The port for which to generate the send code.
 * @param offset The offset in the array representation of the port.
 * @param token The token to be sent.
 * @return generate type conversion as well as put code.
 * @exception IllegalActionException If the receiver adapter isnot found or it encounters an error while generating the send code.
 */
public String generatePutCode(IOPort sourcePort,String offset,String token) throws IllegalActionException {
  TypedIOPort sinkPort=(TypedIOPort)getComponent().getContainer();
  if (sinkPort.isOutput()) {
    StringBuffer code=new StringBuffer();
    ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort portAdapter=(ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.IOPort)getAdapter(sinkPort);
    for (int channel=0; channel < sinkPort.getWidth(); channel++) {
      code.append(portAdapter.generatePutCode(Integer.toString(channel),offset,token));
    }
    return code.toString();
  }
  int sinkChannel=sinkPort.getChannelForReceiver(getComponent());
  Channel source=new Channel(sourcePort,0);
  Channel sink=new Channel(sinkPort,sinkChannel);
  token=((NamedProgramCodeGeneratorAdapter)getAdapter(getComponent().getContainer().getContainer())).getTemplateParser().generateTypeConvertStatement(source,sink,0,token);
  token=_removeSink(token);
  Actor actor=(Actor)sinkPort.getContainer();
  Director director=actor.getDirector();
  String depth=Integer.toString(((CausalityInterfaceForComposites)director.getCausalityInterface()).getDepthOfActor(actor));
  Parameter relativeDeadline=(Parameter)sinkPort.getAttribute("String_Node_Str");
  String deadlineSecsString=null;
  String deadlineNsecsString=null;
  if (relativeDeadline != null) {
    double value=((DoubleToken)relativeDeadline.getToken()).doubleValue();
    int intPart=(int)value;
    int fracPart=(int)((value - intPart) * 1000000000.0);
    deadlineSecsString=Integer.toString(intPart);
    deadlineNsecsString=Integer.toString(fracPart);
  }
 else {
    deadlineSecsString="String_Node_Str";
    deadlineNsecsString="String_Node_Str";
  }
  Parameter offsetTime=(Parameter)sinkPort.getAttribute("String_Node_Str");
  String offsetSecsString=null;
  String offsetNsecsString=null;
  if (offsetTime != null) {
    double value=((DoubleToken)((ArrayToken)offsetTime.getToken()).arrayValue()[sinkChannel]).doubleValue();
    int intPart=(int)value;
    int fracPart=(int)((value - intPart) * 1000000000.0);
    offsetSecsString=Integer.toString(intPart);
    offsetNsecsString=Integer.toString(fracPart);
  }
 else {
    throw new IllegalActionException(sinkPort,"String_Node_Str");
  }
  String sinkName=NamedProgramCodeGeneratorAdapter.generateName(sinkPort.getContainer());
  List args=new ArrayList();
  args.add(sinkPort.getType().toString());
  args.add(token);
  args.add(sinkName);
  args.add("String_Node_Str" + sinkName + "String_Node_Str"+ sinkPort.getName()+ "String_Node_Str"+ sinkPort.getChannelForReceiver(getComponent())+ "String_Node_Str");
  args.add(depth);
  args.add(deadlineSecsString);
  args.add(deadlineNsecsString);
  args.add(offsetSecsString);
  args.add(offsetNsecsString);
  return _templateParser.generateBlockCode("String_Node_Str",args);
}