[cfe-commits] r80106 - in /cfe/trunk: clang.xcodeproj/project.pbxproj include/clang/Basic/Diagnostic.h include/clang/Basic/PartialDiagnostic.h
Anders Carlsson
andersca at mac.com
Wed Aug 26 09:23:53 PDT 2009
Author: andersca
Date: Wed Aug 26 11:23:53 2009
New Revision: 80106
URL: http://llvm.org/viewvc/llvm-project?rev=80106&view=rev
Log:
Add the partially implemented PartialDiagnostic class.
Added:
cfe/trunk/include/clang/Basic/PartialDiagnostic.h
Modified:
cfe/trunk/clang.xcodeproj/project.pbxproj
cfe/trunk/include/clang/Basic/Diagnostic.h
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=80106&r1=80105&r2=80106&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Wed Aug 26 11:23:53 2009
@@ -378,6 +378,7 @@
1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
1AA1D91610125DE30078DEBC /* RecordLayoutBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = RecordLayoutBuilder.cpp; path = lib/AST/RecordLayoutBuilder.cpp; sourceTree = "<group>"; tabWidth = 2; };
1AA1D91710125DE30078DEBC /* RecordLayoutBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = RecordLayoutBuilder.h; path = lib/AST/RecordLayoutBuilder.h; sourceTree = "<group>"; tabWidth = 2; };
+ 1AB290021045858B00FE33D8 /* PartialDiagnostic.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = PartialDiagnostic.h; sourceTree = "<group>"; tabWidth = 2; };
1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGBuiltin.cpp; path = lib/CodeGen/CGBuiltin.cpp; sourceTree = "<group>"; tabWidth = 2; };
1ADF47AE0F782C3200E48A8A /* SemaTemplateInstantiateDecl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaTemplateInstantiateDecl.cpp; path = lib/Sema/SemaTemplateInstantiateDecl.cpp; sourceTree = "<group>"; tabWidth = 2; };
1AE4EE3B103B89CA00888A23 /* TreeTransform.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = TreeTransform.h; path = lib/Sema/TreeTransform.h; sourceTree = "<group>"; tabWidth = 2; };
@@ -1365,6 +1366,7 @@
9063F2280F9E911F002F7251 /* OnDiskHashTable.h */,
DE8824560ED1244600CBC30A /* OperatorKinds.def */,
DE8824530ED1243E00CBC30A /* OperatorKinds.h */,
+ 1AB290021045858B00FE33D8 /* PartialDiagnostic.h */,
DEAABDF70F5F477C0098928A /* PrettyStackTrace.h */,
DED7D7350A524295003AD0FB /* SourceLocation.h */,
DED7D7360A524295003AD0FB /* SourceManager.h */,
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=80106&r1=80105&r2=80106&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Aug 26 11:23:53 2009
@@ -24,11 +24,12 @@
}
namespace clang {
- class DiagnosticClient;
- class SourceRange;
class DiagnosticBuilder;
+ class DiagnosticClient;
class IdentifierInfo;
class LangOptions;
+ class PartialDiagnostic;
+ class SourceRange;
// Import the diagnostic enums themselves.
namespace diag {
Added: cfe/trunk/include/clang/Basic/PartialDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/PartialDiagnostic.h?rev=80106&view=auto
==============================================================================
--- cfe/trunk/include/clang/Basic/PartialDiagnostic.h (added)
+++ cfe/trunk/include/clang/Basic/PartialDiagnostic.h Wed Aug 26 11:23:53 2009
@@ -0,0 +1,97 @@
+#ifndef LLVM_CLANG_PARTIALDIAGNOSTIC_H
+#define LLVM_CLANG_PARTIALDIAGNOSTIC_H
+
+#include "clang/AST/Type.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+
+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).
+ /// A single diagnostic with more than that almost certainly has to
+ /// be simplified anyway.
+ MaxArguments = 10
+ };
+
+ /// NumDiagArgs - This contains the number of entries in Arguments.
+ unsigned char NumDiagArgs;
+
+ /// NumDiagRanges - This is the number of ranges in the DiagRanges array.
+ unsigned char NumDiagRanges;
+
+ /// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum
+ /// values, with one for each argument. This specifies whether the argument
+ /// is in DiagArgumentsStr or in DiagArguments.
+ unsigned char DiagArgumentsKind[MaxArguments];
+
+ /// DiagArgumentsVal - The values for the various substitution positions.
+ /// This is used when the argument is not an std::string. The specific value
+ /// is mangled into an intptr_t and the intepretation depends on exactly
+ /// what sort of argument kind it is.
+ mutable intptr_t DiagArgumentsVal[MaxArguments];
+
+ /// DiagRanges - The list of ranges added to this diagnostic. It currently
+ /// only support 10 ranges, could easily be extended if needed.
+ mutable const SourceRange *DiagRanges[10];
+ };
+
+ mutable Storage *DiagStorage;
+
+ void AddTaggedVal(intptr_t V, Diagnostic::ArgumentKind Kind) const {
+ assert(DiagStorage->NumDiagArgs < Storage::MaxArguments &&
+ "Too many arguments to diagnostic!");
+ DiagStorage->DiagArgumentsKind[DiagStorage->NumDiagArgs] = Kind;
+ DiagStorage->DiagArgumentsVal[DiagStorage->NumDiagArgs++] = V;
+ }
+
+ void AddSourceRange(const SourceRange &R) const {
+ assert(DiagStorage->NumDiagRanges <
+ llvm::array_lengthof(DiagStorage->DiagRanges) &&
+ "Too many arguments to diagnostic!");
+ DiagStorage->DiagRanges[DiagStorage->NumDiagRanges++] = &R;
+ }
+
+ void operator=(const PartialDiagnostic &); // DO NOT IMPLEMENT
+
+public:
+ explicit PartialDiagnostic(unsigned DiagID)
+ : DiagID(DiagID), DiagStorage(new Storage) { }
+
+ PartialDiagnostic(const PartialDiagnostic &Other)
+ : DiagStorage(Other.DiagStorage) {
+ Other.DiagStorage = 0;
+ }
+
+ ~PartialDiagnostic() {
+ delete DiagStorage;
+ }
+
+ friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
+ QualType T) {
+ PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
+ Diagnostic::ak_qualtype);
+ return PD;
+ }
+
+ friend inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
+ const SourceRange &R) {
+ PD.AddSourceRange(R);
+ return PD;
+ }
+};
+
+PartialDiagnostic PDiag(unsigned DiagID) {
+ return PartialDiagnostic(DiagID);
+}
+
+
+} // end namespace clang
+#endif
More information about the cfe-commits
mailing list