add direct support for signed and unsigned integer arguments to diagnostics.

llvm-svn: 59598
This commit is contained in:
Chris Lattner 2008-11-19 07:22:31 +00:00
parent 327984f4c4
commit 91aea716c6
4 changed files with 55 additions and 2 deletions

View 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;
}
}
}

View 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]) &&

View 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;
}

View 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;
}