[cfe-commits] r59797 - /cfe/trunk/include/clang/Basic/Diagnostic.h
Chris Lattner
sabre at nondot.org
Thu Nov 20 22:54:20 PST 2008
Author: lattner
Date: Fri Nov 21 00:54:20 2008
New Revision: 59797
URL: http://llvm.org/viewvc/llvm-project?rev=59797&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=59797&r1=59796&r2=59797&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Fri Nov 21 00:54:20 2008
@@ -336,58 +336,26 @@
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<intptr_t>(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<intptr_t>(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 @@
void FormatDiagnostic(llvm::SmallVectorImpl<char> &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<intptr_t>(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<intptr_t>(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
More information about the cfe-commits
mailing list