Program: 72914
Project: 72914
Buggy source:
/** 
 * In this function we generate the code for the construction of the receivers within the C Code. It generates the calls to RemoteReceiverSet and RemoteFarReceiverSet recursively.
 * @return The generated code.
 * @exception IllegalActionException If thrown while appending to thethe block or processing the macros.
 */
public String generateConstructorReceiversFunction() throws IllegalActionException {
  CodeStream codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  LinkedList args=new LinkedList();
  ptolemy.actor.CompositeActor TopActor=(ptolemy.actor.CompositeActor)getComponent();
  String sanitizedContainerName=CodeGeneratorAdapter.generateName(TopActor);
  String sanitizedContainerNameForArgs="String_Node_Str" + sanitizedContainerName + "String_Node_Str";
  codeStream.append(_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ _eol);
  List inputPortList=TopActor.inputPortList();
  List outputPortList=TopActor.outputPortList();
  Iterator<?> ports=inputPortList.iterator();
  int i=0;
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    Receiver[][] farReceivers=port.getRemoteReceivers();
    for (int j=0; j < farReceivers.length; j++) {
      args.clear();
      args.add(sanitizedContainerNameForArgs);
      args.add(Integer.toString(i));
      args.add(Integer.toString(j));
      codeStream.appendCodeBlock("String_Node_Str",args,true);
    }
    Receiver[][] receivers=port.deepGetReceivers();
    int cpt=0;
    for (int j=0; j < receivers.length; j++) {
      for (int k=0; k < receivers[j].length; k++) {
        Receiver r=receivers[j][k];
        if (r.getContainer().getContainer() instanceof ModalController) {
          continue;
        }
        args.clear();
        args.add(sanitizedContainerNameForArgs);
        args.add(Integer.toString(i));
        args.add(Integer.toString(cpt++));
        String farActorName=CodeGeneratorAdapter.generateName(r.getContainer().getContainer());
        String farActorNameForArgs=farActorName;
        if (r.getContainer().getContainer() instanceof CompositeActor)         farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
        args.add(farActorName);
        args.add(farActorNameForArgs);
        args.add(r.getContainer().getName());
        int farChannelNumber=r.getContainer().getChannelForReceiver(r);
        args.add(Integer.toString(farChannelNumber));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
      }
    }
    i++;
  }
  ports=outputPortList.iterator();
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    Receiver[][] farReceivers=port.getRemoteReceivers();
    String enumFarReceivers=_eol + "String_Node_Str";
    int channel=0;
    for (int k=0; k < farReceivers.length; k++) {
      if (TopActor instanceof ptolemy.cg.lib.CompiledCompositeActor)       break;
      for (int j=0; j < farReceivers[k].length; j++) {
        Receiver r=farReceivers[k][j];
        if (r.getContainer().getContainer() instanceof ModalController) {
          continue;
        }
        args.clear();
        args.add(sanitizedContainerNameForArgs);
        args.add(Integer.toString(i));
        args.add(Integer.toString(channel++));
        NamedObj farActor=r.getContainer().getContainer();
        String farActorName=CodeGeneratorAdapter.generateName(farActor);
        String farActorNameForArgs;
        if (farActor instanceof CompositeActor)         farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
 else         farActorNameForArgs=farActorName;
        args.add(farActorName);
        args.add(farActorNameForArgs);
        args.add(r.getContainer().getName());
        int farChannelNumber=r.getContainer().getChannelForReceiver(r);
        args.add(Integer.toString(farChannelNumber));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
        enumFarReceivers+=sanitizedContainerName + "String_Node_Str" + port.getName()+ "String_Node_Str"+ farActorName+ "String_Node_Str"+ r.getContainer().getName()+ "String_Node_Str"+ farChannelNumber+ "String_Node_Str";
      }
    }
    if (enumFarReceivers.length() > 7) {
      enumFarReceivers=enumFarReceivers.substring(0,enumFarReceivers.length() - 2);
      enumFarReceivers+="String_Node_Str" + _eol;
      _enumPortNumbersDefinition+=enumFarReceivers;
    }
    Receiver[][] insideReceivers=port.getInsideReceivers();
    for (int j=0; j < insideReceivers.length; j++) {
      args.clear();
      args.add(sanitizedContainerNameForArgs);
      args.add(Integer.toString(i));
      args.add(Integer.toString(j));
      codeStream.appendCodeBlock("String_Node_Str",args,true);
    }
    i++;
  }
  List actorList=TopActor.deepEntityList();
  Iterator<?> actors=actorList.iterator();
  actors=actorList.iterator();
  while (actors.hasNext()) {
    NamedObj actor=(NamedObj)actors.next();
    String sanitizedActorName=CodeGeneratorAdapter.generateName(actor);
    Actor act=(Actor)actor;
    if (act instanceof CompositeActor) {
      codeStream.append(_eol + sanitizedActorName + "String_Node_Str");
      continue;
    }
    if (act instanceof ModalController) {
      continue;
    }
    args.clear();
    inputPortList=act.inputPortList();
    outputPortList=act.outputPortList();
    ports=inputPortList.iterator();
    i=0;
    while (ports.hasNext()) {
      TypedIOPort port=(TypedIOPort)ports.next();
      if (!port.isOutsideConnected())       continue;
      Receiver[][] farReceivers=port.getRemoteReceivers();
      for (int j=0; j < farReceivers.length; j++) {
        args.clear();
        args.add(sanitizedActorName);
        args.add(Integer.toString(i));
        args.add(Integer.toString(j));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
      }
      if (act instanceof CompositeActor) {
        Receiver[][] insideReceivers=port.getInsideReceivers();
        int cpt=0;
        for (int j=0; j < insideReceivers.length; j++) {
          for (int k=0; k < insideReceivers[j].length; k++) {
            Receiver r=insideReceivers[j][k];
            args.clear();
            args.add(sanitizedActorName);
            args.add(Integer.toString(i));
            args.add(Integer.toString(cpt++));
            String farActorName=CodeGeneratorAdapter.generateName(r.getContainer().getContainer());
            String farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
            args.add(farActorName);
            args.add(farActorNameForArgs);
            args.add(r.getContainer().getName());
            int farChannelNumber=r.getContainer().getChannelForReceiver(r);
            args.add(Integer.toString(farChannelNumber));
            codeStream.appendCodeBlock("String_Node_Str",args,true);
          }
        }
      }
      i++;
    }
    ports=outputPortList.iterator();
    while (ports.hasNext()) {
      TypedIOPort port=(TypedIOPort)ports.next();
      if (!port.isOutsideConnected())       continue;
      Receiver[][] farReceivers=port.getRemoteReceivers();
      String enumFarReceivers=_eol + "String_Node_Str";
      int channel=0;
      for (int k=0; k < farReceivers.length; k++) {
        if (farReceivers[k] == null)         continue;
        for (int j=0; j < farReceivers[k].length; j++) {
          Receiver r=farReceivers[k][j];
          args.clear();
          args.add(sanitizedActorName);
          args.add(Integer.toString(i));
          args.add(Integer.toString(channel++));
          NamedObj farActor=r.getContainer().getContainer();
          String farActorName=CodeGeneratorAdapter.generateName(farActor);
          String farActorNameForArgs;
          if (farActor instanceof CompositeActor)           farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
 else           farActorNameForArgs=farActorName;
          args.add(farActorName);
          args.add(farActorNameForArgs);
          args.add(r.getContainer().getName());
          int farChannelNumber=r.getContainer().getChannelForReceiver(r);
          args.add(Integer.toString(farChannelNumber));
          codeStream.appendCodeBlock("String_Node_Str",args,true);
          enumFarReceivers+=sanitizedActorName + "String_Node_Str" + port.getName()+ "String_Node_Str"+ farActorName+ "String_Node_Str"+ r.getContainer().getName()+ "String_Node_Str"+ farChannelNumber+ "String_Node_Str";
        }
      }
      if (enumFarReceivers.length() > 7) {
        enumFarReceivers=enumFarReceivers.substring(0,enumFarReceivers.length() - 2);
        enumFarReceivers+="String_Node_Str" + _eol;
        _enumPortNumbersDefinition+=enumFarReceivers;
      }
      if (act instanceof CompositeActor) {
        Receiver[][] insideReceivers=port.getInsideReceivers();
        for (int j=0; j < insideReceivers.length; j++) {
          args.clear();
          args.add(sanitizedActorName);
          args.add(Integer.toString(i));
          args.add(Integer.toString(j));
          codeStream.appendCodeBlock("String_Node_Str",args,true);
        }
      }
      i++;
    }
  }
  codeStream.append(_eol + "String_Node_Str" + _eol);
  return codeStream.toString();
}

