From 2cb836eb16afea6a7e07109bdec37e85c44d7bd7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 21 Nov 2008 06:54:20 +0000 Subject: [PATCH] move diagnostic insertion methods to be free methods instead of in the DiagnosticInfo class. This requires marking them as taking a const DiagnosticInfo, which is bogus (they logically mutate DI), but works with the C++ type system. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59797 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Diagnostic.h | 79 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 0b68a2e363..94c77406ae 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -336,58 +336,26 @@ public: return *DiagObj->DiagRanges[Idx]; } - DiagnosticInfo &operator<<(const std::string &S) { + void AddString(const std::string &S) const { assert((unsigned)DiagObj->NumDiagArgs < Diagnostic::MaxArguments && "Too many arguments to diagnostic!"); DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = ak_std_string; DiagObj->DiagArgumentsStr[DiagObj->NumDiagArgs++] = S; - return *this; } - DiagnosticInfo &operator<<(const char *Str) { + void AddTaggedVal(intptr_t V, ArgumentKind Kind) const { assert((unsigned)DiagObj->NumDiagArgs < Diagnostic::MaxArguments && "Too many arguments to diagnostic!"); - DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = ak_c_string; - DiagObj->DiagArgumentsVal[DiagObj->NumDiagArgs++] = - reinterpret_cast(Str); - return *this; + DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = Kind; + DiagObj->DiagArgumentsVal[DiagObj->NumDiagArgs++] = V; } - 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 IdentifierInfo *II) { - assert((unsigned)DiagObj->NumDiagArgs < Diagnostic::MaxArguments && - "Too many arguments to diagnostic!"); - DiagObj->DiagArgumentsKind[DiagObj->NumDiagArgs] = ak_identifierinfo; - DiagObj->DiagArgumentsVal[DiagObj->NumDiagArgs++] = - reinterpret_cast(II); - return *this; - } - - - - - DiagnosticInfo &operator<<(const SourceRange &R) { + void AddSourceRange(const SourceRange &R) const { assert((unsigned)DiagObj->NumDiagArgs < sizeof(DiagObj->DiagRanges)/sizeof(DiagObj->DiagRanges[0]) && "Too many arguments to diagnostic!"); DiagObj->DiagRanges[DiagObj->NumDiagRanges++] = &R; - return *this; - } + } /// FormatDiagnostic - Format this diagnostic into a string, substituting the /// formal arguments into the %0 slots. The result is appended onto the Str @@ -395,6 +363,41 @@ public: void FormatDiagnostic(llvm::SmallVectorImpl &OutStr) const; }; +inline const DiagnosticInfo &operator<<(const DiagnosticInfo &DI, + const std::string &S) { + DI.AddString(S); + return DI; +} + +inline const DiagnosticInfo &operator<<(const DiagnosticInfo &DI, + const char *Str) { + DI.AddTaggedVal(reinterpret_cast(Str), DiagnosticInfo::ak_c_string); + return DI; +} + +inline const DiagnosticInfo &operator<<(const DiagnosticInfo &DI, int I) { + DI.AddTaggedVal(I, DiagnosticInfo::ak_sint); + return DI; +} + +inline const DiagnosticInfo &operator<<(const DiagnosticInfo &DI, unsigned I) { + DI.AddTaggedVal(I, DiagnosticInfo::ak_uint); + return DI; +} + +inline const DiagnosticInfo &operator<<(const DiagnosticInfo &DI, + const IdentifierInfo *II){ + DI.AddTaggedVal(reinterpret_cast(II), + DiagnosticInfo::ak_identifierinfo); + return DI; +} + +inline const DiagnosticInfo &operator<<(const DiagnosticInfo &DI, + const SourceRange &R) { + DI.AddSourceRange(R); + return DI; +} + /// Report - Issue the message to the client. DiagID is a member of the /// diag::kind enum. This actually returns a new instance of DiagnosticInfo -- 2.40.0