Program: 72911
Project: 72911
Buggy source:
/** 
 * Generate code and append it to the given string buffer. Write the code to the directory specified by the codeDirectory parameter.  The file name is a sanitized version of the model name with a suffix that is based on last package name of the <i>generatorPackage</i> parameter.  Thus if the <i>codeDirectory</i> is <code>$HOME</code>, the name of the model is <code>Foo</code> and the <i>generatorPackage</i> is <code>ptolemy.codegen.c</code>, then the file that is written will be <code>$HOME/Foo.c</code> This method is the main entry point. We do not call the super method because it is too different from it. For instance, there is not only one file generated, but a few. The code generation algorithm works as followed : We generate a file with the name of the model (+ .c) and its header file. In this file we have the implementation of a ptolemy manager in C (  {@link ptolemy.actor.Manager}. Also for, each Composite Actor (including the top level container) We generate the files implementing the behavior of the director and of all the actors. (sources files are in the src directory and header files in includes directory) Moreover, for each folder a makefile is generated.
 * @param code The given string buffer.
 * @return The return value of the last subprocess that was executed.or -1 if no commands were executed.
 * @exception KernelException If the target file cannot be overwrittenor write-to-file throw any exception.
 */
protected int _generateCode(StringBuffer code) throws KernelException {
  long startTime=new Date().getTime();
  long overallStartTime=startTime;
  StringBuffer codeMainH=new StringBuffer();
  StringBuffer codeTypesH=new StringBuffer();
  StringBuffer codeTypesC=new StringBuffer();
  _reset();
  _sanitizedModelName=CodeGeneratorAdapter.generateName(_model);
  _analyzeTypeConversions();
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  String directory=codeDirectory.stringValue();
  if (!directory.endsWith("String_Node_Str"))   directory+="String_Node_Str";
  String directorySrc=directory + "String_Node_Str";
  String directoryIncludes=directory + "String_Node_Str";
  String directoryBuild=directory + "String_Node_Str";
  _deleteDirectory(directorySrc);
  if (!_includes.contains("String_Node_Str" + directoryIncludes))   _includes.add("String_Node_Str" + directoryIncludes);
  if (new File(directorySrc).mkdirs() || new File(directoryIncludes).mkdirs() || new File(directoryBuild).mkdirs()) {
    directory+="String_Node_Str";
  }
  CompositeActor container=(CompositeActor)getContainer();
  String sanitizedNameContainer=CodeGeneratorAdapter.generateName(container);
  _generateAndWriteCompositeActorCode(container,"String_Node_Str");
  String sharedCode=_generateSharedCode();
  String declareSharedCode=_generateDeclareSharedCode();
  String[] typeResolutionCode=generateTypeConvertCodeCandH();
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  code.append(generateCopyright());
  codeMainH.append(generateCopyright());
  codeTypesH.append(generateCopyright());
  codeTypesC.append(generateCopyright());
  codeMainH.append("String_Node_Str" + _sanitizedModelName.toUpperCase() + "String_Node_Str"+ _eol+ "String_Node_Str"+ _sanitizedModelName.toUpperCase()+ "String_Node_Str"+ _eol);
  codeMainH.append(_eol + "String_Node_Str" + _sanitizedModelName+ "String_Node_Str");
  codeMainH.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + "String_Node_Str" + _sanitizedModelName+ "String_Node_Str");
  if (((BooleanToken)measureTime.getToken()).booleanValue()) {
    code.append(_eol + "String_Node_Str");
    code.append(_eol + "String_Node_Str");
  }
  codeMainH.append(_eol + _eol + "String_Node_Str");
  code.append(generateMainEntryCode());
  code.append(generateMainExitCode());
  codeMainH.append(_eol + "String_Node_Str");
  codeMainH.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + sanitizedNameContainer + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  codeMainH.append(generateInitializeProcedureName());
  code.append(generateInitializeEntryCode());
  code.append(_eol + "String_Node_Str");
  code.append(_eol + sanitizedNameContainer + "String_Node_Str"+ _eol);
  code.append(generateInitializeExitCode());
  codeMainH.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + sanitizedNameContainer + "String_Node_Str");
  code.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  codeMainH.append(generateWrapupProcedureName());
  code.append(generateWrapupEntryCode());
  code.append(_eol + sanitizedNameContainer + "String_Node_Str");
  code.append(generateWrapupExitCode());
  codeMainH.append(_eol + "String_Node_Str");
  codeTypesH.append("String_Node_Str" + _sanitizedModelName.toUpperCase() + "String_Node_Str"+ _eol+ "String_Node_Str"+ _sanitizedModelName.toUpperCase()+ "String_Node_Str"+ _eol);
  codeTypesH.append(_eol + typeResolutionCode[0]);
  typeResolutionCode[0]=null;
  codeTypesH.append(comment("String_Node_Str"));
  codeTypesC.append(typeResolutionCode[1]);
  typeResolutionCode[1]=null;
  codeTypesC.append(comment("String_Node_Str"));
  codeTypesC.append(sharedCode);
  sharedCode=null;
  codeTypesH.append(declareSharedCode);
  declareSharedCode=null;
  codeTypesH.append(comment("String_Node_Str"));
  codeTypesH.append("String_Node_Str");
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  code=_finalPassOverCode(code);
  codeMainH=_finalPassOverCode(codeMainH);
  codeTypesH=_finalPassOverCode(codeTypesH);
  codeTypesC=_finalPassOverCode(codeTypesC);
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  _writeCodeFileName(code,_sanitizedModelName + "String_Node_Str",true,false);
  _writeCodeFileName(codeMainH,"String_Node_Str" + _sanitizedModelName + "String_Node_Str",true,false);
  _writeCodeFileName(codeTypesH,"String_Node_Str" + _sanitizedModelName + "String_Node_Str",true,false);
  _writeCodeFileName(codeTypesC,"String_Node_Str" + _sanitizedModelName + "String_Node_Str",true,false);
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  code=null;
  codeMainH=null;
  codeTypesH=null;
  codeTypesC=null;
  _writeMakefile(container,directory);
  _printTimeAndMemory(startTime,"String_Node_Str");
  if (_executeCommands == null) {
    _executeCommands=new StreamExec();
  }
  _printTimeAndMemory(overallStartTime,"String_Node_Str");
  return _executeCommands();
}

