Program: 72915
Project: 72915
Buggy source:
/** 
 * In this function we generate the code for the construction of the ports within the C Code. It generates the calls to IOPortSet recursively.
 * @return The generated code.
 * @exception IllegalActionException If thrown while appending to thethe block or processing the macros.
 */
public String generateConstructorPortsFunction() 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);
  String enumString=_eol + "String_Node_Str";
  List inputPortList=TopActor.inputPortList();
  List outputPortList=TopActor.outputPortList();
  Iterator<?> ports=inputPortList.iterator();
  int j=0;
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    args.clear();
    args.add(sanitizedContainerNameForArgs);
    args.add(Integer.toString(j++));
    args.add("String_Node_Str" + port.getName() + "String_Node_Str");
    args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
    args.add(Boolean.toString(port.isInput()));
    args.add(Boolean.toString(port.isOutput()));
    args.add(Boolean.toString(port.isMultiport()));
    int widthInside=port.getWidthInside();
    int widthOutside=0;
    Receiver[][] receivers=port.deepGetReceivers();
    for (int cpt=0; cpt < receivers.length; cpt++) {
      widthOutside+=receivers[cpt].length;
    }
    args.add(Integer.toString(widthInside));
    args.add(Integer.toString(widthOutside));
    codeStream.appendCodeBlock("String_Node_Str",args,true);
    enumString+="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ port.getName()+ "String_Node_Str";
  }
  ports=outputPortList.iterator();
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    args.clear();
    args.add(sanitizedContainerNameForArgs);
    args.add(Integer.toString(j++));
    args.add("String_Node_Str" + port.getName() + "String_Node_Str");
    args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
    args.add(Boolean.toString(port.isInput()));
    args.add(Boolean.toString(port.isOutput()));
    args.add(Boolean.toString(port.isMultiport()));
    args.add(Integer.toString(port.getWidth()));
    int widthOutside=0;
    for (    Receiver[] r : port.getRemoteReceivers()) {
      if (TopActor instanceof ptolemy.cg.lib.CompiledCompositeActor)       break;
      if (r != null)       widthOutside+=r.length;
    }
    args.add(Integer.toString(widthOutside));
    codeStream.appendCodeBlock("String_Node_Str",args,true);
    enumString+="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ port.getName()+ "String_Node_Str";
  }
  if (enumString.length() > 7) {
    enumString=enumString.substring(0,enumString.length() - 2);
    enumString+="String_Node_Str" + _eol;
    _enumPortNumbersDefinition+=enumString;
  }
  List actorList=TopActor.deepEntityList();
  Iterator<?> actors=actorList.iterator();
  actors=actorList.iterator();
  while (actors.hasNext()) {
    NamedObj actor=(NamedObj)actors.next();
    String sanitizedActorName=CodeGeneratorAdapter.generateName(actor);
    String sanitizedActorNameForArgs=sanitizedActorName;
    Actor act=(Actor)actor;
    if (act instanceof CompositeActor)     codeStream.append(_eol + sanitizedActorName + "String_Node_Str");
 else     if (act instanceof ModalController) {
      continue;
    }
 else {
      args.clear();
      enumString=_eol + "String_Node_Str";
      inputPortList=act.inputPortList();
      outputPortList=act.outputPortList();
      ports=inputPortList.iterator();
      j=0;
      while (ports.hasNext()) {
        TypedIOPort port=(TypedIOPort)ports.next();
        if (!port.isOutsideConnected())         continue;
        args.clear();
        args.add(sanitizedActorNameForArgs);
        args.add(Integer.toString(j++));
        args.add("String_Node_Str" + port.getName() + "String_Node_Str");
        args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
        args.add(Boolean.toString(port.isInput()));
        args.add(Boolean.toString(port.isOutput()));
        args.add(Boolean.toString(port.isMultiport()));
        args.add(Integer.toString(port.getWidth()));
        args.add(Integer.toString(0));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
        enumString+="String_Node_Str" + sanitizedActorName + "String_Node_Str"+ port.getName()+ "String_Node_Str";
      }
      ports=outputPortList.iterator();
      while (ports.hasNext()) {
        TypedIOPort port=(TypedIOPort)ports.next();
        if (!port.isOutsideConnected())         continue;
        args.clear();
        args.add(sanitizedActorNameForArgs);
        args.add(Integer.toString(j++));
        args.add("String_Node_Str" + port.getName() + "String_Node_Str");
        args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
        args.add(Boolean.toString(port.isInput()));
        args.add(Boolean.toString(port.isOutput()));
        args.add(Boolean.toString(port.isMultiport()));
        args.add(Integer.toString(0));
        int widthOutside=0;
        for (        Receiver[] r : port.getRemoteReceivers())         if (r != null)         widthOutside+=r.length;
        args.add(Integer.toString(widthOutside));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
        enumString+="String_Node_Str" + sanitizedActorName + "String_Node_Str"+ port.getName()+ "String_Node_Str";
      }
      if (enumString.length() > 7) {
        enumString=enumString.substring(0,enumString.length() - 2);
        enumString+="String_Node_Str" + _eol;
        _enumPortNumbersDefinition+=enumString;
      }
    }
  }
  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 ports within the C Code. It generates the calls to IOPortSet recursively.
 * @return The generated code.
 * @exception IllegalActionException If thrown while appending to thethe block or processing the macros.
 */
