blob: 31f56e99bf4f8a2756d5697eda3c89476ca157d5 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Diagnostic-related interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/Diagnostic.h"
Chris Lattner27ceb9d2009-04-15 07:01:18 +000015
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 Lattner43b628c2008-11-19 07:32:16 +000024#include "clang/Basic/IdentifierTable.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000025#include "clang/Basic/SourceLocation.h"
Chris Lattnerf4c83962008-11-19 06:51:40 +000026#include "llvm/ADT/SmallVector.h"
Chris Lattner30bc9652008-11-19 07:22:31 +000027#include "llvm/ADT/StringExtras.h"
Chris Lattner182745a2007-12-02 01:09:57 +000028#include <vector>
29#include <map>
Chris Lattner87cf5ac2008-03-10 17:04:53 +000030#include <cstring>
Reid Spencer5f016e22007-07-11 17:01:13 +000031using namespace clang;
32
Chris Lattner182745a2007-12-02 01:09:57 +000033//===----------------------------------------------------------------------===//
34// Builtin Diagnostic information
35//===----------------------------------------------------------------------===//
36
Chris Lattner27ceb9d2009-04-15 07:01:18 +000037// DefaultDiagnosticMappings - This specifies the default mapping for each diag,
38// based on its kind. Yay for macros?
39
40struct DefaultMappingInfo {
41 unsigned DiagID : 14;
42 unsigned Mapping : 2;
43};
44
Chris Lattner27ceb9d2009-04-15 07:01:18 +000045static const DefaultMappingInfo DefaultMappings[] = {
Chris Lattner691f1ae2009-04-16 04:12:40 +000046#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC) { diag::ENUM, DEFAULT_MAPPING-1 },
Chris Lattner27ceb9d2009-04-15 07:01:18 +000047#include "clang/Basic/DiagnosticCommonKinds.inc"
48#include "clang/Basic/DiagnosticDriverKinds.inc"
49#include "clang/Basic/DiagnosticFrontendKinds.inc"
50#include "clang/Basic/DiagnosticLexKinds.inc"
51#include "clang/Basic/DiagnosticParseKinds.inc"
52#include "clang/Basic/DiagnosticASTKinds.inc"
53#include "clang/Basic/DiagnosticSemaKinds.inc"
54#include "clang/Basic/DiagnosticAnalysisKinds.inc"
55{ 0, 0 }
56};
Chris Lattner8a941e02009-04-15 16:56:26 +000057#undef DIAG
Chris Lattner27ceb9d2009-04-15 07:01:18 +000058
Chris Lattner691f1ae2009-04-16 04:12:40 +000059static unsigned GetDefaultDiagMapping(unsigned DiagID) {
60 // FIXME: Binary search.
61 for (unsigned i = 0, e = sizeof(DefaultMappings)/sizeof(DefaultMappings[0]);
62 i != e; ++i)
63 if (DefaultMappings[i].DiagID == DiagID)
64 return DefaultMappings[i].Mapping+1;
65 return diag::MAP_FATAL;
66}
67
68
Chris Lattner27ceb9d2009-04-15 07:01:18 +000069// Diagnostic classes.
Reid Spencer5f016e22007-07-11 17:01:13 +000070enum {
Chris Lattner8a941e02009-04-15 16:56:26 +000071 CLASS_NOTE = 0x01,
72 CLASS_WARNING = 0x02,
73 CLASS_EXTENSION = 0x03,
74 CLASS_ERROR = 0x04
Reid Spencer5f016e22007-07-11 17:01:13 +000075};
76
Chris Lattner27ceb9d2009-04-15 07:01:18 +000077/// DiagnosticClasses - The class for each diagnostic.
Chris Lattner4ac072a2009-04-15 16:44:12 +000078#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC) CLASS,
Chris Lattner27ceb9d2009-04-15 07:01:18 +000079static unsigned char DiagnosticClassesCommon[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +000080#include "clang/Basic/DiagnosticCommonKinds.inc"
Reid Spencer5f016e22007-07-11 17:01:13 +000081 0
82};
Chris Lattner27ceb9d2009-04-15 07:01:18 +000083static unsigned char DiagnosticClassesDriver[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +000084#include "clang/Basic/DiagnosticDriverKinds.inc"
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000085 0
86};
Chris Lattner27ceb9d2009-04-15 07:01:18 +000087static unsigned char DiagnosticClassesFrontend[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +000088#include "clang/Basic/DiagnosticFrontendKinds.inc"
Daniel Dunbar50f4f462009-03-12 10:14:16 +000089 0
90};
Chris Lattner27ceb9d2009-04-15 07:01:18 +000091static unsigned char DiagnosticClassesLex[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +000092#include "clang/Basic/DiagnosticLexKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +000093 0
94};
Chris Lattner27ceb9d2009-04-15 07:01:18 +000095static unsigned char DiagnosticClassesParse[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +000096#include "clang/Basic/DiagnosticParseKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +000097 0
98};
Chris Lattner27ceb9d2009-04-15 07:01:18 +000099static unsigned char DiagnosticClassesAST[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000100#include "clang/Basic/DiagnosticASTKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000101 0
102};
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000103static unsigned char DiagnosticClassesSema[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000104#include "clang/Basic/DiagnosticSemaKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000105 0
106};
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000107static unsigned char DiagnosticClassesAnalysis[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000108#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000109 0
110};
111#undef DIAG
Reid Spencer5f016e22007-07-11 17:01:13 +0000112
113/// getDiagClass - Return the class field of the diagnostic.
114///
Chris Lattner07506182007-11-30 22:53:43 +0000115static unsigned getBuiltinDiagClass(unsigned DiagID) {
Chris Lattner19e8e2c2009-01-29 17:46:13 +0000116 assert(DiagID < diag::DIAG_UPPER_LIMIT &&
Chris Lattner07506182007-11-30 22:53:43 +0000117 "Diagnostic ID out of range!");
Chris Lattnerfe526d22009-04-15 18:48:23 +0000118 unsigned char *Arr;
119 unsigned ArrSize;
120 if (DiagID <= diag::DIAG_START_DRIVER) {
121 DiagID -= 0;
122 Arr = DiagnosticClassesCommon;
123 ArrSize = sizeof(DiagnosticClassesCommon);
124 } else if (DiagID <= diag::DIAG_START_FRONTEND) {
125 DiagID -= diag::DIAG_START_DRIVER + 1;
126 Arr = DiagnosticClassesDriver;
127 ArrSize = sizeof(DiagnosticClassesDriver);
128 } else if (DiagID <= diag::DIAG_START_LEX) {
129 DiagID -= diag::DIAG_START_FRONTEND + 1;
130 Arr = DiagnosticClassesFrontend;
131 ArrSize = sizeof(DiagnosticClassesFrontend);
132 } else if (DiagID <= diag::DIAG_START_PARSE) {
133 DiagID -= diag::DIAG_START_LEX + 1;
134 Arr = DiagnosticClassesLex;
135 ArrSize = sizeof(DiagnosticClassesLex);
136 } else if (DiagID <= diag::DIAG_START_AST) {
137 DiagID -= diag::DIAG_START_PARSE + 1;
138 Arr = DiagnosticClassesParse;
139 ArrSize = sizeof(DiagnosticClassesParse);
140 } else if (DiagID <= diag::DIAG_START_SEMA) {
141 DiagID -= diag::DIAG_START_AST + 1;
142 Arr = DiagnosticClassesAST;
143 ArrSize = sizeof(DiagnosticClassesAST);
144
145 } else if (DiagID <= diag::DIAG_START_ANALYSIS) {
146 DiagID -= diag::DIAG_START_SEMA + 1;
147 Arr = DiagnosticClassesSema;
148 ArrSize = sizeof(DiagnosticClassesSema);
149 } else {
150 DiagID -= diag::DIAG_START_ANALYSIS + 1;
151 Arr = DiagnosticClassesAnalysis;
152 ArrSize = sizeof(DiagnosticClassesAnalysis);
153 }
154 return DiagID < ArrSize ? Arr[DiagID] : ~0U;
Reid Spencer5f016e22007-07-11 17:01:13 +0000155}
156
157/// DiagnosticText - An english message to print for the diagnostic. These
158/// should be localized.
Chris Lattner4ac072a2009-04-15 16:44:12 +0000159#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC) DESC,
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000160static const char * const DiagnosticTextCommon[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000161#include "clang/Basic/DiagnosticCommonKinds.inc"
Reid Spencer5f016e22007-07-11 17:01:13 +0000162 0
163};
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +0000164static const char * const DiagnosticTextDriver[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000165#include "clang/Basic/DiagnosticDriverKinds.inc"
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +0000166 0
167};
Daniel Dunbar50f4f462009-03-12 10:14:16 +0000168static const char * const DiagnosticTextFrontend[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000169#include "clang/Basic/DiagnosticFrontendKinds.inc"
Daniel Dunbar50f4f462009-03-12 10:14:16 +0000170 0
171};
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000172static const char * const DiagnosticTextLex[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000173#include "clang/Basic/DiagnosticLexKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000174 0
175};
176static const char * const DiagnosticTextParse[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000177#include "clang/Basic/DiagnosticParseKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000178 0
179};
180static const char * const DiagnosticTextAST[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000181#include "clang/Basic/DiagnosticASTKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000182 0
183};
184static const char * const DiagnosticTextSema[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000185#include "clang/Basic/DiagnosticSemaKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000186 0
187};
188static const char * const DiagnosticTextAnalysis[] = {
Sebastian Redl4d7a0892009-03-19 23:18:26 +0000189#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000190 0
191};
192#undef DIAG
Reid Spencer5f016e22007-07-11 17:01:13 +0000193
Chris Lattner182745a2007-12-02 01:09:57 +0000194//===----------------------------------------------------------------------===//
195// Custom Diagnostic information
196//===----------------------------------------------------------------------===//
197
198namespace clang {
199 namespace diag {
200 class CustomDiagInfo {
201 typedef std::pair<Diagnostic::Level, std::string> DiagDesc;
202 std::vector<DiagDesc> DiagInfo;
203 std::map<DiagDesc, unsigned> DiagIDs;
204 public:
205
206 /// getDescription - Return the description of the specified custom
207 /// diagnostic.
208 const char *getDescription(unsigned DiagID) const {
Chris Lattner88eccaf2009-01-29 06:55:46 +0000209 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
Chris Lattner182745a2007-12-02 01:09:57 +0000210 "Invalid diagnosic ID");
Chris Lattner88eccaf2009-01-29 06:55:46 +0000211 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second.c_str();
Chris Lattner182745a2007-12-02 01:09:57 +0000212 }
213
214 /// getLevel - Return the level of the specified custom diagnostic.
215 Diagnostic::Level getLevel(unsigned DiagID) const {
Chris Lattner88eccaf2009-01-29 06:55:46 +0000216 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
Chris Lattner182745a2007-12-02 01:09:57 +0000217 "Invalid diagnosic ID");
Chris Lattner88eccaf2009-01-29 06:55:46 +0000218 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
Chris Lattner182745a2007-12-02 01:09:57 +0000219 }
220
Chris Lattnera1f23cc2008-10-17 21:24:47 +0000221 unsigned getOrCreateDiagID(Diagnostic::Level L, const char *Message,
222 Diagnostic &Diags) {
Chris Lattner182745a2007-12-02 01:09:57 +0000223 DiagDesc D(L, Message);
224 // Check to see if it already exists.
225 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
226 if (I != DiagIDs.end() && I->first == D)
227 return I->second;
228
229 // If not, assign a new ID.
Chris Lattner88eccaf2009-01-29 06:55:46 +0000230 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
Chris Lattner182745a2007-12-02 01:09:57 +0000231 DiagIDs.insert(std::make_pair(D, ID));
232 DiagInfo.push_back(D);
Chris Lattnera1f23cc2008-10-17 21:24:47 +0000233
234 // If this is a warning, and all warnings are supposed to map to errors,
235 // insert the mapping now.
236 if (L == Diagnostic::Warning && Diags.getWarningsAsErrors())
237 Diags.setDiagnosticMapping((diag::kind)ID, diag::MAP_ERROR);
Chris Lattner182745a2007-12-02 01:09:57 +0000238 return ID;
239 }
240 };
241
242 } // end diag namespace
243} // end clang namespace
244
245
246//===----------------------------------------------------------------------===//
247// Common Diagnostic implementation
248//===----------------------------------------------------------------------===//
249
Chris Lattner3fdf4b02008-11-23 09:21:17 +0000250static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT,
251 const char *Modifier, unsigned ML,
252 const char *Argument, unsigned ArgLen,
Chris Lattner92dd3862009-02-19 23:53:20 +0000253 llvm::SmallVectorImpl<char> &Output,
254 void *Cookie) {
Chris Lattner3fdf4b02008-11-23 09:21:17 +0000255 const char *Str = "<can't format argument>";
Chris Lattner22caddc2008-11-23 09:13:29 +0000256 Output.append(Str, Str+strlen(Str));
257}
258
259
Ted Kremenekb4398aa2008-08-07 17:49:57 +0000260Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000261 AllExtensionsSilenced = 0;
Chris Lattner5b4681c2008-05-29 15:36:45 +0000262 IgnoreAllWarnings = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000263 WarningsAsErrors = false;
Daniel Dunbar2fe09972008-09-12 18:10:20 +0000264 SuppressSystemWarnings = false;
Chris Lattnerb54b2762009-04-16 05:04:32 +0000265 ExtBehavior = Ext_Ignore;
Reid Spencer5f016e22007-07-11 17:01:13 +0000266
267 ErrorOccurred = false;
Chris Lattner15221422009-02-06 04:16:02 +0000268 FatalErrorOccurred = false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000269 NumDiagnostics = 0;
270 NumErrors = 0;
Chris Lattner182745a2007-12-02 01:09:57 +0000271 CustomDiagInfo = 0;
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000272 CurDiagID = ~0U;
Douglas Gregor525c4b02009-03-19 18:55:06 +0000273 LastDiagLevel = Ignored;
Chris Lattner22caddc2008-11-23 09:13:29 +0000274
Chris Lattner3fdf4b02008-11-23 09:21:17 +0000275 ArgToStringFn = DummyArgToStringFn;
Chris Lattner92dd3862009-02-19 23:53:20 +0000276 ArgToStringCookie = 0;
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000277
Chris Lattner691f1ae2009-04-16 04:12:40 +0000278 // Set all mappings to 'unset'.
279 memset(DiagMappings, 0, sizeof(DiagMappings));
Reid Spencer5f016e22007-07-11 17:01:13 +0000280}
281
Chris Lattner182745a2007-12-02 01:09:57 +0000282Diagnostic::~Diagnostic() {
283 delete CustomDiagInfo;
284}
285
286/// getCustomDiagID - Return an ID for a diagnostic with the specified message
287/// and level. If this is the first request for this diagnosic, it is
288/// registered and created, otherwise the existing ID is returned.
289unsigned Diagnostic::getCustomDiagID(Level L, const char *Message) {
290 if (CustomDiagInfo == 0)
291 CustomDiagInfo = new diag::CustomDiagInfo();
Chris Lattnera1f23cc2008-10-17 21:24:47 +0000292 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this);
Chris Lattner182745a2007-12-02 01:09:57 +0000293}
294
295
Chris Lattnerf5d23282009-02-17 06:49:55 +0000296/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
297/// level of the specified diagnostic ID is a Warning or Extension.
298/// This only works on builtin diagnostics, not custom ones, and is not legal to
299/// call on NOTEs.
300bool Diagnostic::isBuiltinWarningOrExtension(unsigned DiagID) {
Chris Lattner8a941e02009-04-15 16:56:26 +0000301 return DiagID < diag::DIAG_UPPER_LIMIT &&
302 getBuiltinDiagClass(DiagID) != CLASS_ERROR;
Reid Spencer5f016e22007-07-11 17:01:13 +0000303}
304
Douglas Gregoree1828a2009-03-10 18:03:33 +0000305/// \brief Determine whether the given built-in diagnostic ID is a
306/// Note.
307bool Diagnostic::isBuiltinNote(unsigned DiagID) {
Chris Lattner8a941e02009-04-15 16:56:26 +0000308 return DiagID < diag::DIAG_UPPER_LIMIT &&
309 getBuiltinDiagClass(DiagID) == CLASS_NOTE;
Douglas Gregoree1828a2009-03-10 18:03:33 +0000310}
311
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000312/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
313/// ID is for an extension of some sort.
314///
315bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) {
Chris Lattner8a941e02009-04-15 16:56:26 +0000316 return DiagID < diag::DIAG_UPPER_LIMIT &&
317 getBuiltinDiagClass(DiagID) == CLASS_EXTENSION;
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000318}
319
Reid Spencer5f016e22007-07-11 17:01:13 +0000320
321/// getDescription - Given a diagnostic ID, return a description of the
322/// issue.
Chris Lattner0a14eee2008-11-18 07:04:44 +0000323const char *Diagnostic::getDescription(unsigned DiagID) const {
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +0000324 if (DiagID < diag::DIAG_START_DRIVER)
Chris Lattnerf5d23282009-02-17 06:49:55 +0000325 return DiagnosticTextCommon[DiagID];
Daniel Dunbar50f4f462009-03-12 10:14:16 +0000326 else if (DiagID < diag::DIAG_START_FRONTEND)
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +0000327 return DiagnosticTextDriver[DiagID - diag::DIAG_START_DRIVER - 1];
Daniel Dunbar50f4f462009-03-12 10:14:16 +0000328 else if (DiagID < diag::DIAG_START_LEX)
329 return DiagnosticTextFrontend[DiagID - diag::DIAG_START_FRONTEND - 1];
Chris Lattnerf5d23282009-02-17 06:49:55 +0000330 else if (DiagID < diag::DIAG_START_PARSE)
331 return DiagnosticTextLex[DiagID - diag::DIAG_START_LEX - 1];
332 else if (DiagID < diag::DIAG_START_AST)
333 return DiagnosticTextParse[DiagID - diag::DIAG_START_PARSE - 1];
334 else if (DiagID < diag::DIAG_START_SEMA)
335 return DiagnosticTextAST[DiagID - diag::DIAG_START_AST - 1];
336 else if (DiagID < diag::DIAG_START_ANALYSIS)
337 return DiagnosticTextSema[DiagID - diag::DIAG_START_SEMA - 1];
338 else if (DiagID < diag::DIAG_UPPER_LIMIT)
339 return DiagnosticTextAnalysis[DiagID - diag::DIAG_START_ANALYSIS - 1];
Chris Lattner20c6b3b2009-01-27 18:30:58 +0000340 return CustomDiagInfo->getDescription(DiagID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000341}
342
343/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
344/// object, classify the specified diagnostic ID into a Level, consumable by
345/// the DiagnosticClient.
346Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
Chris Lattner182745a2007-12-02 01:09:57 +0000347 // Handle custom diagnostics, which cannot be mapped.
Chris Lattner19e8e2c2009-01-29 17:46:13 +0000348 if (DiagID >= diag::DIAG_UPPER_LIMIT)
Chris Lattner182745a2007-12-02 01:09:57 +0000349 return CustomDiagInfo->getLevel(DiagID);
Chris Lattner07506182007-11-30 22:53:43 +0000350
351 unsigned DiagClass = getBuiltinDiagClass(DiagID);
Chris Lattner8a941e02009-04-15 16:56:26 +0000352 assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
Chris Lattnerf5d23282009-02-17 06:49:55 +0000353 return getDiagnosticLevel(DiagID, DiagClass);
354}
355
356/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
357/// object, classify the specified diagnostic ID into a Level, consumable by
358/// the DiagnosticClient.
359Diagnostic::Level
360Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000361 // Specific non-error diagnostics may be mapped to various levels from ignored
Chris Lattnerf5d23282009-02-17 06:49:55 +0000362 // to error. Errors can only be mapped to fatal.
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000363 Diagnostic::Level Result = Diagnostic::Fatal;
Chris Lattner691f1ae2009-04-16 04:12:40 +0000364
365 // Get the mapping information, if unset, compute it lazily.
366 unsigned MappingInfo = getDiagnosticMappingInfo((diag::kind)DiagID);
367 if (MappingInfo == 0) {
368 MappingInfo = GetDefaultDiagMapping(DiagID);
369 setDiagnosticMappingInternal(DiagID, MappingInfo, false);
370 }
371
372 switch (MappingInfo & 7) {
373 default: assert(0 && "Unknown mapping!");
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000374 case diag::MAP_IGNORE:
Chris Lattnerb54b2762009-04-16 05:04:32 +0000375 // Ignore this, unless this is an extension diagnostic and we're mapping
376 // them onto warnings or errors.
377 if (!isBuiltinExtensionDiag(DiagID) || // Not an extension
378 ExtBehavior == Ext_Ignore || // Extensions ignored anyway
379 (MappingInfo & 8) != 0) // User explicitly mapped it.
380 return Diagnostic::Ignored;
381 Result = Diagnostic::Warning;
382 if (ExtBehavior == Ext_Error) Result = Diagnostic::Error;
383 break;
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000384 case diag::MAP_ERROR:
385 Result = Diagnostic::Error;
386 break;
387 case diag::MAP_FATAL:
388 Result = Diagnostic::Fatal;
389 break;
390 case diag::MAP_WARNING:
391 // If warnings are globally mapped to ignore or error, do it.
Chris Lattner5b4681c2008-05-29 15:36:45 +0000392 if (IgnoreAllWarnings)
393 return Diagnostic::Ignored;
Chris Lattner2b07d8f2009-04-16 04:32:54 +0000394
395 Result = Diagnostic::Warning;
Chris Lattnerb54b2762009-04-16 05:04:32 +0000396
397 // If this is an extension diagnostic and we're in -pedantic-error mode, and
398 // if the user didn't explicitly map it, upgrade to an error.
399 if (ExtBehavior == Ext_Error &&
400 (MappingInfo & 8) == 0 &&
401 isBuiltinExtensionDiag(DiagID))
402 Result = Diagnostic::Error;
403
Chris Lattner2b07d8f2009-04-16 04:32:54 +0000404 if (WarningsAsErrors)
405 Result = Diagnostic::Error;
406 break;
Chris Lattnerb54b2762009-04-16 05:04:32 +0000407
Chris Lattner2b07d8f2009-04-16 04:32:54 +0000408 case diag::MAP_WARNING_NO_WERROR:
409 // Diagnostics specified with -Wno-error=foo should be set to warnings, but
410 // not be adjusted by -Werror or -pedantic-errors.
411 Result = Diagnostic::Warning;
412
413 // If warnings are globally mapped to ignore or error, do it.
414 if (IgnoreAllWarnings)
415 return Diagnostic::Ignored;
416
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000417 break;
Chris Lattner5b4681c2008-05-29 15:36:45 +0000418 }
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000419
420 // Okay, we're about to return this as a "diagnostic to emit" one last check:
421 // if this is any sort of extension warning, and if we're in an __extension__
422 // block, silence it.
423 if (AllExtensionsSilenced && isBuiltinExtensionDiag(DiagID))
424 return Diagnostic::Ignored;
Reid Spencer5f016e22007-07-11 17:01:13 +0000425
Chris Lattner27ceb9d2009-04-15 07:01:18 +0000426 return Result;
Reid Spencer5f016e22007-07-11 17:01:13 +0000427}
428
Chris Lattner0a14eee2008-11-18 07:04:44 +0000429/// ProcessDiag - This is the method used to report a diagnostic that is
430/// finally fully formed.
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000431void Diagnostic::ProcessDiag() {
432 DiagnosticInfo Info(this);
Douglas Gregor525c4b02009-03-19 18:55:06 +0000433
Reid Spencer5f016e22007-07-11 17:01:13 +0000434 // Figure out the diagnostic level of this message.
Chris Lattnerf5d23282009-02-17 06:49:55 +0000435 Diagnostic::Level DiagLevel;
436 unsigned DiagID = Info.getID();
Reid Spencer5f016e22007-07-11 17:01:13 +0000437
Chris Lattnerf5d23282009-02-17 06:49:55 +0000438 // ShouldEmitInSystemHeader - True if this diagnostic should be produced even
439 // in a system header.
440 bool ShouldEmitInSystemHeader;
441
442 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
443 // Handle custom diagnostics, which cannot be mapped.
444 DiagLevel = CustomDiagInfo->getLevel(DiagID);
445
446 // Custom diagnostics always are emitted in system headers.
447 ShouldEmitInSystemHeader = true;
448 } else {
449 // Get the class of the diagnostic. If this is a NOTE, map it onto whatever
450 // the diagnostic level was for the previous diagnostic so that it is
451 // filtered the same as the previous diagnostic.
452 unsigned DiagClass = getBuiltinDiagClass(DiagID);
Chris Lattner8a941e02009-04-15 16:56:26 +0000453 if (DiagClass == CLASS_NOTE) {
Chris Lattnerf5d23282009-02-17 06:49:55 +0000454 DiagLevel = Diagnostic::Note;
455 ShouldEmitInSystemHeader = false; // extra consideration is needed
456 } else {
457 // If this is not an error and we are in a system header, we ignore it.
458 // Check the original Diag ID here, because we also want to ignore
459 // extensions and warnings in -Werror and -pedantic-errors modes, which
460 // *map* warnings/extensions to errors.
Chris Lattner8a941e02009-04-15 16:56:26 +0000461 ShouldEmitInSystemHeader = DiagClass == CLASS_ERROR;
Chris Lattnerf5d23282009-02-17 06:49:55 +0000462
463 DiagLevel = getDiagnosticLevel(DiagID, DiagClass);
464 }
465 }
466
Douglas Gregor525c4b02009-03-19 18:55:06 +0000467 if (DiagLevel != Diagnostic::Note) {
468 // Record that a fatal error occurred only when we see a second
469 // non-note diagnostic. This allows notes to be attached to the
470 // fatal error, but suppresses any diagnostics that follow those
471 // notes.
472 if (LastDiagLevel == Diagnostic::Fatal)
473 FatalErrorOccurred = true;
474
Chris Lattnerf5d23282009-02-17 06:49:55 +0000475 LastDiagLevel = DiagLevel;
Douglas Gregor525c4b02009-03-19 18:55:06 +0000476 }
477
478 // If a fatal error has already been emitted, silence all subsequent
479 // diagnostics.
480 if (FatalErrorOccurred)
481 return;
482
Chris Lattnerf5d23282009-02-17 06:49:55 +0000483 // If the client doesn't care about this message, don't issue it. If this is
484 // a note and the last real diagnostic was ignored, ignore it too.
485 if (DiagLevel == Diagnostic::Ignored ||
486 (DiagLevel == Diagnostic::Note && LastDiagLevel == Diagnostic::Ignored))
Reid Spencer5f016e22007-07-11 17:01:13 +0000487 return;
Nico Weber7bfaaae2008-08-10 19:59:06 +0000488
Chris Lattnerf5d23282009-02-17 06:49:55 +0000489 // If this diagnostic is in a system header and is not a clang error, suppress
490 // it.
491 if (SuppressSystemWarnings && !ShouldEmitInSystemHeader &&
Chris Lattner0a14eee2008-11-18 07:04:44 +0000492 Info.getLocation().isValid() &&
Chris Lattnerf5d23282009-02-17 06:49:55 +0000493 Info.getLocation().getSpellingLoc().isInSystemHeader() &&
Chris Lattner336f26b2009-02-17 06:52:20 +0000494 (DiagLevel != Diagnostic::Note || LastDiagLevel == Diagnostic::Ignored)) {
495 LastDiagLevel = Diagnostic::Ignored;
Chris Lattner7097d912008-02-03 09:00:04 +0000496 return;
Chris Lattner336f26b2009-02-17 06:52:20 +0000497 }
Chris Lattnerf5d23282009-02-17 06:49:55 +0000498
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 if (DiagLevel >= Diagnostic::Error) {
500 ErrorOccurred = true;
Chris Lattner0a14eee2008-11-18 07:04:44 +0000501 ++NumErrors;
Reid Spencer5f016e22007-07-11 17:01:13 +0000502 }
Chris Lattnerf5d23282009-02-17 06:49:55 +0000503
Reid Spencer5f016e22007-07-11 17:01:13 +0000504 // Finally, report it.
Chris Lattner0a14eee2008-11-18 07:04:44 +0000505 Client->HandleDiagnostic(DiagLevel, Info);
Ted Kremenekcabe6682009-01-23 20:28:53 +0000506 if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics;
Douglas Gregoree1828a2009-03-10 18:03:33 +0000507
Douglas Gregoree1828a2009-03-10 18:03:33 +0000508 CurDiagID = ~0U;
Reid Spencer5f016e22007-07-11 17:01:13 +0000509}
510
Nico Weber7bfaaae2008-08-10 19:59:06 +0000511
Reid Spencer5f016e22007-07-11 17:01:13 +0000512DiagnosticClient::~DiagnosticClient() {}
Nico Weber7bfaaae2008-08-10 19:59:06 +0000513
Chris Lattnerf4c83962008-11-19 06:51:40 +0000514
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000515/// ModifierIs - Return true if the specified modifier matches specified string.
516template <std::size_t StrLen>
517static bool ModifierIs(const char *Modifier, unsigned ModifierLen,
518 const char (&Str)[StrLen]) {
519 return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1);
520}
521
522/// HandleSelectModifier - Handle the integer 'select' modifier. This is used
523/// like this: %select{foo|bar|baz}2. This means that the integer argument
524/// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'.
525/// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'.
526/// This is very useful for certain classes of variant diagnostics.
527static void HandleSelectModifier(unsigned ValNo,
528 const char *Argument, unsigned ArgumentLen,
529 llvm::SmallVectorImpl<char> &OutStr) {
530 const char *ArgumentEnd = Argument+ArgumentLen;
531
532 // Skip over 'ValNo' |'s.
533 while (ValNo) {
534 const char *NextVal = std::find(Argument, ArgumentEnd, '|');
535 assert(NextVal != ArgumentEnd && "Value for integer select modifier was"
536 " larger than the number of options in the diagnostic string!");
537 Argument = NextVal+1; // Skip this string.
538 --ValNo;
539 }
540
541 // Get the end of the value. This is either the } or the |.
542 const char *EndPtr = std::find(Argument, ArgumentEnd, '|');
543 // Add the value to the output string.
544 OutStr.append(Argument, EndPtr);
545}
546
547/// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the
548/// letter 's' to the string if the value is not 1. This is used in cases like
549/// this: "you idiot, you have %4 parameter%s4!".
550static void HandleIntegerSModifier(unsigned ValNo,
551 llvm::SmallVectorImpl<char> &OutStr) {
552 if (ValNo != 1)
553 OutStr.push_back('s');
554}
555
556
Sebastian Redle4c452c2008-11-22 13:44:36 +0000557/// PluralNumber - Parse an unsigned integer and advance Start.
Chris Lattnerd2aa7c92009-04-15 17:13:42 +0000558static unsigned PluralNumber(const char *&Start, const char *End) {
Sebastian Redle4c452c2008-11-22 13:44:36 +0000559 // Programming 101: Parse a decimal number :-)
560 unsigned Val = 0;
561 while (Start != End && *Start >= '0' && *Start <= '9') {
562 Val *= 10;
563 Val += *Start - '0';
564 ++Start;
565 }
566 return Val;
567}
568
569/// TestPluralRange - Test if Val is in the parsed range. Modifies Start.
Chris Lattnerd2aa7c92009-04-15 17:13:42 +0000570static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) {
Sebastian Redle4c452c2008-11-22 13:44:36 +0000571 if (*Start != '[') {
572 unsigned Ref = PluralNumber(Start, End);
573 return Ref == Val;
574 }
575
576 ++Start;
577 unsigned Low = PluralNumber(Start, End);
578 assert(*Start == ',' && "Bad plural expression syntax: expected ,");
579 ++Start;
580 unsigned High = PluralNumber(Start, End);
581 assert(*Start == ']' && "Bad plural expression syntax: expected )");
582 ++Start;
583 return Low <= Val && Val <= High;
584}
585
586/// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
Chris Lattnerd2aa7c92009-04-15 17:13:42 +0000587static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) {
Sebastian Redle4c452c2008-11-22 13:44:36 +0000588 // Empty condition?
589 if (*Start == ':')
590 return true;
591
592 while (1) {
593 char C = *Start;
594 if (C == '%') {
595 // Modulo expression
596 ++Start;
597 unsigned Arg = PluralNumber(Start, End);
598 assert(*Start == '=' && "Bad plural expression syntax: expected =");
599 ++Start;
600 unsigned ValMod = ValNo % Arg;
601 if (TestPluralRange(ValMod, Start, End))
602 return true;
603 } else {
Sebastian Redle2065322008-11-27 07:28:14 +0000604 assert((C == '[' || (C >= '0' && C <= '9')) &&
Sebastian Redle4c452c2008-11-22 13:44:36 +0000605 "Bad plural expression syntax: unexpected character");
606 // Range expression
607 if (TestPluralRange(ValNo, Start, End))
608 return true;
609 }
610
611 // Scan for next or-expr part.
612 Start = std::find(Start, End, ',');
613 if(Start == End)
614 break;
615 ++Start;
616 }
617 return false;
618}
619
620/// HandlePluralModifier - Handle the integer 'plural' modifier. This is used
621/// for complex plural forms, or in languages where all plurals are complex.
622/// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are
623/// conditions that are tested in order, the form corresponding to the first
624/// that applies being emitted. The empty condition is always true, making the
625/// last form a default case.
626/// Conditions are simple boolean expressions, where n is the number argument.
627/// Here are the rules.
628/// condition := expression | empty
629/// empty := -> always true
630/// expression := numeric [',' expression] -> logical or
631/// numeric := range -> true if n in range
632/// | '%' number '=' range -> true if n % number in range
633/// range := number
634/// | '[' number ',' number ']' -> ranges are inclusive both ends
635///
636/// Here are some examples from the GNU gettext manual written in this form:
637/// English:
638/// {1:form0|:form1}
639/// Latvian:
640/// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0}
641/// Gaeilge:
642/// {1:form0|2:form1|:form2}
643/// Romanian:
644/// {1:form0|0,%100=[1,19]:form1|:form2}
645/// Lithuanian:
646/// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1}
647/// Russian (requires repeated form):
648/// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2}
649/// Slovak
650/// {1:form0|[2,4]:form1|:form2}
651/// Polish (requires repeated form):
652/// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2}
653static void HandlePluralModifier(unsigned ValNo,
654 const char *Argument, unsigned ArgumentLen,
Chris Lattnerb54b2762009-04-16 05:04:32 +0000655 llvm::SmallVectorImpl<char> &OutStr) {
Sebastian Redle4c452c2008-11-22 13:44:36 +0000656 const char *ArgumentEnd = Argument + ArgumentLen;
657 while (1) {
658 assert(Argument < ArgumentEnd && "Plural expression didn't match.");
659 const char *ExprEnd = Argument;
660 while (*ExprEnd != ':') {
661 assert(ExprEnd != ArgumentEnd && "Plural missing expression end");
662 ++ExprEnd;
663 }
664 if (EvalPluralExpr(ValNo, Argument, ExprEnd)) {
665 Argument = ExprEnd + 1;
666 ExprEnd = std::find(Argument, ArgumentEnd, '|');
667 OutStr.append(Argument, ExprEnd);
668 return;
669 }
670 Argument = std::find(Argument, ArgumentEnd - 1, '|') + 1;
671 }
672}
673
674
Chris Lattnerf4c83962008-11-19 06:51:40 +0000675/// FormatDiagnostic - Format this diagnostic into a string, substituting the
676/// formal arguments into the %0 slots. The result is appended onto the Str
677/// array.
678void DiagnosticInfo::
679FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
680 const char *DiagStr = getDiags()->getDescription(getID());
681 const char *DiagEnd = DiagStr+strlen(DiagStr);
Nico Weber7bfaaae2008-08-10 19:59:06 +0000682
Chris Lattnerf4c83962008-11-19 06:51:40 +0000683 while (DiagStr != DiagEnd) {
684 if (DiagStr[0] != '%') {
685 // Append non-%0 substrings to Str if we have one.
686 const char *StrEnd = std::find(DiagStr, DiagEnd, '%');
687 OutStr.append(DiagStr, StrEnd);
688 DiagStr = StrEnd;
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000689 continue;
Chris Lattnerf4c83962008-11-19 06:51:40 +0000690 } else if (DiagStr[1] == '%') {
691 OutStr.push_back('%'); // %% -> %.
692 DiagStr += 2;
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000693 continue;
694 }
695
696 // Skip the %.
697 ++DiagStr;
698
699 // This must be a placeholder for a diagnostic argument. The format for a
700 // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0".
701 // The digit is a number from 0-9 indicating which argument this comes from.
702 // The modifier is a string of digits from the set [-a-z]+, arguments is a
703 // brace enclosed string.
704 const char *Modifier = 0, *Argument = 0;
705 unsigned ModifierLen = 0, ArgumentLen = 0;
706
707 // Check to see if we have a modifier. If so eat it.
708 if (!isdigit(DiagStr[0])) {
709 Modifier = DiagStr;
710 while (DiagStr[0] == '-' ||
711 (DiagStr[0] >= 'a' && DiagStr[0] <= 'z'))
712 ++DiagStr;
713 ModifierLen = DiagStr-Modifier;
Chris Lattnerf4c83962008-11-19 06:51:40 +0000714
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000715 // If we have an argument, get it next.
716 if (DiagStr[0] == '{') {
717 ++DiagStr; // Skip {.
718 Argument = DiagStr;
719
720 for (; DiagStr[0] != '}'; ++DiagStr)
721 assert(DiagStr[0] && "Mismatched {}'s in diagnostic string!");
722 ArgumentLen = DiagStr-Argument;
723 ++DiagStr; // Skip }.
Chris Lattnerf4c83962008-11-19 06:51:40 +0000724 }
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000725 }
726
727 assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic");
Chris Lattner22caddc2008-11-23 09:13:29 +0000728 unsigned ArgNo = *DiagStr++ - '0';
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000729
Chris Lattner22caddc2008-11-23 09:13:29 +0000730 switch (getArgKind(ArgNo)) {
Chris Lattner08631c52008-11-23 21:45:46 +0000731 // ---- STRINGS ----
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000732 case Diagnostic::ak_std_string: {
Chris Lattner22caddc2008-11-23 09:13:29 +0000733 const std::string &S = getArgStdStr(ArgNo);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000734 assert(ModifierLen == 0 && "No modifiers for strings yet");
735 OutStr.append(S.begin(), S.end());
736 break;
737 }
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000738 case Diagnostic::ak_c_string: {
Chris Lattner22caddc2008-11-23 09:13:29 +0000739 const char *S = getArgCStr(ArgNo);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000740 assert(ModifierLen == 0 && "No modifiers for strings yet");
741 OutStr.append(S, S + strlen(S));
742 break;
743 }
Chris Lattner08631c52008-11-23 21:45:46 +0000744 // ---- INTEGERS ----
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000745 case Diagnostic::ak_sint: {
Chris Lattner22caddc2008-11-23 09:13:29 +0000746 int Val = getArgSInt(ArgNo);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000747
748 if (ModifierIs(Modifier, ModifierLen, "select")) {
749 HandleSelectModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
750 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
751 HandleIntegerSModifier(Val, OutStr);
Sebastian Redle4c452c2008-11-22 13:44:36 +0000752 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
753 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000754 } else {
755 assert(ModifierLen == 0 && "Unknown integer modifier");
Chris Lattner30bc9652008-11-19 07:22:31 +0000756 // FIXME: Optimize
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000757 std::string S = llvm::itostr(Val);
Chris Lattner30bc9652008-11-19 07:22:31 +0000758 OutStr.append(S.begin(), S.end());
Chris Lattner30bc9652008-11-19 07:22:31 +0000759 }
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000760 break;
761 }
Chris Lattner3cbfe2c2008-11-22 00:59:29 +0000762 case Diagnostic::ak_uint: {
Chris Lattner22caddc2008-11-23 09:13:29 +0000763 unsigned Val = getArgUInt(ArgNo);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000764
765 if (ModifierIs(Modifier, ModifierLen, "select")) {
766 HandleSelectModifier(Val, Argument, ArgumentLen, OutStr);
767 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
768 HandleIntegerSModifier(Val, OutStr);
Sebastian Redle4c452c2008-11-22 13:44:36 +0000769 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
770 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000771 } else {
772 assert(ModifierLen == 0 && "Unknown integer modifier");
773
Chris Lattner30bc9652008-11-19 07:22:31 +0000774 // FIXME: Optimize
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000775 std::string S = llvm::utostr_32(Val);
Chris Lattner30bc9652008-11-19 07:22:31 +0000776 OutStr.append(S.begin(), S.end());
Chris Lattner30bc9652008-11-19 07:22:31 +0000777 }
Chris Lattner22caddc2008-11-23 09:13:29 +0000778 break;
Chris Lattneraf7ae4e2008-11-21 07:50:02 +0000779 }
Chris Lattner08631c52008-11-23 21:45:46 +0000780 // ---- NAMES and TYPES ----
781 case Diagnostic::ak_identifierinfo: {
Chris Lattner08631c52008-11-23 21:45:46 +0000782 const IdentifierInfo *II = getArgIdentifier(ArgNo);
783 assert(ModifierLen == 0 && "No modifiers for strings yet");
Chris Lattnerd0344a42009-02-19 23:45:49 +0000784 OutStr.push_back('\'');
Chris Lattner08631c52008-11-23 21:45:46 +0000785 OutStr.append(II->getName(), II->getName() + II->getLength());
786 OutStr.push_back('\'');
787 break;
788 }
Chris Lattner22caddc2008-11-23 09:13:29 +0000789 case Diagnostic::ak_qualtype:
Chris Lattner011bb4e2008-11-23 20:28:15 +0000790 case Diagnostic::ak_declarationname:
Douglas Gregor47b9a1c2009-02-04 17:27:36 +0000791 case Diagnostic::ak_nameddecl:
Chris Lattner3fdf4b02008-11-23 09:21:17 +0000792 getDiags()->ConvertArgToString(getArgKind(ArgNo), getRawArg(ArgNo),
793 Modifier, ModifierLen,
794 Argument, ArgumentLen, OutStr);
Chris Lattner22caddc2008-11-23 09:13:29 +0000795 break;
Nico Weber7bfaaae2008-08-10 19:59:06 +0000796 }
797 }
Nico Weber7bfaaae2008-08-10 19:59:06 +0000798}
Ted Kremenekcabe6682009-01-23 20:28:53 +0000799
800/// IncludeInDiagnosticCounts - This method (whose default implementation
801/// returns true) indicates whether the diagnostics handled by this
802/// DiagnosticClient should be included in the number of diagnostics
803/// reported by Diagnostic.
804bool DiagnosticClient::IncludeInDiagnosticCounts() const { return true; }