[PATCH] Transform all files in a compilation database if no source files are provided.

Guillaume Papin guillaume.papin at epitech.eu
Wed Sep 11 10:00:10 PDT 2013

  The major comment is about `llvm::report_fatal_error()` I don't think we should use it.

  As for the documentation I'm not the best person to judge that, it looks okay to me.

Comment at: clang-modernize/tool/ClangModernize.cpp:300
@@ +299,3 @@
+        ErrorMessage);
+  // Try to auto-detect a compilation database from the frist source.
+  if (!SourcePaths.empty()) {

Comment at: clang-modernize/tool/ClangModernize.cpp:302-310
@@ +301,11 @@
+  if (!SourcePaths.empty()) {
+    CompilationDatabase *Compilations =
+        CompilationDatabase::autoDetectFromSource(SourcePaths[0], ErrorMessage);
+    // If no compilation database can be detected from source then we create a
+    // fixed compilation database with c++11 support.
+    if (!Compilations) {
+      std::string CommandLine[] = { "-std=c++11" };
+      return new FixedCompilationDatabase(".", CommandLine);
+    }
+    return Compilations;
+  }
I would return the compilation database directly.

    if (CompilationDatabase *Compilations =
      return Compilations;

    std::string CommandLine[] = { "-std=c++11" };
    return new FixedCompilationDatabase(".", CommandLine);

Comment at: clang-modernize/tool/ClangModernize.cpp:363
@@ +362,3 @@
+    if (GlobalOptions.ModifiableFiles.isIncludeListEmpty())
+      llvm::report_fatal_error("Use -include to indicate which files of the "
+                               "compilation database to transform.");
I don't think using `llvm::report_fatal_error()` is necessary, the doc (http://llvm.org/docs/doxygen/html/namespacellvm.html#a1f6978055dbb761b380de39070e34bd3) says:

void llvm::report_fatal_error (const char *reason, bool gen_crash_diag = true)

  Reports a serious error, calling any installed error handler. These functions
  are intended to be used for error conditions which are outside the control of
  the compiler (I/O errors, invalid user input, etc.)
  If no error handler is installed the default is to print the message to
  standard error, followed by a newline. After the error handler is called this
  function will call exit(1), it does not return.

Comment at: clang-modernize/tool/ClangModernize.cpp:372
@@ +371,3 @@
+  if (Sources.empty())
+    llvm::report_fatal_error("Could not determine sources to transform.");
`llvm::report_fatal_error()` again

Comment at: docs/ModernizerUsage.rst:47
@@ +46,3 @@
+  In order to transform all files in a compilation database the following
+  command line can be used :
nit: unnecessary space before ':'.

Comment at: docs/ModernizerUsage.rst:20
@@ -19,3 +19,3 @@
 transformations that are supported by the given compilers will be applied.
 General Command Line Options
I know Edwin asked me to put the specific behavior of the command line arguments that enables the transforms here, just under the usage. I'm wondering if the behavior for the input files should be documented here as well.


More information about the cfe-commits mailing list