16 #ifndef LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H 17 #define LLVM_CLANG_BASIC_PARTIALDIAGNOSTIC_H 22 #include "llvm/ADT/SmallVector.h" 23 #include "llvm/ADT/StringRef.h" 27 #include <type_traits> 86 static const unsigned NumCached = 16;
89 unsigned NumFreeListEntries;
97 if (NumFreeListEntries == 0)
109 if (S >= Cached && S <= Cached + NumCached) {
110 FreeList[NumFreeListEntries++] = S;
124 mutable unsigned DiagID = 0;
127 mutable Storage *DiagStorage =
nullptr;
138 DiagStorage = Allocator->
Allocate();
140 assert(Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)));
159 void freeStorageSlow() {
162 else if (Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)))
164 DiagStorage =
nullptr;
169 DiagStorage = getStorage();
174 void AddFixItHint(
const FixItHint &Hint)
const {
179 DiagStorage = getStorage();
192 : DiagID(DiagID), Allocator(&Allocator) {}
195 : DiagID(Other.DiagID), Allocator(Other.Allocator) {
196 if (Other.DiagStorage) {
197 DiagStorage = getStorage();
198 *DiagStorage = *Other.DiagStorage;
203 : DiagID(Other.DiagID), DiagStorage(Other.DiagStorage),
204 Allocator(Other.Allocator) {
205 Other.DiagStorage =
nullptr;
209 : DiagID(Other.DiagID), DiagStorage(DiagStorage),
211 if (Other.DiagStorage)
212 *this->DiagStorage = *Other.DiagStorage;
216 : DiagID(Other.getID()), Allocator(&Allocator) {
218 for (
unsigned I = 0, N = Other.
getNumArgs(); I != N; ++I) {
226 for (
unsigned I = 0, N = Other.
getNumRanges(); I != N; ++I)
235 DiagID = Other.DiagID;
236 if (Other.DiagStorage) {
238 DiagStorage = getStorage();
240 *DiagStorage = *Other.DiagStorage;
251 DiagID = Other.DiagID;
252 DiagStorage = Other.DiagStorage;
253 Allocator = Other.Allocator;
255 Other.DiagStorage =
nullptr;
264 std::swap(DiagID, PD.DiagID);
265 std::swap(DiagStorage, PD.DiagStorage);
266 std::swap(Allocator, PD.Allocator);
273 DiagStorage = getStorage();
276 "Too many arguments to diagnostic!");
283 DiagStorage = getStorage();
286 "Too many arguments to diagnostic!");
297 for (
unsigned i = 0, e = DiagStorage->
NumDiagArgs; i != e; ++i) {
330 this->DiagID = DiagID;
338 assert(DiagStorage &&
"No diagnostic storage?");
339 assert(I < DiagStorage->
NumDiagArgs &&
"Not enough diagnostic args");
384 typename std::enable_if<std::is_same<T, DeclContext>::value,
400 PD.AddSourceRange(R);
406 PD.AddFixItHint(Hint);
423 #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)
__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)
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.
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.
__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.
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
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...