public String generateConstructorPortsFunction() 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);
  StringBuffer enumString=new StringBuffer(_eol + "String_Node_Str");
  List inputPortList=TopActor.inputPortList();
  List outputPortList=TopActor.outputPortList();
  Iterator<?> ports=inputPortList.iterator();
  int j=0;
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    args.clear();
    args.add(sanitizedContainerNameForArgs);
    args.add(Integer.toString(j++));
    args.add("String_Node_Str" + port.getName() + "String_Node_Str");
    args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
    args.add(Boolean.toString(port.isInput()));
    args.add(Boolean.toString(port.isOutput()));
    args.add(Boolean.toString(port.isMultiport()));
    int widthInside=port.getWidthInside();
    int widthOutside=0;
    Receiver[][] receivers=port.deepGetReceivers();
    for (int cpt=0; cpt < receivers.length; cpt++) {
      widthOutside+=receivers[cpt].length;
    }
    args.add(Integer.toString(widthInside));
    args.add(Integer.toString(widthOutside));
    codeStream.appendCodeBlock("String_Node_Str",args,true);
    enumString.append("String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ port.getName()+ "String_Node_Str");
  }
  ports=outputPortList.iterator();
  while (ports.hasNext()) {
    TypedIOPort port=(TypedIOPort)ports.next();
    if (!port.isOutsideConnected())     continue;
    args.clear();
    args.add(sanitizedContainerNameForArgs);
    args.add(Integer.toString(j++));
    args.add("String_Node_Str" + port.getName() + "String_Node_Str");
    args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
    args.add(Boolean.toString(port.isInput()));
    args.add(Boolean.toString(port.isOutput()));
    args.add(Boolean.toString(port.isMultiport()));
    args.add(Integer.toString(port.getWidth()));
    int widthOutside=0;
    for (    Receiver[] r : port.getRemoteReceivers()) {
      if (TopActor instanceof ptolemy.cg.lib.CompiledCompositeActor)       break;
      if (r != null)       widthOutside+=r.length;
    }
    args.add(Integer.toString(widthOutside));
    codeStream.appendCodeBlock("String_Node_Str",args,true);
    enumString.append("String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ port.getName()+ "String_Node_Str");
  }
  if (enumString.length() > 7) {
    enumString.delete(enumString.length() - 2,enumString.length());
    enumString.append("String_Node_Str" + _eol);
    _enumPortNumbersDefinition+=enumString.toString();
  }
  List actorList=TopActor.deepEntityList();
  Iterator<?> actors=actorList.iterator();
  actors=actorList.iterator();
  while (actors.hasNext()) {
    NamedObj actor=(NamedObj)actors.next();
    String sanitizedActorName=CodeGeneratorAdapter.generateName(actor);
    String sanitizedActorNameForArgs=sanitizedActorName;
    Actor act=(Actor)actor;
    if (act instanceof CompositeActor)     codeStream.append(_eol + sanitizedActorName + "String_Node_Str");
 else     if (act instanceof ModalController) {
      continue;
    }
 else {
      args.clear();
      enumString=new StringBuffer(_eol + "String_Node_Str");
      inputPortList=act.inputPortList();
      outputPortList=act.outputPortList();
      ports=inputPortList.iterator();
      j=0;
      while (ports.hasNext()) {
        TypedIOPort port=(TypedIOPort)ports.next();
        if (!port.isOutsideConnected())         continue;
        args.clear();
        args.add(sanitizedActorNameForArgs);
        args.add(Integer.toString(j++));
        args.add("String_Node_Str" + port.getName() + "String_Node_Str");
        args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
        args.add(Boolean.toString(port.isInput()));
        args.add(Boolean.toString(port.isOutput()));
        args.add(Boolean.toString(port.isMultiport()));
        args.add(Integer.toString(port.getWidth()));
        args.add(Integer.toString(0));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
        enumString.append("String_Node_Str" + sanitizedActorName + "String_Node_Str"+ port.getName()+ "String_Node_Str");
      }
      ports=outputPortList.iterator();
      while (ports.hasNext()) {
        TypedIOPort port=(TypedIOPort)ports.next();
        if (!port.isOutsideConnected())         continue;
        args.clear();
        args.add(sanitizedActorNameForArgs);
        args.add(Integer.toString(j++));
        args.add("String_Node_Str" + port.getName() + "String_Node_Str");
        args.add("String_Node_Str" + getCodeGenerator().codeGenType(port.getType()) + "String_Node_Str");
        args.add(Boolean.toString(port.isInput()));
        args.add(Boolean.toString(port.isOutput()));
        args.add(Boolean.toString(port.isMultiport()));
        args.add(Integer.toString(0));
        int widthOutside=0;
        for (        Receiver[] r : port.getRemoteReceivers())         if (r != null)         widthOutside+=r.length;
        args.add(Integer.toString(widthOutside));
        codeStream.appendCodeBlock("String_Node_Str",args,true);
        enumString.append("String_Node_Str" + sanitizedActorName + "String_Node_Str"+ port.getName()+ "String_Node_Str");
      }
      if (enumString.length() > 7) {
        enumString.delete(enumString.length() - 2,enumString.length());
        enumString.append("String_Node_Str" + _eol);
        _enumPortNumbersDefinition+=enumString.toString();
      }
    }
  }
  codeStream.append(_eol + "String_Node_Str" + _eol);
  return codeStream.toString();
}