[cfe-commits] r103080 - in /cfe/trunk: include/clang/Driver/Options.td lib/Driver/Driver.cpp

Chris Lattner sabre at nondot.org
Tue May 4 22:53:24 PDT 2010


Author: lattner
Date: Wed May  5 00:53:24 2010
New Revision: 103080

URL: http://llvm.org/viewvc/llvm-project?rev=103080&view=rev
Log:
add a new --print-diagnostic-categories option, which causes the driver to
print out all of the category numbers with their description.  This is useful
for clients that want to map the numbers produced by 
--fdiagnostics-show-category=id to their human readable string form.  The
output is simple but utilitarian:

$ clang --print-diagnostic-categories
1,Format String
2,Something Else

This implements rdar://7928193

Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=103080&r1=103079&r2=103080&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed May  5 00:53:24 2010
@@ -668,6 +668,7 @@
 def _prefix_EQ : Joined<"--prefix=">, Alias<B>, Flags<[RenderSeparate]>;
 def _prefix : Separate<"--prefix">, Alias<B>;
 def _preprocess : Flag<"--preprocess">, Alias<E>;
+def _print_diagnostic_categories : Flag<"--print-diagnostic-categories">;
 def _print_file_name_EQ : Joined<"--print-file-name=">, Alias<print_file_name_EQ>;
 def _print_file_name : Separate<"--print-file-name">, Alias<print_file_name_EQ>;
 def _print_libgcc_file_name : Flag<"--print-libgcc-file-name">, Alias<print_libgcc_file_name>;

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=103080&r1=103079&r2=103080&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed May  5 00:53:24 2010
@@ -291,6 +291,14 @@
   OS << "Thread model: " << "posix" << '\n';
 }
 
+/// PrintDiagnosticCategories - Implement the --print-diagnostic-categories
+/// option.
+static void PrintDiagnosticCategories(llvm::raw_ostream &OS) {
+  for (unsigned i = 1; // Skip the empty category.
+       const char *CategoryName = Diagnostic::getCategoryNameFromID(i); ++i)
+    OS << i << ',' << CategoryName << '\n';
+}
+
 bool Driver::HandleImmediateArgs(const Compilation &C) {
   // The order these options are handled in in gcc is all over the place, but we
   // don't expect inconsistencies w.r.t. that to matter in practice.
@@ -299,6 +307,11 @@
     llvm::outs() << CLANG_VERSION_STRING "\n";
     return false;
   }
+  
+  if (C.getArgs().hasArg(options::OPT__print_diagnostic_categories)) {
+    PrintDiagnosticCategories(llvm::outs());
+    return false;
+  }
 
   if (C.getArgs().hasArg(options::OPT__help) ||
       C.getArgs().hasArg(options::OPT__help_hidden)) {





More information about the cfe-commits mailing list