]> granicus.if.org Git - clang/commitdiff
implement framework for -fdiagnostics-show-option, but tblgen isn't
authorChris Lattner <sabre@nondot.org>
Thu, 16 Apr 2009 05:44:38 +0000 (05:44 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 16 Apr 2009 05:44:38 +0000 (05:44 +0000)
passing down the right info yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69268 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b877366520dc0516668d5e20b0f531a6321b7385..4359bf9dfda2a0a11deaf9ef58167b936764ad7a 100644 (file)
@@ -302,6 +302,10 @@ public:
   ///
   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
index f0cc4a0ca0af9ab4fda93a093f052e777a0be6d2..9341b89f56ab9d164974926979a777cfca780f36 100644 (file)
@@ -37,15 +37,18 @@ class TextDiagnosticPrinter : public DiagnosticClient {
   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;
index 31f56e99bf4f8a2756d5697eda3c89476ca157d5..16cb111e2c2ade04c62915e4b55a08b1c3011e2f 100644 (file)
@@ -65,6 +65,13 @@ static unsigned GetDefaultDiagMapping(unsigned DiagID) {
   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 {
index c472a140cbf5d737c18158b65e454ff175a6921a..24f66dac7f48c38b86a479ae7521c6c3e1988513 100644 (file)
@@ -308,6 +308,11 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
   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
index bab2ab7a140e85331f142af718f42c1523142eeb..62bf467f0d8260849fc373ecdfc37bd19f25af3c 100644 (file)
@@ -93,7 +93,6 @@ bool clang::ProcessWarningOptions(Diagnostic &Diags) {
   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) {
index 345a42158513ad377a610d90f3a4af6509f2f005..7d1ce40135246cfdb7b9de90ca9063bc1f19f6bf 100644 (file)
@@ -303,6 +303,9 @@ static llvm::cl::opt<bool>
 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 @@ int main(int argc, char **argv) {
                                                !NoShowColumn,
                                                !NoCaretDiagnostics,
                                                !NoShowLocation,
-                                               PrintSourceRangeInfo);
+                                               PrintSourceRangeInfo,
+                                               PrintDiagnosticOption);
   } else {
     // When checking diagnostics, just buffer them up.
     TextDiagClient = new TextDiagnosticBuffer();