Diagnostic.cpp revision 93ea5cb0edf8e509c5113e70cb05ee247c9bdf6b
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 16#include "clang/Lex/LexDiagnostic.h" 17#include "clang/Parse/ParseDiagnostic.h" 18#include "clang/AST/ASTDiagnostic.h" 19#include "clang/Sema/SemaDiagnostic.h" 20#include "clang/Frontend/FrontendDiagnostic.h" 21#include "clang/Analysis/AnalysisDiagnostic.h" 22#include "clang/Driver/DriverDiagnostic.h" 23 24#include "clang/Basic/FileManager.h" 25#include "clang/Basic/IdentifierTable.h" 26#include "clang/Basic/SourceLocation.h" 27#include "clang/Basic/SourceManager.h" 28#include "llvm/ADT/SmallVector.h" 29#include "llvm/ADT/StringExtras.h" 30#include "llvm/Support/raw_ostream.h" 31#include <vector> 32#include <map> 33#include <cstring> 34using namespace clang; 35 36//===----------------------------------------------------------------------===// 37// Builtin Diagnostic information 38//===----------------------------------------------------------------------===// 39 40// Diagnostic classes. 41enum { 42 CLASS_NOTE = 0x01, 43 CLASS_WARNING = 0x02, 44 CLASS_EXTENSION = 0x03, 45 CLASS_ERROR = 0x04 46}; 47 48struct StaticDiagInfoRec { 49 unsigned short DiagID; 50 unsigned Mapping : 3; 51 unsigned Class : 3; 52 bool SFINAE : 1; 53 const char *Description; 54 const char *OptionGroup; 55 56 bool operator<(const StaticDiagInfoRec &RHS) const { 57 return DiagID < RHS.DiagID; 58 } 59 bool operator>(const StaticDiagInfoRec &RHS) const { 60 return DiagID > RHS.DiagID; 61 } 62}; 63 64static const StaticDiagInfoRec StaticDiagInfo[] = { 65#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,SFINAE) \ 66 { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, DESC, GROUP }, 67#include "clang/Basic/DiagnosticCommonKinds.inc" 68#include "clang/Basic/DiagnosticDriverKinds.inc" 69#include "clang/Basic/DiagnosticFrontendKinds.inc" 70#include "clang/Basic/DiagnosticLexKinds.inc" 71#include "clang/Basic/DiagnosticParseKinds.inc" 72#include "clang/Basic/DiagnosticASTKinds.inc" 73#include "clang/Basic/DiagnosticSemaKinds.inc" 74#include "clang/Basic/DiagnosticAnalysisKinds.inc" 75 { 0, 0, 0, 0, 0, 0} 76}; 77#undef DIAG 78 79/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID, 80/// or null if the ID is invalid. 81static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { 82 unsigned NumDiagEntries = sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1; 83 84 // If assertions are enabled, verify that the StaticDiagInfo array is sorted. 85#ifndef NDEBUG 86 static bool IsFirst = true; 87 if (IsFirst) { 88 for (unsigned i = 1; i != NumDiagEntries; ++i) { 89 assert(StaticDiagInfo[i-1].DiagID != StaticDiagInfo[i].DiagID && 90 "Diag ID conflict, the enums at the start of clang::diag (in " 91 "Diagnostic.h) probably need to be increased"); 92 93 assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] && 94 "Improperly sorted diag info"); 95 } 96 IsFirst = false; 97 } 98#endif 99 100 // Search the diagnostic table with a binary search. 101 StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0, 0 }; 102 103 const StaticDiagInfoRec *Found = 104 std::lower_bound(StaticDiagInfo, StaticDiagInfo + NumDiagEntries, Find); 105 if (Found == StaticDiagInfo + NumDiagEntries || 106 Found->DiagID != DiagID) 107 return 0; 108 109 return Found; 110} 111 112static unsigned GetDefaultDiagMapping(unsigned DiagID) { 113 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) 114 return Info->Mapping; 115 return diag::MAP_FATAL; 116} 117 118/// getWarningOptionForDiag - Return the lowest-level warning option that 119/// enables the specified diagnostic. If there is no -Wfoo flag that controls 120/// the diagnostic, this returns null. 121const char *Diagnostic::getWarningOptionForDiag(unsigned DiagID) { 122 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) 123 return Info->OptionGroup; 124 return 0; 125} 126 127bool Diagnostic::isBuiltinSFINAEDiag(unsigned DiagID) { 128 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) 129 return Info->SFINAE && Info->Class == CLASS_ERROR; 130 return false; 131} 132 133/// getDiagClass - Return the class field of the diagnostic. 134/// 135static unsigned getBuiltinDiagClass(unsigned DiagID) { 136 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) 137 return Info->Class; 138 return ~0U; 139} 140 141//===----------------------------------------------------------------------===// 142// Custom Diagnostic information 143//===----------------------------------------------------------------------===// 144 145namespace clang { 146 namespace diag { 147 class CustomDiagInfo { 148 typedef std::pair<Diagnostic::Level, std::string> DiagDesc; 149 std::vector<DiagDesc> DiagInfo; 150 std::map<DiagDesc, unsigned> DiagIDs; 151 public: 152 153 /// getDescription - Return the description of the specified custom 154 /// diagnostic. 155 const char *getDescription(unsigned DiagID) const { 156 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() && 157 "Invalid diagnosic ID"); 158 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second.c_str(); 159 } 160 161 /// getLevel - Return the level of the specified custom diagnostic. 162 Diagnostic::Level getLevel(unsigned DiagID) const { 163 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() && 164 "Invalid diagnosic ID"); 165 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first; 166 } 167 168 unsigned getOrCreateDiagID(Diagnostic::Level L, llvm::StringRef Message, 169 Diagnostic &Diags) { 170 DiagDesc D(L, Message); 171 // Check to see if it already exists. 172 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D); 173 if (I != DiagIDs.end() && I->first == D) 174 return I->second; 175 176 // If not, assign a new ID. 177 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT; 178 DiagIDs.insert(std::make_pair(D, ID)); 179 DiagInfo.push_back(D); 180 return ID; 181 } 182 }; 183 184 } // end diag namespace 185} // end clang namespace 186 187 188//===----------------------------------------------------------------------===// 189// Common Diagnostic implementation 190//===----------------------------------------------------------------------===// 191 192static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT, 193 const char *Modifier, unsigned ML, 194 const char *Argument, unsigned ArgLen, 195 const Diagnostic::ArgumentValue *PrevArgs, 196 unsigned NumPrevArgs, 197 llvm::SmallVectorImpl<char> &Output, 198 void *Cookie) { 199 const char *Str = "<can't format argument>"; 200 Output.append(Str, Str+strlen(Str)); 201} 202 203 204Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) { 205 AllExtensionsSilenced = 0; 206 IgnoreAllWarnings = false; 207 WarningsAsErrors = false; 208 ErrorsAsFatal = false; 209 SuppressSystemWarnings = false; 210 SuppressAllDiagnostics = false; 211 ExtBehavior = Ext_Ignore; 212 213 ErrorOccurred = false; 214 FatalErrorOccurred = false; 215 NumDiagnostics = 0; 216 217 NumErrors = 0; 218 CustomDiagInfo = 0; 219 CurDiagID = ~0U; 220 LastDiagLevel = Ignored; 221 222 ArgToStringFn = DummyArgToStringFn; 223 ArgToStringCookie = 0; 224 225 DelayedDiagID = 0; 226 227 // Set all mappings to 'unset'. 228 DiagMappings BlankDiags(diag::DIAG_UPPER_LIMIT/2, 0); 229 DiagMappingsStack.push_back(BlankDiags); 230} 231 232Diagnostic::~Diagnostic() { 233 delete CustomDiagInfo; 234} 235 236 237void Diagnostic::pushMappings() { 238 // Avoids undefined behavior when the stack has to resize. 239 DiagMappingsStack.reserve(DiagMappingsStack.size() + 1); 240 DiagMappingsStack.push_back(DiagMappingsStack.back()); 241} 242 243bool Diagnostic::popMappings() { 244 if (DiagMappingsStack.size() == 1) 245 return false; 246 247 DiagMappingsStack.pop_back(); 248 return true; 249} 250 251/// getCustomDiagID - Return an ID for a diagnostic with the specified message 252/// and level. If this is the first request for this diagnosic, it is 253/// registered and created, otherwise the existing ID is returned. 254unsigned Diagnostic::getCustomDiagID(Level L, llvm::StringRef Message) { 255 if (CustomDiagInfo == 0) 256 CustomDiagInfo = new diag::CustomDiagInfo(); 257 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this); 258} 259 260 261/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic 262/// level of the specified diagnostic ID is a Warning or Extension. 263/// This only works on builtin diagnostics, not custom ones, and is not legal to 264/// call on NOTEs. 265bool Diagnostic::isBuiltinWarningOrExtension(unsigned DiagID) { 266 return DiagID < diag::DIAG_UPPER_LIMIT && 267 getBuiltinDiagClass(DiagID) != CLASS_ERROR; 268} 269 270/// \brief Determine whether the given built-in diagnostic ID is a 271/// Note. 272bool Diagnostic::isBuiltinNote(unsigned DiagID) { 273 return DiagID < diag::DIAG_UPPER_LIMIT && 274 getBuiltinDiagClass(DiagID) == CLASS_NOTE; 275} 276 277/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic 278/// ID is for an extension of some sort. 279/// 280bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) { 281 return DiagID < diag::DIAG_UPPER_LIMIT && 282 getBuiltinDiagClass(DiagID) == CLASS_EXTENSION; 283} 284 285 286/// getDescription - Given a diagnostic ID, return a description of the 287/// issue. 288const char *Diagnostic::getDescription(unsigned DiagID) const { 289 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) 290 return Info->Description; 291 return CustomDiagInfo->getDescription(DiagID); 292} 293 294void Diagnostic::SetDelayedDiagnostic(unsigned DiagID, llvm::StringRef Arg1, 295 llvm::StringRef Arg2) { 296 if (DelayedDiagID) 297 return; 298 299 DelayedDiagID = DiagID; 300 DelayedDiagArg1 = Arg1; 301 DelayedDiagArg1 = Arg2; 302} 303 304void Diagnostic::ReportDelayed() { 305 Report(DelayedDiagID) << DelayedDiagArg1 << DelayedDiagArg2; 306 DelayedDiagID = 0; 307 DelayedDiagArg1.clear(); 308 DelayedDiagArg2.clear(); 309} 310 311/// getDiagnosticLevel - Based on the way the client configured the Diagnostic 312/// object, classify the specified diagnostic ID into a Level, consumable by 313/// the DiagnosticClient. 314Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { 315 // Handle custom diagnostics, which cannot be mapped. 316 if (DiagID >= diag::DIAG_UPPER_LIMIT) 317 return CustomDiagInfo->getLevel(DiagID); 318 319 unsigned DiagClass = getBuiltinDiagClass(DiagID); 320 assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!"); 321 return getDiagnosticLevel(DiagID, DiagClass); 322} 323 324/// getDiagnosticLevel - Based on the way the client configured the Diagnostic 325/// object, classify the specified diagnostic ID into a Level, consumable by 326/// the DiagnosticClient. 327Diagnostic::Level 328Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const { 329 // Specific non-error diagnostics may be mapped to various levels from ignored 330 // to error. Errors can only be mapped to fatal. 331 Diagnostic::Level Result = Diagnostic::Fatal; 332 333 // Get the mapping information, if unset, compute it lazily. 334 unsigned MappingInfo = getDiagnosticMappingInfo((diag::kind)DiagID); 335 if (MappingInfo == 0) { 336 MappingInfo = GetDefaultDiagMapping(DiagID); 337 setDiagnosticMappingInternal(DiagID, MappingInfo, false); 338 } 339 340 switch (MappingInfo & 7) { 341 default: assert(0 && "Unknown mapping!"); 342 case diag::MAP_IGNORE: 343 // Ignore this, unless this is an extension diagnostic and we're mapping 344 // them onto warnings or errors. 345 if (!isBuiltinExtensionDiag(DiagID) || // Not an extension 346 ExtBehavior == Ext_Ignore || // Extensions ignored anyway 347 (MappingInfo & 8) != 0) // User explicitly mapped it. 348 return Diagnostic::Ignored; 349 Result = Diagnostic::Warning; 350 if (ExtBehavior == Ext_Error) Result = Diagnostic::Error; 351 if (Result == Diagnostic::Error && ErrorsAsFatal) 352 Result = Diagnostic::Fatal; 353 break; 354 case diag::MAP_ERROR: 355 Result = Diagnostic::Error; 356 if (ErrorsAsFatal) 357 Result = Diagnostic::Fatal; 358 break; 359 case diag::MAP_FATAL: 360 Result = Diagnostic::Fatal; 361 break; 362 case diag::MAP_WARNING: 363 // If warnings are globally mapped to ignore or error, do it. 364 if (IgnoreAllWarnings) 365 return Diagnostic::Ignored; 366 367 Result = Diagnostic::Warning; 368 369 // If this is an extension diagnostic and we're in -pedantic-error mode, and 370 // if the user didn't explicitly map it, upgrade to an error. 371 if (ExtBehavior == Ext_Error && 372 (MappingInfo & 8) == 0 && 373 isBuiltinExtensionDiag(DiagID)) 374 Result = Diagnostic::Error; 375 376 if (WarningsAsErrors) 377 Result = Diagnostic::Error; 378 if (Result == Diagnostic::Error && ErrorsAsFatal) 379 Result = Diagnostic::Fatal; 380 break; 381 382 case diag::MAP_WARNING_NO_WERROR: 383 // Diagnostics specified with -Wno-error=foo should be set to warnings, but 384 // not be adjusted by -Werror or -pedantic-errors. 385 Result = Diagnostic::Warning; 386 387 // If warnings are globally mapped to ignore or error, do it. 388 if (IgnoreAllWarnings) 389 return Diagnostic::Ignored; 390 391 break; 392 393 case diag::MAP_ERROR_NO_WFATAL: 394 // Diagnostics specified as -Wno-fatal-error=foo should be errors, but 395 // unaffected by -Wfatal-errors. 396 Result = Diagnostic::Error; 397 break; 398 } 399 400 // Okay, we're about to return this as a "diagnostic to emit" one last check: 401 // if this is any sort of extension warning, and if we're in an __extension__ 402 // block, silence it. 403 if (AllExtensionsSilenced && isBuiltinExtensionDiag(DiagID)) 404 return Diagnostic::Ignored; 405 406 return Result; 407} 408 409struct WarningOption { 410 const char *Name; 411 const short *Members; 412 const char *SubGroups; 413}; 414 415#define GET_DIAG_ARRAYS 416#include "clang/Basic/DiagnosticGroups.inc" 417#undef GET_DIAG_ARRAYS 418 419// Second the table of options, sorted by name for fast binary lookup. 420static const WarningOption OptionTable[] = { 421#define GET_DIAG_TABLE 422#include "clang/Basic/DiagnosticGroups.inc" 423#undef GET_DIAG_TABLE 424}; 425static const size_t OptionTableSize = 426sizeof(OptionTable) / sizeof(OptionTable[0]); 427 428static bool WarningOptionCompare(const WarningOption &LHS, 429 const WarningOption &RHS) { 430 return strcmp(LHS.Name, RHS.Name) < 0; 431} 432 433static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping, 434 Diagnostic &Diags) { 435 // Option exists, poke all the members of its diagnostic set. 436 if (const short *Member = Group->Members) { 437 for (; *Member != -1; ++Member) 438 Diags.setDiagnosticMapping(*Member, Mapping); 439 } 440 441 // Enable/disable all subgroups along with this one. 442 if (const char *SubGroups = Group->SubGroups) { 443 for (; *SubGroups != (char)-1; ++SubGroups) 444 MapGroupMembers(&OptionTable[(unsigned char)*SubGroups], Mapping, Diags); 445 } 446} 447 448/// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g. 449/// "unknown-pragmas" to have the specified mapping. This returns true and 450/// ignores the request if "Group" was unknown, false otherwise. 451bool Diagnostic::setDiagnosticGroupMapping(const char *Group, 452 diag::Mapping Map) { 453 454 WarningOption Key = { Group, 0, 0 }; 455 const WarningOption *Found = 456 std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key, 457 WarningOptionCompare); 458 if (Found == OptionTable + OptionTableSize || 459 strcmp(Found->Name, Group) != 0) 460 return true; // Option not found. 461 462 MapGroupMembers(Found, Map, *this); 463 return false; 464} 465 466 467/// ProcessDiag - This is the method used to report a diagnostic that is 468/// finally fully formed. 469bool Diagnostic::ProcessDiag() { 470 DiagnosticInfo Info(this); 471 472 if (SuppressAllDiagnostics) 473 return false; 474 475 // Figure out the diagnostic level of this message. 476 Diagnostic::Level DiagLevel; 477 unsigned DiagID = Info.getID(); 478 479 // ShouldEmitInSystemHeader - True if this diagnostic should be produced even 480 // in a system header. 481 bool ShouldEmitInSystemHeader; 482 483 if (DiagID >= diag::DIAG_UPPER_LIMIT) { 484 // Handle custom diagnostics, which cannot be mapped. 485 DiagLevel = CustomDiagInfo->getLevel(DiagID); 486 487 // Custom diagnostics always are emitted in system headers. 488 ShouldEmitInSystemHeader = true; 489 } else { 490 // Get the class of the diagnostic. If this is a NOTE, map it onto whatever 491 // the diagnostic level was for the previous diagnostic so that it is 492 // filtered the same as the previous diagnostic. 493 unsigned DiagClass = getBuiltinDiagClass(DiagID); 494 if (DiagClass == CLASS_NOTE) { 495 DiagLevel = Diagnostic::Note; 496 ShouldEmitInSystemHeader = false; // extra consideration is needed 497 } else { 498 // If this is not an error and we are in a system header, we ignore it. 499 // Check the original Diag ID here, because we also want to ignore 500 // extensions and warnings in -Werror and -pedantic-errors modes, which 501 // *map* warnings/extensions to errors. 502 ShouldEmitInSystemHeader = DiagClass == CLASS_ERROR; 503 504 DiagLevel = getDiagnosticLevel(DiagID, DiagClass); 505 } 506 } 507 508 if (DiagLevel != Diagnostic::Note) { 509 // Record that a fatal error occurred only when we see a second 510 // non-note diagnostic. This allows notes to be attached to the 511 // fatal error, but suppresses any diagnostics that follow those 512 // notes. 513 if (LastDiagLevel == Diagnostic::Fatal) 514 FatalErrorOccurred = true; 515 516 LastDiagLevel = DiagLevel; 517 } 518 519 // If a fatal error has already been emitted, silence all subsequent 520 // diagnostics. 521 if (FatalErrorOccurred) 522 return false; 523 524 // If the client doesn't care about this message, don't issue it. If this is 525 // a note and the last real diagnostic was ignored, ignore it too. 526 if (DiagLevel == Diagnostic::Ignored || 527 (DiagLevel == Diagnostic::Note && LastDiagLevel == Diagnostic::Ignored)) 528 return false; 529 530 // If this diagnostic is in a system header and is not a clang error, suppress 531 // it. 532 if (SuppressSystemWarnings && !ShouldEmitInSystemHeader && 533 Info.getLocation().isValid() && 534 Info.getLocation().getInstantiationLoc().isInSystemHeader() && 535 (DiagLevel != Diagnostic::Note || LastDiagLevel == Diagnostic::Ignored)) { 536 LastDiagLevel = Diagnostic::Ignored; 537 return false; 538 } 539 540 if (DiagLevel >= Diagnostic::Error) { 541 ErrorOccurred = true; 542 ++NumErrors; 543 } 544 545 // Finally, report it. 546 Client->HandleDiagnostic(DiagLevel, Info); 547 if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics; 548 549 CurDiagID = ~0U; 550 551 return true; 552} 553 554bool DiagnosticBuilder::Emit() { 555 // If DiagObj is null, then its soul was stolen by the copy ctor 556 // or the user called Emit(). 557 if (DiagObj == 0) return false; 558 559 // When emitting diagnostics, we set the final argument count into 560 // the Diagnostic object. 561 DiagObj->NumDiagArgs = NumArgs; 562 DiagObj->NumDiagRanges = NumRanges; 563 DiagObj->NumCodeModificationHints = NumCodeModificationHints; 564 565 // Process the diagnostic, sending the accumulated information to the 566 // DiagnosticClient. 567 bool Emitted = DiagObj->ProcessDiag(); 568 569 // Clear out the current diagnostic object. 570 DiagObj->Clear(); 571 572 // If there was a delayed diagnostic, emit it now. 573 if (DiagObj->DelayedDiagID) 574 DiagObj->ReportDelayed(); 575 576 // This diagnostic is dead. 577 DiagObj = 0; 578 579 return Emitted; 580} 581 582 583DiagnosticClient::~DiagnosticClient() {} 584 585 586/// ModifierIs - Return true if the specified modifier matches specified string. 587template <std::size_t StrLen> 588static bool ModifierIs(const char *Modifier, unsigned ModifierLen, 589 const char (&Str)[StrLen]) { 590 return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1); 591} 592 593/// ScanForward - Scans forward, looking for the given character, skipping 594/// nested clauses and escaped characters. 595static const char *ScanFormat(const char *I, const char *E, char Target) { 596 unsigned Depth = 0; 597 598 for ( ; I != E; ++I) { 599 if (Depth == 0 && *I == Target) return I; 600 if (Depth != 0 && *I == '}') Depth--; 601 602 if (*I == '%') { 603 I++; 604 if (I == E) break; 605 606 // Escaped characters get implicitly skipped here. 607 608 // Format specifier. 609 if (!isdigit(*I) && !ispunct(*I)) { 610 for (I++; I != E && !isdigit(*I) && *I != '{'; I++) ; 611 if (I == E) break; 612 if (*I == '{') 613 Depth++; 614 } 615 } 616 } 617 return E; 618} 619 620/// HandleSelectModifier - Handle the integer 'select' modifier. This is used 621/// like this: %select{foo|bar|baz}2. This means that the integer argument 622/// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'. 623/// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'. 624/// This is very useful for certain classes of variant diagnostics. 625static void HandleSelectModifier(const DiagnosticInfo &DInfo, unsigned ValNo, 626 const char *Argument, unsigned ArgumentLen, 627 llvm::SmallVectorImpl<char> &OutStr) { 628 const char *ArgumentEnd = Argument+ArgumentLen; 629 630 // Skip over 'ValNo' |'s. 631 while (ValNo) { 632 const char *NextVal = ScanFormat(Argument, ArgumentEnd, '|'); 633 assert(NextVal != ArgumentEnd && "Value for integer select modifier was" 634 " larger than the number of options in the diagnostic string!"); 635 Argument = NextVal+1; // Skip this string. 636 --ValNo; 637 } 638 639 // Get the end of the value. This is either the } or the |. 640 const char *EndPtr = ScanFormat(Argument, ArgumentEnd, '|'); 641 642 // Recursively format the result of the select clause into the output string. 643 DInfo.FormatDiagnostic(Argument, EndPtr, OutStr); 644} 645 646/// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the 647/// letter 's' to the string if the value is not 1. This is used in cases like 648/// this: "you idiot, you have %4 parameter%s4!". 649static void HandleIntegerSModifier(unsigned ValNo, 650 llvm::SmallVectorImpl<char> &OutStr) { 651 if (ValNo != 1) 652 OutStr.push_back('s'); 653} 654 655/// HandleOrdinalModifier - Handle the integer 'ord' modifier. This 656/// prints the ordinal form of the given integer, with 1 corresponding 657/// to the first ordinal. Currently this is hard-coded to use the 658/// English form. 659static void HandleOrdinalModifier(unsigned ValNo, 660 llvm::SmallVectorImpl<char> &OutStr) { 661 assert(ValNo != 0 && "ValNo must be strictly positive!"); 662 663 llvm::raw_svector_ostream Out(OutStr); 664 665 // We could use text forms for the first N ordinals, but the numeric 666 // forms are actually nicer in diagnostics because they stand out. 667 Out << ValNo; 668 669 // It is critically important that we do this perfectly for 670 // user-written sequences with over 100 elements. 671 switch (ValNo % 100) { 672 case 11: 673 case 12: 674 case 13: 675 Out << "th"; return; 676 default: 677 switch (ValNo % 10) { 678 case 1: Out << "st"; return; 679 case 2: Out << "nd"; return; 680 case 3: Out << "rd"; return; 681 default: Out << "th"; return; 682 } 683 } 684} 685 686 687/// PluralNumber - Parse an unsigned integer and advance Start. 688static unsigned PluralNumber(const char *&Start, const char *End) { 689 // Programming 101: Parse a decimal number :-) 690 unsigned Val = 0; 691 while (Start != End && *Start >= '0' && *Start <= '9') { 692 Val *= 10; 693 Val += *Start - '0'; 694 ++Start; 695 } 696 return Val; 697} 698 699/// TestPluralRange - Test if Val is in the parsed range. Modifies Start. 700static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) { 701 if (*Start != '[') { 702 unsigned Ref = PluralNumber(Start, End); 703 return Ref == Val; 704 } 705 706 ++Start; 707 unsigned Low = PluralNumber(Start, End); 708 assert(*Start == ',' && "Bad plural expression syntax: expected ,"); 709 ++Start; 710 unsigned High = PluralNumber(Start, End); 711 assert(*Start == ']' && "Bad plural expression syntax: expected )"); 712 ++Start; 713 return Low <= Val && Val <= High; 714} 715 716/// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier. 717static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) { 718 // Empty condition? 719 if (*Start == ':') 720 return true; 721 722 while (1) { 723 char C = *Start; 724 if (C == '%') { 725 // Modulo expression 726 ++Start; 727 unsigned Arg = PluralNumber(Start, End); 728 assert(*Start == '=' && "Bad plural expression syntax: expected ="); 729 ++Start; 730 unsigned ValMod = ValNo % Arg; 731 if (TestPluralRange(ValMod, Start, End)) 732 return true; 733 } else { 734 assert((C == '[' || (C >= '0' && C <= '9')) && 735 "Bad plural expression syntax: unexpected character"); 736 // Range expression 737 if (TestPluralRange(ValNo, Start, End)) 738 return true; 739 } 740 741 // Scan for next or-expr part. 742 Start = std::find(Start, End, ','); 743 if (Start == End) 744 break; 745 ++Start; 746 } 747 return false; 748} 749 750/// HandlePluralModifier - Handle the integer 'plural' modifier. This is used 751/// for complex plural forms, or in languages where all plurals are complex. 752/// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are 753/// conditions that are tested in order, the form corresponding to the first 754/// that applies being emitted. The empty condition is always true, making the 755/// last form a default case. 756/// Conditions are simple boolean expressions, where n is the number argument. 757/// Here are the rules. 758/// condition := expression | empty 759/// empty := -> always true 760/// expression := numeric [',' expression] -> logical or 761/// numeric := range -> true if n in range 762/// | '%' number '=' range -> true if n % number in range 763/// range := number 764/// | '[' number ',' number ']' -> ranges are inclusive both ends 765/// 766/// Here are some examples from the GNU gettext manual written in this form: 767/// English: 768/// {1:form0|:form1} 769/// Latvian: 770/// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0} 771/// Gaeilge: 772/// {1:form0|2:form1|:form2} 773/// Romanian: 774/// {1:form0|0,%100=[1,19]:form1|:form2} 775/// Lithuanian: 776/// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1} 777/// Russian (requires repeated form): 778/// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2} 779/// Slovak 780/// {1:form0|[2,4]:form1|:form2} 781/// Polish (requires repeated form): 782/// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2} 783static void HandlePluralModifier(unsigned ValNo, 784 const char *Argument, unsigned ArgumentLen, 785 llvm::SmallVectorImpl<char> &OutStr) { 786 const char *ArgumentEnd = Argument + ArgumentLen; 787 while (1) { 788 assert(Argument < ArgumentEnd && "Plural expression didn't match."); 789 const char *ExprEnd = Argument; 790 while (*ExprEnd != ':') { 791 assert(ExprEnd != ArgumentEnd && "Plural missing expression end"); 792 ++ExprEnd; 793 } 794 if (EvalPluralExpr(ValNo, Argument, ExprEnd)) { 795 Argument = ExprEnd + 1; 796 ExprEnd = ScanFormat(Argument, ArgumentEnd, '|'); 797 OutStr.append(Argument, ExprEnd); 798 return; 799 } 800 Argument = ScanFormat(Argument, ArgumentEnd - 1, '|') + 1; 801 } 802} 803 804 805/// FormatDiagnostic - Format this diagnostic into a string, substituting the 806/// formal arguments into the %0 slots. The result is appended onto the Str 807/// array. 808void DiagnosticInfo:: 809FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const { 810 const char *DiagStr = getDiags()->getDescription(getID()); 811 const char *DiagEnd = DiagStr+strlen(DiagStr); 812 813 FormatDiagnostic(DiagStr, DiagEnd, OutStr); 814} 815 816void DiagnosticInfo:: 817FormatDiagnostic(const char *DiagStr, const char *DiagEnd, 818 llvm::SmallVectorImpl<char> &OutStr) const { 819 820 /// FormattedArgs - Keep track of all of the arguments formatted by 821 /// ConvertArgToString and pass them into subsequent calls to 822 /// ConvertArgToString, allowing the implementation to avoid redundancies in 823 /// obvious cases. 824 llvm::SmallVector<Diagnostic::ArgumentValue, 8> FormattedArgs; 825 826 while (DiagStr != DiagEnd) { 827 if (DiagStr[0] != '%') { 828 // Append non-%0 substrings to Str if we have one. 829 const char *StrEnd = std::find(DiagStr, DiagEnd, '%'); 830 OutStr.append(DiagStr, StrEnd); 831 DiagStr = StrEnd; 832 continue; 833 } else if (ispunct(DiagStr[1])) { 834 OutStr.push_back(DiagStr[1]); // %% -> %. 835 DiagStr += 2; 836 continue; 837 } 838 839 // Skip the %. 840 ++DiagStr; 841 842 // This must be a placeholder for a diagnostic argument. The format for a 843 // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0". 844 // The digit is a number from 0-9 indicating which argument this comes from. 845 // The modifier is a string of digits from the set [-a-z]+, arguments is a 846 // brace enclosed string. 847 const char *Modifier = 0, *Argument = 0; 848 unsigned ModifierLen = 0, ArgumentLen = 0; 849 850 // Check to see if we have a modifier. If so eat it. 851 if (!isdigit(DiagStr[0])) { 852 Modifier = DiagStr; 853 while (DiagStr[0] == '-' || 854 (DiagStr[0] >= 'a' && DiagStr[0] <= 'z')) 855 ++DiagStr; 856 ModifierLen = DiagStr-Modifier; 857 858 // If we have an argument, get it next. 859 if (DiagStr[0] == '{') { 860 ++DiagStr; // Skip {. 861 Argument = DiagStr; 862 863 DiagStr = ScanFormat(DiagStr, DiagEnd, '}'); 864 assert(DiagStr != DiagEnd && "Mismatched {}'s in diagnostic string!"); 865 ArgumentLen = DiagStr-Argument; 866 ++DiagStr; // Skip }. 867 } 868 } 869 870 assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic"); 871 unsigned ArgNo = *DiagStr++ - '0'; 872 873 Diagnostic::ArgumentKind Kind = getArgKind(ArgNo); 874 875 switch (Kind) { 876 // ---- STRINGS ---- 877 case Diagnostic::ak_std_string: { 878 const std::string &S = getArgStdStr(ArgNo); 879 assert(ModifierLen == 0 && "No modifiers for strings yet"); 880 OutStr.append(S.begin(), S.end()); 881 break; 882 } 883 case Diagnostic::ak_c_string: { 884 const char *S = getArgCStr(ArgNo); 885 assert(ModifierLen == 0 && "No modifiers for strings yet"); 886 887 // Don't crash if get passed a null pointer by accident. 888 if (!S) 889 S = "(null)"; 890 891 OutStr.append(S, S + strlen(S)); 892 break; 893 } 894 // ---- INTEGERS ---- 895 case Diagnostic::ak_sint: { 896 int Val = getArgSInt(ArgNo); 897 898 if (ModifierIs(Modifier, ModifierLen, "select")) { 899 HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen, OutStr); 900 } else if (ModifierIs(Modifier, ModifierLen, "s")) { 901 HandleIntegerSModifier(Val, OutStr); 902 } else if (ModifierIs(Modifier, ModifierLen, "plural")) { 903 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr); 904 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) { 905 HandleOrdinalModifier((unsigned)Val, OutStr); 906 } else { 907 assert(ModifierLen == 0 && "Unknown integer modifier"); 908 llvm::raw_svector_ostream(OutStr) << Val; 909 } 910 break; 911 } 912 case Diagnostic::ak_uint: { 913 unsigned Val = getArgUInt(ArgNo); 914 915 if (ModifierIs(Modifier, ModifierLen, "select")) { 916 HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr); 917 } else if (ModifierIs(Modifier, ModifierLen, "s")) { 918 HandleIntegerSModifier(Val, OutStr); 919 } else if (ModifierIs(Modifier, ModifierLen, "plural")) { 920 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr); 921 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) { 922 HandleOrdinalModifier(Val, OutStr); 923 } else { 924 assert(ModifierLen == 0 && "Unknown integer modifier"); 925 llvm::raw_svector_ostream(OutStr) << Val; 926 } 927 break; 928 } 929 // ---- NAMES and TYPES ---- 930 case Diagnostic::ak_identifierinfo: { 931 const IdentifierInfo *II = getArgIdentifier(ArgNo); 932 assert(ModifierLen == 0 && "No modifiers for strings yet"); 933 934 // Don't crash if get passed a null pointer by accident. 935 if (!II) { 936 const char *S = "(null)"; 937 OutStr.append(S, S + strlen(S)); 938 continue; 939 } 940 941 llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\''; 942 break; 943 } 944 case Diagnostic::ak_qualtype: 945 case Diagnostic::ak_declarationname: 946 case Diagnostic::ak_nameddecl: 947 case Diagnostic::ak_nestednamespec: 948 case Diagnostic::ak_declcontext: 949 getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo), 950 Modifier, ModifierLen, 951 Argument, ArgumentLen, 952 FormattedArgs.data(), FormattedArgs.size(), 953 OutStr); 954 break; 955 } 956 957 // Remember this argument info for subsequent formatting operations. Turn 958 // std::strings into a null terminated string to make it be the same case as 959 // all the other ones. 960 if (Kind != Diagnostic::ak_std_string) 961 FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo))); 962 else 963 FormattedArgs.push_back(std::make_pair(Diagnostic::ak_c_string, 964 (intptr_t)getArgStdStr(ArgNo).c_str())); 965 966 } 967} 968 969StoredDiagnostic::StoredDiagnostic() { } 970 971StoredDiagnostic::StoredDiagnostic(Diagnostic::Level Level, 972 llvm::StringRef Message) 973 : Level(Level), Loc(), Message(Message) { } 974 975StoredDiagnostic::StoredDiagnostic(Diagnostic::Level Level, 976 const DiagnosticInfo &Info) 977 : Level(Level), Loc(Info.getLocation()) 978{ 979 llvm::SmallString<64> Message; 980 Info.FormatDiagnostic(Message); 981 this->Message.assign(Message.begin(), Message.end()); 982 983 Ranges.reserve(Info.getNumRanges()); 984 for (unsigned I = 0, N = Info.getNumRanges(); I != N; ++I) 985 Ranges.push_back(Info.getRange(I)); 986 987 FixIts.reserve(Info.getNumCodeModificationHints()); 988 for (unsigned I = 0, N = Info.getNumCodeModificationHints(); I != N; ++I) 989 FixIts.push_back(Info.getCodeModificationHint(I)); 990} 991 992StoredDiagnostic::~StoredDiagnostic() { } 993 994static void WriteUnsigned(llvm::raw_ostream &OS, unsigned Value) { 995 OS.write((const char *)&Value, sizeof(unsigned)); 996} 997 998static void WriteString(llvm::raw_ostream &OS, llvm::StringRef String) { 999 WriteUnsigned(OS, String.size()); 1000 OS.write(String.data(), String.size()); 1001} 1002 1003static void WriteSourceLocation(llvm::raw_ostream &OS, 1004 SourceManager *SM, 1005 SourceLocation Location) { 1006 if (!SM || Location.isInvalid()) { 1007 // If we don't have a source manager or this location is invalid, 1008 // just write an invalid location. 1009 WriteUnsigned(OS, 0); 1010 WriteUnsigned(OS, 0); 1011 WriteUnsigned(OS, 0); 1012 return; 1013 } 1014 1015 Location = SM->getInstantiationLoc(Location); 1016 std::pair<FileID, unsigned> Decomposed = SM->getDecomposedLoc(Location); 1017 1018 WriteString(OS, SM->getFileEntryForID(Decomposed.first)->getName()); 1019 WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second)); 1020 WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second)); 1021} 1022 1023void StoredDiagnostic::Serialize(llvm::raw_ostream &OS) const { 1024 SourceManager *SM = 0; 1025 if (getLocation().isValid()) 1026 SM = &const_cast<SourceManager &>(getLocation().getManager()); 1027 1028 // Write a short header to help identify diagnostics. 1029 OS << (char)0x06 << (char)0x07; 1030 1031 // Write the diagnostic level and location. 1032 WriteUnsigned(OS, (unsigned)Level); 1033 WriteSourceLocation(OS, SM, getLocation()); 1034 1035 // Write the diagnostic message. 1036 llvm::SmallString<64> Message; 1037 WriteString(OS, getMessage()); 1038 1039 // Count the number of ranges that don't point into macros, since 1040 // only simple file ranges serialize well. 1041 unsigned NumNonMacroRanges = 0; 1042 for (range_iterator R = range_begin(), REnd = range_end(); R != REnd; ++R) { 1043 if (R->getBegin().isMacroID() || R->getEnd().isMacroID()) 1044 continue; 1045 1046 ++NumNonMacroRanges; 1047 } 1048 1049 // Write the ranges. 1050 WriteUnsigned(OS, NumNonMacroRanges); 1051 if (NumNonMacroRanges) { 1052 for (range_iterator R = range_begin(), REnd = range_end(); R != REnd; ++R) { 1053 if (R->getBegin().isMacroID() || R->getEnd().isMacroID()) 1054 continue; 1055 1056 WriteSourceLocation(OS, SM, R->getBegin()); 1057 WriteSourceLocation(OS, SM, R->getEnd()); 1058 } 1059 } 1060 1061 // Determine if all of the fix-its involve rewrites with simple file 1062 // locations (not in macro instantiations). If so, we can write 1063 // fix-it information. 1064 unsigned NumFixIts = 0; 1065 for (fixit_iterator F = fixit_begin(), FEnd = fixit_end(); F != FEnd; ++F) { 1066 if (F->RemoveRange.isValid() && 1067 (F->RemoveRange.getBegin().isMacroID() || 1068 F->RemoveRange.getEnd().isMacroID())) { 1069 NumFixIts = 0; 1070 break; 1071 } 1072 1073 if (F->InsertionLoc.isValid() && F->InsertionLoc.isMacroID()) { 1074 NumFixIts = 0; 1075 break; 1076 } 1077 1078 ++NumFixIts; 1079 } 1080 1081 // Write the fix-its. 1082 WriteUnsigned(OS, NumFixIts); 1083 for (fixit_iterator F = fixit_begin(), FEnd = fixit_end(); F != FEnd; ++F) { 1084 WriteSourceLocation(OS, SM, F->RemoveRange.getBegin()); 1085 WriteSourceLocation(OS, SM, F->RemoveRange.getEnd()); 1086 WriteSourceLocation(OS, SM, F->InsertionLoc); 1087 WriteString(OS, F->CodeToInsert); 1088 } 1089} 1090 1091static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd, 1092 unsigned &Value) { 1093 if (Memory + sizeof(unsigned) > MemoryEnd) 1094 return true; 1095 1096 memmove(&Value, Memory, sizeof(unsigned)); 1097 Memory += sizeof(unsigned); 1098 return false; 1099} 1100 1101static bool ReadSourceLocation(FileManager &FM, SourceManager &SM, 1102 const char *&Memory, const char *MemoryEnd, 1103 SourceLocation &Location) { 1104 // Read the filename. 1105 unsigned FileNameLen = 0; 1106 if (ReadUnsigned(Memory, MemoryEnd, FileNameLen) || 1107 Memory + FileNameLen > MemoryEnd) 1108 return true; 1109 1110 llvm::StringRef FileName(Memory, FileNameLen); 1111 Memory += FileNameLen; 1112 1113 // Read the line, column. 1114 unsigned Line = 0, Column = 0; 1115 if (ReadUnsigned(Memory, MemoryEnd, Line) || 1116 ReadUnsigned(Memory, MemoryEnd, Column)) 1117 return true; 1118 1119 if (FileName.empty()) { 1120 Location = SourceLocation(); 1121 return false; 1122 } 1123 1124 const FileEntry *File = FM.getFile(FileName); 1125 if (!File) 1126 return true; 1127 1128 // Make sure that this file has an entry in the source manager. 1129 if (!SM.hasFileInfo(File)) 1130 SM.createFileID(File, SourceLocation(), SrcMgr::C_User); 1131 1132 Location = SM.getLocation(File, Line, Column); 1133 return false; 1134} 1135 1136StoredDiagnostic 1137StoredDiagnostic::Deserialize(FileManager &FM, SourceManager &SM, 1138 const char *&Memory, const char *MemoryEnd) { 1139 while (true) { 1140 if (Memory == MemoryEnd) 1141 return StoredDiagnostic(); 1142 1143 if (*Memory != 0x06) { 1144 ++Memory; 1145 continue; 1146 } 1147 1148 ++Memory; 1149 if (Memory == MemoryEnd) 1150 return StoredDiagnostic(); 1151 1152 if (*Memory != 0x07) { 1153 ++Memory; 1154 continue; 1155 } 1156 1157 // We found the header. We're done. 1158 ++Memory; 1159 break; 1160 } 1161 1162 // Read the severity level. 1163 unsigned Level = 0; 1164 if (ReadUnsigned(Memory, MemoryEnd, Level) || Level > Diagnostic::Fatal) 1165 return StoredDiagnostic(); 1166 1167 // Read the source location. 1168 SourceLocation Location; 1169 if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Location)) 1170 return StoredDiagnostic(); 1171 1172 // Read the diagnostic text. 1173 if (Memory == MemoryEnd) 1174 return StoredDiagnostic(); 1175 1176 unsigned MessageLen = 0; 1177 if (ReadUnsigned(Memory, MemoryEnd, MessageLen) || 1178 Memory + MessageLen > MemoryEnd) 1179 return StoredDiagnostic(); 1180 1181 llvm::StringRef Message(Memory, MessageLen); 1182 Memory += MessageLen; 1183 1184 1185 // At this point, we have enough information to form a diagnostic. Do so. 1186 StoredDiagnostic Diag; 1187 Diag.Level = (Diagnostic::Level)Level; 1188 Diag.Loc = FullSourceLoc(Location, SM); 1189 Diag.Message = Message; 1190 if (Memory == MemoryEnd) 1191 return Diag; 1192 1193 // Read the source ranges. 1194 unsigned NumSourceRanges = 0; 1195 if (ReadUnsigned(Memory, MemoryEnd, NumSourceRanges)) 1196 return Diag; 1197 for (unsigned I = 0; I != NumSourceRanges; ++I) { 1198 SourceLocation Begin, End; 1199 if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Begin) || 1200 ReadSourceLocation(FM, SM, Memory, MemoryEnd, End)) 1201 return Diag; 1202 1203 Diag.Ranges.push_back(SourceRange(Begin, End)); 1204 } 1205 1206 // Read the fix-it hints. 1207 unsigned NumFixIts = 0; 1208 if (ReadUnsigned(Memory, MemoryEnd, NumFixIts)) 1209 return Diag; 1210 for (unsigned I = 0; I != NumFixIts; ++I) { 1211 SourceLocation RemoveBegin, RemoveEnd, InsertionLoc; 1212 unsigned InsertLen = 0; 1213 if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveBegin) || 1214 ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveEnd) || 1215 ReadSourceLocation(FM, SM, Memory, MemoryEnd, InsertionLoc) || 1216 ReadUnsigned(Memory, MemoryEnd, InsertLen) || 1217 Memory + InsertLen > MemoryEnd) { 1218 Diag.FixIts.clear(); 1219 return Diag; 1220 } 1221 1222 CodeModificationHint Hint; 1223 Hint.RemoveRange = SourceRange(RemoveBegin, RemoveEnd); 1224 Hint.InsertionLoc = InsertionLoc; 1225 Hint.CodeToInsert.assign(Memory, Memory + InsertLen); 1226 Memory += InsertLen; 1227 Diag.FixIts.push_back(Hint); 1228 } 1229 1230 return Diag; 1231} 1232 1233/// IncludeInDiagnosticCounts - This method (whose default implementation 1234/// returns true) indicates whether the diagnostics handled by this 1235/// DiagnosticClient should be included in the number of diagnostics 1236/// reported by Diagnostic. 1237bool DiagnosticClient::IncludeInDiagnosticCounts() const { return true; } 1238