Program: 72874
Project: 72874
Buggy source:
/** 
 * Generate type conversion code. Determine the proper code put into the source to support dynamic type resolution. First, find out the different types used in the model. Second, find out the different polymorphic functions used. (note: types and functions are independent of each other). Third, append code blocks according to the functions used, and read from files according to the types referenced. Fourth, generate type resolution code, which consists of constants (MAX_NUM_TYPE, MAX_NUM_FUNC), the type map, the function map, function definitions read from the files, and function table. Note that this method is really different from the super one because it splits the code in a .c part and a .h part.
 * @return The type resolution code.
 * @exception IllegalActionException If an error occurs when generatingthe type resolution code, or if the adapter class for the model director cannot be found, or if an error occurs when the adapter actor generates the type resolution code.
 */
public String[] generateTypeConvertCodeCandH() throws IllegalActionException {
  StringBuffer codeH=new StringBuffer();
  StringBuffer codeC=new StringBuffer();
  codeC.append("String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + comment("String_Node_Str" + getContainer().getFullName()));
  codeC.append(_eol + comment("String_Node_Str" + getContainer().getFullName()));
  CodeStream sharedStream=new CodeStream("String_Node_Str",this);
  sharedStream.appendCodeBlock("String_Node_Str");
  codeH.append(sharedStream.toString());
  HashSet<String> functions=_getReferencedFunctions();
  HashSet<String> types=_getTypeIDToUsed(_getNewTypesUsed(functions));
  String[] typesArray=new String[types.size()];
  types.toArray(typesArray);
  CodeStream[] typeStreams=new CodeStream[types.size()];
  StringBuffer typeMembers=new StringBuffer();
  codeH.append("String_Node_Str" + _eol);
  codeH.append("String_Node_Str" + _eol);
  codeH.append("String_Node_Str" + _eol);
  for (int i=0; i < typesArray.length; i++) {
    if (typesArray[i].endsWith("String_Node_Str")) {
      typeStreams[i]=new CodeStream("String_Node_Str" + typesArray[i].substring(0,typesArray[i].indexOf("String_Node_Str")) + "String_Node_Str",this);
    }
 else {
      typeStreams[i]=new CodeStream("String_Node_Str" + typesArray[i] + "String_Node_Str",this);
      codeH.append("String_Node_Str" + typesArray[i] + "String_Node_Str"+ i+ _eol);
      typeMembers.append(typesArray[i] + "String_Node_Str" + typesArray[i]+ "String_Node_Str");
      if (i < typesArray.length - 1) {
        typeMembers.append(_eol);
      }
    }
  }
  String[] functionsArray=new String[functions.size()];
  functions.toArray(functionsArray);
  boolean defineEmptyToken=false;
  int offset=0;
  for (int i=0; i < functionsArray.length; i++) {
    if (functionsArray[i].equals("String_Node_Str")) {
      offset=1;
    }
 else {
      codeH.append("String_Node_Str" + functionsArray[i] + "String_Node_Str"+ (i - offset)+ _eol);
      if (functionsArray[i].equals("String_Node_Str")) {
        defineEmptyToken=true;
      }
    }
  }
  codeH.append("String_Node_Str" + _eol);
  for (int i=0; i < typesArray.length; i++) {
    typeStreams[i].appendCodeBlock("String_Node_Str");
    codeH.append(typeStreams[i].toString());
  }
  ArrayList<String> args=new ArrayList<String>();
  ArrayList<String> functionsDeclared=new ArrayList<String>();
  if (typeMembers.length() != 0) {
    sharedStream.clear();
    args.add(typeMembers.toString());
    sharedStream.appendCodeBlock("String_Node_Str",args);
    if (defineEmptyToken) {
      sharedStream.append("String_Node_Str" + comment("String_Node_Str") + _eol);
    }
    codeH.append(sharedStream.toString());
  }
  boolean defineUnsupportedTypeFunctionMethod=false;
  boolean defineScalarDeleteMethod=false;
  StringBuffer convertImplementation=new StringBuffer(_eol + "String_Node_Str" + _eol);
  convertImplementation.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol);
  String convertDeclaration=_eol + "String_Node_Str" + _eol;
  codeH.append(convertDeclaration);
  for (int i=0; i < typesArray.length; i++) {
    typeStreams[i].clear();
    typeStreams[i].appendCodeBlock("String_Node_Str");
    codeH.append(typeStreams[i].toString());
    typeStreams[i].clear();
    typeStreams[i].appendCodeBlock("String_Node_Str",true);
    codeC.append(typeStreams[i].toString());
    convertImplementation.append(_eol + "String_Node_Str" + typesArray[i]+ "String_Node_Str");
    convertImplementation.append(_eol + "String_Node_Str" + typesArray[i]+ "String_Node_Str"+ _eol+ "String_Node_Str");
  }
  convertImplementation.append(_eol + "String_Node_Str" + _eol+ "String_Node_Str"+ _eol);
  codeC.append(convertImplementation.toString());
  sharedStream.clear();
  sharedStream.appendCodeBlock("String_Node_Str");
  codeH.append(sharedStream.toString());
  sharedStream.clear();
  sharedStream.appendCodeBlock("String_Node_Str");
  codeC.append(sharedStream.toString());
  sharedStream.clear();
  StringBuffer typeFunctionCode=new StringBuffer();
  for (int i=0; i < typesArray.length; i++) {
    typeStreams[i].clear();
    if (typesArray[i].endsWith("String_Node_Str")) {
      continue;
    }
    for (    String element : functionsArray) {
      String functionName=typesArray[i] + "String_Node_Str" + element;
      try {
        if (element.equals("String_Node_Str") && (typesArray[i].equals("String_Node_Str") || typesArray[i].equals("String_Node_Str"))) {
          if (!functions.contains("String_Node_Str")) {
            markFunctionCalled(typesArray[i] + "String_Node_Str",null);
          }
        }
 else {
          if (!_unsupportedTypeFunctions.contains(functionName) && !_overloadedFunctionSet.contains(functionName)) {
            markFunctionCalled(functionName,null);
          }
        }
      }
 catch (      IllegalActionException ex) {
        typeStreams[i].append("String_Node_Str" + functionName + "String_Node_Str"+ _eol);
        _unsupportedTypeFunctions.add(functionName);
        System.out.println("String_Node_Str" + functionName + "String_Node_Str");
      }
    }
    typeFunctionCode.append(processCode(typeStreams[i].toString()));
  }
  for (int i=0; i < types.size(); i++) {
    if (typesArray[i].endsWith("String_Node_Str"))     continue;
    for (int j=0; j < functionsArray.length; j++) {
      String functionName=typesArray[i] + "String_Node_Str" + functionsArray[j];
      if (_unsupportedTypeFunctions.contains(functionName)) {
        defineUnsupportedTypeFunctionMethod=true;
      }
      if (_scalarDeleteTypes.contains(typesArray[i]) && functionsArray[j].equals("String_Node_Str")) {
        defineScalarDeleteMethod=true;
      }
      if (functionsArray[j].equals("String_Node_Str") && (typesArray[i].equals("String_Node_Str") || typesArray[i].equals("String_Node_Str"))) {
        boolean foundEquals=false;
        for (        String element : functionsArray) {
          if (element.equals("String_Node_Str")) {
            foundEquals=true;
          }
        }
        if (!foundEquals) {
          args.clear();
          functionName=typesArray[i] + "String_Node_Str";
          if (!_unsupportedTypeFunctions.contains(functionName)) {
            args.add(functionName);
            functionsDeclared.add(functionName);
            sharedStream.appendCodeBlock("String_Node_Str",args);
          }
        }
      }
      if (!_scalarDeleteTypes.contains(typesArray[i]) || !functionsArray[j].equals("String_Node_Str")) {
        args.clear();
        if (!_unsupportedTypeFunctions.contains(functionName) && !functionName.endsWith("String_Node_Str")) {
          args.add(functionName);
          functionsDeclared.add(functionName);
          sharedStream.append("String_Node_Str" + _eol);
          sharedStream.appendCodeBlock("String_Node_Str",args);
        }
      }
    }
  }
  codeH.append(sharedStream.toString());
  sharedStream.clear();
  if (defineUnsupportedTypeFunctionMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  if (defineScalarDeleteMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  codeC.append(sharedStream.toString());
  sharedStream.clear();
  if (defineUnsupportedTypeFunctionMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  if (defineScalarDeleteMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  codeH.append(sharedStream.toString());
  codeC.append(_overloadedFunctions.toString());
  codeH.append(_overloadedFunctionsDeclaration.toString());
  codeC.append(generateFunctionTable(typesArray,functionsArray));
  codeH.append("String_Node_Str" + typesArray.length + _eol);
  codeH.append("String_Node_Str" + functionsArray.length + _eol);
  codeH.append("String_Node_Str" + "String_Node_Str" + _eol);
  codeH.append(typeFunctionCode);
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  String[] result=new String[2];
  result[0]=processCode(codeH.toString());
  result[1]=processCode(codeC.toString());
  return result;
}

Fixed version (ground truth):
/** 
 * Generate type conversion code. Determine the proper code put into the source to support dynamic type resolution. First, find out the different types used in the model. Second, find out the different polymorphic functions used. (note: types and functions are independent of each other). Third, append code blocks according to the functions used, and read from files according to the types referenced. Fourth, generate type resolution code, which consists of constants (MAX_NUM_TYPE, MAX_NUM_FUNC), the type map, the function map, function definitions read from the files, and function table. Note that this method is really different from the super one because it splits the code in a .c part and a .h part.
 * @return The type resolution code.
 * @exception IllegalActionException If an error occurs when generatingthe type resolution code, or if the adapter class for the model director cannot be found, or if an error occurs when the adapter actor generates the type resolution code.
 */
public String[] generateTypeConvertCodeCandH() throws IllegalActionException {
  StringBuffer codeH=new StringBuffer();
  StringBuffer codeC=new StringBuffer();
  codeC.append("String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + comment("String_Node_Str" + getContainer().getFullName()));
  codeC.append(_eol + comment("String_Node_Str" + getContainer().getFullName()));
  CodeStream sharedStream=new CodeStream("String_Node_Str",this);
  sharedStream.appendCodeBlock("String_Node_Str");
  codeH.append(sharedStream.toString());
  HashSet<String> functions=_getReferencedFunctions();
  HashSet<String> types=_getTypeIDToUsed(_getNewTypesUsed(functions));
  String[] typesArray=new String[types.size()];
  types.toArray(typesArray);
  CodeStream[] typeStreams=new CodeStream[types.size()];
  StringBuffer typeMembers=new StringBuffer();
  codeH.append("String_Node_Str" + _eol);
  codeH.append("String_Node_Str" + _eol);
  if (!types.contains("String_Node_Str"))   codeH.append("String_Node_Str" + _eol);
  for (int i=0; i < typesArray.length; i++) {
    if (typesArray[i].endsWith("String_Node_Str")) {
      typeStreams[i]=new CodeStream("String_Node_Str" + typesArray[i].substring(0,typesArray[i].indexOf("String_Node_Str")) + "String_Node_Str",this);
    }
 else {
      typeStreams[i]=new CodeStream("String_Node_Str" + typesArray[i] + "String_Node_Str",this);
      codeH.append("String_Node_Str" + typesArray[i] + "String_Node_Str"+ i+ _eol);
      typeMembers.append(typesArray[i] + "String_Node_Str" + typesArray[i]+ "String_Node_Str");
      if (i < typesArray.length - 1) {
        typeMembers.append(_eol);
      }
    }
  }
  String[] functionsArray=new String[functions.size()];
  functions.toArray(functionsArray);
  boolean defineEmptyToken=false;
  int offset=0;
  for (int i=0; i < functionsArray.length; i++) {
    if (functionsArray[i].equals("String_Node_Str")) {
      offset=1;
    }
 else {
      codeH.append("String_Node_Str" + functionsArray[i] + "String_Node_Str"+ (i - offset)+ _eol);
      if (functionsArray[i].equals("String_Node_Str")) {
        defineEmptyToken=true;
      }
    }
  }
  codeH.append("String_Node_Str" + _eol);
  for (int i=0; i < typesArray.length; i++) {
    typeStreams[i].appendCodeBlock("String_Node_Str");
    codeH.append(typeStreams[i].toString());
  }
  ArrayList<String> args=new ArrayList<String>();
  ArrayList<String> functionsDeclared=new ArrayList<String>();
  if (typeMembers.length() != 0) {
    sharedStream.clear();
    args.add(typeMembers.toString());
    sharedStream.appendCodeBlock("String_Node_Str",args);
    if (defineEmptyToken) {
      sharedStream.append("String_Node_Str" + comment("String_Node_Str") + _eol);
    }
    codeH.append(sharedStream.toString());
  }
  boolean defineUnsupportedTypeFunctionMethod=false;
  boolean defineScalarDeleteMethod=false;
  StringBuffer convertImplementation=new StringBuffer(_eol + "String_Node_Str" + _eol);
  convertImplementation.append("String_Node_Str" + _eol + "String_Node_Str"+ _eol);
  String convertDeclaration=_eol + "String_Node_Str" + _eol;
  codeH.append(convertDeclaration);
  for (int i=0; i < typesArray.length; i++) {
    typeStreams[i].clear();
    typeStreams[i].appendCodeBlock("String_Node_Str");
    codeH.append(typeStreams[i].toString());
    typeStreams[i].clear();
    typeStreams[i].appendCodeBlock("String_Node_Str",true);
    codeC.append(typeStreams[i].toString());
    convertImplementation.append(_eol + "String_Node_Str" + typesArray[i]+ "String_Node_Str");
    convertImplementation.append(_eol + "String_Node_Str" + typesArray[i]+ "String_Node_Str"+ _eol+ "String_Node_Str");
  }
  convertImplementation.append(_eol + "String_Node_Str" + _eol+ "String_Node_Str"+ _eol);
  codeC.append(convertImplementation.toString());
  sharedStream.clear();
  sharedStream.appendCodeBlock("String_Node_Str");
  codeH.append(sharedStream.toString());
  sharedStream.clear();
  sharedStream.appendCodeBlock("String_Node_Str");
  codeC.append(sharedStream.toString());
  sharedStream.clear();
  StringBuffer typeFunctionCode=new StringBuffer();
  for (int i=0; i < typesArray.length; i++) {
    typeStreams[i].clear();
    if (typesArray[i].endsWith("String_Node_Str")) {
      continue;
    }
    for (    String element : functionsArray) {
      String functionName=typesArray[i] + "String_Node_Str" + element;
      try {
        if (element.equals("String_Node_Str") && (typesArray[i].equals("String_Node_Str") || typesArray[i].equals("String_Node_Str"))) {
          if (!functions.contains("String_Node_Str")) {
            markFunctionCalled(typesArray[i] + "String_Node_Str",null);
          }
        }
 else {
          if (!_unsupportedTypeFunctions.contains(functionName) && !_overloadedFunctionSet.contains(functionName)) {
            markFunctionCalled(functionName,null);
          }
        }
      }
 catch (      IllegalActionException ex) {
        typeStreams[i].append("String_Node_Str" + functionName + "String_Node_Str"+ _eol);
        _unsupportedTypeFunctions.add(functionName);
        System.out.println("String_Node_Str" + functionName + "String_Node_Str");
      }
    }
    typeFunctionCode.append(processCode(typeStreams[i].toString()));
  }
  for (int i=0; i < types.size(); i++) {
    if (typesArray[i].endsWith("String_Node_Str"))     continue;
    for (int j=0; j < functionsArray.length; j++) {
      String functionName=typesArray[i] + "String_Node_Str" + functionsArray[j];
      if (_unsupportedTypeFunctions.contains(functionName)) {
        defineUnsupportedTypeFunctionMethod=true;
      }
      if (_scalarDeleteTypes.contains(typesArray[i]) && functionsArray[j].equals("String_Node_Str")) {
        defineScalarDeleteMethod=true;
      }
      if (functionsArray[j].equals("String_Node_Str") && (typesArray[i].equals("String_Node_Str") || typesArray[i].equals("String_Node_Str"))) {
        boolean foundEquals=false;
        for (        String element : functionsArray) {
          if (element.equals("String_Node_Str")) {
            foundEquals=true;
          }
        }
        if (!foundEquals) {
          args.clear();
          functionName=typesArray[i] + "String_Node_Str";
          if (!_unsupportedTypeFunctions.contains(functionName)) {
            args.add(functionName);
            functionsDeclared.add(functionName);
            sharedStream.appendCodeBlock("String_Node_Str",args);
          }
        }
      }
      if (!_scalarDeleteTypes.contains(typesArray[i]) || !functionsArray[j].equals("String_Node_Str")) {
        args.clear();
        if (!_unsupportedTypeFunctions.contains(functionName) && !functionName.endsWith("String_Node_Str")) {
          args.add(functionName);
          functionsDeclared.add(functionName);
          sharedStream.append("String_Node_Str" + _eol);
          sharedStream.appendCodeBlock("String_Node_Str",args);
        }
      }
    }
  }
  codeH.append(sharedStream.toString());
  sharedStream.clear();
  if (defineUnsupportedTypeFunctionMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  if (defineScalarDeleteMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  codeC.append(sharedStream.toString());
  sharedStream.clear();
  if (defineUnsupportedTypeFunctionMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  if (defineScalarDeleteMethod) {
    sharedStream.appendCodeBlock("String_Node_Str");
  }
  codeH.append(sharedStream.toString());
  codeC.append(_overloadedFunctions.toString());
  codeH.append(_overloadedFunctionsDeclaration.toString());
  codeC.append(generateFunctionTable(typesArray,functionsArray));
  codeH.append("String_Node_Str" + typesArray.length + _eol);
  codeH.append("String_Node_Str" + functionsArray.length + _eol);
  codeH.append("String_Node_Str" + "String_Node_Str" + _eol);
  codeH.append(typeFunctionCode);
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  codeH.append(_eol + "String_Node_Str");
  String[] result=new String[2];
  result[0]=processCode(codeH.toString());
  result[1]=processCode(codeC.toString());
  return result;
}