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;
131 DiagStorage = Allocator->
Allocate();
133 assert(Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)));
152 void freeStorageSlow() {
155 else if (Allocator != reinterpret_cast<StorageAllocator *>(~
uintptr_t(0)))
157 DiagStorage =
nullptr;
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)
214 for (
unsigned I = 0, N = Other.
getNumArgs(); I != N; ++I) {
222 for (
unsigned I = 0, N = Other.
getNumRanges(); I != N; ++I)
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;
334 assert(DiagStorage &&
"No diagnostic storage?");
335 assert(I < DiagStorage->
NumDiagArgs &&
"Not enough diagnostic args");
380 typename std::enable_if<std::is_same<T, DeclContext>::value,
396 PD.AddSourceRange(R);
402 PD.AddFixItHint(Hint);
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.
Concrete class used by the front-end to report problems and issues.
The maximum number of arguments we can hold.
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.
const FunctionProtoType * T
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.
void AddString(StringRef S) const
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
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) ...
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...