24#include "llvm/ADT/SmallString.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringExtras.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/Support/ConvertUTF.h"
29#include "llvm/Support/CrashRecoveryContext.h"
30#include "llvm/Support/Unicode.h"
31#include "llvm/Support/raw_ostream.h"
62 StringRef Modifier, StringRef Argument,
67 StringRef Str =
"<can't format argument>";
68 Output.append(Str.begin(), Str.end());
75 : Diags(
std::move(diags)), DiagOpts(
std::move(DiagOpts)) {
89 DiagStatesByLoc.dump(*SourceMgr);
93 DiagStatesByLoc.dump(*SourceMgr, DiagName);
97 bool ShouldOwnClient) {
98 Owner.reset(ShouldOwnClient ? client :
nullptr);
103 DiagStateOnPushStack.push_back(GetCurDiagState());
107 if (DiagStateOnPushStack.empty())
110 if (DiagStateOnPushStack.back() != GetCurDiagState()) {
112 PushDiagStatePoint(DiagStateOnPushStack.back(),
Loc);
114 DiagStateOnPushStack.pop_back();
119 ErrorOccurred =
false;
120 UncompilableErrorOccurred =
false;
121 FatalErrorOccurred =
false;
122 UnrecoverableErrorOccurred =
false;
126 TrapNumErrorsOccurred = 0;
127 TrapNumUnrecoverableErrorsOccurred = 0;
129 CurDiagID = std::numeric_limits<unsigned>::max();
136 DiagStatesByLoc.clear();
137 DiagStateOnPushStack.clear();
141 DiagStates.emplace_back();
142 DiagStatesByLoc.appendFirst(&DiagStates.back());
147 StringRef Arg2, StringRef Arg3) {
151 DelayedDiagID = DiagID;
152 DelayedDiagArg1 = Arg1.str();
153 DelayedDiagArg2 = Arg2.str();
154 DelayedDiagArg3 = Arg3.str();
157void DiagnosticsEngine::ReportDelayed() {
158 unsigned ID = DelayedDiagID;
160 Report(ID) << DelayedDiagArg1 << DelayedDiagArg2 << DelayedDiagArg3;
165 std::pair<iterator, bool>
Result =
172 return Result.first->second;
175void DiagnosticsEngine::DiagStateMap::appendFirst(DiagState *State) {
176 assert(Files.empty() &&
"not first");
177 FirstDiagState = CurDiagState = State;
181void DiagnosticsEngine::DiagStateMap::append(
SourceManager &SrcMgr,
184 CurDiagState = State;
185 CurDiagStateLoc =
Loc;
188 unsigned Offset = Decomp.second;
189 for (
File *F = getFile(SrcMgr, Decomp.first); F;
190 Offset = F->ParentOffset, F = F->Parent) {
191 F->HasLocalTransitions =
true;
192 auto &
Last = F->StateTransitions.back();
193 assert(
Last.Offset <= Offset &&
"state transitions added out of order");
195 if (
Last.Offset == Offset) {
196 if (
Last.State == State)
202 F->StateTransitions.push_back({State, Offset});
206DiagnosticsEngine::DiagState *
207DiagnosticsEngine::DiagStateMap::lookup(
SourceManager &SrcMgr,
211 return FirstDiagState;
214 const File *F = getFile(SrcMgr, Decomp.first);
215 return F->lookup(Decomp.second);
218DiagnosticsEngine::DiagState *
219DiagnosticsEngine::DiagStateMap::File::lookup(
unsigned Offset)
const {
221 llvm::partition_point(StateTransitions, [=](
const DiagStatePoint &
P) {
222 return P.Offset <= Offset;
224 assert(OnePastIt != StateTransitions.begin() &&
"missing initial state");
225 return OnePastIt[-1].State;
228DiagnosticsEngine::DiagStateMap::File *
229DiagnosticsEngine::DiagStateMap::getFile(
SourceManager &SrcMgr,
232 auto Range = Files.equal_range(ID);
234 return &
Range.first->second;
235 auto &F = Files.insert(
Range.first, std::make_pair(ID,
File()))->second;
241 F.Parent = getFile(SrcMgr, Decomp.first);
242 F.ParentOffset = Decomp.second;
243 F.StateTransitions.push_back({F.Parent->lookup(Decomp.second), 0});
252 F.StateTransitions.push_back({FirstDiagState, 0});
257void DiagnosticsEngine::DiagStateMap::dump(
SourceManager &SrcMgr,
258 StringRef DiagName)
const {
259 llvm::errs() <<
"diagnostic state at ";
260 CurDiagStateLoc.print(llvm::errs(), SrcMgr);
261 llvm::errs() <<
": " << CurDiagState <<
"\n";
263 for (
auto &F : Files) {
267 bool PrintedOuterHeading =
false;
268 auto PrintOuterHeading = [&] {
269 if (PrintedOuterHeading)
return;
270 PrintedOuterHeading =
true;
272 llvm::errs() <<
"File " << &
File <<
" <FileID " <<
ID.getHashValue()
275 if (F.second.Parent) {
276 std::pair<FileID, unsigned> Decomp =
278 assert(
File.ParentOffset == Decomp.second);
279 llvm::errs() <<
" parent " <<
File.Parent <<
" <FileID "
280 << Decomp.first.getHashValue() <<
"> ";
283 .
print(llvm::errs(), SrcMgr);
285 if (
File.HasLocalTransitions)
286 llvm::errs() <<
" has_local_transitions";
287 llvm::errs() <<
"\n";
290 if (DiagName.empty())
293 for (DiagStatePoint &Transition :
File.StateTransitions) {
294 bool PrintedInnerHeading =
false;
295 auto PrintInnerHeading = [&] {
296 if (PrintedInnerHeading)
return;
297 PrintedInnerHeading =
true;
303 .
print(llvm::errs(), SrcMgr);
304 llvm::errs() <<
": state " << Transition.State <<
":\n";
307 if (DiagName.empty())
310 for (
auto &Mapping : *Transition.State) {
313 if (!DiagName.empty() && DiagName != Option)
319 llvm::errs() <<
"<unknown " << Mapping.first <<
">";
321 llvm::errs() << Option;
322 llvm::errs() <<
": ";
324 switch (Mapping.second.getSeverity()) {
332 if (!Mapping.second.isUser())
333 llvm::errs() <<
" default";
334 if (Mapping.second.isPragma())
335 llvm::errs() <<
" pragma";
336 if (Mapping.second.hasNoWarningAsError())
337 llvm::errs() <<
" no-error";
338 if (Mapping.second.hasNoErrorAsFatal())
339 llvm::errs() <<
" no-fatal";
340 if (Mapping.second.wasUpgradedFromWarning())
341 llvm::errs() <<
" overruled";
342 llvm::errs() <<
"\n";
348void DiagnosticsEngine::PushDiagStatePoint(DiagState *State,
350 assert(
Loc.
isValid() &&
"Adding invalid loc point");
351 DiagStatesByLoc.append(*SourceMgr,
Loc, State);
357 "Can only map builtin diagnostics");
358 assert((Diags->isBuiltinWarningOrExtension(
Diag) ||
360 "Cannot map errors into warnings!");
361 assert((L.
isInvalid() || SourceMgr) &&
"No SourceMgr for valid location");
365 bool WasUpgradedFromWarning =
false;
371 WasUpgradedFromWarning =
true;
384 if ((L.
isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
385 DiagStatesByLoc.getCurDiagState()) {
390 DiagStatesByLoc.getCurDiagState()->setMapping(
Diag, Mapping);
397 DiagStates.push_back(*GetCurDiagState());
398 DiagStates.back().setMapping(
Diag, Mapping);
399 PushDiagStatePoint(&DiagStates.back(), L);
407 if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags))
490 std::vector<diag::kind> AllDiags;
495 if (Diags->isBuiltinWarningOrExtension(
Diag))
500 assert(CurDiagID == std::numeric_limits<unsigned>::max() &&
501 "Multiple diagnostics in flight at once!");
504 CurDiagID = storedDiag.
getID();
515 assert(Client &&
"DiagnosticConsumer not set!");
524 CurDiagID = std::numeric_limits<unsigned>::max();
528 assert(
getClient() &&
"DiagnosticClient not set!");
541 Diags->EmitDiag(*
this, DiagLevel);
546 Emitted = ProcessDiag();
553 if (!Force && DelayedDiagID)
573template <std::
size_t StrLen>
574static bool ModifierIs(
const char *Modifier,
unsigned ModifierLen,
575 const char (&Str)[StrLen]) {
576 return StrLen-1 == ModifierLen && memcmp(Modifier, Str, StrLen-1) == 0;
584 for ( ; I !=
E; ++I) {
585 if (Depth == 0 && *I ==
Target)
return I;
586 if (Depth != 0 && *I ==
'}') Depth--;
596 for (I++; I !=
E && !
isDigit(*I) && *I !=
'{'; I++) ;
612 const char *Argument,
unsigned ArgumentLen,
614 const char *ArgumentEnd = Argument+ArgumentLen;
618 const char *NextVal =
ScanFormat(Argument, ArgumentEnd,
'|');
619 assert(NextVal != ArgumentEnd &&
"Value for integer select modifier was"
620 " larger than the number of options in the diagnostic string!");
621 Argument = NextVal+1;
626 const char *EndPtr =
ScanFormat(Argument, ArgumentEnd,
'|');
638 OutStr.push_back(
's');
647 assert(ValNo != 0 &&
"ValNo must be strictly positive!");
649 llvm::raw_svector_ostream Out(OutStr);
653 Out << ValNo << llvm::getOrdinalSuffix(ValNo);
660 while (Start != End && *Start >=
'0' && *Start <=
'9') {
677 assert(*Start ==
',' &&
"Bad plural expression syntax: expected ,");
680 assert(*Start ==
']' &&
"Bad plural expression syntax: expected )");
682 return Low <= Val && Val <= High;
697 assert(*Start ==
'=' &&
"Bad plural expression syntax: expected =");
699 unsigned ValMod = ValNo % Arg;
703 assert((
C ==
'[' || (
C >=
'0' &&
C <=
'9')) &&
704 "Bad plural expression syntax: unexpected character");
711 Start = std::find(Start, End,
',');
753 const char *Argument,
unsigned ArgumentLen,
755 const char *ArgumentEnd = Argument + ArgumentLen;
757 assert(Argument < ArgumentEnd &&
"Plural expression didn't match.");
758 const char *ExprEnd = Argument;
759 while (*ExprEnd !=
':') {
760 assert(ExprEnd != ArgumentEnd &&
"Plural missing expression end");
764 Argument = ExprEnd + 1;
765 ExprEnd =
ScanFormat(Argument, ArgumentEnd,
'|');
772 Argument =
ScanFormat(Argument, ArgumentEnd - 1,
'|') + 1;
781 case tok::identifier:
793 if (StoredDiagMessage.has_value()) {
794 OutStr.append(StoredDiagMessage->begin(), StoredDiagMessage->end());
808 OutStr.reserve(OutStr.size() + Str.size());
809 auto *
Begin =
reinterpret_cast<const unsigned char *
>(Str.data());
810 llvm::raw_svector_ostream OutStream(OutStr);
811 const unsigned char *End =
Begin + Str.size();
812 while (
Begin != End) {
819 if (llvm::isLegalUTF8Sequence(
Begin, End)) {
820 llvm::UTF32 CodepointValue;
821 llvm::UTF32 *CpPtr = &CodepointValue;
822 const unsigned char *CodepointBegin =
Begin;
823 const unsigned char *CodepointEnd =
825 llvm::ConversionResult Res = llvm::ConvertUTF8toUTF32(
826 &
Begin, CodepointEnd, &CpPtr, CpPtr + 1, llvm::strictConversion);
829 llvm::conversionOK == Res &&
830 "the sequence is legal UTF-8 but we couldn't convert it to UTF-32");
831 assert(
Begin == CodepointEnd &&
832 "we must be further along in the string now");
833 if (llvm::sys::unicode::isPrintable(CodepointValue) ||
834 llvm::sys::unicode::isFormatting(CodepointValue)) {
835 OutStr.append(CodepointBegin, CodepointEnd);
839 OutStream <<
"<U+" << llvm::format_hex_no_prefix(CodepointValue, 4,
true)
844 OutStream <<
"<" << llvm::format_hex_no_prefix(*
Begin, 2,
true) <<
">";
855 if (DiagEnd - DiagStr == 2 && StringRef(DiagStr, DiagEnd - DiagStr) ==
"%0" &&
873 for (
unsigned i = 0, e =
getNumArgs(); i < e; ++i)
877 while (DiagStr != DiagEnd) {
878 if (DiagStr[0] !=
'%') {
880 const char *StrEnd = std::find(DiagStr, DiagEnd,
'%');
881 OutStr.append(DiagStr, StrEnd);
885 OutStr.push_back(DiagStr[1]);
898 const char *Modifier =
nullptr, *Argument =
nullptr;
899 unsigned ModifierLen = 0, ArgumentLen = 0;
904 while (DiagStr[0] ==
'-' ||
905 (DiagStr[0] >=
'a' && DiagStr[0] <=
'z'))
907 ModifierLen = DiagStr-Modifier;
910 if (DiagStr[0] ==
'{') {
915 assert(DiagStr != DiagEnd &&
"Mismatched {}'s in diagnostic string!");
916 ArgumentLen = DiagStr-Argument;
921 assert(
isDigit(*DiagStr) &&
"Invalid format for argument in diagnostic");
922 unsigned ArgNo = *DiagStr++ -
'0';
925 unsigned ArgNo2 = ArgNo;
928 if (
ModifierIs(Modifier, ModifierLen,
"diff")) {
929 assert(*DiagStr ==
',' &&
isDigit(*(DiagStr + 1)) &&
930 "Invalid format for diff modifier");
932 ArgNo2 = *DiagStr++ -
'0';
943 const char *ArgumentEnd = Argument + ArgumentLen;
946 "Found too many '|'s in a %diff modifier!");
948 const char *SecondDollar =
ScanFormat(FirstDollar + 1,
Pipe,
'$');
949 const char ArgStr1[] = {
'%',
static_cast<char>(
'0' + ArgNo) };
950 const char ArgStr2[] = {
'%',
static_cast<char>(
'0' + ArgNo2) };
964 assert(ModifierLen == 0 &&
"No modifiers for strings yet");
970 assert(ModifierLen == 0 &&
"No modifiers for strings yet");
982 if (
ModifierIs(Modifier, ModifierLen,
"select")) {
985 }
else if (
ModifierIs(Modifier, ModifierLen,
"s")) {
987 }
else if (
ModifierIs(Modifier, ModifierLen,
"plural")) {
990 }
else if (
ModifierIs(Modifier, ModifierLen,
"ordinal")) {
993 assert(ModifierLen == 0 &&
"Unknown integer modifier");
994 llvm::raw_svector_ostream(OutStr) << Val;
1001 if (
ModifierIs(Modifier, ModifierLen,
"select")) {
1003 }
else if (
ModifierIs(Modifier, ModifierLen,
"s")) {
1005 }
else if (
ModifierIs(Modifier, ModifierLen,
"plural")) {
1008 }
else if (
ModifierIs(Modifier, ModifierLen,
"ordinal")) {
1011 assert(ModifierLen == 0 &&
"Unknown integer modifier");
1012 llvm::raw_svector_ostream(OutStr) << Val;
1019 assert(ModifierLen == 0 &&
"No modifiers for token kinds yet");
1021 llvm::raw_svector_ostream Out(OutStr);
1024 Out <<
'\'' << S <<
'\'';
1033 Out <<
'<' << S <<
'>';
1041 assert(ModifierLen == 0 &&
"No modifiers for strings yet");
1045 const char *S =
"(null)";
1046 OutStr.append(S, S + strlen(S));
1050 llvm::raw_svector_ostream(OutStr) <<
'\'' << II->
getName() <<
'\'';
1062 StringRef(Modifier, ModifierLen),
1063 StringRef(Argument, ArgumentLen),
1065 OutStr, QualTypeVals);
1077 const char *ArgumentEnd = Argument + ArgumentLen;
1086 StringRef(Modifier, ModifierLen),
1087 StringRef(Argument, ArgumentLen),
1089 Tree, QualTypeVals);
1091 if (!
Tree.empty()) {
1099 const char *FirstDollar =
ScanFormat(Argument, ArgumentEnd,
'$');
1100 const char *SecondDollar =
ScanFormat(FirstDollar + 1, ArgumentEnd,
'$');
1109 StringRef(Modifier, ModifierLen),
1110 StringRef(Argument, ArgumentLen),
1112 OutStr, QualTypeVals);
1123 StringRef(Modifier, ModifierLen),
1124 StringRef(Argument, ArgumentLen),
1126 OutStr, QualTypeVals);
1143 FormattedArgs.push_back(std::make_pair(Kind,
getRawArg(ArgNo)));
1150 OutStr.append(
Tree.begin(),
Tree.end());
1155 : ID(ID), Level(Level), Message(Message) {}
1159 : ID(Info.getID()), Level(Level) {
1161 "Valid source location without setting a source manager for diagnostic");
1166 this->Message.assign(Message.begin(), Message.end());
1175 : ID(ID), Level(Level),
Loc(
Loc), Message(Message),
1176 Ranges(Ranges.begin(), Ranges.end()), FixIts(FixIts.begin(), FixIts.end())
1194void IgnoringDiagConsumer::anchor() {}
1201 Target.HandleDiagnostic(DiagLevel, Info);
1210 return Target.IncludeInDiagnosticCounts();
1213PartialDiagnostic::DiagStorageAllocator::DiagStorageAllocator() {
1214 for (
unsigned I = 0; I != NumCached; ++I)
1215 FreeList[I] = Cached + I;
1216 NumFreeListEntries = NumCached;
1219PartialDiagnostic::DiagStorageAllocator::~DiagStorageAllocator() {
1222 assert((NumFreeListEntries == NumCached ||
1223 llvm::CrashRecoveryContext::isRecoveringFromCrash()) &&
1224 "A partial is on the lam");
static const char * ScanFormat(const char *I, const char *E, char Target)
ScanForward - Scans forward, looking for the given character, skipping nested clauses and escaped cha...
static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
HandlePluralModifier - Handle the integer 'plural' modifier.
static void HandleIntegerSModifier(unsigned ValNo, SmallVectorImpl< char > &OutStr)
HandleIntegerSModifier - Handle the integer 's' modifier.
static void DummyArgToStringFn(DiagnosticsEngine::ArgumentKind AK, intptr_t QT, StringRef Modifier, StringRef Argument, ArrayRef< DiagnosticsEngine::ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, void *Cookie, ArrayRef< intptr_t > QualTypeVals)
static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End)
EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
static unsigned PluralNumber(const char *&Start, const char *End)
PluralNumber - Parse an unsigned integer and advance Start.
static void HandleSelectModifier(const Diagnostic &DInfo, unsigned ValNo, const char *Argument, unsigned ArgumentLen, SmallVectorImpl< char > &OutStr)
HandleSelectModifier - Handle the integer 'select' modifier.
static bool ModifierIs(const char *Modifier, unsigned ModifierLen, const char(&Str)[StrLen])
ModifierIs - Return true if the specified modifier matches specified string.
static bool TestPluralRange(unsigned Val, const char *&Start, const char *End)
TestPluralRange - Test if Val is in the parsed range. Modifies Start.
static void HandleOrdinalModifier(unsigned ValNo, SmallVectorImpl< char > &OutStr)
HandleOrdinalModifier - Handle the integer 'ord' modifier.
static const char * getTokenDescForDiagnostic(tok::TokenKind Kind)
Returns the friendly description for a token kind that will appear without quotes in diagnostic messa...
Defines the Diagnostic-related interfaces.
Defines the Diagnostic IDs-related interfaces.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Target Target
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the clang::TokenKind enum and support functions.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
virtual ~DiagnosticConsumer()
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
unsigned NumErrors
Number of errors reported.
unsigned NumWarnings
Number of warnings reported.
virtual bool IncludeInDiagnosticCounts() const
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
static StringRef getWarningOptionForDiag(unsigned DiagID)
Return the lowest-level warning option that enables the specified diagnostic.
Level
The level of the diagnostic, after it has been through mapping.
static void getAllDiagnostics(diag::Flavor Flavor, std::vector< diag::kind > &Diags)
Get the set of all diagnostic IDs.
static DiagnosticMapping getDefaultMapping(unsigned DiagID)
Get the default mapping for this diagnostic.
void setNoWarningAsError(bool Value)
void setSeverity(diag::Severity Value)
diag::Severity getSeverity() const
void setUpgradedFromWarning(bool Value)
void setNoErrorAsFatal(bool Value)
bool hasNoWarningAsError() const
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
const SourceLocation & getLocation() const
const std::string & getArgStdStr(unsigned Idx) const
Return the provided argument string specified by Idx.
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots.
uint64_t getRawArg(unsigned Idx) const
Return the specified non-string argument in an opaque form.
const char * getArgCStr(unsigned Idx) const
Return the specified C string argument.
const IdentifierInfo * getArgIdentifier(unsigned Idx) const
Return the specified IdentifierInfo argument.
SourceManager & getSourceManager() const
ArrayRef< FixItHint > getFixItHints() const
unsigned getNumArgs() const
bool hasSourceManager() const
DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const
Return the kind of the specified index.
int64_t getArgSInt(unsigned Idx) const
Return the specified signed integer argument.
uint64_t getArgUInt(unsigned Idx) const
Return the specified unsigned integer argument.
ArrayRef< CharSourceRange > getRanges() const
Return an array reference for this diagnostic's ranges.
const DiagnosticsEngine * getDiags() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
void setSeverityForAll(diag::Flavor Flavor, diag::Severity Map, SourceLocation Loc=SourceLocation())
Add the specified mapping to all diagnostics of the specified flavor.
LLVM_DUMP_METHOD void dump() const
void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)
Set the diagnostic client associated with this diagnostic object.
void Clear()
Clear out the current diagnostic.
void pushMappings(SourceLocation Loc)
Copies the current DiagMappings and pushes the new copy onto the top of the stack.
void setSeverity(diag::kind Diag, diag::Severity Map, SourceLocation Loc)
This allows the client to specify that certain warnings are ignored.
Level
The level of the diagnostic, after it has been through mapping.
DiagnosticConsumer * getClient()
@ ak_nameddecl
NamedDecl *.
@ ak_declcontext
DeclContext *.
@ ak_addrspace
address space
@ ak_identifierinfo
IdentifierInfo.
@ ak_qualtype_pair
pair<QualType, QualType>
@ ak_c_string
const char *
@ ak_declarationname
DeclarationName.
@ ak_tokenkind
enum TokenKind : unsigned
@ ak_std_string
std::string
@ ak_nestednamespec
NestedNameSpecifier *.
DiagnosticsEngine(IntrusiveRefCntPtr< DiagnosticIDs > Diags, IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts, DiagnosticConsumer *client=nullptr, bool ShouldOwnClient=true)
bool EmitCurrentDiagnostic(bool Force=false)
Emit the current diagnostic and clear the diagnostic state.
bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled)
Set the error-as-fatal flag for the given diagnostic group.
bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled)
Set the warning-as-error flag for the given diagnostic group.
void ConvertArgToString(ArgumentKind Kind, intptr_t Val, StringRef Modifier, StringRef Argument, ArrayRef< ArgumentValue > PrevArgs, SmallVectorImpl< char > &Output, ArrayRef< intptr_t > QualTypeVals) const
Converts a diagnostic argument (as an intptr_t) into the string that represents it.
void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1="", StringRef Arg2="", StringRef Arg3="")
Set the "delayed" diagnostic that will be emitted once the current diagnostic completes.
bool setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc=SourceLocation())
Change an entire diagnostic group (e.g.
bool popMappings(SourceLocation Loc)
Pops the current DiagMappings off the top of the stack, causing the new top of the stack to be the ac...
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
void Reset(bool soft=false)
Reset the state of the diagnostic object to its initial configuration.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool IncludeInDiagnosticCounts() const override
Indicates whether the diagnostics handled by this DiagnosticConsumer should be included in the number...
~ForwardingDiagnosticConsumer() override
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
A SourceLocation and its associated SourceManager.
bool hasManager() const
Checks whether the SourceManager is present.
const SourceManager & getManager() const
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Encodes a location in the source.
std::string printToString(const SourceManager &SM) const
bool isValid() const
Return true if this is a valid SourceLocation object.
void print(raw_ostream &OS, const SourceManager &SM) const
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
llvm::MemoryBufferRef getBufferOrFake(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
std::pair< FileID, unsigned > getDecomposedIncludedLoc(FileID FID) const
Returns the "included/expanded in" decomposed location of the given FileID.
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
range_iterator range_begin() const
StoredDiagnostic()=default
DiagnosticsEngine::Level getLevel() const
fixit_iterator fixit_begin() const
const FullSourceLoc & getLocation() const
range_iterator range_end() const
StringRef getMessage() const
fixit_iterator fixit_end() const
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
void AddString(StringRef V) const
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
@ Warning
Present this diagnostic as a warning.
@ Fatal
Present this diagnostic as a fatal error.
@ Error
Present this diagnostic as an error.
@ Remark
Present this diagnostic as a remark.
@ Ignored
Do not present this diagnostic, ignore it.
Flavor
Flavors of diagnostics we can emit.
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
const char * getPunctuatorSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple punctuation tokens like '!' or '', and returns NULL for literal and...
The JSON file list parser is used to communicate input to InstallAPI.
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
@ Result
The result type of a method or function.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
void EscapeStringForDiagnostic(StringRef Str, SmallVectorImpl< char > &OutStr)
EscapeStringForDiagnostic - Append Str to the diagnostic buffer, escaping non-printable characters an...
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t',...
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
LLVM_READONLY bool isPunctuation(unsigned char c)
Return true if this character is an ASCII punctuation character.
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...
SmallVector< CharSourceRange, 8 > DiagRanges
The list of ranges added to this diagnostic.
unsigned char NumDiagArgs
The number of entries in Arguments.
SmallVector< FixItHint, 6 > FixItHints
If valid, provides a hint with some code to insert, remove, or modify at a particular position.
unsigned TemplateDiffUsed