Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Diagnostic-related interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 43b628c | 2008-11-19 07:32:16 +0000 | [diff] [blame] | 24 | #include "clang/Basic/IdentifierTable.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 25 | #include "clang/Basic/SourceLocation.h" |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | 30bc965 | 2008-11-19 07:22:31 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 23e47c6 | 2009-10-17 18:12:14 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 29 | #include <vector> |
| 30 | #include <map> |
Chris Lattner | 87cf5ac | 2008-03-10 17:04:53 +0000 | [diff] [blame] | 31 | #include <cstring> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Builtin Diagnostic information |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
Chris Lattner | 121f60c | 2009-04-16 06:07:15 +0000 | [diff] [blame] | 38 | // Diagnostic classes. |
| 39 | enum { |
| 40 | CLASS_NOTE = 0x01, |
| 41 | CLASS_WARNING = 0x02, |
| 42 | CLASS_EXTENSION = 0x03, |
| 43 | CLASS_ERROR = 0x04 |
| 44 | }; |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 45 | |
Chris Lattner | 33dd282 | 2009-04-16 06:00:24 +0000 | [diff] [blame] | 46 | struct StaticDiagInfoRec { |
Chris Lattner | 121f60c | 2009-04-16 06:07:15 +0000 | [diff] [blame] | 47 | unsigned short DiagID; |
| 48 | unsigned Mapping : 3; |
| 49 | unsigned Class : 3; |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 50 | bool SFINAE : 1; |
Chris Lattner | 121f60c | 2009-04-16 06:07:15 +0000 | [diff] [blame] | 51 | const char *Description; |
Chris Lattner | 33dd282 | 2009-04-16 06:00:24 +0000 | [diff] [blame] | 52 | const char *OptionGroup; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 54 | bool operator<(const StaticDiagInfoRec &RHS) const { |
| 55 | return DiagID < RHS.DiagID; |
| 56 | } |
| 57 | bool operator>(const StaticDiagInfoRec &RHS) const { |
| 58 | return DiagID > RHS.DiagID; |
| 59 | } |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Chris Lattner | 33dd282 | 2009-04-16 06:00:24 +0000 | [diff] [blame] | 62 | static const StaticDiagInfoRec StaticDiagInfo[] = { |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 63 | #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,SFINAE) \ |
| 64 | { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, DESC, GROUP }, |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 65 | #include "clang/Basic/DiagnosticCommonKinds.inc" |
| 66 | #include "clang/Basic/DiagnosticDriverKinds.inc" |
| 67 | #include "clang/Basic/DiagnosticFrontendKinds.inc" |
| 68 | #include "clang/Basic/DiagnosticLexKinds.inc" |
| 69 | #include "clang/Basic/DiagnosticParseKinds.inc" |
| 70 | #include "clang/Basic/DiagnosticASTKinds.inc" |
| 71 | #include "clang/Basic/DiagnosticSemaKinds.inc" |
| 72 | #include "clang/Basic/DiagnosticAnalysisKinds.inc" |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 73 | { 0, 0, 0, 0, 0, 0} |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 74 | }; |
Chris Lattner | 8a941e0 | 2009-04-15 16:56:26 +0000 | [diff] [blame] | 75 | #undef DIAG |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 76 | |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 77 | /// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID, |
| 78 | /// or null if the ID is invalid. |
Chris Lattner | 33dd282 | 2009-04-16 06:00:24 +0000 | [diff] [blame] | 79 | static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 80 | unsigned NumDiagEntries = sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1; |
| 81 | |
| 82 | // If assertions are enabled, verify that the StaticDiagInfo array is sorted. |
| 83 | #ifndef NDEBUG |
| 84 | static bool IsFirst = true; |
| 85 | if (IsFirst) { |
Chris Lattner | 5a3ce9b | 2009-10-16 02:34:51 +0000 | [diff] [blame] | 86 | for (unsigned i = 1; i != NumDiagEntries; ++i) { |
| 87 | assert(StaticDiagInfo[i-1].DiagID != StaticDiagInfo[i].DiagID && |
| 88 | "Diag ID conflict, the enums at the start of clang::diag (in " |
| 89 | "Diagnostic.h) probably need to be increased"); |
| 90 | |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 91 | assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] && |
| 92 | "Improperly sorted diag info"); |
Chris Lattner | 5a3ce9b | 2009-10-16 02:34:51 +0000 | [diff] [blame] | 93 | } |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 94 | IsFirst = false; |
| 95 | } |
| 96 | #endif |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 98 | // Search the diagnostic table with a binary search. |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 99 | StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0, 0 }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 101 | const StaticDiagInfoRec *Found = |
| 102 | std::lower_bound(StaticDiagInfo, StaticDiagInfo + NumDiagEntries, Find); |
| 103 | if (Found == StaticDiagInfo + NumDiagEntries || |
| 104 | Found->DiagID != DiagID) |
| 105 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | |
Chris Lattner | 87d854e | 2009-04-16 06:13:46 +0000 | [diff] [blame] | 107 | return Found; |
Chris Lattner | 33dd282 | 2009-04-16 06:00:24 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static unsigned GetDefaultDiagMapping(unsigned DiagID) { |
| 111 | if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) |
Chris Lattner | 121f60c | 2009-04-16 06:07:15 +0000 | [diff] [blame] | 112 | return Info->Mapping; |
Chris Lattner | 691f1ae | 2009-04-16 04:12:40 +0000 | [diff] [blame] | 113 | return diag::MAP_FATAL; |
| 114 | } |
| 115 | |
Chris Lattner | d51d74a | 2009-04-16 05:44:38 +0000 | [diff] [blame] | 116 | /// getWarningOptionForDiag - Return the lowest-level warning option that |
| 117 | /// enables the specified diagnostic. If there is no -Wfoo flag that controls |
| 118 | /// the diagnostic, this returns null. |
| 119 | const char *Diagnostic::getWarningOptionForDiag(unsigned DiagID) { |
Chris Lattner | 33dd282 | 2009-04-16 06:00:24 +0000 | [diff] [blame] | 120 | if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) |
| 121 | return Info->OptionGroup; |
| 122 | return 0; |
Chris Lattner | d51d74a | 2009-04-16 05:44:38 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 125 | bool Diagnostic::isBuiltinSFINAEDiag(unsigned DiagID) { |
| 126 | if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) |
Douglas Gregor | 8439fac | 2009-06-15 16:52:15 +0000 | [diff] [blame] | 127 | return Info->SFINAE && Info->Class == CLASS_ERROR; |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 128 | return false; |
| 129 | } |
| 130 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 131 | /// getDiagClass - Return the class field of the diagnostic. |
| 132 | /// |
Chris Lattner | 0750618 | 2007-11-30 22:53:43 +0000 | [diff] [blame] | 133 | static unsigned getBuiltinDiagClass(unsigned DiagID) { |
Chris Lattner | 121f60c | 2009-04-16 06:07:15 +0000 | [diff] [blame] | 134 | if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) |
| 135 | return Info->Class; |
| 136 | return ~0U; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 139 | //===----------------------------------------------------------------------===// |
| 140 | // Custom Diagnostic information |
| 141 | //===----------------------------------------------------------------------===// |
| 142 | |
| 143 | namespace clang { |
| 144 | namespace diag { |
| 145 | class CustomDiagInfo { |
| 146 | typedef std::pair<Diagnostic::Level, std::string> DiagDesc; |
| 147 | std::vector<DiagDesc> DiagInfo; |
| 148 | std::map<DiagDesc, unsigned> DiagIDs; |
| 149 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 151 | /// getDescription - Return the description of the specified custom |
| 152 | /// diagnostic. |
| 153 | const char *getDescription(unsigned DiagID) const { |
Chris Lattner | 88eccaf | 2009-01-29 06:55:46 +0000 | [diff] [blame] | 154 | assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() && |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 155 | "Invalid diagnosic ID"); |
Chris Lattner | 88eccaf | 2009-01-29 06:55:46 +0000 | [diff] [blame] | 156 | return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second.c_str(); |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 157 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 159 | /// getLevel - Return the level of the specified custom diagnostic. |
| 160 | Diagnostic::Level getLevel(unsigned DiagID) const { |
Chris Lattner | 88eccaf | 2009-01-29 06:55:46 +0000 | [diff] [blame] | 161 | assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() && |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 162 | "Invalid diagnosic ID"); |
Chris Lattner | 88eccaf | 2009-01-29 06:55:46 +0000 | [diff] [blame] | 163 | return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first; |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 164 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 165 | |
Daniel Dunbar | 32d4d80 | 2009-12-01 17:42:06 +0000 | [diff] [blame] | 166 | unsigned getOrCreateDiagID(Diagnostic::Level L, llvm::StringRef Message, |
Chris Lattner | a1f23cc | 2008-10-17 21:24:47 +0000 | [diff] [blame] | 167 | Diagnostic &Diags) { |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 168 | DiagDesc D(L, Message); |
| 169 | // Check to see if it already exists. |
| 170 | std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D); |
| 171 | if (I != DiagIDs.end() && I->first == D) |
| 172 | return I->second; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 173 | |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 174 | // If not, assign a new ID. |
Chris Lattner | 88eccaf | 2009-01-29 06:55:46 +0000 | [diff] [blame] | 175 | unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT; |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 176 | DiagIDs.insert(std::make_pair(D, ID)); |
| 177 | DiagInfo.push_back(D); |
| 178 | return ID; |
| 179 | } |
| 180 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | |
| 182 | } // end diag namespace |
| 183 | } // end clang namespace |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 184 | |
| 185 | |
| 186 | //===----------------------------------------------------------------------===// |
| 187 | // Common Diagnostic implementation |
| 188 | //===----------------------------------------------------------------------===// |
| 189 | |
Chris Lattner | 3fdf4b0 | 2008-11-23 09:21:17 +0000 | [diff] [blame] | 190 | static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT, |
| 191 | const char *Modifier, unsigned ML, |
| 192 | const char *Argument, unsigned ArgLen, |
Chris Lattner | b54d8af | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 193 | const Diagnostic::ArgumentValue *PrevArgs, |
| 194 | unsigned NumPrevArgs, |
Chris Lattner | 92dd386 | 2009-02-19 23:53:20 +0000 | [diff] [blame] | 195 | llvm::SmallVectorImpl<char> &Output, |
| 196 | void *Cookie) { |
Chris Lattner | 3fdf4b0 | 2008-11-23 09:21:17 +0000 | [diff] [blame] | 197 | const char *Str = "<can't format argument>"; |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 198 | Output.append(Str, Str+strlen(Str)); |
| 199 | } |
| 200 | |
| 201 | |
Ted Kremenek | b4398aa | 2008-08-07 17:49:57 +0000 | [diff] [blame] | 202 | Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) { |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 203 | AllExtensionsSilenced = 0; |
Chris Lattner | 5b4681c | 2008-05-29 15:36:45 +0000 | [diff] [blame] | 204 | IgnoreAllWarnings = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 205 | WarningsAsErrors = false; |
Chris Lattner | e663c72 | 2009-12-22 23:12:53 +0000 | [diff] [blame] | 206 | ErrorsAsFatal = false; |
Daniel Dunbar | 2fe0997 | 2008-09-12 18:10:20 +0000 | [diff] [blame] | 207 | SuppressSystemWarnings = false; |
Douglas Gregor | 81b747b | 2009-09-17 21:32:03 +0000 | [diff] [blame] | 208 | SuppressAllDiagnostics = false; |
Chris Lattner | b54b276 | 2009-04-16 05:04:32 +0000 | [diff] [blame] | 209 | ExtBehavior = Ext_Ignore; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 211 | ErrorOccurred = false; |
Chris Lattner | 1522142 | 2009-02-06 04:16:02 +0000 | [diff] [blame] | 212 | FatalErrorOccurred = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 213 | NumDiagnostics = 0; |
Steve Naroff | e0c4d89 | 2009-12-05 02:14:08 +0000 | [diff] [blame] | 214 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 215 | NumErrors = 0; |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 216 | CustomDiagInfo = 0; |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 217 | CurDiagID = ~0U; |
Douglas Gregor | 525c4b0 | 2009-03-19 18:55:06 +0000 | [diff] [blame] | 218 | LastDiagLevel = Ignored; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 219 | |
Chris Lattner | 3fdf4b0 | 2008-11-23 09:21:17 +0000 | [diff] [blame] | 220 | ArgToStringFn = DummyArgToStringFn; |
Chris Lattner | 92dd386 | 2009-02-19 23:53:20 +0000 | [diff] [blame] | 221 | ArgToStringCookie = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 222 | |
Chris Lattner | 691f1ae | 2009-04-16 04:12:40 +0000 | [diff] [blame] | 223 | // Set all mappings to 'unset'. |
Chris Lattner | 04ae2df | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 224 | DiagMappings BlankDiags(diag::DIAG_UPPER_LIMIT/2, 0); |
| 225 | DiagMappingsStack.push_back(BlankDiags); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 228 | Diagnostic::~Diagnostic() { |
| 229 | delete CustomDiagInfo; |
| 230 | } |
| 231 | |
Chris Lattner | 04ae2df | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 232 | |
| 233 | void Diagnostic::pushMappings() { |
John Thompson | ca2c3e2 | 2009-10-23 02:21:17 +0000 | [diff] [blame] | 234 | // Avoids undefined behavior when the stack has to resize. |
| 235 | DiagMappingsStack.reserve(DiagMappingsStack.size() + 1); |
Chris Lattner | 04ae2df | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 236 | DiagMappingsStack.push_back(DiagMappingsStack.back()); |
| 237 | } |
| 238 | |
| 239 | bool Diagnostic::popMappings() { |
| 240 | if (DiagMappingsStack.size() == 1) |
| 241 | return false; |
| 242 | |
| 243 | DiagMappingsStack.pop_back(); |
| 244 | return true; |
| 245 | } |
| 246 | |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 247 | /// getCustomDiagID - Return an ID for a diagnostic with the specified message |
| 248 | /// and level. If this is the first request for this diagnosic, it is |
| 249 | /// registered and created, otherwise the existing ID is returned. |
Daniel Dunbar | 32d4d80 | 2009-12-01 17:42:06 +0000 | [diff] [blame] | 250 | unsigned Diagnostic::getCustomDiagID(Level L, llvm::StringRef Message) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | if (CustomDiagInfo == 0) |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 252 | CustomDiagInfo = new diag::CustomDiagInfo(); |
Chris Lattner | a1f23cc | 2008-10-17 21:24:47 +0000 | [diff] [blame] | 253 | return CustomDiagInfo->getOrCreateDiagID(L, Message, *this); |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 257 | /// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic |
| 258 | /// level of the specified diagnostic ID is a Warning or Extension. |
| 259 | /// This only works on builtin diagnostics, not custom ones, and is not legal to |
| 260 | /// call on NOTEs. |
| 261 | bool Diagnostic::isBuiltinWarningOrExtension(unsigned DiagID) { |
Chris Lattner | 8a941e0 | 2009-04-15 16:56:26 +0000 | [diff] [blame] | 262 | return DiagID < diag::DIAG_UPPER_LIMIT && |
| 263 | getBuiltinDiagClass(DiagID) != CLASS_ERROR; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 266 | /// \brief Determine whether the given built-in diagnostic ID is a |
| 267 | /// Note. |
| 268 | bool Diagnostic::isBuiltinNote(unsigned DiagID) { |
Chris Lattner | 8a941e0 | 2009-04-15 16:56:26 +0000 | [diff] [blame] | 269 | return DiagID < diag::DIAG_UPPER_LIMIT && |
| 270 | getBuiltinDiagClass(DiagID) == CLASS_NOTE; |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 273 | /// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic |
| 274 | /// ID is for an extension of some sort. |
| 275 | /// |
| 276 | bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) { |
Chris Lattner | 8a941e0 | 2009-04-15 16:56:26 +0000 | [diff] [blame] | 277 | return DiagID < diag::DIAG_UPPER_LIMIT && |
| 278 | getBuiltinDiagClass(DiagID) == CLASS_EXTENSION; |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 281 | |
| 282 | /// getDescription - Given a diagnostic ID, return a description of the |
| 283 | /// issue. |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 284 | const char *Diagnostic::getDescription(unsigned DiagID) const { |
Chris Lattner | 121f60c | 2009-04-16 06:07:15 +0000 | [diff] [blame] | 285 | if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) |
| 286 | return Info->Description; |
Chris Lattner | 20c6b3b | 2009-01-27 18:30:58 +0000 | [diff] [blame] | 287 | return CustomDiagInfo->getDescription(DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /// getDiagnosticLevel - Based on the way the client configured the Diagnostic |
| 291 | /// object, classify the specified diagnostic ID into a Level, consumable by |
| 292 | /// the DiagnosticClient. |
| 293 | Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const { |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 294 | // Handle custom diagnostics, which cannot be mapped. |
Chris Lattner | 19e8e2c | 2009-01-29 17:46:13 +0000 | [diff] [blame] | 295 | if (DiagID >= diag::DIAG_UPPER_LIMIT) |
Chris Lattner | 182745a | 2007-12-02 01:09:57 +0000 | [diff] [blame] | 296 | return CustomDiagInfo->getLevel(DiagID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 297 | |
Chris Lattner | 0750618 | 2007-11-30 22:53:43 +0000 | [diff] [blame] | 298 | unsigned DiagClass = getBuiltinDiagClass(DiagID); |
Chris Lattner | 8a941e0 | 2009-04-15 16:56:26 +0000 | [diff] [blame] | 299 | assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!"); |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 300 | return getDiagnosticLevel(DiagID, DiagClass); |
| 301 | } |
| 302 | |
| 303 | /// getDiagnosticLevel - Based on the way the client configured the Diagnostic |
| 304 | /// object, classify the specified diagnostic ID into a Level, consumable by |
| 305 | /// the DiagnosticClient. |
| 306 | Diagnostic::Level |
| 307 | Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 308 | // Specific non-error diagnostics may be mapped to various levels from ignored |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 309 | // to error. Errors can only be mapped to fatal. |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 310 | Diagnostic::Level Result = Diagnostic::Fatal; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
Chris Lattner | 691f1ae | 2009-04-16 04:12:40 +0000 | [diff] [blame] | 312 | // Get the mapping information, if unset, compute it lazily. |
| 313 | unsigned MappingInfo = getDiagnosticMappingInfo((diag::kind)DiagID); |
| 314 | if (MappingInfo == 0) { |
| 315 | MappingInfo = GetDefaultDiagMapping(DiagID); |
| 316 | setDiagnosticMappingInternal(DiagID, MappingInfo, false); |
| 317 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 318 | |
Chris Lattner | 691f1ae | 2009-04-16 04:12:40 +0000 | [diff] [blame] | 319 | switch (MappingInfo & 7) { |
| 320 | default: assert(0 && "Unknown mapping!"); |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 321 | case diag::MAP_IGNORE: |
Chris Lattner | b54b276 | 2009-04-16 05:04:32 +0000 | [diff] [blame] | 322 | // Ignore this, unless this is an extension diagnostic and we're mapping |
| 323 | // them onto warnings or errors. |
| 324 | if (!isBuiltinExtensionDiag(DiagID) || // Not an extension |
| 325 | ExtBehavior == Ext_Ignore || // Extensions ignored anyway |
| 326 | (MappingInfo & 8) != 0) // User explicitly mapped it. |
| 327 | return Diagnostic::Ignored; |
| 328 | Result = Diagnostic::Warning; |
| 329 | if (ExtBehavior == Ext_Error) Result = Diagnostic::Error; |
Chris Lattner | e663c72 | 2009-12-22 23:12:53 +0000 | [diff] [blame] | 330 | if (Result == Diagnostic::Error && ErrorsAsFatal) |
| 331 | Result = Diagnostic::Fatal; |
Chris Lattner | b54b276 | 2009-04-16 05:04:32 +0000 | [diff] [blame] | 332 | break; |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 333 | case diag::MAP_ERROR: |
| 334 | Result = Diagnostic::Error; |
Chris Lattner | e663c72 | 2009-12-22 23:12:53 +0000 | [diff] [blame] | 335 | if (ErrorsAsFatal) |
| 336 | Result = Diagnostic::Fatal; |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 337 | break; |
| 338 | case diag::MAP_FATAL: |
| 339 | Result = Diagnostic::Fatal; |
| 340 | break; |
| 341 | case diag::MAP_WARNING: |
| 342 | // If warnings are globally mapped to ignore or error, do it. |
Chris Lattner | 5b4681c | 2008-05-29 15:36:45 +0000 | [diff] [blame] | 343 | if (IgnoreAllWarnings) |
| 344 | return Diagnostic::Ignored; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 345 | |
Chris Lattner | 2b07d8f | 2009-04-16 04:32:54 +0000 | [diff] [blame] | 346 | Result = Diagnostic::Warning; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | |
Chris Lattner | b54b276 | 2009-04-16 05:04:32 +0000 | [diff] [blame] | 348 | // If this is an extension diagnostic and we're in -pedantic-error mode, and |
| 349 | // if the user didn't explicitly map it, upgrade to an error. |
| 350 | if (ExtBehavior == Ext_Error && |
| 351 | (MappingInfo & 8) == 0 && |
| 352 | isBuiltinExtensionDiag(DiagID)) |
| 353 | Result = Diagnostic::Error; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 354 | |
Chris Lattner | 2b07d8f | 2009-04-16 04:32:54 +0000 | [diff] [blame] | 355 | if (WarningsAsErrors) |
| 356 | Result = Diagnostic::Error; |
Chris Lattner | e663c72 | 2009-12-22 23:12:53 +0000 | [diff] [blame] | 357 | if (Result == Diagnostic::Error && ErrorsAsFatal) |
| 358 | Result = Diagnostic::Fatal; |
Chris Lattner | 2b07d8f | 2009-04-16 04:32:54 +0000 | [diff] [blame] | 359 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | |
Chris Lattner | 2b07d8f | 2009-04-16 04:32:54 +0000 | [diff] [blame] | 361 | case diag::MAP_WARNING_NO_WERROR: |
| 362 | // Diagnostics specified with -Wno-error=foo should be set to warnings, but |
| 363 | // not be adjusted by -Werror or -pedantic-errors. |
| 364 | Result = Diagnostic::Warning; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Chris Lattner | 2b07d8f | 2009-04-16 04:32:54 +0000 | [diff] [blame] | 366 | // If warnings are globally mapped to ignore or error, do it. |
| 367 | if (IgnoreAllWarnings) |
| 368 | return Diagnostic::Ignored; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 370 | break; |
Chris Lattner | e663c72 | 2009-12-22 23:12:53 +0000 | [diff] [blame] | 371 | |
| 372 | case diag::MAP_ERROR_NO_WFATAL: |
| 373 | // Diagnostics specified as -Wno-fatal-error=foo should be errors, but |
| 374 | // unaffected by -Wfatal-errors. |
| 375 | Result = Diagnostic::Error; |
| 376 | break; |
Chris Lattner | 5b4681c | 2008-05-29 15:36:45 +0000 | [diff] [blame] | 377 | } |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 378 | |
| 379 | // Okay, we're about to return this as a "diagnostic to emit" one last check: |
| 380 | // if this is any sort of extension warning, and if we're in an __extension__ |
| 381 | // block, silence it. |
| 382 | if (AllExtensionsSilenced && isBuiltinExtensionDiag(DiagID)) |
| 383 | return Diagnostic::Ignored; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 384 | |
Chris Lattner | 27ceb9d | 2009-04-15 07:01:18 +0000 | [diff] [blame] | 385 | return Result; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Chris Lattner | 3bc172b | 2009-04-19 22:34:23 +0000 | [diff] [blame] | 388 | struct WarningOption { |
| 389 | const char *Name; |
| 390 | const short *Members; |
| 391 | const char *SubGroups; |
| 392 | }; |
| 393 | |
| 394 | #define GET_DIAG_ARRAYS |
| 395 | #include "clang/Basic/DiagnosticGroups.inc" |
| 396 | #undef GET_DIAG_ARRAYS |
| 397 | |
| 398 | // Second the table of options, sorted by name for fast binary lookup. |
| 399 | static const WarningOption OptionTable[] = { |
| 400 | #define GET_DIAG_TABLE |
| 401 | #include "clang/Basic/DiagnosticGroups.inc" |
| 402 | #undef GET_DIAG_TABLE |
| 403 | }; |
| 404 | static const size_t OptionTableSize = |
| 405 | sizeof(OptionTable) / sizeof(OptionTable[0]); |
| 406 | |
| 407 | static bool WarningOptionCompare(const WarningOption &LHS, |
| 408 | const WarningOption &RHS) { |
| 409 | return strcmp(LHS.Name, RHS.Name) < 0; |
| 410 | } |
| 411 | |
| 412 | static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping, |
| 413 | Diagnostic &Diags) { |
| 414 | // Option exists, poke all the members of its diagnostic set. |
| 415 | if (const short *Member = Group->Members) { |
| 416 | for (; *Member != -1; ++Member) |
| 417 | Diags.setDiagnosticMapping(*Member, Mapping); |
| 418 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | |
Chris Lattner | 3bc172b | 2009-04-19 22:34:23 +0000 | [diff] [blame] | 420 | // Enable/disable all subgroups along with this one. |
| 421 | if (const char *SubGroups = Group->SubGroups) { |
| 422 | for (; *SubGroups != (char)-1; ++SubGroups) |
| 423 | MapGroupMembers(&OptionTable[(unsigned char)*SubGroups], Mapping, Diags); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g. |
| 428 | /// "unknown-pragmas" to have the specified mapping. This returns true and |
| 429 | /// ignores the request if "Group" was unknown, false otherwise. |
| 430 | bool Diagnostic::setDiagnosticGroupMapping(const char *Group, |
| 431 | diag::Mapping Map) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Chris Lattner | 3bc172b | 2009-04-19 22:34:23 +0000 | [diff] [blame] | 433 | WarningOption Key = { Group, 0, 0 }; |
| 434 | const WarningOption *Found = |
| 435 | std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key, |
| 436 | WarningOptionCompare); |
| 437 | if (Found == OptionTable + OptionTableSize || |
| 438 | strcmp(Found->Name, Group) != 0) |
| 439 | return true; // Option not found. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
Chris Lattner | 3bc172b | 2009-04-19 22:34:23 +0000 | [diff] [blame] | 441 | MapGroupMembers(Found, Map, *this); |
| 442 | return false; |
| 443 | } |
| 444 | |
| 445 | |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 446 | /// ProcessDiag - This is the method used to report a diagnostic that is |
| 447 | /// finally fully formed. |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 448 | bool Diagnostic::ProcessDiag() { |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 449 | DiagnosticInfo Info(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | |
Douglas Gregor | 81b747b | 2009-09-17 21:32:03 +0000 | [diff] [blame] | 451 | if (SuppressAllDiagnostics) |
| 452 | return false; |
| 453 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 454 | // Figure out the diagnostic level of this message. |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 455 | Diagnostic::Level DiagLevel; |
| 456 | unsigned DiagID = Info.getID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 457 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 458 | // ShouldEmitInSystemHeader - True if this diagnostic should be produced even |
| 459 | // in a system header. |
| 460 | bool ShouldEmitInSystemHeader; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 461 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 462 | if (DiagID >= diag::DIAG_UPPER_LIMIT) { |
| 463 | // Handle custom diagnostics, which cannot be mapped. |
| 464 | DiagLevel = CustomDiagInfo->getLevel(DiagID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 465 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 466 | // Custom diagnostics always are emitted in system headers. |
| 467 | ShouldEmitInSystemHeader = true; |
| 468 | } else { |
| 469 | // Get the class of the diagnostic. If this is a NOTE, map it onto whatever |
| 470 | // the diagnostic level was for the previous diagnostic so that it is |
| 471 | // filtered the same as the previous diagnostic. |
| 472 | unsigned DiagClass = getBuiltinDiagClass(DiagID); |
Chris Lattner | 8a941e0 | 2009-04-15 16:56:26 +0000 | [diff] [blame] | 473 | if (DiagClass == CLASS_NOTE) { |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 474 | DiagLevel = Diagnostic::Note; |
| 475 | ShouldEmitInSystemHeader = false; // extra consideration is needed |
| 476 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 477 | // If this is not an error and we are in a system header, we ignore it. |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 478 | // Check the original Diag ID here, because we also want to ignore |
| 479 | // extensions and warnings in -Werror and -pedantic-errors modes, which |
| 480 | // *map* warnings/extensions to errors. |
Chris Lattner | 8a941e0 | 2009-04-15 16:56:26 +0000 | [diff] [blame] | 481 | ShouldEmitInSystemHeader = DiagClass == CLASS_ERROR; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 482 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 483 | DiagLevel = getDiagnosticLevel(DiagID, DiagClass); |
| 484 | } |
| 485 | } |
| 486 | |
Douglas Gregor | 525c4b0 | 2009-03-19 18:55:06 +0000 | [diff] [blame] | 487 | if (DiagLevel != Diagnostic::Note) { |
| 488 | // Record that a fatal error occurred only when we see a second |
| 489 | // non-note diagnostic. This allows notes to be attached to the |
| 490 | // fatal error, but suppresses any diagnostics that follow those |
| 491 | // notes. |
| 492 | if (LastDiagLevel == Diagnostic::Fatal) |
| 493 | FatalErrorOccurred = true; |
| 494 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 495 | LastDiagLevel = DiagLevel; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | } |
Douglas Gregor | 525c4b0 | 2009-03-19 18:55:06 +0000 | [diff] [blame] | 497 | |
| 498 | // If a fatal error has already been emitted, silence all subsequent |
| 499 | // diagnostics. |
| 500 | if (FatalErrorOccurred) |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 501 | return false; |
Douglas Gregor | 525c4b0 | 2009-03-19 18:55:06 +0000 | [diff] [blame] | 502 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 503 | // If the client doesn't care about this message, don't issue it. If this is |
| 504 | // a note and the last real diagnostic was ignored, ignore it too. |
| 505 | if (DiagLevel == Diagnostic::Ignored || |
| 506 | (DiagLevel == Diagnostic::Note && LastDiagLevel == Diagnostic::Ignored)) |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 507 | return false; |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 508 | |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 509 | // If this diagnostic is in a system header and is not a clang error, suppress |
| 510 | // it. |
| 511 | if (SuppressSystemWarnings && !ShouldEmitInSystemHeader && |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 512 | Info.getLocation().isValid() && |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 513 | Info.getLocation().getSpellingLoc().isInSystemHeader() && |
Chris Lattner | 336f26b | 2009-02-17 06:52:20 +0000 | [diff] [blame] | 514 | (DiagLevel != Diagnostic::Note || LastDiagLevel == Diagnostic::Ignored)) { |
| 515 | LastDiagLevel = Diagnostic::Ignored; |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 516 | return false; |
Chris Lattner | 336f26b | 2009-02-17 06:52:20 +0000 | [diff] [blame] | 517 | } |
Chris Lattner | f5d2328 | 2009-02-17 06:49:55 +0000 | [diff] [blame] | 518 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 519 | if (DiagLevel >= Diagnostic::Error) { |
| 520 | ErrorOccurred = true; |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 521 | ++NumErrors; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 522 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 524 | // Finally, report it. |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 525 | Client->HandleDiagnostic(DiagLevel, Info); |
Ted Kremenek | cabe668 | 2009-01-23 20:28:53 +0000 | [diff] [blame] | 526 | if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics; |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 527 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 528 | CurDiagID = ~0U; |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 529 | |
| 530 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 533 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 534 | DiagnosticClient::~DiagnosticClient() {} |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 535 | |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 536 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 537 | /// ModifierIs - Return true if the specified modifier matches specified string. |
| 538 | template <std::size_t StrLen> |
| 539 | static bool ModifierIs(const char *Modifier, unsigned ModifierLen, |
| 540 | const char (&Str)[StrLen]) { |
| 541 | return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1); |
| 542 | } |
| 543 | |
| 544 | /// HandleSelectModifier - Handle the integer 'select' modifier. This is used |
| 545 | /// like this: %select{foo|bar|baz}2. This means that the integer argument |
| 546 | /// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'. |
| 547 | /// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'. |
| 548 | /// This is very useful for certain classes of variant diagnostics. |
| 549 | static void HandleSelectModifier(unsigned ValNo, |
| 550 | const char *Argument, unsigned ArgumentLen, |
| 551 | llvm::SmallVectorImpl<char> &OutStr) { |
| 552 | const char *ArgumentEnd = Argument+ArgumentLen; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 554 | // Skip over 'ValNo' |'s. |
| 555 | while (ValNo) { |
| 556 | const char *NextVal = std::find(Argument, ArgumentEnd, '|'); |
| 557 | assert(NextVal != ArgumentEnd && "Value for integer select modifier was" |
| 558 | " larger than the number of options in the diagnostic string!"); |
| 559 | Argument = NextVal+1; // Skip this string. |
| 560 | --ValNo; |
| 561 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 562 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 563 | // Get the end of the value. This is either the } or the |. |
| 564 | const char *EndPtr = std::find(Argument, ArgumentEnd, '|'); |
| 565 | // Add the value to the output string. |
| 566 | OutStr.append(Argument, EndPtr); |
| 567 | } |
| 568 | |
| 569 | /// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the |
| 570 | /// letter 's' to the string if the value is not 1. This is used in cases like |
| 571 | /// this: "you idiot, you have %4 parameter%s4!". |
| 572 | static void HandleIntegerSModifier(unsigned ValNo, |
| 573 | llvm::SmallVectorImpl<char> &OutStr) { |
| 574 | if (ValNo != 1) |
| 575 | OutStr.push_back('s'); |
| 576 | } |
| 577 | |
| 578 | |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 579 | /// PluralNumber - Parse an unsigned integer and advance Start. |
Chris Lattner | d2aa7c9 | 2009-04-15 17:13:42 +0000 | [diff] [blame] | 580 | static unsigned PluralNumber(const char *&Start, const char *End) { |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 581 | // Programming 101: Parse a decimal number :-) |
| 582 | unsigned Val = 0; |
| 583 | while (Start != End && *Start >= '0' && *Start <= '9') { |
| 584 | Val *= 10; |
| 585 | Val += *Start - '0'; |
| 586 | ++Start; |
| 587 | } |
| 588 | return Val; |
| 589 | } |
| 590 | |
| 591 | /// TestPluralRange - Test if Val is in the parsed range. Modifies Start. |
Chris Lattner | d2aa7c9 | 2009-04-15 17:13:42 +0000 | [diff] [blame] | 592 | static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) { |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 593 | if (*Start != '[') { |
| 594 | unsigned Ref = PluralNumber(Start, End); |
| 595 | return Ref == Val; |
| 596 | } |
| 597 | |
| 598 | ++Start; |
| 599 | unsigned Low = PluralNumber(Start, End); |
| 600 | assert(*Start == ',' && "Bad plural expression syntax: expected ,"); |
| 601 | ++Start; |
| 602 | unsigned High = PluralNumber(Start, End); |
| 603 | assert(*Start == ']' && "Bad plural expression syntax: expected )"); |
| 604 | ++Start; |
| 605 | return Low <= Val && Val <= High; |
| 606 | } |
| 607 | |
| 608 | /// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier. |
Chris Lattner | d2aa7c9 | 2009-04-15 17:13:42 +0000 | [diff] [blame] | 609 | static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) { |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 610 | // Empty condition? |
| 611 | if (*Start == ':') |
| 612 | return true; |
| 613 | |
| 614 | while (1) { |
| 615 | char C = *Start; |
| 616 | if (C == '%') { |
| 617 | // Modulo expression |
| 618 | ++Start; |
| 619 | unsigned Arg = PluralNumber(Start, End); |
| 620 | assert(*Start == '=' && "Bad plural expression syntax: expected ="); |
| 621 | ++Start; |
| 622 | unsigned ValMod = ValNo % Arg; |
| 623 | if (TestPluralRange(ValMod, Start, End)) |
| 624 | return true; |
| 625 | } else { |
Sebastian Redl | e206532 | 2008-11-27 07:28:14 +0000 | [diff] [blame] | 626 | assert((C == '[' || (C >= '0' && C <= '9')) && |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 627 | "Bad plural expression syntax: unexpected character"); |
| 628 | // Range expression |
| 629 | if (TestPluralRange(ValNo, Start, End)) |
| 630 | return true; |
| 631 | } |
| 632 | |
| 633 | // Scan for next or-expr part. |
| 634 | Start = std::find(Start, End, ','); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | if (Start == End) |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 636 | break; |
| 637 | ++Start; |
| 638 | } |
| 639 | return false; |
| 640 | } |
| 641 | |
| 642 | /// HandlePluralModifier - Handle the integer 'plural' modifier. This is used |
| 643 | /// for complex plural forms, or in languages where all plurals are complex. |
| 644 | /// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are |
| 645 | /// conditions that are tested in order, the form corresponding to the first |
| 646 | /// that applies being emitted. The empty condition is always true, making the |
| 647 | /// last form a default case. |
| 648 | /// Conditions are simple boolean expressions, where n is the number argument. |
| 649 | /// Here are the rules. |
| 650 | /// condition := expression | empty |
| 651 | /// empty := -> always true |
| 652 | /// expression := numeric [',' expression] -> logical or |
| 653 | /// numeric := range -> true if n in range |
| 654 | /// | '%' number '=' range -> true if n % number in range |
| 655 | /// range := number |
| 656 | /// | '[' number ',' number ']' -> ranges are inclusive both ends |
| 657 | /// |
| 658 | /// Here are some examples from the GNU gettext manual written in this form: |
| 659 | /// English: |
| 660 | /// {1:form0|:form1} |
| 661 | /// Latvian: |
| 662 | /// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0} |
| 663 | /// Gaeilge: |
| 664 | /// {1:form0|2:form1|:form2} |
| 665 | /// Romanian: |
| 666 | /// {1:form0|0,%100=[1,19]:form1|:form2} |
| 667 | /// Lithuanian: |
| 668 | /// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1} |
| 669 | /// Russian (requires repeated form): |
| 670 | /// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2} |
| 671 | /// Slovak |
| 672 | /// {1:form0|[2,4]:form1|:form2} |
| 673 | /// Polish (requires repeated form): |
| 674 | /// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2} |
| 675 | static void HandlePluralModifier(unsigned ValNo, |
| 676 | const char *Argument, unsigned ArgumentLen, |
Chris Lattner | b54b276 | 2009-04-16 05:04:32 +0000 | [diff] [blame] | 677 | llvm::SmallVectorImpl<char> &OutStr) { |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 678 | const char *ArgumentEnd = Argument + ArgumentLen; |
| 679 | while (1) { |
| 680 | assert(Argument < ArgumentEnd && "Plural expression didn't match."); |
| 681 | const char *ExprEnd = Argument; |
| 682 | while (*ExprEnd != ':') { |
| 683 | assert(ExprEnd != ArgumentEnd && "Plural missing expression end"); |
| 684 | ++ExprEnd; |
| 685 | } |
| 686 | if (EvalPluralExpr(ValNo, Argument, ExprEnd)) { |
| 687 | Argument = ExprEnd + 1; |
| 688 | ExprEnd = std::find(Argument, ArgumentEnd, '|'); |
| 689 | OutStr.append(Argument, ExprEnd); |
| 690 | return; |
| 691 | } |
| 692 | Argument = std::find(Argument, ArgumentEnd - 1, '|') + 1; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 697 | /// FormatDiagnostic - Format this diagnostic into a string, substituting the |
| 698 | /// formal arguments into the %0 slots. The result is appended onto the Str |
| 699 | /// array. |
| 700 | void DiagnosticInfo:: |
| 701 | FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const { |
| 702 | const char *DiagStr = getDiags()->getDescription(getID()); |
| 703 | const char *DiagEnd = DiagStr+strlen(DiagStr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 704 | |
Chris Lattner | b54d8af | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 705 | /// FormattedArgs - Keep track of all of the arguments formatted by |
| 706 | /// ConvertArgToString and pass them into subsequent calls to |
| 707 | /// ConvertArgToString, allowing the implementation to avoid redundancies in |
| 708 | /// obvious cases. |
| 709 | llvm::SmallVector<Diagnostic::ArgumentValue, 8> FormattedArgs; |
| 710 | |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 711 | while (DiagStr != DiagEnd) { |
| 712 | if (DiagStr[0] != '%') { |
| 713 | // Append non-%0 substrings to Str if we have one. |
| 714 | const char *StrEnd = std::find(DiagStr, DiagEnd, '%'); |
| 715 | OutStr.append(DiagStr, StrEnd); |
| 716 | DiagStr = StrEnd; |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 717 | continue; |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 718 | } else if (DiagStr[1] == '%') { |
| 719 | OutStr.push_back('%'); // %% -> %. |
| 720 | DiagStr += 2; |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 721 | continue; |
| 722 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 723 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 724 | // Skip the %. |
| 725 | ++DiagStr; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 727 | // This must be a placeholder for a diagnostic argument. The format for a |
| 728 | // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0". |
| 729 | // The digit is a number from 0-9 indicating which argument this comes from. |
| 730 | // The modifier is a string of digits from the set [-a-z]+, arguments is a |
| 731 | // brace enclosed string. |
| 732 | const char *Modifier = 0, *Argument = 0; |
| 733 | unsigned ModifierLen = 0, ArgumentLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 734 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 735 | // Check to see if we have a modifier. If so eat it. |
| 736 | if (!isdigit(DiagStr[0])) { |
| 737 | Modifier = DiagStr; |
| 738 | while (DiagStr[0] == '-' || |
| 739 | (DiagStr[0] >= 'a' && DiagStr[0] <= 'z')) |
| 740 | ++DiagStr; |
| 741 | ModifierLen = DiagStr-Modifier; |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 742 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 743 | // If we have an argument, get it next. |
| 744 | if (DiagStr[0] == '{') { |
| 745 | ++DiagStr; // Skip {. |
| 746 | Argument = DiagStr; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 748 | for (; DiagStr[0] != '}'; ++DiagStr) |
| 749 | assert(DiagStr[0] && "Mismatched {}'s in diagnostic string!"); |
| 750 | ArgumentLen = DiagStr-Argument; |
| 751 | ++DiagStr; // Skip }. |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 752 | } |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 753 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 754 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 755 | assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic"); |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 756 | unsigned ArgNo = *DiagStr++ - '0'; |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 757 | |
Chris Lattner | b54d8af | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 758 | Diagnostic::ArgumentKind Kind = getArgKind(ArgNo); |
| 759 | |
| 760 | switch (Kind) { |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 761 | // ---- STRINGS ---- |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 762 | case Diagnostic::ak_std_string: { |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 763 | const std::string &S = getArgStdStr(ArgNo); |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 764 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
| 765 | OutStr.append(S.begin(), S.end()); |
| 766 | break; |
| 767 | } |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 768 | case Diagnostic::ak_c_string: { |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 769 | const char *S = getArgCStr(ArgNo); |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 770 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
Daniel Dunbar | e46e354 | 2009-04-20 06:13:16 +0000 | [diff] [blame] | 771 | |
| 772 | // Don't crash if get passed a null pointer by accident. |
| 773 | if (!S) |
| 774 | S = "(null)"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 775 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 776 | OutStr.append(S, S + strlen(S)); |
| 777 | break; |
| 778 | } |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 779 | // ---- INTEGERS ---- |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 780 | case Diagnostic::ak_sint: { |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 781 | int Val = getArgSInt(ArgNo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 783 | if (ModifierIs(Modifier, ModifierLen, "select")) { |
| 784 | HandleSelectModifier((unsigned)Val, Argument, ArgumentLen, OutStr); |
| 785 | } else if (ModifierIs(Modifier, ModifierLen, "s")) { |
| 786 | HandleIntegerSModifier(Val, OutStr); |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 787 | } else if (ModifierIs(Modifier, ModifierLen, "plural")) { |
| 788 | HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr); |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 789 | } else { |
| 790 | assert(ModifierLen == 0 && "Unknown integer modifier"); |
Daniel Dunbar | 23e47c6 | 2009-10-17 18:12:14 +0000 | [diff] [blame] | 791 | llvm::raw_svector_ostream(OutStr) << Val; |
Chris Lattner | 30bc965 | 2008-11-19 07:22:31 +0000 | [diff] [blame] | 792 | } |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 793 | break; |
| 794 | } |
Chris Lattner | 3cbfe2c | 2008-11-22 00:59:29 +0000 | [diff] [blame] | 795 | case Diagnostic::ak_uint: { |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 796 | unsigned Val = getArgUInt(ArgNo); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 797 | |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 798 | if (ModifierIs(Modifier, ModifierLen, "select")) { |
| 799 | HandleSelectModifier(Val, Argument, ArgumentLen, OutStr); |
| 800 | } else if (ModifierIs(Modifier, ModifierLen, "s")) { |
| 801 | HandleIntegerSModifier(Val, OutStr); |
Sebastian Redl | e4c452c | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 802 | } else if (ModifierIs(Modifier, ModifierLen, "plural")) { |
| 803 | HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr); |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 804 | } else { |
| 805 | assert(ModifierLen == 0 && "Unknown integer modifier"); |
Daniel Dunbar | 23e47c6 | 2009-10-17 18:12:14 +0000 | [diff] [blame] | 806 | llvm::raw_svector_ostream(OutStr) << Val; |
Chris Lattner | 30bc965 | 2008-11-19 07:22:31 +0000 | [diff] [blame] | 807 | } |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 808 | break; |
Chris Lattner | af7ae4e | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 809 | } |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 810 | // ---- NAMES and TYPES ---- |
| 811 | case Diagnostic::ak_identifierinfo: { |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 812 | const IdentifierInfo *II = getArgIdentifier(ArgNo); |
| 813 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
Daniel Dunbar | e46e354 | 2009-04-20 06:13:16 +0000 | [diff] [blame] | 814 | |
| 815 | // Don't crash if get passed a null pointer by accident. |
| 816 | if (!II) { |
| 817 | const char *S = "(null)"; |
| 818 | OutStr.append(S, S + strlen(S)); |
| 819 | continue; |
| 820 | } |
| 821 | |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 822 | llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\''; |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 823 | break; |
| 824 | } |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 825 | case Diagnostic::ak_qualtype: |
Chris Lattner | 011bb4e | 2008-11-23 20:28:15 +0000 | [diff] [blame] | 826 | case Diagnostic::ak_declarationname: |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 827 | case Diagnostic::ak_nameddecl: |
Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 828 | case Diagnostic::ak_nestednamespec: |
Douglas Gregor | 3f09327 | 2009-10-13 21:16:44 +0000 | [diff] [blame] | 829 | case Diagnostic::ak_declcontext: |
Chris Lattner | b54d8af | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 830 | getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo), |
Chris Lattner | 3fdf4b0 | 2008-11-23 09:21:17 +0000 | [diff] [blame] | 831 | Modifier, ModifierLen, |
Chris Lattner | b54d8af | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 832 | Argument, ArgumentLen, |
| 833 | FormattedArgs.data(), FormattedArgs.size(), |
| 834 | OutStr); |
Chris Lattner | 22caddc | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 835 | break; |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 836 | } |
Chris Lattner | b54d8af | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 837 | |
| 838 | // Remember this argument info for subsequent formatting operations. Turn |
| 839 | // std::strings into a null terminated string to make it be the same case as |
| 840 | // all the other ones. |
| 841 | if (Kind != Diagnostic::ak_std_string) |
| 842 | FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo))); |
| 843 | else |
| 844 | FormattedArgs.push_back(std::make_pair(Diagnostic::ak_c_string, |
| 845 | (intptr_t)getArgStdStr(ArgNo).c_str())); |
| 846 | |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 847 | } |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 848 | } |
Ted Kremenek | cabe668 | 2009-01-23 20:28:53 +0000 | [diff] [blame] | 849 | |
| 850 | /// IncludeInDiagnosticCounts - This method (whose default implementation |
| 851 | /// returns true) indicates whether the diagnostics handled by this |
| 852 | /// DiagnosticClient should be included in the number of diagnostics |
| 853 | /// reported by Diagnostic. |
| 854 | bool DiagnosticClient::IncludeInDiagnosticCounts() const { return true; } |