blob: e1183c602ca5584881d83d72708f7c4091e8242c [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Diagnostic-related interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/Diagnostic.h"
Chris Lattner43b628c2008-11-19 07:32:16 +000015#include "clang/Basic/IdentifierTable.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/Basic/SourceLocation.h"
Chris Lattnerf4c83962008-11-19 06:51:40 +000017#include "llvm/ADT/SmallVector.h"
Chris Lattner30bc9652008-11-19 07:22:31 +000018#include "llvm/ADT/StringExtras.h"
Chris Lattner182745a2007-12-02 01:09:57 +000019#include <vector>
20#include <map>
Chris Lattner87cf5ac2008-03-10 17:04:53 +000021#include <cstring>
Reid Spencer5f016e22007-07-11 17:01:13 +000022using namespace clang;
23
Chris Lattner182745a2007-12-02 01:09:57 +000024//===----------------------------------------------------------------------===//
25// Builtin Diagnostic information
26//===----------------------------------------------------------------------===//
27
Reid Spencer5f016e22007-07-11 17:01:13 +000028/// Flag values for diagnostics.
29enum {
30 // Diagnostic classes.
31 NOTE = 0x01,
32 WARNING = 0x02,
33 EXTENSION = 0x03,
Daniel Dunbar4489fe12008-08-05 00:07:51 +000034 EXTWARN = 0x04,
35 ERROR = 0x05,
Reid Spencer5f016e22007-07-11 17:01:13 +000036 class_mask = 0x07
37};
38
39/// DiagnosticFlags - A set of flags, or'd together, that describe the
40/// diagnostic.
41static unsigned char DiagnosticFlags[] = {
42#define DIAG(ENUM,FLAGS,DESC) FLAGS,
43#include "clang/Basic/DiagnosticKinds.def"
44 0
45};
46
47/// getDiagClass - Return the class field of the diagnostic.
48///
Chris Lattner07506182007-11-30 22:53:43 +000049static unsigned getBuiltinDiagClass(unsigned DiagID) {
50 assert(DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
51 "Diagnostic ID out of range!");
Reid Spencer5f016e22007-07-11 17:01:13 +000052 return DiagnosticFlags[DiagID] & class_mask;
53}
54
55/// DiagnosticText - An english message to print for the diagnostic. These
56/// should be localized.
57static const char * const DiagnosticText[] = {
58#define DIAG(ENUM,FLAGS,DESC) DESC,
59#include "clang/Basic/DiagnosticKinds.def"
60 0
61};
62
Chris Lattner182745a2007-12-02 01:09:57 +000063//===----------------------------------------------------------------------===//
64// Custom Diagnostic information
65//===----------------------------------------------------------------------===//
66
67namespace clang {
68 namespace diag {
69 class CustomDiagInfo {
70 typedef std::pair<Diagnostic::Level, std::string> DiagDesc;
71 std::vector<DiagDesc> DiagInfo;
72 std::map<DiagDesc, unsigned> DiagIDs;
73 public:
74
75 /// getDescription - Return the description of the specified custom
76 /// diagnostic.
77 const char *getDescription(unsigned DiagID) const {
78 assert(this && DiagID-diag::NUM_BUILTIN_DIAGNOSTICS < DiagInfo.size() &&
79 "Invalid diagnosic ID");
80 return DiagInfo[DiagID-diag::NUM_BUILTIN_DIAGNOSTICS].second.c_str();
81 }
82
83 /// getLevel - Return the level of the specified custom diagnostic.
84 Diagnostic::Level getLevel(unsigned DiagID) const {
85 assert(this && DiagID-diag::NUM_BUILTIN_DIAGNOSTICS < DiagInfo.size() &&
86 "Invalid diagnosic ID");
87 return DiagInfo[DiagID-diag::NUM_BUILTIN_DIAGNOSTICS].first;
88 }
89
Chris Lattnera1f23cc2008-10-17 21:24:47 +000090 unsigned getOrCreateDiagID(Diagnostic::Level L, const char *Message,
91 Diagnostic &Diags) {
Chris Lattner182745a2007-12-02 01:09:57 +000092 DiagDesc D(L, Message);
93 // Check to see if it already exists.
94 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
95 if (I != DiagIDs.end() && I->first == D)
96 return I->second;
97
98 // If not, assign a new ID.
99 unsigned ID = DiagInfo.size()+diag::NUM_BUILTIN_DIAGNOSTICS;
100 DiagIDs.insert(std::make_pair(D, ID));
101 DiagInfo.push_back(D);
Chris Lattnera1f23cc2008-10-17 21:24:47 +0000102
103 // If this is a warning, and all warnings are supposed to map to errors,
104 // insert the mapping now.
105 if (L == Diagnostic::Warning && Diags.getWarningsAsErrors())
106 Diags.setDiagnosticMapping((diag::kind)ID, diag::MAP_ERROR);
Chris Lattner182745a2007-12-02 01:09:57 +0000107 return ID;
108 }
109 };
110
111 } // end diag namespace
112} // end clang namespace
113
114
115//===----------------------------------------------------------------------===//
116// Common Diagnostic implementation
117//===----------------------------------------------------------------------===//
118
Ted Kremenekb4398aa2008-08-07 17:49:57 +0000119Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
Chris Lattner5b4681c2008-05-29 15:36:45 +0000120 IgnoreAllWarnings = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000121 WarningsAsErrors = false;
122 WarnOnExtensions = false;
123 ErrorOnExtensions = false;
Daniel Dunbar2fe09972008-09-12 18:10:20 +0000124 SuppressSystemWarnings = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000125 // Clear all mappings, setting them to MAP_DEFAULT.
126 memset(DiagMappings, 0, sizeof(DiagMappings));
127
128 ErrorOccurred = false;
129 NumDiagnostics = 0;
130 NumErrors = 0;
Chris Lattner182745a2007-12-02 01:09:57 +0000131 CustomDiagInfo = 0;
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000132 CurDiagID = ~0U;
Reid Spencer5f016e22007-07-11 17:01:13 +0000133}
134
Chris Lattner182745a2007-12-02 01:09:57 +0000135Diagnostic::~Diagnostic() {
136 delete CustomDiagInfo;
137}
138
139/// getCustomDiagID - Return an ID for a diagnostic with the specified message
140/// and level. If this is the first request for this diagnosic, it is
141/// registered and created, otherwise the existing ID is returned.
142unsigned Diagnostic::getCustomDiagID(Level L, const char *Message) {
143 if (CustomDiagInfo == 0)
144 CustomDiagInfo = new diag::CustomDiagInfo();
Chris Lattnera1f23cc2008-10-17 21:24:47 +0000145 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this);
Chris Lattner182745a2007-12-02 01:09:57 +0000146}
147
148
Chris Lattner07506182007-11-30 22:53:43 +0000149/// isBuiltinNoteWarningOrExtension - Return true if the unmapped diagnostic
150/// level of the specified diagnostic ID is a Note, Warning, or Extension.
151/// Note that this only works on builtin diagnostics, not custom ones.
152bool Diagnostic::isBuiltinNoteWarningOrExtension(unsigned DiagID) {
153 return DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
154 getBuiltinDiagClass(DiagID) < ERROR;
Reid Spencer5f016e22007-07-11 17:01:13 +0000155}
156
157
158/// getDescription - Given a diagnostic ID, return a description of the
159/// issue.
Chris Lattner0a14eee2008-11-18 07:04:44 +0000160const char *Diagnostic::getDescription(unsigned DiagID) const {
Chris Lattner07506182007-11-30 22:53:43 +0000161 if (DiagID < diag::NUM_BUILTIN_DIAGNOSTICS)
162 return DiagnosticText[DiagID];
163 else
Chris Lattner182745a2007-12-02 01:09:57 +0000164 return CustomDiagInfo->getDescription(DiagID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000165}
166
167/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
168/// object, classify the specified diagnostic ID into a Level, consumable by
169/// the DiagnosticClient.
170Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
Chris Lattner182745a2007-12-02 01:09:57 +0000171 // Handle custom diagnostics, which cannot be mapped.
172 if (DiagID >= diag::NUM_BUILTIN_DIAGNOSTICS)
173 return CustomDiagInfo->getLevel(DiagID);
Chris Lattner07506182007-11-30 22:53:43 +0000174
175 unsigned DiagClass = getBuiltinDiagClass(DiagID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000176
177 // Specific non-error diagnostics may be mapped to various levels from ignored
178 // to error.
179 if (DiagClass < ERROR) {
180 switch (getDiagnosticMapping((diag::kind)DiagID)) {
181 case diag::MAP_DEFAULT: break;
Chris Lattner5b4681c2008-05-29 15:36:45 +0000182 case diag::MAP_IGNORE: return Diagnostic::Ignored;
Reid Spencer5f016e22007-07-11 17:01:13 +0000183 case diag::MAP_WARNING: DiagClass = WARNING; break;
184 case diag::MAP_ERROR: DiagClass = ERROR; break;
185 }
186 }
187
188 // Map diagnostic classes based on command line argument settings.
189 if (DiagClass == EXTENSION) {
190 if (ErrorOnExtensions)
191 DiagClass = ERROR;
192 else if (WarnOnExtensions)
193 DiagClass = WARNING;
194 else
195 return Ignored;
Daniel Dunbar4489fe12008-08-05 00:07:51 +0000196 } else if (DiagClass == EXTWARN) {
197 DiagClass = ErrorOnExtensions ? ERROR : WARNING;
Reid Spencer5f016e22007-07-11 17:01:13 +0000198 }
199
Chris Lattner5b4681c2008-05-29 15:36:45 +0000200 // If warnings are globally mapped to ignore or error, do it.
201 if (DiagClass == WARNING) {
202 if (IgnoreAllWarnings)
203 return Diagnostic::Ignored;
204 if (WarningsAsErrors)
205 DiagClass = ERROR;
206 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000207
208 switch (DiagClass) {
209 default: assert(0 && "Unknown diagnostic class!");
210 case NOTE: return Diagnostic::Note;
211 case WARNING: return Diagnostic::Warning;
212 case ERROR: return Diagnostic::Error;
Reid Spencer5f016e22007-07-11 17:01:13 +0000213 }
214}
215
Chris Lattner0a14eee2008-11-18 07:04:44 +0000216/// ProcessDiag - This is the method used to report a diagnostic that is
217/// finally fully formed.
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000218void Diagnostic::ProcessDiag() {
219 DiagnosticInfo Info(this);
220
Reid Spencer5f016e22007-07-11 17:01:13 +0000221 // Figure out the diagnostic level of this message.
Chris Lattner0a14eee2008-11-18 07:04:44 +0000222 Diagnostic::Level DiagLevel = getDiagnosticLevel(Info.getID());
Reid Spencer5f016e22007-07-11 17:01:13 +0000223
224 // If the client doesn't care about this message, don't issue it.
225 if (DiagLevel == Diagnostic::Ignored)
226 return;
Nico Weber7bfaaae2008-08-10 19:59:06 +0000227
Nico Weber7bfaaae2008-08-10 19:59:06 +0000228 // If this is not an error and we are in a system header, ignore it. We
Chris Lattner0a14eee2008-11-18 07:04:44 +0000229 // have to check on the original Diag ID here, because we also want to
Nico Weber7bfaaae2008-08-10 19:59:06 +0000230 // ignore extensions and warnings in -Werror and -pedantic-errors modes,
231 // which *map* warnings/extensions to errors.
Daniel Dunbar2fe09972008-09-12 18:10:20 +0000232 if (SuppressSystemWarnings &&
Chris Lattner0a14eee2008-11-18 07:04:44 +0000233 Info.getID() < diag::NUM_BUILTIN_DIAGNOSTICS &&
234 getBuiltinDiagClass(Info.getID()) != ERROR &&
235 Info.getLocation().isValid() &&
236 Info.getLocation().getPhysicalLoc().isInSystemHeader())
Chris Lattner7097d912008-02-03 09:00:04 +0000237 return;
Reid Spencer5f016e22007-07-11 17:01:13 +0000238
239 if (DiagLevel >= Diagnostic::Error) {
240 ErrorOccurred = true;
Nico Weber7bfaaae2008-08-10 19:59:06 +0000241
Chris Lattner0a14eee2008-11-18 07:04:44 +0000242 ++NumErrors;
Reid Spencer5f016e22007-07-11 17:01:13 +0000243 }
244
Reid Spencer5f016e22007-07-11 17:01:13 +0000245 // Finally, report it.
Chris Lattner0a14eee2008-11-18 07:04:44 +0000246 Client->HandleDiagnostic(DiagLevel, Info);
247 ++NumDiagnostics;
Reid Spencer5f016e22007-07-11 17:01:13 +0000248}
249
Nico Weber7bfaaae2008-08-10 19:59:06 +0000250
Reid Spencer5f016e22007-07-11 17:01:13 +0000251DiagnosticClient::~DiagnosticClient() {}
Nico Weber7bfaaae2008-08-10 19:59:06 +0000252
Chris Lattnerf4c83962008-11-19 06:51:40 +0000253
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000254/// ModifierIs - Return true if the specified modifier matches specified string.
255template <std::size_t StrLen>
256static bool ModifierIs(const char *Modifier, unsigned ModifierLen,
257 const char (&Str)[StrLen]) {
258 return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1);
259}
260
261/// HandleSelectModifier - Handle the integer 'select' modifier. This is used
262/// like this: %select{foo|bar|baz}2. This means that the integer argument
263/// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'.
264/// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'.
265/// This is very useful for certain classes of variant diagnostics.
266static void HandleSelectModifier(unsigned ValNo,
267 const char *Argument, unsigned ArgumentLen,
268 llvm::SmallVectorImpl<char> &OutStr) {
269 const char *ArgumentEnd = Argument+ArgumentLen;
270
271 // Skip over 'ValNo' |'s.
272 while (ValNo) {
273 const char *NextVal = std::find(Argument, ArgumentEnd, '|');
274 assert(NextVal != ArgumentEnd && "Value for integer select modifier was"
275 " larger than the number of options in the diagnostic string!");
276 Argument = NextVal+1; // Skip this string.
277 --ValNo;
278 }
279
280 // Get the end of the value. This is either the } or the |.
281 const char *EndPtr = std::find(Argument, ArgumentEnd, '|');
282 // Add the value to the output string.
283 OutStr.append(Argument, EndPtr);
284}
285
286/// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the
287/// letter 's' to the string if the value is not 1. This is used in cases like
288/// this: "you idiot, you have %4 parameter%s4!".
289static void HandleIntegerSModifier(unsigned ValNo,
290 llvm::SmallVectorImpl<char> &OutStr) {
291 if (ValNo != 1)
292 OutStr.push_back('s');
293}
294
295
Sebastian Redle4c452c2008-11-22 13:44:36 +0000296/// PluralNumber - Parse an unsigned integer and advance Start.
297static unsigned PluralNumber(const char *&Start, const char *End)
298{
299 // Programming 101: Parse a decimal number :-)
300 unsigned Val = 0;
301 while (Start != End && *Start >= '0' && *Start <= '9') {
302 Val *= 10;
303 Val += *Start - '0';
304 ++Start;
305 }
306 return Val;
307}
308
309/// TestPluralRange - Test if Val is in the parsed range. Modifies Start.
310static bool TestPluralRange(unsigned Val, const char *&Start, const char *End)
311{
312 if (*Start != '[') {
313 unsigned Ref = PluralNumber(Start, End);
314 return Ref == Val;
315 }
316
317 ++Start;
318 unsigned Low = PluralNumber(Start, End);
319 assert(*Start == ',' && "Bad plural expression syntax: expected ,");
320 ++Start;
321 unsigned High = PluralNumber(Start, End);
322 assert(*Start == ']' && "Bad plural expression syntax: expected )");
323 ++Start;
324 return Low <= Val && Val <= High;
325}
326
327/// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
328static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End)
329{
330 // Empty condition?
331 if (*Start == ':')
332 return true;
333
334 while (1) {
335 char C = *Start;
336 if (C == '%') {
337 // Modulo expression
338 ++Start;
339 unsigned Arg = PluralNumber(Start, End);
340 assert(*Start == '=' && "Bad plural expression syntax: expected =");
341 ++Start;
342 unsigned ValMod = ValNo % Arg;
343 if (TestPluralRange(ValMod, Start, End))
344 return true;
345 } else {
346 assert(C == '[' || (C >= '0' && C <= '9') &&
347 "Bad plural expression syntax: unexpected character");
348 // Range expression
349 if (TestPluralRange(ValNo, Start, End))
350 return true;
351 }
352
353 // Scan for next or-expr part.
354 Start = std::find(Start, End, ',');
355 if(Start == End)
356 break;
357 ++Start;
358 }
359 return false;
360}
361
362/// HandlePluralModifier - Handle the integer 'plural' modifier. This is used
363/// for complex plural forms, or in languages where all plurals are complex.
364/// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are
365/// conditions that are tested in order, the form corresponding to the first
366/// that applies being emitted. The empty condition is always true, making the
367/// last form a default case.
368/// Conditions are simple boolean expressions, where n is the number argument.
369/// Here are the rules.
370/// condition := expression | empty
371/// empty := -> always true
372/// expression := numeric [',' expression] -> logical or
373/// numeric := range -> true if n in range
374/// | '%' number '=' range -> true if n % number in range
375/// range := number
376/// | '[' number ',' number ']' -> ranges are inclusive both ends
377///
378/// Here are some examples from the GNU gettext manual written in this form:
379/// English:
380/// {1:form0|:form1}
381/// Latvian:
382/// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0}
383/// Gaeilge:
384/// {1:form0|2:form1|:form2}
385/// Romanian:
386/// {1:form0|0,%100=[1,19]:form1|:form2}
387/// Lithuanian:
388/// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1}
389/// Russian (requires repeated form):
390/// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2}
391/// Slovak
392/// {1:form0|[2,4]:form1|:form2}
393/// Polish (requires repeated form):
394/// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2}
395static void HandlePluralModifier(unsigned ValNo,
396 const char *Argument, unsigned ArgumentLen,
397 llvm::SmallVectorImpl<char> &OutStr)
398{
399 const char *ArgumentEnd = Argument + ArgumentLen;
400 while (1) {
401 assert(Argument < ArgumentEnd && "Plural expression didn't match.");
402 const char *ExprEnd = Argument;
403 while (*ExprEnd != ':') {
404 assert(ExprEnd != ArgumentEnd && "Plural missing expression end");
405 ++ExprEnd;
406 }
407 if (EvalPluralExpr(ValNo, Argument, ExprEnd)) {
408 Argument = ExprEnd + 1;
409 ExprEnd = std::find(Argument, ArgumentEnd, '|');
410 OutStr.append(Argument, ExprEnd);
411 return;
412 }
413 Argument = std::find(Argument, ArgumentEnd - 1, '|') + 1;
414 }
415}
416
417
Chris Lattnerf4c83962008-11-19 06:51:40 +0000418/// FormatDiagnostic - Format this diagnostic into a string, substituting the
419/// formal arguments into the %0 slots. The result is appended onto the Str
420/// array.
421void DiagnosticInfo::
422FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
423 const char *DiagStr = getDiags()->getDescription(getID());
424 const char *DiagEnd = DiagStr+strlen(DiagStr);
Nico Weber7bfaaae2008-08-10 19:59:06 +0000425
Chris Lattnerf4c83962008-11-19 06:51:40 +0000426 while (DiagStr != DiagEnd) {
427 if (DiagStr[0] != '%') {
428 // Append non-%0 substrings to Str if we have one.
429 const char *StrEnd = std::find(DiagStr, DiagEnd, '%');
430 OutStr.append(DiagStr, StrEnd);
431 DiagStr = StrEnd;
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000432 continue;
Chris Lattnerf4c83962008-11-19 06:51:40 +0000433 } else if (DiagStr[1] == '%') {
434 OutStr.push_back('%'); // %% -> %.
435 DiagStr += 2;
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000436 continue;
437 }
438
439 // Skip the %.
440 ++DiagStr;
441
442 // This must be a placeholder for a diagnostic argument. The format for a
443 // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0".
444 // The digit is a number from 0-9 indicating which argument this comes from.
445 // The modifier is a string of digits from the set [-a-z]+, arguments is a
446 // brace enclosed string.
447 const char *Modifier = 0, *Argument = 0;
448 unsigned ModifierLen = 0, ArgumentLen = 0;
449
450 // Check to see if we have a modifier. If so eat it.
451 if (!isdigit(DiagStr[0])) {
452 Modifier = DiagStr;
453 while (DiagStr[0] == '-' ||
454 (DiagStr[0] >= 'a' && DiagStr[0] <= 'z'))
455 ++DiagStr;
456 ModifierLen = DiagStr-Modifier;
Chris Lattnerf4c83962008-11-19 06:51:40 +0000457
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000458 // If we have an argument, get it next.
459 if (DiagStr[0] == '{') {
460 ++DiagStr; // Skip {.
461 Argument = DiagStr;
462
463 for (; DiagStr[0] != '}'; ++DiagStr)
464 assert(DiagStr[0] && "Mismatched {}'s in diagnostic string!");
465 ArgumentLen = DiagStr-Argument;
466 ++DiagStr; // Skip }.
Chris Lattnerf4c83962008-11-19 06:51:40 +0000467 }
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000468 }
469
470 assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic");
471 unsigned StrNo = *DiagStr++ - '0';
472
473 switch (getArgKind(StrNo)) {
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000474 case Diagnostic::ak_std_string: {
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000475 const std::string &S = getArgStdStr(StrNo);
476 assert(ModifierLen == 0 && "No modifiers for strings yet");
477 OutStr.append(S.begin(), S.end());
478 break;
479 }
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000480 case Diagnostic::ak_c_string: {
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000481 const char *S = getArgCStr(StrNo);
482 assert(ModifierLen == 0 && "No modifiers for strings yet");
483 OutStr.append(S, S + strlen(S));
484 break;
485 }
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000486 case Diagnostic::ak_identifierinfo: {
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000487 const IdentifierInfo *II = getArgIdentifier(StrNo);
488 assert(ModifierLen == 0 && "No modifiers for strings yet");
489 OutStr.append(II->getName(), II->getName() + II->getLength());
490 break;
491 }
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000492 case Diagnostic::ak_sint: {
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000493 int Val = getArgSInt(StrNo);
494
495 if (ModifierIs(Modifier, ModifierLen, "select")) {
496 HandleSelectModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
497 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
498 HandleIntegerSModifier(Val, OutStr);
Sebastian Redle4c452c2008-11-22 13:44:36 +0000499 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
500 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000501 } else {
502 assert(ModifierLen == 0 && "Unknown integer modifier");
Chris Lattner30bc9652008-11-19 07:22:31 +0000503 // FIXME: Optimize
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000504 std::string S = llvm::itostr(Val);
Chris Lattner30bc9652008-11-19 07:22:31 +0000505 OutStr.append(S.begin(), S.end());
Chris Lattner30bc9652008-11-19 07:22:31 +0000506 }
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000507 break;
508 }
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000509 case Diagnostic::ak_uint: {
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000510 unsigned Val = getArgUInt(StrNo);
511
512 if (ModifierIs(Modifier, ModifierLen, "select")) {
513 HandleSelectModifier(Val, Argument, ArgumentLen, OutStr);
514 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
515 HandleIntegerSModifier(Val, OutStr);
Sebastian Redle4c452c2008-11-22 13:44:36 +0000516 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
517 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000518 } else {
519 assert(ModifierLen == 0 && "Unknown integer modifier");
520
Chris Lattner30bc9652008-11-19 07:22:31 +0000521 // FIXME: Optimize
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000522 std::string S = llvm::utostr_32(Val);
Chris Lattner30bc9652008-11-19 07:22:31 +0000523 OutStr.append(S.begin(), S.end());
524 break;
525 }
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000526 }
Nico Weber7bfaaae2008-08-10 19:59:06 +0000527 }
528 }
Nico Weber7bfaaae2008-08-10 19:59:06 +0000529}