15 #ifndef LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H 16 #define LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H 21 #include "llvm/ADT/SmallVector.h" 22 #include "llvm/ADT/StringRef.h" 26 #include <type_traits> 85 static const unsigned NumCached = 16;
88 unsigned NumFreeListEntries;
96 if (NumFreeListEntries == 0)
108 if (S >= Cached && S <= Cached + NumCached) {
109 FreeList[NumFreeListEntries++] = S;
123 mutable unsigned DiagID = 0;
126 mutable Storage *DiagStorage =
nullptr;
137 DiagStorage = Allocator->
Allocate();
139 assert(Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)));
158 void freeStorageSlow() {
161 else if (Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)))
163 DiagStorage =
nullptr;
168 DiagStorage = getStorage();
173 void AddFixItHint(
const FixItHint &Hint)
const {
178 DiagStorage = getStorage();
191 : DiagID(DiagID), Allocator(&Allocator) {}
194 : DiagID(Other.DiagID), Allocator(Other.Allocator) {
195 if (Other.DiagStorage) {
196 DiagStorage = getStorage();
197 *DiagStorage = *Other.DiagStorage;
202 : DiagID(Other.DiagID), DiagStorage(Other.DiagStorage),
203 Allocator(Other.Allocator) {
204 Other.DiagStorage =
nullptr;
208 : DiagID(Other.DiagID), DiagStorage(DiagStorage),
210 if (Other.DiagStorage)
211 *this->DiagStorage = *Other.DiagStorage;
215 : DiagID(Other.getID()), Allocator(&Allocator) {
217 for (
unsigned I = 0, N = Other.
getNumArgs(); I != N; ++I) {
225 for (
unsigned I = 0, N = Other.
getNumRanges(); I != N; ++I)
234 DiagID = Other.DiagID;
235 if (Other.DiagStorage) {
237 DiagStorage = getStorage();
239 *DiagStorage = *Other.DiagStorage;
250 DiagID = Other.DiagID;
251 DiagStorage = Other.DiagStorage;
252 Allocator = Other.Allocator;
254 Other.DiagStorage =
nullptr;
263 std::swap(DiagID, PD.DiagID);
264 std::swap(DiagStorage, PD.DiagStorage);
265 std::swap(Allocator, PD.Allocator);
272 DiagStorage = getStorage();
275 "Too many arguments to diagnostic!");
282 DiagStorage = getStorage();
285 "Too many arguments to diagnostic!");
296 for (
unsigned i = 0, e = DiagStorage->
NumDiagArgs; i != e; ++i) {
329 this->DiagID = DiagID;
337 assert(DiagStorage &&
"No diagnostic storage?");
338 assert(I < DiagStorage->
NumDiagArgs &&
"Not enough diagnostic args");
383 typename std::enable_if<std::is_same<T, DeclContext>::value,
399 PD.AddSourceRange(R);
405 PD.AddFixItHint(Hint);
422 #endif // LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H void AddFixItHint(const FixItHint &Hint) const
PartialDiagnostic(const PartialDiagnostic &Other, Storage *DiagStorage)
PartialDiagnostic(const PartialDiagnostic &Other)
static CharSourceRange getTokenRange(SourceRange R)
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
PartialDiagnostic(const Diagnostic &Other, StorageAllocator &Allocator)
PartialDiagnostic(PartialDiagnostic &&Other)
DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const
Return the kind of the specified index.
const std::string & getArgStdStr(unsigned Idx) const
Return the provided argument string specified by Idx.
unsigned getDiagID() const
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, StringRef S)
void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const
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 AddString(StringRef V) const
const FixItHint & getFixItHint(unsigned Idx) 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.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, const IdentifierInfo *II)
intptr_t getRawArg(unsigned Idx) const
Return the specified non-string argument in an opaque form.
Defines the Diagnostic-related interfaces.
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, const FixItHint &Hint)
PartialDiagnostic & operator=(const PartialDiagnostic &Other)
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, const CharSourceRange &R)
A little helper class used to produce diagnostics.
Represents a character-granular source range.
unsigned getNumRanges() const
Return the number of source ranges associated with this diagnostic.
std::string DiagArgumentsStr[MaxArguments]
The values for the various substitution positions that have string arguments.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
An allocator for Storage objects, which uses a small cache to objects, used to reduce malloc()/free()...
void Clear()
Clear out the current diagnostic.
SmallVector< CharSourceRange, 8 > DiagRanges
The list of ranges added to this diagnostic.
void EmitToString(DiagnosticsEngine &Diags, SmallVectorImpl< char > &Buf) const
The result type of a method or function.
StringRef getStringArg(unsigned I)
Retrieve the string argument at the given index.
Storage * Allocate()
Allocate new storage.
PartialDiagnostic & operator=(PartialDiagnostic &&Other)
void Emit(const DiagnosticBuilder &DB) const
PartialDiagnostic(NullDiagnostic)
Create a null partial diagnostic, which cannot carry a payload, and only exists to be swapped with a ...
void AddSourceRange(const CharSourceRange &R) const
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type...
const CharSourceRange & getRange(unsigned Idx) const
intptr_t DiagArgumentsVal[MaxArguments]
The values for the various substitution positions.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
void AddString(StringRef S) const
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, int I)
Dataflow Directional Tag Classes.
friend const PartialDiagnostic & operator<<(const PartialDiagnostic &PD, SourceRange R)
unsigned getNumFixItHints() const
void Deallocate(Storage *S)
Free the given storage object.
PartialDiagnostic(unsigned DiagID, StorageAllocator &Allocator)
Defines the clang::SourceLocation class and associated facilities.
unsigned getNumArgs() const
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
The maximum number of arguments we can hold.
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...