[Heikki Kultala] This patch contains the ABI changes for the TCE target.
[clang.git] / lib / Basic / Diagnostic.cpp
blob31e33315cce2052c3027ea0f5fb88fc70e44f56c
1 //===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Diagnostic-related interfaces.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Basic/IdentifierTable.h"
16 #include "clang/Basic/PartialDiagnostic.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Support/raw_ostream.h"
19 using namespace clang;
21 static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT,
22 const char *Modifier, unsigned ML,
23 const char *Argument, unsigned ArgLen,
24 const Diagnostic::ArgumentValue *PrevArgs,
25 unsigned NumPrevArgs,
26 llvm::SmallVectorImpl<char> &Output,
27 void *Cookie) {
28 const char *Str = "<can't format argument>";
29 Output.append(Str, Str+strlen(Str));
33 Diagnostic::Diagnostic(const llvm::IntrusiveRefCntPtr<DiagnosticIDs> &diags,
34 DiagnosticClient *client, bool ShouldOwnClient)
35 : Diags(diags), Client(client), OwnsDiagClient(ShouldOwnClient),
36 SourceMgr(0) {
37 ArgToStringFn = DummyArgToStringFn;
38 ArgToStringCookie = 0;
40 AllExtensionsSilenced = 0;
41 IgnoreAllWarnings = false;
42 WarningsAsErrors = false;
43 ErrorsAsFatal = false;
44 SuppressSystemWarnings = false;
45 SuppressAllDiagnostics = false;
46 ShowOverloads = Ovl_All;
47 ExtBehavior = Ext_Ignore;
49 ErrorLimit = 0;
50 TemplateBacktraceLimit = 0;
52 // Create a DiagState and DiagStatePoint representing diagnostic changes
53 // through command-line.
54 DiagStates.push_back(DiagState());
55 PushDiagStatePoint(&DiagStates.back(), SourceLocation());
57 Reset();
60 Diagnostic::~Diagnostic() {
61 if (OwnsDiagClient)
62 delete Client;
65 void Diagnostic::setClient(DiagnosticClient *client, bool ShouldOwnClient) {
66 if (OwnsDiagClient && Client)
67 delete Client;
69 Client = client;
70 OwnsDiagClient = ShouldOwnClient;
73 void Diagnostic::pushMappings(SourceLocation Loc) {
74 DiagStateOnPushStack.push_back(GetCurDiagState());
77 bool Diagnostic::popMappings(SourceLocation Loc) {
78 if (DiagStateOnPushStack.empty())
79 return false;
81 if (DiagStateOnPushStack.back() != GetCurDiagState()) {
82 // State changed at some point between push/pop.
83 PushDiagStatePoint(DiagStateOnPushStack.back(), Loc);
85 DiagStateOnPushStack.pop_back();
86 return true;
89 void Diagnostic::Reset() {
90 ErrorOccurred = false;
91 FatalErrorOccurred = false;
93 NumWarnings = 0;
94 NumErrors = 0;
95 NumErrorsSuppressed = 0;
96 CurDiagID = ~0U;
97 // Set LastDiagLevel to an "unset" state. If we set it to 'Ignored', notes
98 // using a Diagnostic associated to a translation unit that follow
99 // diagnostics from a Diagnostic associated to anoter t.u. will not be
100 // displayed.
101 LastDiagLevel = (DiagnosticIDs::Level)-1;
102 DelayedDiagID = 0;
105 void Diagnostic::SetDelayedDiagnostic(unsigned DiagID, llvm::StringRef Arg1,
106 llvm::StringRef Arg2) {
107 if (DelayedDiagID)
108 return;
110 DelayedDiagID = DiagID;
111 DelayedDiagArg1 = Arg1.str();
112 DelayedDiagArg2 = Arg2.str();
115 void Diagnostic::ReportDelayed() {
116 Report(DelayedDiagID) << DelayedDiagArg1 << DelayedDiagArg2;
117 DelayedDiagID = 0;
118 DelayedDiagArg1.clear();
119 DelayedDiagArg2.clear();
122 Diagnostic::DiagStatePointsTy::iterator
123 Diagnostic::GetDiagStatePointForLoc(SourceLocation L) const {
124 assert(!DiagStatePoints.empty());
125 assert(DiagStatePoints.front().Loc.isInvalid() &&
126 "Should have created a DiagStatePoint for command-line");
128 FullSourceLoc Loc(L, *SourceMgr);
129 if (Loc.isInvalid())
130 return DiagStatePoints.end() - 1;
132 DiagStatePointsTy::iterator Pos = DiagStatePoints.end();
133 FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
134 if (LastStateChangePos.isValid() &&
135 Loc.isBeforeInTranslationUnitThan(LastStateChangePos))
136 Pos = std::upper_bound(DiagStatePoints.begin(), DiagStatePoints.end(),
137 DiagStatePoint(0, Loc));
138 --Pos;
139 return Pos;
142 /// \brief This allows the client to specify that certain
143 /// warnings are ignored. Notes can never be mapped, errors can only be
144 /// mapped to fatal, and WARNINGs and EXTENSIONs can be mapped arbitrarily.
146 /// \param The source location that this change of diagnostic state should
147 /// take affect. It can be null if we are setting the latest state.
148 void Diagnostic::setDiagnosticMapping(diag::kind Diag, diag::Mapping Map,
149 SourceLocation L) {
150 assert(Diag < diag::DIAG_UPPER_LIMIT &&
151 "Can only map builtin diagnostics");
152 assert((Diags->isBuiltinWarningOrExtension(Diag) ||
153 (Map == diag::MAP_FATAL || Map == diag::MAP_ERROR)) &&
154 "Cannot map errors into warnings!");
155 assert(!DiagStatePoints.empty());
157 bool isPragma = L.isValid();
158 FullSourceLoc Loc(L, *SourceMgr);
159 FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
161 // Common case; setting all the diagnostics of a group in one place.
162 if (Loc.isInvalid() || Loc == LastStateChangePos) {
163 setDiagnosticMappingInternal(Diag, Map, GetCurDiagState(), true, isPragma);
164 return;
167 // Another common case; modifying diagnostic state in a source location
168 // after the previous one.
169 if ((Loc.isValid() && LastStateChangePos.isInvalid()) ||
170 LastStateChangePos.isBeforeInTranslationUnitThan(Loc)) {
171 // A diagnostic pragma occured, create a new DiagState initialized with
172 // the current one and a new DiagStatePoint to record at which location
173 // the new state became active.
174 DiagStates.push_back(*GetCurDiagState());
175 PushDiagStatePoint(&DiagStates.back(), Loc);
176 setDiagnosticMappingInternal(Diag, Map, GetCurDiagState(), true, isPragma);
177 return;
180 // We allow setting the diagnostic state in random source order for
181 // completeness but it should not be actually happening in normal practice.
183 DiagStatePointsTy::iterator Pos = GetDiagStatePointForLoc(Loc);
184 assert(Pos != DiagStatePoints.end());
186 // Update all diagnostic states that are active after the given location.
187 for (DiagStatePointsTy::iterator
188 I = Pos+1, E = DiagStatePoints.end(); I != E; ++I) {
189 setDiagnosticMappingInternal(Diag, Map, I->State, true, isPragma);
192 // If the location corresponds to an existing point, just update its state.
193 if (Pos->Loc == Loc) {
194 setDiagnosticMappingInternal(Diag, Map, Pos->State, true, isPragma);
195 return;
198 // Create a new state/point and fit it into the vector of DiagStatePoints
199 // so that the vector is always ordered according to location.
200 Pos->Loc.isBeforeInTranslationUnitThan(Loc);
201 DiagStates.push_back(*Pos->State);
202 DiagState *NewState = &DiagStates.back();
203 setDiagnosticMappingInternal(Diag, Map, NewState, true, isPragma);
204 DiagStatePoints.insert(Pos+1, DiagStatePoint(NewState,
205 FullSourceLoc(Loc, *SourceMgr)));
208 void DiagnosticBuilder::FlushCounts() {
209 DiagObj->NumDiagArgs = NumArgs;
210 DiagObj->NumDiagRanges = NumRanges;
211 DiagObj->NumFixItHints = NumFixItHints;
214 bool DiagnosticBuilder::Emit() {
215 // If DiagObj is null, then its soul was stolen by the copy ctor
216 // or the user called Emit().
217 if (DiagObj == 0) return false;
219 // When emitting diagnostics, we set the final argument count into
220 // the Diagnostic object.
221 FlushCounts();
223 // Process the diagnostic, sending the accumulated information to the
224 // DiagnosticClient.
225 bool Emitted = DiagObj->ProcessDiag();
227 // Clear out the current diagnostic object.
228 unsigned DiagID = DiagObj->CurDiagID;
229 DiagObj->Clear();
231 // If there was a delayed diagnostic, emit it now.
232 if (DiagObj->DelayedDiagID && DiagObj->DelayedDiagID != DiagID)
233 DiagObj->ReportDelayed();
235 // This diagnostic is dead.
236 DiagObj = 0;
238 return Emitted;
242 DiagnosticClient::~DiagnosticClient() {}
244 void DiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
245 const DiagnosticInfo &Info) {
246 if (!IncludeInDiagnosticCounts())
247 return;
249 if (DiagLevel == Diagnostic::Warning)
250 ++NumWarnings;
251 else if (DiagLevel >= Diagnostic::Error)
252 ++NumErrors;
255 /// ModifierIs - Return true if the specified modifier matches specified string.
256 template <std::size_t StrLen>
257 static bool ModifierIs(const char *Modifier, unsigned ModifierLen,
258 const char (&Str)[StrLen]) {
259 return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1);
262 /// ScanForward - Scans forward, looking for the given character, skipping
263 /// nested clauses and escaped characters.
264 static const char *ScanFormat(const char *I, const char *E, char Target) {
265 unsigned Depth = 0;
267 for ( ; I != E; ++I) {
268 if (Depth == 0 && *I == Target) return I;
269 if (Depth != 0 && *I == '}') Depth--;
271 if (*I == '%') {
272 I++;
273 if (I == E) break;
275 // Escaped characters get implicitly skipped here.
277 // Format specifier.
278 if (!isdigit(*I) && !ispunct(*I)) {
279 for (I++; I != E && !isdigit(*I) && *I != '{'; I++) ;
280 if (I == E) break;
281 if (*I == '{')
282 Depth++;
286 return E;
289 /// HandleSelectModifier - Handle the integer 'select' modifier. This is used
290 /// like this: %select{foo|bar|baz}2. This means that the integer argument
291 /// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'.
292 /// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'.
293 /// This is very useful for certain classes of variant diagnostics.
294 static void HandleSelectModifier(const DiagnosticInfo &DInfo, unsigned ValNo,
295 const char *Argument, unsigned ArgumentLen,
296 llvm::SmallVectorImpl<char> &OutStr) {
297 const char *ArgumentEnd = Argument+ArgumentLen;
299 // Skip over 'ValNo' |'s.
300 while (ValNo) {
301 const char *NextVal = ScanFormat(Argument, ArgumentEnd, '|');
302 assert(NextVal != ArgumentEnd && "Value for integer select modifier was"
303 " larger than the number of options in the diagnostic string!");
304 Argument = NextVal+1; // Skip this string.
305 --ValNo;
308 // Get the end of the value. This is either the } or the |.
309 const char *EndPtr = ScanFormat(Argument, ArgumentEnd, '|');
311 // Recursively format the result of the select clause into the output string.
312 DInfo.FormatDiagnostic(Argument, EndPtr, OutStr);
315 /// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the
316 /// letter 's' to the string if the value is not 1. This is used in cases like
317 /// this: "you idiot, you have %4 parameter%s4!".
318 static void HandleIntegerSModifier(unsigned ValNo,
319 llvm::SmallVectorImpl<char> &OutStr) {
320 if (ValNo != 1)
321 OutStr.push_back('s');
324 /// HandleOrdinalModifier - Handle the integer 'ord' modifier. This
325 /// prints the ordinal form of the given integer, with 1 corresponding
326 /// to the first ordinal. Currently this is hard-coded to use the
327 /// English form.
328 static void HandleOrdinalModifier(unsigned ValNo,
329 llvm::SmallVectorImpl<char> &OutStr) {
330 assert(ValNo != 0 && "ValNo must be strictly positive!");
332 llvm::raw_svector_ostream Out(OutStr);
334 // We could use text forms for the first N ordinals, but the numeric
335 // forms are actually nicer in diagnostics because they stand out.
336 Out << ValNo;
338 // It is critically important that we do this perfectly for
339 // user-written sequences with over 100 elements.
340 switch (ValNo % 100) {
341 case 11:
342 case 12:
343 case 13:
344 Out << "th"; return;
345 default:
346 switch (ValNo % 10) {
347 case 1: Out << "st"; return;
348 case 2: Out << "nd"; return;
349 case 3: Out << "rd"; return;
350 default: Out << "th"; return;
356 /// PluralNumber - Parse an unsigned integer and advance Start.
357 static unsigned PluralNumber(const char *&Start, const char *End) {
358 // Programming 101: Parse a decimal number :-)
359 unsigned Val = 0;
360 while (Start != End && *Start >= '0' && *Start <= '9') {
361 Val *= 10;
362 Val += *Start - '0';
363 ++Start;
365 return Val;
368 /// TestPluralRange - Test if Val is in the parsed range. Modifies Start.
369 static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) {
370 if (*Start != '[') {
371 unsigned Ref = PluralNumber(Start, End);
372 return Ref == Val;
375 ++Start;
376 unsigned Low = PluralNumber(Start, End);
377 assert(*Start == ',' && "Bad plural expression syntax: expected ,");
378 ++Start;
379 unsigned High = PluralNumber(Start, End);
380 assert(*Start == ']' && "Bad plural expression syntax: expected )");
381 ++Start;
382 return Low <= Val && Val <= High;
385 /// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
386 static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) {
387 // Empty condition?
388 if (*Start == ':')
389 return true;
391 while (1) {
392 char C = *Start;
393 if (C == '%') {
394 // Modulo expression
395 ++Start;
396 unsigned Arg = PluralNumber(Start, End);
397 assert(*Start == '=' && "Bad plural expression syntax: expected =");
398 ++Start;
399 unsigned ValMod = ValNo % Arg;
400 if (TestPluralRange(ValMod, Start, End))
401 return true;
402 } else {
403 assert((C == '[' || (C >= '0' && C <= '9')) &&
404 "Bad plural expression syntax: unexpected character");
405 // Range expression
406 if (TestPluralRange(ValNo, Start, End))
407 return true;
410 // Scan for next or-expr part.
411 Start = std::find(Start, End, ',');
412 if (Start == End)
413 break;
414 ++Start;
416 return false;
419 /// HandlePluralModifier - Handle the integer 'plural' modifier. This is used
420 /// for complex plural forms, or in languages where all plurals are complex.
421 /// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are
422 /// conditions that are tested in order, the form corresponding to the first
423 /// that applies being emitted. The empty condition is always true, making the
424 /// last form a default case.
425 /// Conditions are simple boolean expressions, where n is the number argument.
426 /// Here are the rules.
427 /// condition := expression | empty
428 /// empty := -> always true
429 /// expression := numeric [',' expression] -> logical or
430 /// numeric := range -> true if n in range
431 /// | '%' number '=' range -> true if n % number in range
432 /// range := number
433 /// | '[' number ',' number ']' -> ranges are inclusive both ends
435 /// Here are some examples from the GNU gettext manual written in this form:
436 /// English:
437 /// {1:form0|:form1}
438 /// Latvian:
439 /// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0}
440 /// Gaeilge:
441 /// {1:form0|2:form1|:form2}
442 /// Romanian:
443 /// {1:form0|0,%100=[1,19]:form1|:form2}
444 /// Lithuanian:
445 /// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1}
446 /// Russian (requires repeated form):
447 /// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2}
448 /// Slovak
449 /// {1:form0|[2,4]:form1|:form2}
450 /// Polish (requires repeated form):
451 /// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2}
452 static void HandlePluralModifier(const DiagnosticInfo &DInfo, unsigned ValNo,
453 const char *Argument, unsigned ArgumentLen,
454 llvm::SmallVectorImpl<char> &OutStr) {
455 const char *ArgumentEnd = Argument + ArgumentLen;
456 while (1) {
457 assert(Argument < ArgumentEnd && "Plural expression didn't match.");
458 const char *ExprEnd = Argument;
459 while (*ExprEnd != ':') {
460 assert(ExprEnd != ArgumentEnd && "Plural missing expression end");
461 ++ExprEnd;
463 if (EvalPluralExpr(ValNo, Argument, ExprEnd)) {
464 Argument = ExprEnd + 1;
465 ExprEnd = ScanFormat(Argument, ArgumentEnd, '|');
467 // Recursively format the result of the plural clause into the
468 // output string.
469 DInfo.FormatDiagnostic(Argument, ExprEnd, OutStr);
470 return;
472 Argument = ScanFormat(Argument, ArgumentEnd - 1, '|') + 1;
477 /// FormatDiagnostic - Format this diagnostic into a string, substituting the
478 /// formal arguments into the %0 slots. The result is appended onto the Str
479 /// array.
480 void DiagnosticInfo::
481 FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
482 const char *DiagStr = getDiags()->getDiagnosticIDs()->getDescription(getID());
483 const char *DiagEnd = DiagStr+strlen(DiagStr);
485 FormatDiagnostic(DiagStr, DiagEnd, OutStr);
488 void DiagnosticInfo::
489 FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
490 llvm::SmallVectorImpl<char> &OutStr) const {
492 /// FormattedArgs - Keep track of all of the arguments formatted by
493 /// ConvertArgToString and pass them into subsequent calls to
494 /// ConvertArgToString, allowing the implementation to avoid redundancies in
495 /// obvious cases.
496 llvm::SmallVector<Diagnostic::ArgumentValue, 8> FormattedArgs;
498 while (DiagStr != DiagEnd) {
499 if (DiagStr[0] != '%') {
500 // Append non-%0 substrings to Str if we have one.
501 const char *StrEnd = std::find(DiagStr, DiagEnd, '%');
502 OutStr.append(DiagStr, StrEnd);
503 DiagStr = StrEnd;
504 continue;
505 } else if (ispunct(DiagStr[1])) {
506 OutStr.push_back(DiagStr[1]); // %% -> %.
507 DiagStr += 2;
508 continue;
511 // Skip the %.
512 ++DiagStr;
514 // This must be a placeholder for a diagnostic argument. The format for a
515 // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0".
516 // The digit is a number from 0-9 indicating which argument this comes from.
517 // The modifier is a string of digits from the set [-a-z]+, arguments is a
518 // brace enclosed string.
519 const char *Modifier = 0, *Argument = 0;
520 unsigned ModifierLen = 0, ArgumentLen = 0;
522 // Check to see if we have a modifier. If so eat it.
523 if (!isdigit(DiagStr[0])) {
524 Modifier = DiagStr;
525 while (DiagStr[0] == '-' ||
526 (DiagStr[0] >= 'a' && DiagStr[0] <= 'z'))
527 ++DiagStr;
528 ModifierLen = DiagStr-Modifier;
530 // If we have an argument, get it next.
531 if (DiagStr[0] == '{') {
532 ++DiagStr; // Skip {.
533 Argument = DiagStr;
535 DiagStr = ScanFormat(DiagStr, DiagEnd, '}');
536 assert(DiagStr != DiagEnd && "Mismatched {}'s in diagnostic string!");
537 ArgumentLen = DiagStr-Argument;
538 ++DiagStr; // Skip }.
542 assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic");
543 unsigned ArgNo = *DiagStr++ - '0';
545 Diagnostic::ArgumentKind Kind = getArgKind(ArgNo);
547 switch (Kind) {
548 // ---- STRINGS ----
549 case Diagnostic::ak_std_string: {
550 const std::string &S = getArgStdStr(ArgNo);
551 assert(ModifierLen == 0 && "No modifiers for strings yet");
552 OutStr.append(S.begin(), S.end());
553 break;
555 case Diagnostic::ak_c_string: {
556 const char *S = getArgCStr(ArgNo);
557 assert(ModifierLen == 0 && "No modifiers for strings yet");
559 // Don't crash if get passed a null pointer by accident.
560 if (!S)
561 S = "(null)";
563 OutStr.append(S, S + strlen(S));
564 break;
566 // ---- INTEGERS ----
567 case Diagnostic::ak_sint: {
568 int Val = getArgSInt(ArgNo);
570 if (ModifierIs(Modifier, ModifierLen, "select")) {
571 HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen,
572 OutStr);
573 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
574 HandleIntegerSModifier(Val, OutStr);
575 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
576 HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen,
577 OutStr);
578 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
579 HandleOrdinalModifier((unsigned)Val, OutStr);
580 } else {
581 assert(ModifierLen == 0 && "Unknown integer modifier");
582 llvm::raw_svector_ostream(OutStr) << Val;
584 break;
586 case Diagnostic::ak_uint: {
587 unsigned Val = getArgUInt(ArgNo);
589 if (ModifierIs(Modifier, ModifierLen, "select")) {
590 HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr);
591 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
592 HandleIntegerSModifier(Val, OutStr);
593 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
594 HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen,
595 OutStr);
596 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
597 HandleOrdinalModifier(Val, OutStr);
598 } else {
599 assert(ModifierLen == 0 && "Unknown integer modifier");
600 llvm::raw_svector_ostream(OutStr) << Val;
602 break;
604 // ---- NAMES and TYPES ----
605 case Diagnostic::ak_identifierinfo: {
606 const IdentifierInfo *II = getArgIdentifier(ArgNo);
607 assert(ModifierLen == 0 && "No modifiers for strings yet");
609 // Don't crash if get passed a null pointer by accident.
610 if (!II) {
611 const char *S = "(null)";
612 OutStr.append(S, S + strlen(S));
613 continue;
616 llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\'';
617 break;
619 case Diagnostic::ak_qualtype:
620 case Diagnostic::ak_declarationname:
621 case Diagnostic::ak_nameddecl:
622 case Diagnostic::ak_nestednamespec:
623 case Diagnostic::ak_declcontext:
624 getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo),
625 Modifier, ModifierLen,
626 Argument, ArgumentLen,
627 FormattedArgs.data(), FormattedArgs.size(),
628 OutStr);
629 break;
632 // Remember this argument info for subsequent formatting operations. Turn
633 // std::strings into a null terminated string to make it be the same case as
634 // all the other ones.
635 if (Kind != Diagnostic::ak_std_string)
636 FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo)));
637 else
638 FormattedArgs.push_back(std::make_pair(Diagnostic::ak_c_string,
639 (intptr_t)getArgStdStr(ArgNo).c_str()));
644 StoredDiagnostic::StoredDiagnostic() { }
646 StoredDiagnostic::StoredDiagnostic(Diagnostic::Level Level, unsigned ID,
647 llvm::StringRef Message)
648 : ID(ID), Level(Level), Loc(), Message(Message) { }
650 StoredDiagnostic::StoredDiagnostic(Diagnostic::Level Level,
651 const DiagnosticInfo &Info)
652 : ID(Info.getID()), Level(Level)
654 assert((Info.getLocation().isInvalid() || Info.hasSourceManager()) &&
655 "Valid source location without setting a source manager for diagnostic");
656 if (Info.getLocation().isValid())
657 Loc = FullSourceLoc(Info.getLocation(), Info.getSourceManager());
658 llvm::SmallString<64> Message;
659 Info.FormatDiagnostic(Message);
660 this->Message.assign(Message.begin(), Message.end());
662 Ranges.reserve(Info.getNumRanges());
663 for (unsigned I = 0, N = Info.getNumRanges(); I != N; ++I)
664 Ranges.push_back(Info.getRange(I));
666 FixIts.reserve(Info.getNumFixItHints());
667 for (unsigned I = 0, N = Info.getNumFixItHints(); I != N; ++I)
668 FixIts.push_back(Info.getFixItHint(I));
671 StoredDiagnostic::~StoredDiagnostic() { }
673 /// IncludeInDiagnosticCounts - This method (whose default implementation
674 /// returns true) indicates whether the diagnostics handled by this
675 /// DiagnosticClient should be included in the number of diagnostics
676 /// reported by Diagnostic.
677 bool DiagnosticClient::IncludeInDiagnosticCounts() const { return true; }
679 PartialDiagnostic::StorageAllocator::StorageAllocator() {
680 for (unsigned I = 0; I != NumCached; ++I)
681 FreeList[I] = Cached + I;
682 NumFreeListEntries = NumCached;
685 PartialDiagnostic::StorageAllocator::~StorageAllocator() {
686 assert(NumFreeListEntries == NumCached && "A partial is on the lamb");