[cfe-commits] r59908 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Sema/Sema.cpp

Chris Lattner sabre at nondot.org
Sun Nov 23 01:21:17 PST 2008


Author: lattner
Date: Sun Nov 23 03:21:17 2008
New Revision: 59908

URL: http://llvm.org/viewvc/llvm-project?rev=59908&view=rev
Log:
Genericize the qualtype formating callback to support any diag argument.
No functionality change.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Sema/Sema.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=59908&r1=59907&r2=59908&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Sun Nov 23 03:21:17 2008
@@ -337,8 +337,8 @@
         break;
       case Diagnostic::ak_qualtype: {
         llvm::SmallString<64> Str;
-        Info.getDiags()->ConvertQualTypeToString(Info.getRawArg(i), 0, 0, 0, 0,
-                                                 Str);
+        Info.getDiags()->ConvertArgToString(Info.getArgKind(i),
+                                            Info.getRawArg(i), 0, 0, 0, 0, Str);
         R.addString(std::string(Str.begin(), Str.end()));
         break;
       }

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

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Sun Nov 23 03:21:17 2008
@@ -62,6 +62,15 @@
     Ignored, Note, Warning, Error
   };
   
+  enum ArgumentKind {
+    ak_std_string,     // std::string
+    ak_c_string,       // const char *
+    ak_sint,           // int
+    ak_uint,           // unsigned
+    ak_identifierinfo, // IdentifierInfo
+    ak_qualtype        // QualType
+  };
+  
 private:  
   bool IgnoreAllWarnings;     // Ignore all warnings: -w
   bool WarningsAsErrors;      // Treat warnings like errors: 
@@ -84,12 +93,15 @@
   /// CustomDiagInfo - Information for uniquing and looking up custom diags.
   diag::CustomDiagInfo *CustomDiagInfo;
 
-  /// QualTypeToString - A function pointer that converts QualType's to strings.
+  /// ArgToStringFn - A function pointer that converts an opaque diagnostic
+  /// argument to a strings.  This takes the modifiers and argument that was
+  /// present in the diagnostic.
   /// This is a hack to avoid a layering violation between libbasic and libsema.
-  typedef void (*QTToStringFnTy)(intptr_t QT, const char *Modifier, unsigned ML,
-                                 const char *Argument, unsigned ArgLen,
-                                 llvm::SmallVectorImpl<char> &Output);
-  QTToStringFnTy QualTypeToString;
+  typedef void (*ArgToStringFnTy)(ArgumentKind Kind, intptr_t Val,
+                                  const char *Modifier, unsigned ModifierLen,
+                                  const char *Argument, unsigned ArgumentLen,
+                                  llvm::SmallVectorImpl<char> &Output);
+  ArgToStringFnTy ArgToStringFn;
 public:
   explicit Diagnostic(DiagnosticClient *client = 0);
   ~Diagnostic();
@@ -157,16 +169,17 @@
   unsigned getCustomDiagID(Level L, const char *Message);
   
   
-  /// ConvertQualTypeToString - This method converts a QualType (as an intptr_t)
-  /// into the string that represents it if possible.
-  void ConvertQualTypeToString(intptr_t QT, const char *Modifier, unsigned ML,
-                               const char *Argument, unsigned ArgLen,
-                               llvm::SmallVectorImpl<char> &Output) const {
-    QualTypeToString(QT, Modifier, ML, Argument, ArgLen, Output);
+  /// ConvertArgToString - This method converts a diagnostic argument (as an
+  /// intptr_t) into the string that represents it.
+  void ConvertArgToString(ArgumentKind Kind, intptr_t Val,
+                          const char *Modifier, unsigned ModLen,
+                          const char *Argument, unsigned ArgLen,
+                          llvm::SmallVectorImpl<char> &Output) const {
+    ArgToStringFn(Kind, Val, Modifier, ModLen, Argument, ArgLen, Output);
   }
   
-  void SetQualTypeToStringFn(QTToStringFnTy Fn) {
-    QualTypeToString = Fn;
+  void SetArgToStringFn(ArgToStringFnTy Fn) {
+    ArgToStringFn = Fn;
   }
   
   //===--------------------------------------------------------------------===//
@@ -246,15 +259,6 @@
   /// ProcessDiag - This is the method used to report a diagnostic that is
   /// finally fully formed.
   void ProcessDiag();
-public:
-  enum ArgumentKind {
-    ak_std_string,     // std::string
-    ak_c_string,       // const char *
-    ak_sint,           // int
-    ak_uint,           // unsigned
-    ak_identifierinfo, // IdentifierInfo
-    ak_qualtype        // QualType
-  };
 };
 
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Sun Nov 23 03:21:17 2008
@@ -116,10 +116,11 @@
 // Common Diagnostic implementation
 //===----------------------------------------------------------------------===//
 
-static void DummyQTToStringFnTy(intptr_t QT, const char *Modifier, unsigned ML,
-                                const char *Argument, unsigned ArgLen,
-                                llvm::SmallVectorImpl<char> &Output) {
-  const char *Str = "<can't format QualType>";
+static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT,
+                               const char *Modifier, unsigned ML,
+                               const char *Argument, unsigned ArgLen,
+                               llvm::SmallVectorImpl<char> &Output) {
+  const char *Str = "<can't format argument>";
   Output.append(Str, Str+strlen(Str));
 }
 
@@ -139,7 +140,7 @@
   CustomDiagInfo = 0;
   CurDiagID = ~0U;
   
-  QualTypeToString = DummyQTToStringFnTy;
+  ArgToStringFn = DummyArgToStringFn;
 }
 
 Diagnostic::~Diagnostic() {
@@ -536,9 +537,9 @@
     }
     case Diagnostic::ak_qualtype:
       OutStr.push_back('\'');
-      getDiags()->ConvertQualTypeToString(getRawArg(ArgNo),
-                                          Modifier, ModifierLen,
-                                          Argument, ArgumentLen, OutStr);
+      getDiags()->ConvertArgToString(getArgKind(ArgNo), getRawArg(ArgNo),
+                                     Modifier, ModifierLen,
+                                     Argument, ArgumentLen, OutStr);
       OutStr.push_back('\'');
       break;
     }

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=59908&r1=59907&r2=59908&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sun Nov 23 03:21:17 2008
@@ -22,12 +22,13 @@
 
 /// ConvertQualTypeToStringFn - This function is used to pretty print the 
 /// specified QualType as a string in diagnostics.
-static void ConvertQualTypeToStringFn(intptr_t QT,
+static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t QT,
                                       const char *Modifier, unsigned ML,
                                       const char *Argument, unsigned ArgLen,
                                       llvm::SmallVectorImpl<char> &Output) {
   assert(ML == 0 && ArgLen == 0 && "Invalid modifier for QualType argument");
-
+  assert(Kind == Diagnostic::ak_qualtype);
+  
   QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast<void*>(QT)));
   
   // FIXME: Playing with std::string is really slow.
@@ -126,7 +127,7 @@
     FieldCollector.reset(new CXXFieldCollector());
       
   // Tell diagnostics how to render things from the AST library.
-  PP.getDiagnostics().SetQualTypeToStringFn(ConvertQualTypeToStringFn);
+  PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn);
 }
 
 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. 





More information about the cfe-commits mailing list