[cfe-commits] r80158 - /cfe/trunk/include/clang/Basic/PartialDiagnostic.h
Anders Carlsson
andersca at mac.com
Wed Aug 26 14:48:37 PDT 2009
Author: andersca
Date: Wed Aug 26 16:48:37 2009
New Revision: 80158
URL: http://llvm.org/viewvc/llvm-project?rev=80158&view=rev
Log:
More improvements to PartialDiagnostic.
Modified:
cfe/trunk/include/clang/Basic/PartialDiagnostic.h
Modified: cfe/trunk/include/clang/Basic/PartialDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/PartialDiagnostic.h?rev=80158&r1=80157&r2=80158&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/PartialDiagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/PartialDiagnostic.h Wed Aug 26 16:48:37 2009
@@ -1,3 +1,17 @@
+//===--- PartialDiagnostic.h - Diagnostic "closures" ----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a partial diagnostic that can be emitted anwyhere
+// in a DiagnosticBuilder stream.
+//
+//===----------------------------------------------------------------------===//
+
#ifndef LLVM_CLANG_PARTIALDIAGNOSTIC_H
#define LLVM_CLANG_PARTIALDIAGNOSTIC_H
@@ -8,11 +22,9 @@
namespace clang {
class PartialDiagnostic {
- unsigned DiagID;
-
struct Storage {
Storage() : NumDiagArgs(0), NumDiagRanges(0) { }
-
+
enum {
/// MaxArguments - The maximum number of arguments we can hold. We
/// currently only support up to 10 arguments (%0-%9).
@@ -43,9 +55,16 @@
mutable const SourceRange *DiagRanges[10];
};
+ /// DiagID - The diagnostic ID.
+ mutable unsigned DiagID;
+
+ /// DiagStorare - Storge for args and ranges.
mutable Storage *DiagStorage;
void AddTaggedVal(intptr_t V, Diagnostic::ArgumentKind Kind) const {
+ if (!DiagStorage)
+ DiagStorage = new Storage;
+
assert(DiagStorage->NumDiagArgs < Storage::MaxArguments &&
"Too many arguments to diagnostic!");
DiagStorage->DiagArgumentsKind[DiagStorage->NumDiagArgs] = Kind;
@@ -53,6 +72,9 @@
}
void AddSourceRange(const SourceRange &R) const {
+ if (!DiagStorage)
+ DiagStorage = new Storage;
+
assert(DiagStorage->NumDiagRanges <
llvm::array_lengthof(DiagStorage->DiagRanges) &&
"Too many arguments to diagnostic!");
@@ -63,10 +85,11 @@
public:
explicit PartialDiagnostic(unsigned DiagID)
- : DiagID(DiagID), DiagStorage(new Storage) { }
+ : DiagID(DiagID), DiagStorage(0) { }
PartialDiagnostic(const PartialDiagnostic &Other)
- : DiagStorage(Other.DiagStorage) {
+ : DiagID(Other.DiagID), DiagStorage(Other.DiagStorage) {
+ Other.DiagID = 0;
Other.DiagStorage = 0;
}
@@ -74,6 +97,23 @@
delete DiagStorage;
}
+ unsigned getDiagID() const { return DiagID; }
+
+ void Emit(const DiagnosticBuilder &DB) const {
+ if (!DiagStorage)
+ return;
+
+ // Add all arguments.
+ for (unsigned i = 0, e = DiagStorage->NumDiagArgs; i != e; ++i) {
+ DB.AddTaggedVal(DiagStorage->DiagArgumentsVal[i],
+ (Diagnostic::ArgumentKind)DiagStorage->DiagArgumentsKind[i]);
+ }
+
+ // Add all ranges.
+ for (unsigned i = 0, e = DiagStorage->NumDiagRanges; i != e; ++i)
+ DB.AddSourceRange(*DiagStorage->DiagRanges[i]);
+ }
+
friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
QualType T) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
@@ -86,12 +126,19 @@
PD.AddSourceRange(R);
return PD;
}
+
};
-PartialDiagnostic PDiag(unsigned DiagID) {
+inline PartialDiagnostic PDiag(unsigned DiagID) {
return PartialDiagnostic(DiagID);
}
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+ const PartialDiagnostic &PD) {
+ PD.Emit(DB);
+ return DB;
+}
+
} // end namespace clang
#endif
More information about the cfe-commits
mailing list