Program: 73847
Project: 73847
Buggy source:
/** 
 * Generate the code for the firing of actors according to the SDF schedule.
 * @return The generated fire code.
 * @exception IllegalActionException If the SDF director does not have anattribute called "iterations" or a valid schedule, or the actor to be fired cannot find its associated adapter.
 */
public String generateFireCode() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str")));
  boolean inline=((BooleanToken)getCodeGenerator().inline.getToken()).booleanValue();
  ptolemy.actor.sched.StaticSchedulingDirector director=(ptolemy.actor.sched.StaticSchedulingDirector)getComponent();
  Schedule schedule=director.getScheduler().getSchedule();
  Iterator<?> actorsToFire=schedule.firingIterator();
  while (actorsToFire.hasNext()) {
    Firing firing=(Firing)actorsToFire.next();
    Actor actor=firing.getActor();
    NamedProgramCodeGeneratorAdapter adapter=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(actor);
    if (actor instanceof ModularCodeGenTypedCompositeActor || actor instanceof ModularCompiledSDFTypedCompositeActor) {
      String className=NamedProgramCodeGeneratorAdapter.generateName((NamedObj)actor);
      String actorName=ModularCodeGenTypedCompositeActor.classToActorName(className);
      NamedProgramCodeGeneratorAdapter codegeneratorAdaptor=(NamedProgramCodeGeneratorAdapter)getAdapter((NamedObj)actor);
      code.append("String_Node_Str" + _eol);
      Iterator<?> inputPorts=actor.inputPortList().iterator();
      while (inputPorts.hasNext()) {
        TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
        String type=ptolemy.cg.kernel.generic.program.procedural.java.JavaCodeGenerator.codeGenType2(inputPort.getType());
        for (int i=0; i < inputPort.getWidth(); i++) {
          if (DFUtilities.getTokenConsumptionRate(inputPort) > 1) {
            code.append(type + "String_Node_Str" + actorName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ i+ "String_Node_Str"+ type+ "String_Node_Str"+ DFUtilities.getTokenConsumptionRate(inputPort)+ "String_Node_Str"+ _eol);
          }
 else {
            code.append(type + "String_Node_Str" + actorName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ i+ "String_Node_Str"+ _eol);
          }
        }
      }
      for (int j=0; j < firing.getIterationCount(); j++) {
        inputPorts=actor.inputPortList().iterator();
        while (inputPorts.hasNext()) {
          TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
          String portName=inputPort.getName();
          int rate=DFUtilities.getTokenConsumptionRate(inputPort);
          for (int i=0; i < inputPort.getWidth(); i++) {
            if (i < inputPort.getWidthInside()) {
              String portNameWithChannelNumber=portName;
              if (inputPort.isMultiport()) {
                portNameWithChannelNumber=portName + '#' + i;
              }
              if (rate > 1) {
                for (int k=0; k < rate; k++) {
                  code.append(actorName + "String_Node_Str" + portName+ "String_Node_Str"+ i+ "String_Node_Str"+ k+ "String_Node_Str");
                  code.append(codegeneratorAdaptor.getReference(portNameWithChannelNumber + "String_Node_Str" + k,true));
                  code.append("String_Node_Str" + _eol);
                }
              }
 else {
                code.append(actorName + "String_Node_Str" + portName+ "String_Node_Str"+ i);
                code.append("String_Node_Str" + codegeneratorAdaptor.getReference(portNameWithChannelNumber,true) + "String_Node_Str"+ _eol);
              }
            }
          }
        }
        code.append(actorName + "String_Node_Str");
        inputPorts=actor.inputPortList().iterator();
        boolean addComma=false;
        while (inputPorts.hasNext()) {
          TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
          for (int i=0; i < inputPort.getWidth(); i++) {
            if (addComma) {
              code.append("String_Node_Str");
            }
            code.append(actorName + "String_Node_Str" + inputPort.getName()+ "String_Node_Str"+ i);
            addComma=true;
          }
        }
        code.append("String_Node_Str" + _eol);
        _generateUpdatePortOffsetCode(code,actor);
        Iterator<?> outputPorts=actor.outputPortList().iterator();
        while (outputPorts.hasNext()) {
          TypedIOPort outputPort=(TypedIOPort)outputPorts.next();
          int rate=DFUtilities.getTokenProductionRate(outputPort);
          for (int i=0; i < outputPort.getWidth(); i++) {
            if (rate <= 1) {
              code.append(codegeneratorAdaptor.getReference(outputPort.getName() + "String_Node_Str" + i,true) + "String_Node_Str" + actorName+ "String_Node_Str"+ codegeneratorAdaptor.getReference("String_Node_Str" + outputPort.getName() + "String_Node_Str"+ i,false)+ "String_Node_Str"+ _eol);
            }
 else {
              for (int k=0; k < rate; k++) {
                code.append(codegeneratorAdaptor.getReference(outputPort.getName() + "String_Node_Str" + i+ "String_Node_Str"+ k,true) + "String_Node_Str" + actorName+ "String_Node_Str"+ codegeneratorAdaptor.getReference("String_Node_Str" + outputPort.getName() + "String_Node_Str"+ i+ "String_Node_Str"+ k,false)+ "String_Node_Str"+ _eol);
              }
            }
          }
        }
      }
      code.append("String_Node_Str" + _eol);
    }
 else {
      if (inline) {
        for (int i=0; i < firing.getIterationCount(); i++) {
          code.append(adapter.generateFireCode());
          _generateUpdatePortOffsetCode(code,actor);
        }
      }
 else {
        int count=firing.getIterationCount();
        if (count > 1) {
          code.append("String_Node_Str" + count + "String_Node_Str"+ _eol);
        }
        code.append(generateName((NamedObj)actor) + "String_Node_Str" + _eol);
        _generateUpdatePortOffsetCode(code,actor);
        if (count > 1) {
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  return code.toString();
}

Fixed version (ground truth):
/** 
 * Generate the code for the firing of actors according to the SDF schedule.
 * @return The generated fire code.
 * @exception IllegalActionException If the SDF director does not have anattribute called "iterations" or a valid schedule, or the actor to be fired cannot find its associated adapter.
 */
public String generateFireCode() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str")));
  boolean inline=((BooleanToken)getCodeGenerator().inline.getToken()).booleanValue();
  ptolemy.actor.sched.StaticSchedulingDirector director=(ptolemy.actor.sched.StaticSchedulingDirector)getComponent();
  Schedule schedule=director.getScheduler().getSchedule();
  Iterator<?> actorsToFire=schedule.firingIterator();
  while (actorsToFire.hasNext()) {
    Firing firing=(Firing)actorsToFire.next();
    Actor actor=firing.getActor();
    NamedProgramCodeGeneratorAdapter adapter=(NamedProgramCodeGeneratorAdapter)getCodeGenerator().getAdapter(actor);
    if (actor instanceof ModularCodeGenTypedCompositeActor || actor instanceof ModularCompiledSDFTypedCompositeActor) {
      String className=NamedProgramCodeGeneratorAdapter.generateName((NamedObj)actor);
      String actorName=ModularCodeGenTypedCompositeActor.classToActorName(className);
      NamedProgramCodeGeneratorAdapter codegeneratorAdaptor=(NamedProgramCodeGeneratorAdapter)getAdapter((NamedObj)actor);
      code.append("String_Node_Str" + _eol);
      Iterator<?> inputPorts=actor.inputPortList().iterator();
      while (inputPorts.hasNext()) {
        TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
        String type=ptolemy.cg.kernel.generic.program.procedural.java.JavaCodeGenerator.codeGenType2(inputPort.getType());
        for (int i=0; i < inputPort.getWidth(); i++) {
          if (DFUtilities.getTokenConsumptionRate(inputPort) > 1) {
            code.append(type + "String_Node_Str" + actorName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ i+ "String_Node_Str"+ type+ "String_Node_Str"+ DFUtilities.getTokenConsumptionRate(inputPort)+ "String_Node_Str"+ _eol);
          }
 else {
            code.append(type + "String_Node_Str" + actorName+ "String_Node_Str"+ inputPort.getName()+ "String_Node_Str"+ i+ "String_Node_Str"+ _eol);
          }
        }
      }
      for (int j=0; j < firing.getIterationCount(); j++) {
        inputPorts=actor.inputPortList().iterator();
        while (inputPorts.hasNext()) {
          TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
          String portName=inputPort.getName();
          int rate=DFUtilities.getTokenConsumptionRate(inputPort);
          for (int i=0; i < inputPort.getWidth(); i++) {
            if (i < inputPort.getWidthInside()) {
              String portNameWithChannelNumber=portName;
              if (inputPort.isMultiport()) {
                portNameWithChannelNumber=portName + '#' + i;
              }
              if (rate > 1) {
                for (int k=0; k < rate; k++) {
                  code.append(actorName + "String_Node_Str" + portName+ "String_Node_Str"+ i+ "String_Node_Str"+ k+ "String_Node_Str");
                  code.append(codegeneratorAdaptor.getReference(portNameWithChannelNumber + "String_Node_Str" + k,true));
                  code.append("String_Node_Str" + _eol);
                }
              }
 else {
                code.append(actorName + "String_Node_Str" + portName+ "String_Node_Str"+ i);
                code.append("String_Node_Str" + codegeneratorAdaptor.getReference(portNameWithChannelNumber,true) + "String_Node_Str"+ _eol);
              }
            }
          }
        }
        code.append(actorName + "String_Node_Str");
        inputPorts=actor.inputPortList().iterator();
        boolean addComma=false;
        while (inputPorts.hasNext()) {
          TypedIOPort inputPort=(TypedIOPort)inputPorts.next();
          for (int i=0; i < inputPort.getWidth(); i++) {
            if (addComma) {
              code.append("String_Node_Str");
            }
            code.append(actorName + "String_Node_Str" + inputPort.getName()+ "String_Node_Str"+ i);
            addComma=true;
          }
        }
        code.append("String_Node_Str" + _eol);
        Iterator<?> outputPorts=actor.outputPortList().iterator();
        while (outputPorts.hasNext()) {
          TypedIOPort outputPort=(TypedIOPort)outputPorts.next();
          int rate=DFUtilities.getTokenProductionRate(outputPort);
          for (int i=0; i < outputPort.getWidth(); i++) {
            if (rate <= 1) {
              code.append(codegeneratorAdaptor.getReference(outputPort.getName() + "String_Node_Str" + i,true) + "String_Node_Str" + actorName+ "String_Node_Str"+ codegeneratorAdaptor.getReference("String_Node_Str" + outputPort.getName() + "String_Node_Str"+ i,false)+ "String_Node_Str"+ _eol);
            }
 else {
              for (int k=0; k < rate; k++) {
                code.append(codegeneratorAdaptor.getReference(outputPort.getName() + "String_Node_Str" + i+ "String_Node_Str"+ k,true) + "String_Node_Str" + actorName+ "String_Node_Str"+ codegeneratorAdaptor.getReference("String_Node_Str" + outputPort.getName() + "String_Node_Str"+ i+ "String_Node_Str"+ k,false)+ "String_Node_Str"+ _eol);
              }
            }
          }
        }
        _generateUpdatePortOffsetCode(code,actor);
      }
      code.append("String_Node_Str" + _eol);
    }
 else {
      if (inline) {
        for (int i=0; i < firing.getIterationCount(); i++) {
          code.append(adapter.generateFireCode());
          _generateUpdatePortOffsetCode(code,actor);
        }
      }
 else {
        int count=firing.getIterationCount();
        if (count > 1) {
          code.append("String_Node_Str" + count + "String_Node_Str"+ _eol);
        }
        code.append(generateName((NamedObj)actor) + "String_Node_Str" + _eol);
        _generateUpdatePortOffsetCode(code,actor);
        if (count > 1) {
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  return code.toString();
}