[cfe-commits] r69177 - in /cfe/trunk: include/clang/Basic/Diagnostic.td lib/Basic/Diagnostic.cpp

Chris Lattner sabre at nondot.org
Wed Apr 15 09:56:26 PDT 2009


Author: lattner
Date: Wed Apr 15 11:56:26 2009
New Revision: 69177

URL: http://llvm.org/viewvc/llvm-project?rev=69177&view=rev
Log:
Make diagnostic class explicit in the diag record instead of
implicit from its parenting.  Now that diag mapping is 
explicit, eliminate the fatal and extwarn classes.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.td
    cfe/trunk/lib/Basic/Diagnostic.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.td (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.td Wed Apr 15 11:56:26 2009
@@ -19,6 +19,14 @@
 def MAP_ERROR   : DiagMapping;
 def MAP_FATAL   : DiagMapping;
 
+// Define the diagnostic classes.
+class DiagClass;
+def CLASS_NOTE      : DiagClass;
+def CLASS_WARNING   : DiagClass;
+def CLASS_EXTENSION : DiagClass;
+def CLASS_ERROR     : DiagClass;
+
+
 /*
 class Option<string name, list<OptionControlled> members> : OptionControlled {
   string Name = name;
@@ -31,18 +39,19 @@
 */
 
 // All diagnostics emitted by the compiler are an indirect subclass of this.
-class Diagnostic<string text, DiagMapping defaultmapping> {
+class Diagnostic<string text, DiagClass DC, DiagMapping defaultmapping> {
   /// Component is specified by the file with a big let directive.
   string Component = ?;
   string Text = text;
+  DiagClass Class = DC;
   DiagMapping DefaultMapping = defaultmapping;
 }
 
-class Error<string text>     : Diagnostic<text, MAP_ERROR>;
-class Warning<string text>   : Diagnostic<text, MAP_WARNING>;
-class Extension<string text> : Diagnostic<text, MAP_IGNORE>;
-class ExtWarn<string text>   : Diagnostic<text, MAP_WARNING>;
-class Note<string text>      : Diagnostic<text, MAP_FATAL /*ignored*/>;
+class Error<string str>     : Diagnostic<str, CLASS_ERROR, MAP_ERROR>;
+class Warning<string str>   : Diagnostic<str, CLASS_WARNING, MAP_WARNING>;
+class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_IGNORE>;
+class ExtWarn<string str>   : Diagnostic<str, CLASS_EXTENSION, MAP_WARNING>;
+class Note<string str>      : Diagnostic<str, CLASS_NOTE, MAP_FATAL/*ignored*/>;
 
 // Definitions for Diagnostics.
 include "DiagnosticASTKinds.td"

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

==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Apr 15 11:56:26 2009
@@ -54,15 +54,14 @@
 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
 { 0, 0 }
 };
+#undef DIAG
 
 // Diagnostic classes.
 enum {
-  NOTE       = 0x01,
-  WARNING    = 0x02,
-  EXTENSION  = 0x03,
-  EXTWARN    = 0x04,
-  ERROR      = 0x05,
-  FATAL      = 0x06
+  CLASS_NOTE       = 0x01,
+  CLASS_WARNING    = 0x02,
+  CLASS_EXTENSION  = 0x03,
+  CLASS_ERROR      = 0x04
 };
 
 /// DiagnosticClasses - The class for each diagnostic.
@@ -272,24 +271,23 @@
 /// This only works on builtin diagnostics, not custom ones, and is not legal to
 /// call on NOTEs.
 bool Diagnostic::isBuiltinWarningOrExtension(unsigned DiagID) {
-  return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) < ERROR;
+  return DiagID < diag::DIAG_UPPER_LIMIT &&
+         getBuiltinDiagClass(DiagID) != CLASS_ERROR;
 }
 
 /// \brief Determine whether the given built-in diagnostic ID is a
 /// Note.
 bool Diagnostic::isBuiltinNote(unsigned DiagID) {
-  return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) == NOTE;
+  return DiagID < diag::DIAG_UPPER_LIMIT &&
+    getBuiltinDiagClass(DiagID) == CLASS_NOTE;
 }
 
 /// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
 /// ID is for an extension of some sort.
 ///
 bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) {
-  if (DiagID < diag::DIAG_UPPER_LIMIT) {
-    unsigned Class = getBuiltinDiagClass(DiagID);
-    return Class == EXTENSION || Class == EXTWARN;
-  }
-  return false;
+  return DiagID < diag::DIAG_UPPER_LIMIT &&
+         getBuiltinDiagClass(DiagID) == CLASS_EXTENSION;
 }
 
 
@@ -324,7 +322,7 @@
     return CustomDiagInfo->getLevel(DiagID);
   
   unsigned DiagClass = getBuiltinDiagClass(DiagID);
-  assert(DiagClass != NOTE && "Cannot get the diagnostic level of a note!");
+  assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
   return getDiagnosticLevel(DiagID, DiagClass);
 }
 
@@ -386,7 +384,7 @@
     // the diagnostic level was for the previous diagnostic so that it is
     // filtered the same as the previous diagnostic.
     unsigned DiagClass = getBuiltinDiagClass(DiagID);
-    if (DiagClass == NOTE) {
+    if (DiagClass == CLASS_NOTE) {
       DiagLevel = Diagnostic::Note;
       ShouldEmitInSystemHeader = false;  // extra consideration is needed
     } else {
@@ -394,7 +392,7 @@
       // Check the original Diag ID here, because we also want to ignore
       // extensions and warnings in -Werror and -pedantic-errors modes, which
       // *map* warnings/extensions to errors.
-      ShouldEmitInSystemHeader = DiagClass == ERROR;
+      ShouldEmitInSystemHeader = DiagClass == CLASS_ERROR;
       
       DiagLevel = getDiagnosticLevel(DiagID, DiagClass);
     }





More information about the cfe-commits mailing list