Program: 73844
Project: 73844
Buggy source:
/** 
 * Generate code for transferring enough tokens to complete an internal iteration.
 * @param inputPort 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 generateTransferInputsCode(IOPort inputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenConsumptionRate(inputPort);
  boolean targetCpp=((BooleanToken)((CCodeGenerator)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 (!(inputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(inputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)inputPort).getType();
    String portName=inputPort.getName();
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String tokensFromOneChannel="String_Node_Str" + portName + i;
        String pointerToTokensFromOneChannel="String_Node_Str" + tokensFromOneChannel;
        code.append("String_Node_Str" + tokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetObjectArrayElement(portName,String.valueOf(i),targetCpp)+ "String_Node_Str"+ _eol);
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else {
        }
        String portNameWithChannelNumber=portName;
        if (inputPort.isMultiport()) {
          portNameWithChannelNumber=portName + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(compositeActorAdapter.getReference("String_Node_Str" + portNameWithChannelNumber + "String_Node_Str"+ k));
          if (type == PointerToken.POINTER) {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str"+ _eol);
          }
 else {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str"+ _eol);
          }
        }
        if (type == BaseType.INT) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else {
        }
      }
    }
  }
 else {
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String name=inputPort.getName();
        if (inputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k));
          code.append("String_Node_Str" + _eol);
          code.append(compositeActorAdapter.getReference(name + "String_Node_Str" + k));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  code.append(compositeActorAdapter.generateTypeConvertFireCode(true));
  _updateConnectedPortsOffset(inputPort,code,rate);
}

Fixed version (ground truth):
/** 
 * Generate code for transferring enough tokens to complete an internal iteration.
 * @param inputPort 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 generateTransferInputsCode(IOPort inputPort,StringBuffer code) throws IllegalActionException {
  code.append(CodeStream.indent(getCodeGenerator().comment("String_Node_Str" + "String_Node_Str")));
  int rate=DFUtilities.getTokenConsumptionRate(inputPort);
  boolean targetCpp=((BooleanToken)((CCodeGenerator)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 (!(inputPort instanceof TypedIOPort)) {
      throw new InternalErrorException(inputPort,null,"String_Node_Str");
    }
    Type type=((TypedIOPort)inputPort).getType();
    String portName=inputPort.getName();
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String tokensFromOneChannel="String_Node_Str" + portName + i;
        String pointerToTokensFromOneChannel="String_Node_Str" + tokensFromOneChannel;
        code.append("String_Node_Str" + tokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetObjectArrayElement(portName,String.valueOf(i),targetCpp)+ "String_Node_Str"+ _eol);
        if (type == BaseType.INT) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ CCodegenUtilities.jniGetArrayElements("String_Node_Str",tokensFromOneChannel,targetCpp)+ "String_Node_Str"+ _eol);
        }
 else {
        }
        String portNameWithChannelNumber=portName;
        if (inputPort.isMultiport()) {
          portNameWithChannelNumber=portName + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(compositeActorAdapter.getReference("String_Node_Str" + portNameWithChannelNumber + "String_Node_Str"+ k,false));
          if (type == PointerToken.POINTER) {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str"+ _eol);
          }
 else {
            code.append("String_Node_Str" + pointerToTokensFromOneChannel + "String_Node_Str"+ k+ "String_Node_Str"+ _eol);
          }
        }
        if (type == BaseType.INT) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.DOUBLE) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == PointerToken.POINTER) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else         if (type == BaseType.BOOLEAN) {
          code.append(CCodegenUtilities.jniReleaseArrayElements("String_Node_Str",tokensFromOneChannel,pointerToTokensFromOneChannel,targetCpp) + "String_Node_Str" + _eol);
        }
 else {
        }
      }
    }
  }
 else {
    for (int i=0; i < inputPort.getWidth(); i++) {
      if (i < inputPort.getWidthInside()) {
        String name=inputPort.getName();
        if (inputPort.isMultiport()) {
          name=name + '#' + i;
        }
        for (int k=0; k < rate; k++) {
          code.append(compositeActorAdapter.getReference("String_Node_Str" + name + "String_Node_Str"+ k,false));
          code.append("String_Node_Str" + _eol);
          code.append(compositeActorAdapter.getReference(name + "String_Node_Str" + k,false));
          code.append("String_Node_Str" + _eol);
        }
      }
    }
  }
  code.append(compositeActorAdapter.generateTypeConvertFireCode(true));
  _updateConnectedPortsOffset(inputPort,code,rate);
}