Fixed version (ground truth):
/** 
 * In this function we generate the code for the construction of the receivers within the C Code. It generates the calls to RemoteReceiverSet and RemoteFarReceiverSet recursively.
 * @return The generated code.
 * @exception IllegalActionException If thrown while appending to thethe block or processing the macros.
 */
public String generateConstructorReceiversFunction() throws IllegalActionException {
  CodeStream codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  LinkedList args=new LinkedList();
  ptolemy.actor.CompositeActor TopActor=(ptolemy.actor.CompositeActor)getComponent();
  String sanitizedContainerName=CodeGeneratorAdapter.generateName(TopActor);
  String sanitizedContainerNameForArgs="String_Node_Str" + sanitizedContainerName + "String_Node_Str";
  codeStream.append(_eol + "String_Node_Str" + sanitizedContainerName+ "String_Node_Str"+ _eol);
  List inputPortList=TopActor.inputPortList();
  List outputPortList=TopActor.outputPortList();
  Iterator<?> ports=inputPortList.iterator();
  int i=0;
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    Receiver[][] farReceivers=port.getRemoteReceivers();
    for (int j=0; j < farReceivers.length; j++) {
      args.clear();
      args.add(sanitizedContainerNameForArgs);
      args.add(Integer.toString(i));
      args.add(Integer.toString(j));
      codeStream.appendCodeBlock("String_Node_Str",args,true);
    }
    Receiver[][] receivers=port.deepGetReceivers();
    int cpt=0;
    for (int j=0; j < receivers.length; j++) {
      for (int k=0; k < receivers[j].length; k++) {
        Receiver r=receivers[j][k];
        if (r.getContainer().getContainer() instanceof ModalController) {
          continue;
        }
        args.clear();
        args.add(sanitizedContainerNameForArgs);
        args.add(Integer.toString(i));
        args.add(Integer.toString(cpt++));
        String farActorName=CodeGeneratorAdapter.generateName(r.getContainer().getContainer());
        String farActorNameForArgs=farActorName;
        if (r.getContainer().getContainer() instanceof CompositeActor)         farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
        args.add(farActorName);
        args.add(farActorNameForArgs);
        args.add(r.getContainer().getName());
        int farChannelNumber=r.getContainer().getChannelForReceiver(r);
        args.add(Integer.toString(farChannelNumber));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
      }
    }
    i++;
  }
  ports=outputPortList.iterator();
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    Receiver[][] farReceivers=port.getRemoteReceivers();
    StringBuffer enumFarReceivers=new StringBuffer(_eol + "String_Node_Str");
    int channel=0;
    for (int k=0; k < farReceivers.length; k++) {
      if (TopActor instanceof ptolemy.cg.lib.CompiledCompositeActor)       break;
      for (int j=0; j < farReceivers[k].length; j++) {
        Receiver r=farReceivers[k][j];
        if (r.getContainer().getContainer() instanceof ModalController) {
          continue;
        }
        args.clear();
        args.add(sanitizedContainerNameForArgs);
        args.add(Integer.toString(i));
        args.add(Integer.toString(channel++));
        NamedObj farActor=r.getContainer().getContainer();
        String farActorName=CodeGeneratorAdapter.generateName(farActor);
        String farActorNameForArgs;
        if (farActor instanceof CompositeActor)         farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
 else         farActorNameForArgs=farActorName;
        args.add(farActorName);
        args.add(farActorNameForArgs);
        args.add(r.getContainer().getName());
        int farChannelNumber=r.getContainer().getChannelForReceiver(r);
        args.add(Integer.toString(farChannelNumber));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
        enumFarReceivers.append(sanitizedContainerName + "String_Node_Str" + port.getName()+ "String_Node_Str"+ farActorName+ "String_Node_Str"+ r.getContainer().getName()+ "String_Node_Str"+ farChannelNumber+ "String_Node_Str");
      }
    }
    if (enumFarReceivers.length() > 7) {
      enumFarReceivers.delete(enumFarReceivers.length() - 2,enumFarReceivers.length());
      enumFarReceivers.append("String_Node_Str" + _eol);
      _enumPortNumbersDefinition+=enumFarReceivers.toString();
    }
    Receiver[][] insideReceivers=port.getInsideReceivers();
    for (int j=0; j < insideReceivers.length; j++) {
      args.clear();
      args.add(sanitizedContainerNameForArgs);
      args.add(Integer.toString(i));
      args.add(Integer.toString(j));
      codeStream.appendCodeBlock("String_Node_Str",args,true);
    }
    i++;
  }
  List actorList=TopActor.deepEntityList();
  Iterator<?> actors=actorList.iterator();
  actors=actorList.iterator();
  while (actors.hasNext()) {
    NamedObj actor=(NamedObj)actors.next();
    String sanitizedActorName=CodeGeneratorAdapter.generateName(actor);
    Actor act=(Actor)actor;
    if (act instanceof CompositeActor) {
      codeStream.append(_eol + sanitizedActorName + "String_Node_Str");
      continue;
    }
    if (act instanceof ModalController) {
      continue;
    }
    args.clear();
    inputPortList=act.inputPortList();
    outputPortList=act.outputPortList();
    ports=inputPortList.iterator();
    i=0;
    while (ports.hasNext()) {
      TypedIOPort port=(TypedIOPort)ports.next();
      if (!port.isOutsideConnected())       continue;
      Receiver[][] farReceivers=port.getRemoteReceivers();
      for (int j=0; j < farReceivers.length; j++) {
        args.clear();
        args.add(sanitizedActorName);
        args.add(Integer.toString(i));
        args.add(Integer.toString(j));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
      }
      if (act instanceof CompositeActor) {
        Receiver[][] insideReceivers=port.getInsideReceivers();
        int cpt=0;
        for (int j=0; j < insideReceivers.length; j++) {
          for (int k=0; k < insideReceivers[j].length; k++) {
            Receiver r=insideReceivers[j][k];
            args.clear();
            args.add(sanitizedActorName);
            args.add(Integer.toString(i));
            args.add(Integer.toString(cpt++));
            String farActorName=CodeGeneratorAdapter.generateName(r.getContainer().getContainer());
            String farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
            args.add(farActorName);
            args.add(farActorNameForArgs);
            args.add(r.getContainer().getName());
            int farChannelNumber=r.getContainer().getChannelForReceiver(r);
            args.add(Integer.toString(farChannelNumber));
            codeStream.appendCodeBlock("String_Node_Str",args,true);
          }
        }
      }
      i++;
    }
    ports=outputPortList.iterator();
    while (ports.hasNext()) {
      TypedIOPort port=(TypedIOPort)ports.next();
      if (!port.isOutsideConnected())       continue;
      Receiver[][] farReceivers=port.getRemoteReceivers();
      String enumFarReceivers=_eol + "String_Node_Str";
      int channel=0;
      for (int k=0; k < farReceivers.length; k++) {
        if (farReceivers[k] == null)         continue;
        for (int j=0; j < farReceivers[k].length; j++) {
          Receiver r=farReceivers[k][j];
          args.clear();
          args.add(sanitizedActorName);
          args.add(Integer.toString(i));
          args.add(Integer.toString(channel++));
          NamedObj farActor=r.getContainer().getContainer();
          String farActorName=CodeGeneratorAdapter.generateName(farActor);
          String farActorNameForArgs;
          if (farActor instanceof CompositeActor)           farActorNameForArgs="String_Node_Str" + farActorName + "String_Node_Str";
 else           farActorNameForArgs=farActorName;
          args.add(farActorName);
          args.add(farActorNameForArgs);
          args.add(r.getContainer().getName());
          int farChannelNumber=r.getContainer().getChannelForReceiver(r);
          args.add(Integer.toString(farChannelNumber));
          codeStream.appendCodeBlock("String_Node_Str",args,true);
          enumFarReceivers+=sanitizedActorName + "String_Node_Str" + port.getName()+ "String_Node_Str"+ farActorName+ "String_Node_Str"+ r.getContainer().getName()+ "String_Node_Str"+ farChannelNumber+ "String_Node_Str";
        }
      }
      if (enumFarReceivers.length() > 7) {
        enumFarReceivers=enumFarReceivers.substring(0,enumFarReceivers.length() - 2);
        enumFarReceivers+="String_Node_Str" + _eol;
        _enumPortNumbersDefinition+=enumFarReceivers;
      }
      if (act instanceof CompositeActor) {
        Receiver[][] insideReceivers=port.getInsideReceivers();
        for (int j=0; j < insideReceivers.length; j++) {
          args.clear();
          args.add(sanitizedActorName);
          args.add(Integer.toString(i));
          args.add(Integer.toString(j));
          codeStream.appendCodeBlock("String_Node_Str",args,true);
        }
      }
      i++;
    }
  }
  codeStream.append(_eol + "String_Node_Str" + _eol);
  return codeStream.toString();
}