[cfe-commits] r69271 - /cfe/trunk/lib/Basic/Diagnostic.cpp

Chris Lattner sabre at nondot.org
Wed Apr 15 23:00:24 PDT 2009


Author: lattner
Date: Thu Apr 16 01:00:24 2009
New Revision: 69271

URL: http://llvm.org/viewvc/llvm-project?rev=69271&view=rev
Log:
Implement Diagnostic::getWarningOptionForDiag with information from tblgen,
this implements -fdiagnostics-show-option in clang-cc.

Modified:
    cfe/trunk/lib/Basic/Diagnostic.cpp

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

==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Thu Apr 16 01:00:24 2009
@@ -35,16 +35,17 @@
 //===----------------------------------------------------------------------===//
 
 // DefaultDiagnosticMappings - This specifies the default mapping for each diag,
-// based on its kind.   Yay for macros?
+// based on its kind.
 
-struct DefaultMappingInfo {
+struct StaticDiagInfoRec {
   unsigned DiagID : 14;
   unsigned Mapping : 2;
+  const char *OptionGroup;
 };
 
-static const DefaultMappingInfo DefaultMappings[] = {
+static const StaticDiagInfoRec StaticDiagInfo[] = {
 #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP) \
-  { diag::ENUM, DEFAULT_MAPPING-1 },
+  { diag::ENUM, DEFAULT_MAPPING-1, GROUP },
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
@@ -53,16 +54,22 @@
 #include "clang/Basic/DiagnosticASTKinds.inc"
 #include "clang/Basic/DiagnosticSemaKinds.inc"
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
-{ 0, 0 }
+{ 0, 0, 0 }
 };
 #undef DIAG
 
-static unsigned GetDefaultDiagMapping(unsigned DiagID) {
+static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
   // FIXME: Binary search.
-  for (unsigned i = 0, e = sizeof(DefaultMappings)/sizeof(DefaultMappings[0]);
+  for (unsigned i = 0, e = sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0]);
        i != e; ++i)
-    if (DefaultMappings[i].DiagID == DiagID)
-      return DefaultMappings[i].Mapping+1;
+    if (StaticDiagInfo[i].DiagID == DiagID)
+      return &StaticDiagInfo[i];
+  return 0;
+}
+
+static unsigned GetDefaultDiagMapping(unsigned DiagID) {
+  if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
+    return Info->Mapping+1;
   return diag::MAP_FATAL;
 }
 
@@ -70,7 +77,9 @@
 /// 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";
+  if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
+    return Info->OptionGroup;
+  return 0;
 }
 
 





More information about the cfe-commits mailing list