Program: 72925
Project: 72925
Buggy source:
/** 
 * Generate the transfer inputs code. This is to ensure compatibility between different directors.
 * @return The generated code.
 * @exception IllegalActionException If thrown while appending to thethe block or processing the macros.
 */
public String generateTransfersCode() throws IllegalActionException {
  CodeStream codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  ptolemy.actor.CompositeActor container=(ptolemy.actor.CompositeActor)getComponent();
  String sanitizedContainerName=CodeGeneratorAdapter.generateName(container);
  Director director=container.getDirector();
  ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director directorAdapter=(ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director)getAdapter(director);
  StringBuffer code=new StringBuffer();
  codeStream.append(_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ _eol);
  Iterator<?> inputPorts=container.inputPortList().iterator();
  while (inputPorts.hasNext()) {
    TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
    if (!inputPort.isInsideConnected())     continue;
    if (container instanceof CompiledCompositeActor) {
      directorAdapter.generateTransferInputsCode(inputPort,code);
      codeStream.append(code.toString());
      code=new StringBuffer();
    }
 else {
      Receiver[][] receivers=inputPort.deepGetReceivers();
      for (int channel=0; channel < inputPort.getWidth(); channel++) {
        String hasTokenString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str"+ _eol;
        String getString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str";
        String putString=_eol + "String_Node_Str" + getString+ "String_Node_Str";
        if (receivers[channel].length > 1) {
          int foo=0;
          for (int cpt=0; cpt < receivers[channel].length; cpt++) {
            if (!(receivers[channel][cpt].getContainer().getContainer() instanceof ModalController)) {
              putString+=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ foo+++ "String_Node_Str";
            }
          }
        }
 else         putString+=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ _eol;
        if (container.getDirector() instanceof ptolemy.domains.modal.kernel.FSMDirector) {
          List actorList=container.deepEntityList();
          Iterator<?> actors=actorList.iterator();
          while (actors.hasNext()) {
            NamedObj actor=(NamedObj)actors.next();
            if (actor instanceof ModalController) {
              String actorName=CodeGeneratorAdapter.generateName(actor);
              String type=inputPort.getType().toString().substring(0,1).toUpperCase() + inputPort.getType().toString().substring(1);
              putString+=_eol + actorName + "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ type+ "String_Node_Str"+ _eol;
            }
          }
        }
        String fireAtString="String_Node_Str";
        if (container.getDirector() instanceof DEDirector) {
          NamedObj insideActor=inputPort.deepGetReceivers()[channel][0].getContainer().getContainer();
          String sanitizedNameInsideActor=CodeGeneratorAdapter.generateName(insideActor);
          if (insideActor instanceof CompositeActor)           sanitizedNameInsideActor="String_Node_Str" + sanitizedNameInsideActor + "String_Node_Str";
          fireAtString=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedNameInsideActor+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ _eol;
        }
        codeStream.append(_eol + hasTokenString + putString+ fireAtString+ _eol+ "String_Node_Str"+ _eol);
      }
    }
  }
  codeStream.append(_eol + "String_Node_Str" + _eol);
  codeStream.append(_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ _eol);
  Iterator<?> outputPorts=container.outputPortList().iterator();
  while (outputPorts.hasNext()) {
    TypedIOPort outputPort=(TypedIOPort)outputPorts.next();
    if (!outputPort.isOutsideConnected())     continue;
    if (container instanceof CompiledCompositeActor) {
      directorAdapter.generateTransferOutputsCode(outputPort,code);
      codeStream.append(code.toString());
      code=new StringBuffer();
    }
 else {
      for (int channel=0; channel < outputPort.getWidth(); channel++) {
        String hasTokenString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str"+ _eol;
        String getString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str";
        String putString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str"+ getString+ "String_Node_Str"+ _eol;
        String fireAtString="String_Node_Str";
        CompositeActor topContainer=((CompositeActor)container.getContainer());
        String sanitizedTopContainerName=CodeGeneratorAdapter.generateName(topContainer);
        if (topContainer.getDirector() instanceof DEDirector) {
          NamedObj outsideActor=outputPort.getRemoteReceivers()[channel][0].getContainer().getContainer();
          String sanitizedNameOutsideActor=CodeGeneratorAdapter.generateName(outsideActor);
          if (outsideActor instanceof CompositeActor)           sanitizedNameOutsideActor="String_Node_Str" + sanitizedNameOutsideActor + "String_Node_Str";
          fireAtString=_eol + "String_Node_Str" + sanitizedTopContainerName+ "String_Node_Str"+ sanitizedNameOutsideActor+ "String_Node_Str"+ sanitizedTopContainerName+ "String_Node_Str"+ sanitizedTopContainerName+ "String_Node_Str"+ _eol;
        }
        codeStream.append(_eol + hasTokenString + putString+ fireAtString+ _eol+ "String_Node_Str"+ _eol);
      }
    }
  }
  if (container.getDirector() instanceof ptolemy.domains.modal.kernel.FSMDirector) {
    inputPorts=container.inputPortList().iterator();
    while (inputPorts.hasNext()) {
      TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
      if (!inputPort.isInsideConnected())       continue;
      Receiver[][] receivers=inputPort.deepGetReceivers();
      for (int channel=0; channel < inputPort.getWidth(); channel++) {
        int foo=0;
        for (int cpt=0; cpt < receivers[channel].length; cpt++) {
          if (!(receivers[channel][cpt].getContainer().getContainer() instanceof ModalController)) {
            String hasTokenString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol;
            String putString=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ foo+++ "String_Node_Str";
            codeStream.append(_eol + hasTokenString + putString+ _eol+ "String_Node_Str"+ _eol);
          }
        }
      }
    }
  }
  codeStream.append(_eol + "String_Node_Str" + _eol);
  return processCode(codeStream.toString());
}

