Diagnostic.cpp revision f5d2328fc849288c3a62e43d065685f516d57091
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. 11// 12//===----------------------------------------------------------------------===// 13 14#include "clang/Basic/Diagnostic.h" 15#include "clang/Basic/IdentifierTable.h" 16#include "clang/Basic/SourceLocation.h" 17#include "llvm/ADT/SmallVector.h" 18#include "llvm/ADT/StringExtras.h" 19#include <vector> 20#include <map> 21#include <cstring> 22using namespace clang; 23 24//===----------------------------------------------------------------------===// 25// Builtin Diagnostic information 26//===----------------------------------------------------------------------===// 27 28/// Flag values for diagnostics. 29enum { 30 // Diagnostic classes. 31 NOTE = 0x01, 32 WARNING = 0x02, 33 EXTENSION = 0x03, 34 EXTWARN = 0x04, 35 ERROR = 0x05, 36 FATAL = 0x06, 37 class_mask = 0x07 38}; 39 40/// DiagnosticFlags - A set of flags, or'd together, that describe the 41/// diagnostic. 42#define DIAG(ENUM,FLAGS,DESC) FLAGS, 43static unsigned char DiagnosticFlagsCommon[] = { 44#include "clang/Basic/DiagnosticCommonKinds.def" 45 0 46}; 47static unsigned char DiagnosticFlagsLex[] = { 48#include "clang/Basic/DiagnosticLexKinds.def" 49 0 50}; 51static unsigned char DiagnosticFlagsParse[] = { 52#include "clang/Basic/DiagnosticParseKinds.def" 53 0 54}; 55static unsigned char DiagnosticFlagsAST[] = { 56#include "clang/Basic/DiagnosticASTKinds.def" 57 0 58}; 59static unsigned char DiagnosticFlagsSema[] = { 60#include "clang/Basic/DiagnosticSemaKinds.def" 61 0 62}; 63static unsigned char DiagnosticFlagsAnalysis[] = { 64#include "clang/Basic/DiagnosticAnalysisKinds.def" 65 0 66}; 67#undef DIAG 68 69/// getDiagClass - Return the class field of the diagnostic. 70/// 71static unsigned getBuiltinDiagClass(unsigned DiagID) { 72 assert(DiagID < diag::DIAG_UPPER_LIMIT && 73 "Diagnostic ID out of range!"); 74 unsigned res; 75 if (DiagID < diag::DIAG_START_LEX) 76 res = DiagnosticFlagsCommon[DiagID]; 77 else if (DiagID < diag::DIAG_START_PARSE) 78 res = DiagnosticFlagsLex[DiagID - diag::DIAG_START_LEX - 1]; 79 else if (DiagID < diag::DIAG_START_AST) 80 res = DiagnosticFlagsParse[DiagID - diag::DIAG_START_PARSE - 1]; 81 else if (DiagID < diag::DIAG_START_SEMA) 82 res = DiagnosticFlagsAST[DiagID - diag::DIAG_START_AST - 1]; 83 else if (DiagID < diag::DIAG_START_ANALYSIS) 84 res = DiagnosticFlagsSema[DiagID - diag::DIAG_START_SEMA - 1]; 85 else 86 res = DiagnosticFlagsAnalysis[DiagID - diag::DIAG_START_ANALYSIS - 1]; 87 return res & class_mask; 88} 89 90/// DiagnosticText - An english message to print for the diagnostic. These 91/// should be localized. 92#define DIAG(ENUM,FLAGS,DESC) DESC, 93static const char * const DiagnosticTextCommon[] = { 94#include "clang/Basic/DiagnosticCommonKinds.def" 95 0 96}; 97static const char * const DiagnosticTextLex[] = { 98#include "clang/Basic/DiagnosticLexKinds.def" 99 0 100}; 101static const char * const DiagnosticTextParse[] = { 102#include "clang/Basic/DiagnosticParseKinds.def" 103 0 104}; 105static const char * const DiagnosticTextAST[] = { 106#include "clang/Basic/DiagnosticASTKinds.def" 107 0 108}; 109static const char * const DiagnosticTextSema[] = { 110#include "clang/Basic/DiagnosticSemaKinds.def" 111 0 112}; 113static const char * const DiagnosticTextAnalysis[] = { 114#include "clang/Basic/DiagnosticAnalysisKinds.def" 115 0 116}; 117#undef DIAG 118 119//===----------------------------------------------------------------------===// 120// Custom Diagnostic information 121//===----------------------------------------------------------------------===// 122 123namespace clang { 124 namespace diag { 125 class CustomDiagInfo { 126 typedef std::pair<Diagnostic::Level, std::string> DiagDesc; 127 std::vector<DiagDesc> DiagInfo; 128 std::map<DiagDesc, unsigned> DiagIDs; 129 public: 130 131 /// getDescription - Return the description of the specified custom 132 /// diagnostic. 133 const char *getDescription(unsigned DiagID) const { 134 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() && 135 "Invalid diagnosic ID"); 136 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second.c_str(); 137 } 138 139 /// getLevel - Return the level of the specified custom diagnostic. 140 Diagnostic::Level getLevel(unsigned DiagID) const { 141 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() && 142 "Invalid diagnosic ID"); 143 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first; 144 } 145 146 unsigned getOrCreateDiagID(Diagnostic::Level L, const char *Message, 147 Diagnostic &Diags) { 148 DiagDesc D(L, Message); 149 // Check to see if it already exists. 150 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D); 151 if (I != DiagIDs.end() && I->first == D) 152 return I->second; 153 154 // If not, assign a new ID. 155 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT; 156 DiagIDs.insert(std::make_pair(D, ID)); 157 DiagInfo.push_back(D); 158 159 // If this is a warning, and all warnings are supposed to map to errors, 160 // insert the mapping now. 161 if (L == Diagnostic::Warning && Diags.getWarningsAsErrors()) 162 Diags.setDiagnosticMapping((diag::kind)ID, diag::MAP_ERROR); 163 return ID; 164 } 165 }; 166 167 } // end diag namespace 168} // end clang namespace 169 170 171//===----------------------------------------------------------------------===// 172// Common Diagnostic implementation 173//===----------------------------------------------------------------------===// 174 175static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT, 176 const char *Modifier, unsigned ML, 177 const char *Argument, unsigned ArgLen, 178 llvm::SmallVectorImpl<char> &Output) { 179 const char *Str = "<can't format argument>"; 180 Output.append(Str, Str+strlen(Str)); 181} 182 183 184Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) { 185 IgnoreAllWarnings = false; 186 WarningsAsErrors = false; 187 WarnOnExtensions = false; 188 ErrorOnExtensions = false; 189 SuppressSystemWarnings = false; 190 // Clear all mappings, setting them to MAP_DEFAULT. 191 memset(DiagMappings, 0, sizeof(DiagMappings)); 192 193 ErrorOccurred = false; 194 FatalErrorOccurred = false; 195 NumDiagnostics = 0; 196 NumErrors = 0; 197 CustomDiagInfo = 0; 198 CurDiagID = ~0U; 199 LastDiagLevel = Fatal; 200 201 ArgToStringFn = DummyArgToStringFn; 202} 203 204Diagnostic::~Diagnostic() { 205 delete CustomDiagInfo; 206} 207 208/// getCustomDiagID - Return an ID for a diagnostic with the specified message 209/// and level. If this is the first request for this diagnosic, it is 210/// registered and created, otherwise the existing ID is returned. 211unsigned Diagnostic::getCustomDiagID(Level L, const char *Message) { 212 if (CustomDiagInfo == 0) 213 CustomDiagInfo = new diag::CustomDiagInfo(); 214 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this); 215} 216 217 218/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic 219/// level of the specified diagnostic ID is a Warning or Extension. 220/// This only works on builtin diagnostics, not custom ones, and is not legal to 221/// call on NOTEs. 222bool Diagnostic::isBuiltinWarningOrExtension(unsigned DiagID) { 223 return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) < ERROR; 224} 225 226 227/// getDescription - Given a diagnostic ID, return a description of the 228/// issue. 229const char *Diagnostic::getDescription(unsigned DiagID) const { 230 if (DiagID < diag::DIAG_START_LEX) 231 return DiagnosticTextCommon[DiagID]; 232 else if (DiagID < diag::DIAG_START_PARSE) 233 return DiagnosticTextLex[DiagID - diag::DIAG_START_LEX - 1]; 234 else if (DiagID < diag::DIAG_START_AST) 235 return DiagnosticTextParse[DiagID - diag::DIAG_START_PARSE - 1]; 236 else if (DiagID < diag::DIAG_START_SEMA) 237 return DiagnosticTextAST[DiagID - diag::DIAG_START_AST - 1]; 238 else if (DiagID < diag::DIAG_START_ANALYSIS) 239 return DiagnosticTextSema[DiagID - diag::DIAG_START_SEMA - 1]; 240 else if (DiagID < diag::DIAG_UPPER_LIMIT) 241 return DiagnosticTextAnalysis[DiagID - diag::DIAG_START_ANALYSIS - 1]; 242 return CustomDiagInfo->getDescription(DiagID); 243} 244 245/// getDiagnosticLevel - Based on the way the client configured the Diagnostic 246/// object, classify the specified diagnostic ID into a Level, consumable by 247/// the DiagnosticClient. 248Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { 249 // Handle custom diagnostics, which cannot be mapped. 250 if (DiagID >= diag::DIAG_UPPER_LIMIT) 251 return CustomDiagInfo->getLevel(DiagID); 252 253 unsigned DiagClass = getBuiltinDiagClass(DiagID); 254 assert(DiagClass != NOTE && "Cannot get the diagnostic level of a note!"); 255 return getDiagnosticLevel(DiagID, DiagClass); 256} 257 258/// getDiagnosticLevel - Based on the way the client configured the Diagnostic 259/// object, classify the specified diagnostic ID into a Level, consumable by 260/// the DiagnosticClient. 261Diagnostic::Level 262Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const { 263 // Specific non-error diagnostics may be mapped to various levels from ignored 264 // to error. Errors can only be mapped to fatal. 265 switch (getDiagnosticMapping((diag::kind)DiagID)) { 266 case diag::MAP_DEFAULT: break; 267 case diag::MAP_IGNORE: return Diagnostic::Ignored; 268 case diag::MAP_WARNING: DiagClass = WARNING; break; 269 case diag::MAP_ERROR: DiagClass = ERROR; break; 270 case diag::MAP_FATAL: DiagClass = FATAL; break; 271 } 272 273 // Map diagnostic classes based on command line argument settings. 274 if (DiagClass == EXTENSION) { 275 if (ErrorOnExtensions) 276 DiagClass = ERROR; 277 else if (WarnOnExtensions) 278 DiagClass = WARNING; 279 else 280 return Ignored; 281 } else if (DiagClass == EXTWARN) { 282 DiagClass = ErrorOnExtensions ? ERROR : WARNING; 283 } 284 285 // If warnings are globally mapped to ignore or error, do it. 286 if (DiagClass == WARNING) { 287 if (IgnoreAllWarnings) 288 return Diagnostic::Ignored; 289 if (WarningsAsErrors) 290 DiagClass = ERROR; 291 } 292 293 switch (DiagClass) { 294 default: assert(0 && "Unknown diagnostic class!"); 295 case WARNING: return Diagnostic::Warning; 296 case ERROR: return Diagnostic::Error; 297 case FATAL: return Diagnostic::Fatal; 298 } 299} 300 301/// ProcessDiag - This is the method used to report a diagnostic that is 302/// finally fully formed. 303void Diagnostic::ProcessDiag() { 304 DiagnosticInfo Info(this); 305 306 // If a fatal error has already been emitted, silence all subsequent 307 // diagnostics. 308 if (FatalErrorOccurred) 309 return; 310 311 // Figure out the diagnostic level of this message. 312 Diagnostic::Level DiagLevel; 313 unsigned DiagID = Info.getID(); 314 315 // ShouldEmitInSystemHeader - True if this diagnostic should be produced even 316 // in a system header. 317 bool ShouldEmitInSystemHeader; 318 319 if (DiagID >= diag::DIAG_UPPER_LIMIT) { 320 // Handle custom diagnostics, which cannot be mapped. 321 DiagLevel = CustomDiagInfo->getLevel(DiagID); 322 323 // Custom diagnostics always are emitted in system headers. 324 ShouldEmitInSystemHeader = true; 325 } else { 326 // Get the class of the diagnostic. If this is a NOTE, map it onto whatever 327 // the diagnostic level was for the previous diagnostic so that it is 328 // filtered the same as the previous diagnostic. 329 unsigned DiagClass = getBuiltinDiagClass(DiagID); 330 if (DiagClass == NOTE) { 331 DiagLevel = Diagnostic::Note; 332 ShouldEmitInSystemHeader = false; // extra consideration is needed 333 } else { 334 // If this is not an error and we are in a system header, we ignore it. 335 // Check the original Diag ID here, because we also want to ignore 336 // extensions and warnings in -Werror and -pedantic-errors modes, which 337 // *map* warnings/extensions to errors. 338 ShouldEmitInSystemHeader = DiagClass == ERROR; 339 340 DiagLevel = getDiagnosticLevel(DiagID, DiagClass); 341 } 342 } 343 344 if (DiagLevel != Diagnostic::Note) 345 LastDiagLevel = DiagLevel; 346 347 // If the client doesn't care about this message, don't issue it. If this is 348 // a note and the last real diagnostic was ignored, ignore it too. 349 if (DiagLevel == Diagnostic::Ignored || 350 (DiagLevel == Diagnostic::Note && LastDiagLevel == Diagnostic::Ignored)) 351 return; 352 353 // If this diagnostic is in a system header and is not a clang error, suppress 354 // it. 355 if (SuppressSystemWarnings && !ShouldEmitInSystemHeader && 356 Info.getLocation().isValid() && 357 Info.getLocation().getSpellingLoc().isInSystemHeader() && 358 (DiagLevel != Diagnostic::Note || LastDiagLevel == Diagnostic::Ignored)) 359 return; 360 361 if (DiagLevel >= Diagnostic::Error) { 362 ErrorOccurred = true; 363 ++NumErrors; 364 365 if (DiagLevel == Diagnostic::Fatal) 366 FatalErrorOccurred = true; 367 } 368 369 // Finally, report it. 370 Client->HandleDiagnostic(DiagLevel, Info); 371 if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics; 372} 373 374 375DiagnosticClient::~DiagnosticClient() {} 376 377 378/// ModifierIs - Return true if the specified modifier matches specified string. 379template <std::size_t StrLen> 380static bool ModifierIs(const char *Modifier, unsigned ModifierLen, 381 const char (&Str)[StrLen]) { 382 return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1); 383} 384 385/// HandleSelectModifier - Handle the integer 'select' modifier. This is used 386/// like this: %select{foo|bar|baz}2. This means that the integer argument 387/// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'. 388/// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'. 389/// This is very useful for certain classes of variant diagnostics. 390static void HandleSelectModifier(unsigned ValNo, 391 const char *Argument, unsigned ArgumentLen, 392 llvm::SmallVectorImpl<char> &OutStr) { 393 const char *ArgumentEnd = Argument+ArgumentLen; 394 395 // Skip over 'ValNo' |'s. 396 while (ValNo) { 397 const char *NextVal = std::find(Argument, ArgumentEnd, '|'); 398 assert(NextVal != ArgumentEnd && "Value for integer select modifier was" 399 " larger than the number of options in the diagnostic string!"); 400 Argument = NextVal+1; // Skip this string. 401 --ValNo; 402 } 403 404 // Get the end of the value. This is either the } or the |. 405 const char *EndPtr = std::find(Argument, ArgumentEnd, '|'); 406 // Add the value to the output string. 407 OutStr.append(Argument, EndPtr); 408} 409 410/// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the 411/// letter 's' to the string if the value is not 1. This is used in cases like 412/// this: "you idiot, you have %4 parameter%s4!". 413static void HandleIntegerSModifier(unsigned ValNo, 414 llvm::SmallVectorImpl<char> &OutStr) { 415 if (ValNo != 1) 416 OutStr.push_back('s'); 417} 418 419 420/// PluralNumber - Parse an unsigned integer and advance Start. 421static unsigned PluralNumber(const char *&Start, const char *End) 422{ 423 // Programming 101: Parse a decimal number :-) 424 unsigned Val = 0; 425 while (Start != End && *Start >= '0' && *Start <= '9') { 426 Val *= 10; 427 Val += *Start - '0'; 428 ++Start; 429 } 430 return Val; 431} 432 433/// TestPluralRange - Test if Val is in the parsed range. Modifies Start. 434static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) 435{ 436 if (*Start != '[') { 437 unsigned Ref = PluralNumber(Start, End); 438 return Ref == Val; 439 } 440 441 ++Start; 442 unsigned Low = PluralNumber(Start, End); 443 assert(*Start == ',' && "Bad plural expression syntax: expected ,"); 444 ++Start; 445 unsigned High = PluralNumber(Start, End); 446 assert(*Start == ']' && "Bad plural expression syntax: expected )"); 447 ++Start; 448 return Low <= Val && Val <= High; 449} 450 451/// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier. 452static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) 453{ 454 // Empty condition? 455 if (*Start == ':') 456 return true; 457 458 while (1) { 459 char C = *Start; 460 if (C == '%') { 461 // Modulo expression 462 ++Start; 463 unsigned Arg = PluralNumber(Start, End); 464 assert(*Start == '=' && "Bad plural expression syntax: expected ="); 465 ++Start; 466 unsigned ValMod = ValNo % Arg; 467 if (TestPluralRange(ValMod, Start, End)) 468 return true; 469 } else { 470 assert((C == '[' || (C >= '0' && C <= '9')) && 471 "Bad plural expression syntax: unexpected character"); 472 // Range expression 473 if (TestPluralRange(ValNo, Start, End)) 474 return true; 475 } 476 477 // Scan for next or-expr part. 478 Start = std::find(Start, End, ','); 479 if(Start == End) 480 break; 481 ++Start; 482 } 483 return false; 484} 485 486/// HandlePluralModifier - Handle the integer 'plural' modifier. This is used 487/// for complex plural forms, or in languages where all plurals are complex. 488/// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are 489/// conditions that are tested in order, the form corresponding to the first 490/// that applies being emitted. The empty condition is always true, making the 491/// last form a default case. 492/// Conditions are simple boolean expressions, where n is the number argument. 493/// Here are the rules. 494/// condition := expression | empty 495/// empty := -> always true 496/// expression := numeric [',' expression] -> logical or 497/// numeric := range -> true if n in range 498/// | '%' number '=' range -> true if n % number in range 499/// range := number 500/// | '[' number ',' number ']' -> ranges are inclusive both ends 501/// 502/// Here are some examples from the GNU gettext manual written in this form: 503/// English: 504/// {1:form0|:form1} 505/// Latvian: 506/// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0} 507/// Gaeilge: 508/// {1:form0|2:form1|:form2} 509/// Romanian: 510/// {1:form0|0,%100=[1,19]:form1|:form2} 511/// Lithuanian: 512/// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1} 513/// Russian (requires repeated form): 514/// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2} 515/// Slovak 516/// {1:form0|[2,4]:form1|:form2} 517/// Polish (requires repeated form): 518/// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2} 519static void HandlePluralModifier(unsigned ValNo, 520 const char *Argument, unsigned ArgumentLen, 521 llvm::SmallVectorImpl<char> &OutStr) 522{ 523 const char *ArgumentEnd = Argument + ArgumentLen; 524 while (1) { 525 assert(Argument < ArgumentEnd && "Plural expression didn't match."); 526 const char *ExprEnd = Argument; 527 while (*ExprEnd != ':') { 528 assert(ExprEnd != ArgumentEnd && "Plural missing expression end"); 529 ++ExprEnd; 530 } 531 if (EvalPluralExpr(ValNo, Argument, ExprEnd)) { 532 Argument = ExprEnd + 1; 533 ExprEnd = std::find(Argument, ArgumentEnd, '|'); 534 OutStr.append(Argument, ExprEnd); 535 return; 536 } 537 Argument = std::find(Argument, ArgumentEnd - 1, '|') + 1; 538 } 539} 540 541 542/// FormatDiagnostic - Format this diagnostic into a string, substituting the 543/// formal arguments into the %0 slots. The result is appended onto the Str 544/// array. 545void DiagnosticInfo:: 546FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const { 547 const char *DiagStr = getDiags()->getDescription(getID()); 548 const char *DiagEnd = DiagStr+strlen(DiagStr); 549 550 while (DiagStr != DiagEnd) { 551 if (DiagStr[0] != '%') { 552 // Append non-%0 substrings to Str if we have one. 553 const char *StrEnd = std::find(DiagStr, DiagEnd, '%'); 554 OutStr.append(DiagStr, StrEnd); 555 DiagStr = StrEnd; 556 continue; 557 } else if (DiagStr[1] == '%') { 558 OutStr.push_back('%'); // %% -> %. 559 DiagStr += 2; 560 continue; 561 } 562 563 // Skip the %. 564 ++DiagStr; 565 566 // This must be a placeholder for a diagnostic argument. The format for a 567 // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0". 568 // The digit is a number from 0-9 indicating which argument this comes from. 569 // The modifier is a string of digits from the set [-a-z]+, arguments is a 570 // brace enclosed string. 571 const char *Modifier = 0, *Argument = 0; 572 unsigned ModifierLen = 0, ArgumentLen = 0; 573 574 // Check to see if we have a modifier. If so eat it. 575 if (!isdigit(DiagStr[0])) { 576 Modifier = DiagStr; 577 while (DiagStr[0] == '-' || 578 (DiagStr[0] >= 'a' && DiagStr[0] <= 'z')) 579 ++DiagStr; 580 ModifierLen = DiagStr-Modifier; 581 582 // If we have an argument, get it next. 583 if (DiagStr[0] == '{') { 584 ++DiagStr; // Skip {. 585 Argument = DiagStr; 586 587 for (; DiagStr[0] != '}'; ++DiagStr) 588 assert(DiagStr[0] && "Mismatched {}'s in diagnostic string!"); 589 ArgumentLen = DiagStr-Argument; 590 ++DiagStr; // Skip }. 591 } 592 } 593 594 assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic"); 595 unsigned ArgNo = *DiagStr++ - '0'; 596 597 switch (getArgKind(ArgNo)) { 598 // ---- STRINGS ---- 599 case Diagnostic::ak_std_string: { 600 const std::string &S = getArgStdStr(ArgNo); 601 assert(ModifierLen == 0 && "No modifiers for strings yet"); 602 OutStr.append(S.begin(), S.end()); 603 break; 604 } 605 case Diagnostic::ak_c_string: { 606 const char *S = getArgCStr(ArgNo); 607 assert(ModifierLen == 0 && "No modifiers for strings yet"); 608 OutStr.append(S, S + strlen(S)); 609 break; 610 } 611 // ---- INTEGERS ---- 612 case Diagnostic::ak_sint: { 613 int Val = getArgSInt(ArgNo); 614 615 if (ModifierIs(Modifier, ModifierLen, "select")) { 616 HandleSelectModifier((unsigned)Val, Argument, ArgumentLen, OutStr); 617 } else if (ModifierIs(Modifier, ModifierLen, "s")) { 618 HandleIntegerSModifier(Val, OutStr); 619 } else if (ModifierIs(Modifier, ModifierLen, "plural")) { 620 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr); 621 } else { 622 assert(ModifierLen == 0 && "Unknown integer modifier"); 623 // FIXME: Optimize 624 std::string S = llvm::itostr(Val); 625 OutStr.append(S.begin(), S.end()); 626 } 627 break; 628 } 629 case Diagnostic::ak_uint: { 630 unsigned Val = getArgUInt(ArgNo); 631 632 if (ModifierIs(Modifier, ModifierLen, "select")) { 633 HandleSelectModifier(Val, Argument, ArgumentLen, OutStr); 634 } else if (ModifierIs(Modifier, ModifierLen, "s")) { 635 HandleIntegerSModifier(Val, OutStr); 636 } else if (ModifierIs(Modifier, ModifierLen, "plural")) { 637 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr); 638 } else { 639 assert(ModifierLen == 0 && "Unknown integer modifier"); 640 641 // FIXME: Optimize 642 std::string S = llvm::utostr_32(Val); 643 OutStr.append(S.begin(), S.end()); 644 } 645 break; 646 } 647 // ---- NAMES and TYPES ---- 648 case Diagnostic::ak_identifierinfo: { 649 OutStr.push_back('\''); 650 const IdentifierInfo *II = getArgIdentifier(ArgNo); 651 assert(ModifierLen == 0 && "No modifiers for strings yet"); 652 OutStr.append(II->getName(), II->getName() + II->getLength()); 653 OutStr.push_back('\''); 654 break; 655 } 656 case Diagnostic::ak_qualtype: 657 case Diagnostic::ak_declarationname: 658 case Diagnostic::ak_nameddecl: 659 OutStr.push_back('\''); 660 getDiags()->ConvertArgToString(getArgKind(ArgNo), getRawArg(ArgNo), 661 Modifier, ModifierLen, 662 Argument, ArgumentLen, OutStr); 663 OutStr.push_back('\''); 664 break; 665 } 666 } 667} 668 669/// IncludeInDiagnosticCounts - This method (whose default implementation 670/// returns true) indicates whether the diagnostics handled by this 671/// DiagnosticClient should be included in the number of diagnostics 672/// reported by Diagnostic. 673bool DiagnosticClient::IncludeInDiagnosticCounts() const { return true; } 674