]> granicus.if.org Git - clang/commitdiff
add direct support for signed and unsigned integer arguments to diagnostics.
authorChris Lattner <sabre@nondot.org>
Wed, 19 Nov 2008 07:22:31 +0000 (07:22 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 19 Nov 2008 07:22:31 +0000 (07:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59598 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/BugReporter.h
include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Sema/SemaDeclAttr.cpp

index 72f83bee344b7a7f0f4f9089e93dbd5f6e5e9179..870e9d39f02a6b11d3c6dedb2f4380b1d89ae527 100644 (file)
@@ -21,6 +21,7 @@
 #include "clang/Analysis/PathSensitive/ExplodedGraph.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringExtras.h"
 #include <list>
 
 namespace clang {
@@ -323,6 +324,14 @@ public:
       case DiagnosticInfo::ak_c_string:   
         R.addString(Info.getArgCStr(i));
         break;
+      case DiagnosticInfo::ak_sint:
+        // FIXME: Optimize
+        R.addString(llvm::itostr(Info.getArgSInt(i)));
+        break;
+      case DiagnosticInfo::ak_uint:
+        // FIXME: Optimize
+        R.addString(llvm::utostr_32(Info.getArgUInt(i)));
+        break;
       }
     }
   }
index 303d83cc66d95b2fdfbb74eb0b64f2671bf21e6d..fe3cfeeb31c08f5685dae7449a065c8efc25a38f 100644 (file)
@@ -238,7 +238,9 @@ class DiagnosticInfo {
 public:
   enum ArgumentKind {
     ak_std_string,   // std::string
-    ak_c_string      // const char *
+    ak_c_string,     // const char *
+    ak_sint,         // int
+    ak_uint          // unsigned
   };
   
   
@@ -302,6 +304,18 @@ public:
     return reinterpret_cast<const char*>(DiagObj->DiagArgumentsVal[Idx]);
   }
   
+  /// getArgSInt - Return the specified signed integer argument.
+  int getArgSInt(unsigned Idx) const {
+    assert(getArgKind(Idx) == ak_sint && "invalid argument accessor!");
+    return (int)DiagObj->DiagArgumentsVal[Idx];
+  }
+
+  /// getArgUInt - Return the specified unsigned integer argument.
+  unsigned getArgUInt(unsigned Idx) const {
+    assert(getArgKind(Idx) == ak_uint && "invalid argument accessor!");
+    return (unsigned)DiagObj->DiagArgumentsVal[Idx];
+  }
+  
   /// getNumRanges - Return the number of source ranges associated with this
   /// diagnostic.
   unsigned getNumRanges() const {
@@ -330,6 +344,23 @@ public:
     return *this;
   }
   
+  DiagnosticInfo &operator<<(int I) {
+    assert((unsigned)DiagObj->NumDiagArgs < Diagnostic::MaxArguments &&
+           "Too many arguments to diagnostic!");
+    DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = ak_sint;
+    DiagObj->DiagArgumentsVal[DiagObj->NumDiagArgs++] = I;
+    return *this;
+  }
+  
+  DiagnosticInfo &operator<<(unsigned I) {
+    assert((unsigned)DiagObj->NumDiagArgs < Diagnostic::MaxArguments &&
+           "Too many arguments to diagnostic!");
+    DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = ak_uint;
+    DiagObj->DiagArgumentsVal[DiagObj->NumDiagArgs++] = I;
+    return *this;
+  }
+  
+  
   DiagnosticInfo &operator<<(const SourceRange &R) {
     assert((unsigned)DiagObj->NumDiagArgs < 
            sizeof(DiagObj->DiagRanges)/sizeof(DiagObj->DiagRanges[0]) &&
index e8c24ab0a715c7f3af4acc4b441e6fdd6d2a8d6d..9428b218e54301cfdba15fe638d1681cd8f942a2 100644 (file)
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include <vector>
 #include <map>
 #include <cstring>
@@ -279,6 +280,18 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
         OutStr.append(S, S + strlen(S));
         break;
       }
+      case DiagnosticInfo::ak_sint: {
+        // FIXME: Optimize
+        std::string S = llvm::itostr(getArgSInt(StrNo));
+        OutStr.append(S.begin(), S.end());
+        break;
+      }
+      case DiagnosticInfo::ak_uint: {
+        // FIXME: Optimize
+        std::string S = llvm::utostr_32(getArgUInt(StrNo));
+        OutStr.append(S.begin(), S.end());
+        break;
+      }
       }
       DiagStr += 2;
     }
index 40f70fb3cc1a3c750d2f36e158f65d41c8048847..d83ba8561bd871ae43f84ecb458501f7f7a6e28b 100644 (file)
@@ -328,7 +328,7 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
         
     if (x < 1 || x > NumArgs) {
       S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
-       << "nonnull" << llvm::utostr_32(I.getArgNum()) << Ex->getSourceRange();
+       << "nonnull" << I.getArgNum() << Ex->getSourceRange();
       return;
     }