Fixed version (ground truth):
/** 
 * Generate the transfer inputs code. This is to ensure compatibility between different directors.
 * @return The generated code.
 * @exception IllegalActionException If thrown while appending to thethe block or processing the macros.
 */
public String generateTransfersCode() throws IllegalActionException {
  CodeStream codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  ptolemy.actor.CompositeActor container=(ptolemy.actor.CompositeActor)getComponent();
  String sanitizedContainerName=CodeGeneratorAdapter.generateName(container);
  Director director=container.getDirector();
  ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director directorAdapter=(ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director)getAdapter(director);
  StringBuffer code=new StringBuffer();
  codeStream.append(_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ _eol);
  Iterator<?> inputPorts=container.inputPortList().iterator();
  while (inputPorts.hasNext()) {
    TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
    if (!inputPort.isInsideConnected())     continue;
    if (container instanceof CompiledCompositeActor) {
      directorAdapter.generateTransferInputsCode(inputPort,code);
      codeStream.append(code.toString());
      code=new StringBuffer();
    }
 else {
      Receiver[][] receivers=inputPort.deepGetReceivers();
      for (int channel=0; channel < inputPort.getWidth(); channel++) {
        String hasTokenString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str"+ _eol;
        String getString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str";
        String putString=_eol + "String_Node_Str" + getString+ "String_Node_Str";
        if (receivers[channel].length > 1) {
          int foo=0;
          for (int cpt=0; cpt < receivers[channel].length; cpt++) {
            if (!(receivers[channel][cpt].getContainer().getContainer() instanceof ModalController)) {
              putString+=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ foo+++ "String_Node_Str";
            }
          }
        }
 else         putString+=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str"+ _eol;
        if (container.getDirector() instanceof ptolemy.domains.modal.kernel.FSMDirector) {
          List actorList=container.deepEntityList();
          Iterator<?> actors=actorList.iterator();
          while (actors.hasNext()) {
            NamedObj actor=(NamedObj)actors.next();
            if (actor instanceof ModalController) {
              String actorName=CodeGeneratorAdapter.generateName(actor);
              String type=inputPort.getType().toString().substring(0,1).toUpperCase() + inputPort.getType().toString().substring(1);
              putString+=_eol + actorName + "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ type+ "String_Node_Str"+ _eol;
            }
          }
        }
        String fireAtString="String_Node_Str";
        if (container.getDirector() instanceof DEDirector) {
          NamedObj insideActor=inputPort.deepGetReceivers()[channel][0].getContainer().getContainer();
          String sanitizedNameInsideActor=CodeGeneratorAdapter.generateName(insideActor);
          if (insideActor instanceof CompositeActor)           sanitizedNameInsideActor="String_Node_Str" + sanitizedNameInsideActor + "String_Node_Str";
          fireAtString=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedNameInsideActor+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ _eol;
        }
        codeStream.append(_eol + hasTokenString + putString+ fireAtString+ _eol+ "String_Node_Str"+ _eol);
      }
    }
  }
  codeStream.append(_eol + "String_Node_Str" + _eol);
  codeStream.append(_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ _eol);
  Iterator<?> outputPorts=container.outputPortList().iterator();
  while (outputPorts.hasNext()) {
    TypedIOPort outputPort=(TypedIOPort)outputPorts.next();
    if (!outputPort.isOutsideConnected())     continue;
    if (container instanceof CompiledCompositeActor) {
      directorAdapter.generateTransferOutputsCode(outputPort,code);
      codeStream.append(code.toString());
      code=new StringBuffer();
    }
 else {
      for (int channel=0; channel < outputPort.getWidth(); channel++) {
        String hasTokenString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str"+ _eol;
        String getString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str";
        String putString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ channel+ "String_Node_Str"+ getString+ "String_Node_Str"+ _eol;
        String fireAtString="String_Node_Str";
        CompositeActor topContainer=((CompositeActor)container.getContainer());
        String sanitizedTopContainerName=CodeGeneratorAdapter.generateName(topContainer);
        if (topContainer.getDirector() instanceof DEDirector) {
          NamedObj outsideActor=outputPort.getRemoteReceivers()[channel][0].getContainer().getContainer();
          String sanitizedNameOutsideActor=CodeGeneratorAdapter.generateName(outsideActor);
          if (outsideActor instanceof CompositeActor)           sanitizedNameOutsideActor="String_Node_Str" + sanitizedNameOutsideActor + "String_Node_Str";
          fireAtString=_eol + "String_Node_Str" + sanitizedTopContainerName+ "String_Node_Str"+ sanitizedNameOutsideActor+ "String_Node_Str"+ sanitizedTopContainerName+ "String_Node_Str"+ sanitizedTopContainerName+ "String_Node_Str"+ _eol;
        }
        codeStream.append(_eol + hasTokenString + putString+ fireAtString+ _eol+ "String_Node_Str"+ _eol);
      }
    }
  }
  if (container.getDirector() instanceof ptolemy.domains.modal.kernel.FSMDirector) {
    inputPorts=container.inputPortList().iterator();
    while (inputPorts.hasNext()) {
      TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
      if (!inputPort.isInsideConnected())       continue;
      Receiver[][] receivers=inputPort.deepGetReceivers();
      for (int channel=0; channel < inputPort.getWidth(); channel++) {
        int foo=0;
        for (int cpt=0; cpt < receivers[channel].length; cpt++) {
          if (!(receivers[channel][cpt].getContainer().getContainer() instanceof ModalController)) {
            String hasTokenString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol;
            String putString=_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ foo+++ "String_Node_Str";
            codeStream.append(_eol + hasTokenString + putString+ _eol+ "String_Node_Str"+ _eol);
          }
        }
      }
    }
  }
  codeStream.append(_eol + "String_Node_Str" + _eol);
  return processCode(codeStream.toString());
}