Program: 72901
Project: 72901
Buggy source:
/** 
 * Generate code for transferring enough tokens to fulfill the output production rate.
 * @param outputPort The port to transfer tokens.
 * @param code The string buffer that the generated code is appended to.
 * @exception IllegalActionException If thrown while transferring tokens.
 */
public void generateTransferOutputsCode(IOPort outputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenProductionRate(outputPort);
  boolean targetCpp=((BooleanToken)getCodeGenerator().generateCpp.getToken()).booleanValue();
  CompositeActor container=(CompositeActor)getComponent().getContainer();
  TypedCompositeActor compositeActorAdapter=(TypedCompositeActor)getCodeGenerator().getAdapter(container);
  if (container instanceof CompiledCompositeActor && ((BooleanToken)getCodeGenerator().generateEmbeddedCode.getToken()).booleanValue()) {
    if (_portNumber == 0) {
      int numberOfOutputPorts=container.outputPortList().size();
      code.append("String_Node_Str" + _objClass + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
      code.append("String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfOutputPorts),"String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
    }
    String portName=outputPort.getName();
    String tokensToThisPort="String_Node_Str" + portName;
    if (!(outputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(outputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)outputPort).getType();
    String exceptionMessage="String_Node_Str" + "String_Node_Str" + "String_Node_Str" + outputPort.getName() + "String_Node_Str"+ type+ "String_Node_Str"+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ "String_Node_Str";
    int numberOfChannels=outputPort.getWidthInside();
    code.append("String_Node_Str" + tokensToThisPort + "String_Node_Str"+ _eol);
    if (type == BaseType.INT) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.DOUBLE) {
      if (!_doubleFlag) {
        code.append("String_Node_Str" + _objClassD + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _doubleFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassD,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == PointerToken.POINTER) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.BOOLEAN) {
      if (!_booleanFlag) {
        code.append("String_Node_Str" + CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
        _booleanFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),"String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
    }
 else {
      throw new IllegalActionException(outputPort,exceptionMessage);
    }
    System.out.println("String_Node_Str" + outputPort.getWidthInside());
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      String tokensToOneChannel="String_Node_Str" + portName;
      if (i == 0) {
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else {
          throw new IllegalActionException(outputPort,exceptionMessage);
        }
      }
      String portNameWithChannelNumber=portName;
      if (outputPort.isMultiport()) {
        portNameWithChannelNumber=portName + '#' + i;
      }
      for (int k=0; k < rate; k++) {
        if (type == PointerToken.POINTER) {
          code.append(tokensToOneChannel + "String_Node_Str" + k+ "String_Node_Str");
        }
 else {
          code.append(tokensToOneChannel + "String_Node_Str" + k+ "String_Node_Str");
        }
        code.append("String_Node_Str" + portNameWithChannelNumber + "String_Node_Str"+ _eol);
      }
      String tokensToOneChannelArray="String_Node_Str" + portName + i;
      if (type == BaseType.INT) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.DOUBLE) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == PointerToken.POINTER) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.BOOLEAN) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else {
        throw new IllegalActionException(outputPort,exceptionMessage);
      }
      code.append(CCodegenUtilities.jniSetObjectArrayElement(tokensToThisPort,String.valueOf(i),tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
      code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
    }
    code.append(CCodegenUtilities.jniSetObjectArrayElement("String_Node_Str",String.valueOf(_portNumber),tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    _portNumber++;
  }
 else {
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      if (i < outputPort.getWidth()) {
        String name=outputPort.getName();
        if (outputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(CodeStream.indent(compositeActorAdapter.getReference(name + "String_Node_Str" + k,false)));
          code.append("String_Node_Str" + _eol);
          code.append(CodeStream.indent(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k,false)));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Generate code for transferring enough tokens to fulfill the output production rate.
 * @param outputPort The port to transfer tokens.
 * @param code The string buffer that the generated code is appended to.
 * @exception IllegalActionException If thrown while transferring tokens.
 */
public void generateTransferOutputsCode(IOPort outputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenProductionRate(outputPort);
  boolean targetCpp=((BooleanToken)getCodeGenerator().generateCpp.getToken()).booleanValue();
  CompositeActor container=(CompositeActor)getComponent().getContainer();
  TypedCompositeActor compositeActorAdapter=(TypedCompositeActor)getCodeGenerator().getAdapter(container);
  if (container instanceof CompiledCompositeActor && ((BooleanToken)getCodeGenerator().generateEmbeddedCode.getToken()).booleanValue()) {
    if (_portNumber == 0) {
      int numberOfOutputPorts=container.outputPortList().size();
      code.append("String_Node_Str" + _objClass + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
      code.append("String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfOutputPorts),"String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
    }
    String portName=outputPort.getName();
    String tokensToThisPort="String_Node_Str" + portName;
    if (!(outputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(outputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)outputPort).getType();
    String exceptionMessage="String_Node_Str" + "String_Node_Str" + "String_Node_Str" + outputPort.getName() + "String_Node_Str"+ type+ "String_Node_Str"+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ "String_Node_Str";
    int numberOfChannels=outputPort.getWidthInside();
    code.append("String_Node_Str" + tokensToThisPort + "String_Node_Str"+ _eol);
    if (type == BaseType.INT) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.DOUBLE) {
      if (!_doubleFlag) {
        code.append("String_Node_Str" + _objClassD + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _doubleFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassD,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == PointerToken.POINTER) {
      if (!_intFlag) {
        code.append("String_Node_Str" + _objClassI + "String_Node_Str"+ CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
        _intFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),_objClassI,targetCpp)+ "String_Node_Str"+ _eol);
    }
 else     if (type == BaseType.BOOLEAN) {
      if (!_booleanFlag) {
        code.append("String_Node_Str" + CCodegenUtilities.jniFindClass("String_Node_Str",targetCpp) + "String_Node_Str"+ _eol);
        _booleanFlag=true;
      }
      code.append(tokensToThisPort + "String_Node_Str" + CCodegenUtilities.jniNewObjectArray(String.valueOf(numberOfChannels),"String_Node_Str",targetCpp)+ "String_Node_Str"+ _eol);
    }
 else {
      throw new IllegalActionException(outputPort,exceptionMessage);
    }
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      String tokensToOneChannel="String_Node_Str" + portName;
      if (i == 0) {
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + tokensToOneChannel + "String_Node_Str"+ rate+ "String_Node_Str"+ _eol);
        }
 else {
          throw new IllegalActionException(outputPort,exceptionMessage);
        }
      }
      String portNameWithChannelNumber=portName;
      if (outputPort.isMultiport()) {
        portNameWithChannelNumber=portName + '#' + i;
      }
      for (int k=0; k < rate; k++) {
        String sanitizedContainerName=CodeGeneratorAdapter.generateName(container);
        String hasTokenString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ i+ "String_Node_Str"+ _eol;
        code.append(hasTokenString);
        String getString="String_Node_Str" + sanitizedContainerName + "String_Node_Str"+ sanitizedContainerName+ "String_Node_Str"+ outputPort.getName()+ "String_Node_Str"+ i+ "String_Node_Str";
        if (type == BaseType.INT)         getString+="String_Node_Str";
 else         if (type == BaseType.DOUBLE)         getString+="String_Node_Str";
 else         if (type == BaseType.BOOLEAN)         getString+="String_Node_Str";
 else         throw new IllegalActionException(outputPort,exceptionMessage);
        code.append(_eol + tokensToOneChannel + "String_Node_Str"+ k+ "String_Node_Str"+ getString+ _eol);
      }
      String tokensToOneChannelArray="String_Node_Str" + portName + i;
      if (type == BaseType.INT) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.DOUBLE) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == PointerToken.POINTER) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else       if (type == BaseType.BOOLEAN) {
        code.append("String_Node_Str" + tokensToOneChannelArray + "String_Node_Str"+ CCodegenUtilities.jniNewArray("String_Node_Str",String.valueOf(rate),targetCpp)+ "String_Node_Str"+ _eol);
        code.append(CCodegenUtilities.jniSetArrayRegion("String_Node_Str",tokensToOneChannelArray,"String_Node_Str",String.valueOf(rate),tokensToOneChannel,targetCpp) + "String_Node_Str" + _eol);
      }
 else {
        throw new IllegalActionException(outputPort,exceptionMessage);
      }
      code.append(CCodegenUtilities.jniSetObjectArrayElement(tokensToThisPort,String.valueOf(i),tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
      code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToOneChannelArray,targetCpp) + "String_Node_Str" + _eol);
    }
    code.append(CCodegenUtilities.jniSetObjectArrayElement("String_Node_Str",String.valueOf(_portNumber),tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    code.append(CCodegenUtilities.jniDeleteLocalRef(tokensToThisPort,targetCpp) + "String_Node_Str" + _eol);
    _portNumber++;
  }
 else {
    for (int i=0; i < outputPort.getWidthInside(); i++) {
      if (i < outputPort.getWidth()) {
        String name=outputPort.getName();
        if (outputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(CodeStream.indent(compositeActorAdapter.getReference(name + "String_Node_Str" + k,false)));
          code.append("String_Node_Str" + _eol);
          code.append(CodeStream.indent(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k,false)));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
}