Fixed version (ground truth):
/** 
 * Generate code and append it to the given string buffer. Write the code to the directory specified by the codeDirectory parameter.  The file name is a sanitized version of the model name with a suffix that is based on last package name of the <i>generatorPackage</i> parameter.  Thus if the <i>codeDirectory</i> is <code>$HOME</code>, the name of the model is <code>Foo</code> and the <i>generatorPackage</i> is <code>ptolemy.codegen.c</code>, then the file that is written will be <code>$HOME/Foo.c</code> This method is the main entry point. We do not call the super method because it is too different from it. For instance, there is not only one file generated, but a few. The code generation algorithm works as followed : We generate a file with the name of the model (+ .c) and its header file. In this file we have the implementation of a ptolemy manager in C (  {@link ptolemy.actor.Manager}. Also for, each Composite Actor (including the top level container) We generate the files implementing the behavior of the director and of all the actors. (sources files are in the src directory and header files in includes directory) Moreover, for each folder a makefile is generated.
 * @param code The given string buffer.
 * @return The return value of the last subprocess that was executed.or -1 if no commands were executed.
 * @exception KernelException If the target file cannot be overwrittenor write-to-file throw any exception.
 */
protected int _generateCode(StringBuffer code) throws KernelException {
  long startTime=new Date().getTime();
  long overallStartTime=startTime;
  StringBuffer codeMainH=new StringBuffer();
  StringBuffer codeTypesH=new StringBuffer();
  StringBuffer codeTypesC=new StringBuffer();
  _reset();
  _sanitizedModelName=CodeGeneratorAdapter.generateName(_model);
  _analyzeTypeConversions();
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  String directory=codeDirectory.stringValue();
  if (!directory.endsWith("String_Node_Str"))   directory+="String_Node_Str";
  String directorySrc=directory + "String_Node_Str";
  String directoryIncludes=directory + "String_Node_Str";
  String directoryBuild=directory + "String_Node_Str";
  _deleteDirectory(directorySrc);
  if (!_includes.contains("String_Node_Str" + directoryIncludes))   _includes.add("String_Node_Str" + directoryIncludes);
  if (new File(directorySrc).mkdirs() && new File(directoryIncludes).mkdirs() && new File(directoryBuild).mkdirs()) {
    directory+="String_Node_Str";
  }
  CompositeActor container=(CompositeActor)getContainer();
  String sanitizedNameContainer=CodeGeneratorAdapter.generateName(container);
  _generateAndWriteCompositeActorCode(container,"String_Node_Str");
  String sharedCode=_generateSharedCode();
  String declareSharedCode=_generateDeclareSharedCode();
  String[] typeResolutionCode=generateTypeConvertCodeCandH();
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  code.append(generateCopyright());
  codeMainH.append(generateCopyright());
  codeTypesH.append(generateCopyright());
  codeTypesC.append(generateCopyright());
  codeMainH.append("String_Node_Str" + _sanitizedModelName.toUpperCase() + "String_Node_Str"+ _eol+ "String_Node_Str"+ _sanitizedModelName.toUpperCase()+ "String_Node_Str"+ _eol);
  codeMainH.append(_eol + "String_Node_Str" + _sanitizedModelName+ "String_Node_Str");
  codeMainH.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + "String_Node_Str" + _sanitizedModelName+ "String_Node_Str");
  if (((BooleanToken)measureTime.getToken()).booleanValue()) {
    code.append(_eol + "String_Node_Str");
    code.append(_eol + "String_Node_Str");
  }
  codeMainH.append(_eol + _eol + "String_Node_Str");
  code.append(generateMainEntryCode());
  code.append(generateMainExitCode());
  codeMainH.append(_eol + "String_Node_Str");
  codeMainH.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + sanitizedNameContainer + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  codeMainH.append(generateInitializeProcedureName());
  code.append(generateInitializeEntryCode());
  code.append(_eol + "String_Node_Str");
  code.append(_eol + sanitizedNameContainer + "String_Node_Str"+ _eol);
  code.append(generateInitializeExitCode());
  codeMainH.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + sanitizedNameContainer + "String_Node_Str");
  code.append(_eol + "String_Node_Str" + sanitizedNameContainer+ "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  code.append(_eol + "String_Node_Str");
  codeMainH.append(generateWrapupProcedureName());
  code.append(generateWrapupEntryCode());
  code.append(_eol + sanitizedNameContainer + "String_Node_Str");
  code.append(generateWrapupExitCode());
  codeMainH.append(_eol + "String_Node_Str");
  codeTypesH.append("String_Node_Str" + _sanitizedModelName.toUpperCase() + "String_Node_Str"+ _eol+ "String_Node_Str"+ _sanitizedModelName.toUpperCase()+ "String_Node_Str"+ _eol);
  codeTypesH.append(_eol + typeResolutionCode[0]);
  typeResolutionCode[0]=null;
  codeTypesH.append(comment("String_Node_Str"));
  codeTypesC.append(typeResolutionCode[1]);
  typeResolutionCode[1]=null;
  codeTypesC.append(comment("String_Node_Str"));
  codeTypesC.append(sharedCode);
  sharedCode=null;
  codeTypesH.append(declareSharedCode);
  declareSharedCode=null;
  codeTypesH.append(comment("String_Node_Str"));
  codeTypesH.append("String_Node_Str");
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  code=_finalPassOverCode(code);
  codeMainH=_finalPassOverCode(codeMainH);
  codeTypesH=_finalPassOverCode(codeTypesH);
  codeTypesC=_finalPassOverCode(codeTypesC);
  startTime=_printTimeAndMemory(startTime,"String_Node_Str");
  _writeCodeFileName(code,_sanitizedModelName + "String_Node_Str",true,false);
  _writeCodeFileName(codeMainH,"String_Node_Str" + _sanitizedModelName + "String_Node_Str",true,false);
  _writeCodeFileName(codeTypesH,"String_Node_Str" + _sanitizedModelName + "String_Node_Str",true,false);
  _writeCodeFileName(codeTypesC,"String_Node_Str" + _sanitizedModelName + "String_Node_Str",true,false);
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directoryIncludes,"String_Node_Str");
  _copyCFileTosrc("String_Node_Str",directorySrc,"String_Node_Str");
  code=null;
  codeMainH=null;
  codeTypesH=null;
  codeTypesC=null;
  _writeMakefile(container,directory);
  _printTimeAndMemory(startTime,"String_Node_Str");
  if (_executeCommands == null) {
    _executeCommands=new StreamExec();
  }
  _printTimeAndMemory(overallStartTime,"String_Node_Str");
  return _executeCommands();
}