16 #ifndef LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H
17 #define LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/Support/Compiler.h"
23 #include "llvm/Support/DataTypes.h"
79 static const unsigned NumCached = 16;
82 unsigned NumFreeListEntries;
90 if (NumFreeListEntries == 0)
102 if (S >= Cached && S <= Cached + NumCached) {
103 FreeList[NumFreeListEntries++] =
S;
117 mutable unsigned DiagID;
120 mutable Storage *DiagStorage;
123 StorageAllocator *Allocator;
126 Storage *getStorage()
const {
131 DiagStorage = Allocator->
Allocate();
133 assert(Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)));
134 DiagStorage =
new Storage;
152 void freeStorageSlow() {
155 else if (Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)))
157 DiagStorage =
nullptr;
160 void AddSourceRange(
const CharSourceRange &R)
const {
162 DiagStorage = getStorage();
167 void AddFixItHint(
const FixItHint &Hint)
const {
172 DiagStorage = getStorage();
182 : DiagID(0), DiagStorage(nullptr), Allocator(nullptr) { }
185 : DiagID(DiagID), DiagStorage(nullptr), Allocator(&Allocator) { }
188 : DiagID(Other.DiagID), DiagStorage(nullptr), Allocator(Other.Allocator)
190 if (Other.DiagStorage) {
191 DiagStorage = getStorage();
192 *DiagStorage = *Other.DiagStorage;
197 : DiagID(Other.DiagID), DiagStorage(Other.DiagStorage),
198 Allocator(Other.Allocator) {
199 Other.DiagStorage =
nullptr;
203 : DiagID(Other.DiagID), DiagStorage(DiagStorage),
206 if (Other.DiagStorage)
207 *this->DiagStorage = *Other.DiagStorage;
211 : DiagID(Other.getID()), DiagStorage(nullptr), Allocator(&Allocator)
231 DiagID = Other.DiagID;
232 if (Other.DiagStorage) {
234 DiagStorage = getStorage();
236 *DiagStorage = *Other.DiagStorage;
247 DiagID = Other.DiagID;
248 DiagStorage = Other.DiagStorage;
249 Allocator = Other.Allocator;
251 Other.DiagStorage =
nullptr;
260 std::swap(DiagID, PD.DiagID);
261 std::swap(DiagStorage, PD.DiagStorage);
262 std::swap(Allocator, PD.Allocator);
269 DiagStorage = getStorage();
272 "Too many arguments to diagnostic!");
279 DiagStorage = getStorage();
282 "Too many arguments to diagnostic!");
293 for (
unsigned i = 0, e = DiagStorage->
NumDiagArgs; i != e; ++i) {
326 this->DiagID = DiagID;
371 typename std::enable_if<std::is_same<T, DeclContext>::value,
387 PD.AddSourceRange(R);
393 PD.AddFixItHint(Hint);
void AddString(StringRef V) const
unsigned getNumArgs() const
PartialDiagnostic(const PartialDiagnostic &Other, Storage *DiagStorage)
PartialDiagnostic(const PartialDiagnostic &Other)
static CharSourceRange getTokenRange(SourceRange R)
const std::string & getArgStdStr(unsigned Idx) const
Return the provided argument string specified by Idx.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
PartialDiagnostic(const Diagnostic &Other, StorageAllocator &Allocator)
PartialDiagnostic(PartialDiagnostic &&Other)
The maximum number of arguments we can hold.
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, StringRef S)
One of these records is kept for each identifier that is lexed.
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, const char *S)
unsigned char NumDiagArgs
The number of entries in Arguments.
void EmitToString(DiagnosticsEngine &Diags, SmallVectorImpl< char > &Buf) const
void Reset(unsigned DiagID=0)
Clear out this partial diagnostic, giving it a new diagnostic ID and removing all of its arguments...
unsigned char DiagArgumentsKind[MaxArguments]
Specifies for each argument whether it is in DiagArgumentsStr or in DiagArguments.
unsigned getDiagID() const
unsigned getNumRanges() const
Return the number of source ranges associated with this diagnostic.
Concrete class used by the front-end to report problems and issues.
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, const IdentifierInfo *II)
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, const FixItHint &Hint)
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type...
PartialDiagnostic & operator=(const PartialDiagnostic &Other)
detail::InMemoryDirectory::const_iterator I
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, const CharSourceRange &R)
void Emit(const DiagnosticBuilder &DB) const
A little helper class used to produce diagnostics.
Represents a character-granular source range.
std::string DiagArgumentsStr[MaxArguments]
The values for the various substitution positions that have string arguments.
An allocator for Storage objects, which uses a small cache to objects, used to reduce malloc()/free()...
intptr_t getRawArg(unsigned Idx) const
Return the specified non-string argument in an opaque form.
void AddString(StringRef S) const
void Clear()
Clear out the current diagnostic.
SmallVector< CharSourceRange, 8 > DiagRanges
The list of ranges added to this diagnostic.
void AddSourceRange(const CharSourceRange &R) const
The result type of a method or function.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Storage * Allocate()
Allocate new storage.
void AddFixItHint(const FixItHint &Hint) const
PartialDiagnostic & operator=(PartialDiagnostic &&Other)
PartialDiagnostic(NullDiagnostic)
Create a null partial diagnostic, which cannot carry a payload, and only exists to be swapped with a ...
intptr_t DiagArgumentsVal[MaxArguments]
The values for the various substitution positions.
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const
Return the kind of the specified index.
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, int I)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, SourceRange R)
const FixItHint & getFixItHint(unsigned Idx) const
Defines the Diagnostic-related interfaces.
void Deallocate(Storage *S)
Free the given storage object.
PartialDiagnostic(unsigned DiagID, StorageAllocator &Allocator)
Defines the clang::SourceLocation class and associated facilities.
const CharSourceRange & getRange(unsigned Idx) const
unsigned getNumFixItHints() const
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, unsigned I)
A trivial tuple used to represent a source range.
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots...
void swap(PartialDiagnostic &PD)
SmallVector< FixItHint, 6 > FixItHints
If valid, provides a hint with some code to insert, remove, or modify at a particular position...