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