[cfe-commits] r69268 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Frontend/TextDiagnosticPrinter.h lib/Basic/Diagnostic.cpp lib/Frontend/TextDiagnosticPrinter.cpp tools/clang-cc/Warnings.cpp tools/clang-cc/clang-cc.cpp

Chris Lattner sabre at nondot.org
Wed Apr 15 22:44:39 PDT 2009


Author: lattner
Date: Thu Apr 16 00:44:38 2009
New Revision: 69268

URL: http://llvm.org/viewvc/llvm-project?rev=69268&view=rev
Log:
implement framework for -fdiagnostics-show-option, but tblgen isn't
passing down the right info yet.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
    cfe/trunk/tools/clang-cc/Warnings.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=69268&r1=69267&r2=69268&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Apr 16 00:44:38 2009
@@ -302,6 +302,10 @@
   ///
   static bool isBuiltinExtensionDiag(unsigned DiagID);
   
+  /// getWarningOptionForDiag - Return the lowest-level warning option that
+  /// enables the specified diagnostic.  If there is no -Wfoo flag that controls
+  /// the diagnostic, this returns null.
+  static const char *getWarningOptionForDiag(unsigned DiagID);
 
   /// getDiagnosticLevel - Based on the way the client configured the Diagnostic
   /// object, classify the specified diagnostic ID into a Level, consumable by

Modified: cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h?rev=69268&r1=69267&r2=69268&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h Thu Apr 16 00:44:38 2009
@@ -37,15 +37,18 @@
   bool CaretDiagnostics;
   bool ShowLocation;
   bool PrintRangeInfo;
+  bool PrintDiagnosticOption;
 public:
   TextDiagnosticPrinter(llvm::raw_ostream &os,
                         bool showColumn = true,
                         bool caretDiagnistics = true, bool showLocation = true,
-                        bool printRangeInfo = true)
+                        bool printRangeInfo = true,
+                        bool printDiagnosticOption = true)
     : OS(os), LangOpts(0),
       LastCaretDiagnosticWasNote(false), ShowColumn(showColumn), 
       CaretDiagnostics(caretDiagnistics), ShowLocation(showLocation),
-      PrintRangeInfo(printRangeInfo) {}
+      PrintRangeInfo(printRangeInfo),
+      PrintDiagnosticOption(printDiagnosticOption) {}
 
   void SetLangOpts(const LangOptions &LO) {
     LangOpts = &LO;

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=69268&r1=69267&r2=69268&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Thu Apr 16 00:44:38 2009
@@ -65,6 +65,13 @@
   return diag::MAP_FATAL;
 }
 
+/// getWarningOptionForDiag - Return the lowest-level warning option that
+/// enables the specified diagnostic.  If there is no -Wfoo flag that controls
+/// the diagnostic, this returns null.
+const char *Diagnostic::getWarningOptionForDiag(unsigned DiagID) {
+  return 0; //"Wfoo";
+}
+
 
 // Diagnostic classes.
 enum {

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=69268&r1=69267&r2=69268&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Thu Apr 16 00:44:38 2009
@@ -308,6 +308,11 @@
   llvm::SmallString<100> OutStr;
   Info.FormatDiagnostic(OutStr);
   OS.write(OutStr.begin(), OutStr.size());
+  
+  if (PrintDiagnosticOption)
+    if (const char *Option = Diagnostic::getWarningOptionForDiag(Info.getID()))
+      OS << " [-" << Option << ']';
+  
   OS << '\n';
   
   // If caret diagnostics are enabled and we have location, we want to

Modified: cfe/trunk/tools/clang-cc/Warnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Warnings.cpp?rev=69268&r1=69267&r2=69268&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Warnings.cpp (original)
+++ cfe/trunk/tools/clang-cc/Warnings.cpp Thu Apr 16 00:44:38 2009
@@ -93,7 +93,6 @@
   else
     Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore);
   
-  // FIXME: -fdiagnostics-show-option
   // FIXME: -Wfatal-errors / -Wfatal-errors=foo
 
   for (unsigned i = 0, e = OptWarnings.size(); i != e; ++i) {

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=69268&r1=69267&r2=69268&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Thu Apr 16 00:44:38 2009
@@ -303,6 +303,9 @@
 PrintSourceRangeInfo("fprint-source-range-info",
                     llvm::cl::desc("Print source range spans in numeric form"));
 
+static llvm::cl::opt<bool>
+PrintDiagnosticOption("fdiagnostics-show-option",
+             llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
 
 //===----------------------------------------------------------------------===//
 // C++ Visualization.
@@ -2227,7 +2230,8 @@
                                                !NoShowColumn,
                                                !NoCaretDiagnostics,
                                                !NoShowLocation,
-                                               PrintSourceRangeInfo);
+                                               PrintSourceRangeInfo,
+                                               PrintDiagnosticOption);
   } else {
     // When checking diagnostics, just buffer them up.
     TextDiagClient = new TextDiagnosticBuffer();





More information about the cfe-commits mailing list