blob: 31d3b34c816aeec97a777126107cf1a23d9e9afb [file] [log] [blame]
Chris Lattner22eb9722006-06-18 05:43:12 +00001//===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner22eb9722006-06-18 05:43:12 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Diagnostic-related interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Basic/Diagnostic.h"
Chris Lattnere007de32009-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
Douglas Gregorac0605e2010-01-28 06:00:51 +000024#include "clang/Basic/FileManager.h"
Chris Lattnerb91fd172008-11-19 07:32:16 +000025#include "clang/Basic/IdentifierTable.h"
Chris Lattner22eb9722006-06-18 05:43:12 +000026#include "clang/Basic/SourceLocation.h"
Douglas Gregorac0605e2010-01-28 06:00:51 +000027#include "clang/Basic/SourceManager.h"
Chris Lattner23be0672008-11-19 06:51:40 +000028#include "llvm/ADT/SmallVector.h"
Chris Lattner91aea712008-11-19 07:22:31 +000029#include "llvm/ADT/StringExtras.h"
Daniel Dunbare3633792009-10-17 18:12:14 +000030#include "llvm/Support/raw_ostream.h"
Chris Lattnere6535cf2007-12-02 01:09:57 +000031#include <vector>
32#include <map>
Chris Lattner0d799d32008-03-10 17:04:53 +000033#include <cstring>
Chris Lattner22eb9722006-06-18 05:43:12 +000034using namespace clang;
35
Chris Lattnere6535cf2007-12-02 01:09:57 +000036//===----------------------------------------------------------------------===//
37// Builtin Diagnostic information
38//===----------------------------------------------------------------------===//
39
Chris Lattner6c440322009-04-16 06:07:15 +000040// Diagnostic classes.
41enum {
42 CLASS_NOTE = 0x01,
43 CLASS_WARNING = 0x02,
44 CLASS_EXTENSION = 0x03,
45 CLASS_ERROR = 0x04
46};
Chris Lattnere007de32009-04-15 07:01:18 +000047
Chris Lattner6a64cc62009-04-16 06:00:24 +000048struct StaticDiagInfoRec {
Chris Lattner6c440322009-04-16 06:07:15 +000049 unsigned short DiagID;
50 unsigned Mapping : 3;
51 unsigned Class : 3;
Douglas Gregor33834512009-06-14 07:33:30 +000052 bool SFINAE : 1;
Chris Lattner6c440322009-04-16 06:07:15 +000053 const char *Description;
Chris Lattner6a64cc62009-04-16 06:00:24 +000054 const char *OptionGroup;
Mike Stump11289f42009-09-09 15:08:12 +000055
Chris Lattner2d49eed2009-04-16 06:13:46 +000056 bool operator<(const StaticDiagInfoRec &RHS) const {
57 return DiagID < RHS.DiagID;
58 }
59 bool operator>(const StaticDiagInfoRec &RHS) const {
60 return DiagID > RHS.DiagID;
61 }
Chris Lattnere007de32009-04-15 07:01:18 +000062};
63
Chris Lattner6a64cc62009-04-16 06:00:24 +000064static const StaticDiagInfoRec StaticDiagInfo[] = {
Douglas Gregor33834512009-06-14 07:33:30 +000065#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,SFINAE) \
66 { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, DESC, GROUP },
Chris Lattnere007de32009-04-15 07:01:18 +000067#include "clang/Basic/DiagnosticCommonKinds.inc"
68#include "clang/Basic/DiagnosticDriverKinds.inc"
69#include "clang/Basic/DiagnosticFrontendKinds.inc"
70#include "clang/Basic/DiagnosticLexKinds.inc"
71#include "clang/Basic/DiagnosticParseKinds.inc"
72#include "clang/Basic/DiagnosticASTKinds.inc"
73#include "clang/Basic/DiagnosticSemaKinds.inc"
74#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Douglas Gregor33834512009-06-14 07:33:30 +000075 { 0, 0, 0, 0, 0, 0}
Chris Lattnere007de32009-04-15 07:01:18 +000076};
Chris Lattnere6c831d2009-04-15 16:56:26 +000077#undef DIAG
Chris Lattnere007de32009-04-15 07:01:18 +000078
Chris Lattner2d49eed2009-04-16 06:13:46 +000079/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID,
80/// or null if the ID is invalid.
Chris Lattner6a64cc62009-04-16 06:00:24 +000081static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
Chris Lattner2d49eed2009-04-16 06:13:46 +000082 unsigned NumDiagEntries = sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1;
83
84 // If assertions are enabled, verify that the StaticDiagInfo array is sorted.
85#ifndef NDEBUG
86 static bool IsFirst = true;
87 if (IsFirst) {
Chris Lattnercb4e68c2009-10-16 02:34:51 +000088 for (unsigned i = 1; i != NumDiagEntries; ++i) {
89 assert(StaticDiagInfo[i-1].DiagID != StaticDiagInfo[i].DiagID &&
90 "Diag ID conflict, the enums at the start of clang::diag (in "
91 "Diagnostic.h) probably need to be increased");
92
Chris Lattner2d49eed2009-04-16 06:13:46 +000093 assert(StaticDiagInfo[i-1] < StaticDiagInfo[i] &&
94 "Improperly sorted diag info");
Chris Lattnercb4e68c2009-10-16 02:34:51 +000095 }
Chris Lattner2d49eed2009-04-16 06:13:46 +000096 IsFirst = false;
97 }
98#endif
Mike Stump11289f42009-09-09 15:08:12 +000099
Chris Lattner2d49eed2009-04-16 06:13:46 +0000100 // Search the diagnostic table with a binary search.
Douglas Gregor33834512009-06-14 07:33:30 +0000101 StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0, 0 };
Mike Stump11289f42009-09-09 15:08:12 +0000102
Chris Lattner2d49eed2009-04-16 06:13:46 +0000103 const StaticDiagInfoRec *Found =
104 std::lower_bound(StaticDiagInfo, StaticDiagInfo + NumDiagEntries, Find);
105 if (Found == StaticDiagInfo + NumDiagEntries ||
106 Found->DiagID != DiagID)
107 return 0;
Mike Stump11289f42009-09-09 15:08:12 +0000108
Chris Lattner2d49eed2009-04-16 06:13:46 +0000109 return Found;
Chris Lattner6a64cc62009-04-16 06:00:24 +0000110}
111
112static unsigned GetDefaultDiagMapping(unsigned DiagID) {
113 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Chris Lattner6c440322009-04-16 06:07:15 +0000114 return Info->Mapping;
Chris Lattner411c0ff2009-04-16 04:12:40 +0000115 return diag::MAP_FATAL;
116}
117
Chris Lattner22cb8182009-04-16 05:44:38 +0000118/// getWarningOptionForDiag - Return the lowest-level warning option that
119/// enables the specified diagnostic. If there is no -Wfoo flag that controls
120/// the diagnostic, this returns null.
121const char *Diagnostic::getWarningOptionForDiag(unsigned DiagID) {
Chris Lattner6a64cc62009-04-16 06:00:24 +0000122 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
123 return Info->OptionGroup;
124 return 0;
Chris Lattner22cb8182009-04-16 05:44:38 +0000125}
126
Douglas Gregor33834512009-06-14 07:33:30 +0000127bool Diagnostic::isBuiltinSFINAEDiag(unsigned DiagID) {
128 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
Douglas Gregor15e08d82009-06-15 16:52:15 +0000129 return Info->SFINAE && Info->Class == CLASS_ERROR;
Douglas Gregor33834512009-06-14 07:33:30 +0000130 return false;
131}
132
Chris Lattner22eb9722006-06-18 05:43:12 +0000133/// getDiagClass - Return the class field of the diagnostic.
134///
Chris Lattner4431a1b2007-11-30 22:53:43 +0000135static unsigned getBuiltinDiagClass(unsigned DiagID) {
Chris Lattner6c440322009-04-16 06:07:15 +0000136 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
137 return Info->Class;
138 return ~0U;
Chris Lattner22eb9722006-06-18 05:43:12 +0000139}
140
Chris Lattnere6535cf2007-12-02 01:09:57 +0000141//===----------------------------------------------------------------------===//
142// Custom Diagnostic information
143//===----------------------------------------------------------------------===//
144
145namespace clang {
146 namespace diag {
147 class CustomDiagInfo {
148 typedef std::pair<Diagnostic::Level, std::string> DiagDesc;
149 std::vector<DiagDesc> DiagInfo;
150 std::map<DiagDesc, unsigned> DiagIDs;
151 public:
Mike Stump11289f42009-09-09 15:08:12 +0000152
Chris Lattnere6535cf2007-12-02 01:09:57 +0000153 /// getDescription - Return the description of the specified custom
154 /// diagnostic.
155 const char *getDescription(unsigned DiagID) const {
Chris Lattner36790cf2009-01-29 06:55:46 +0000156 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
Chris Lattnere6535cf2007-12-02 01:09:57 +0000157 "Invalid diagnosic ID");
Chris Lattner36790cf2009-01-29 06:55:46 +0000158 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second.c_str();
Chris Lattnere6535cf2007-12-02 01:09:57 +0000159 }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Chris Lattnere6535cf2007-12-02 01:09:57 +0000161 /// getLevel - Return the level of the specified custom diagnostic.
162 Diagnostic::Level getLevel(unsigned DiagID) const {
Chris Lattner36790cf2009-01-29 06:55:46 +0000163 assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
Chris Lattnere6535cf2007-12-02 01:09:57 +0000164 "Invalid diagnosic ID");
Chris Lattner36790cf2009-01-29 06:55:46 +0000165 return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
Chris Lattnere6535cf2007-12-02 01:09:57 +0000166 }
Mike Stump11289f42009-09-09 15:08:12 +0000167
Daniel Dunbar4886c812009-12-01 17:42:06 +0000168 unsigned getOrCreateDiagID(Diagnostic::Level L, llvm::StringRef Message,
Chris Lattnerf0a5f842008-10-17 21:24:47 +0000169 Diagnostic &Diags) {
Chris Lattnere6535cf2007-12-02 01:09:57 +0000170 DiagDesc D(L, Message);
171 // Check to see if it already exists.
172 std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
173 if (I != DiagIDs.end() && I->first == D)
174 return I->second;
Mike Stump11289f42009-09-09 15:08:12 +0000175
Chris Lattnere6535cf2007-12-02 01:09:57 +0000176 // If not, assign a new ID.
Chris Lattner36790cf2009-01-29 06:55:46 +0000177 unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
Chris Lattnere6535cf2007-12-02 01:09:57 +0000178 DiagIDs.insert(std::make_pair(D, ID));
179 DiagInfo.push_back(D);
180 return ID;
181 }
182 };
Mike Stump11289f42009-09-09 15:08:12 +0000183
184 } // end diag namespace
185} // end clang namespace
Chris Lattnere6535cf2007-12-02 01:09:57 +0000186
187
188//===----------------------------------------------------------------------===//
189// Common Diagnostic implementation
190//===----------------------------------------------------------------------===//
191
Chris Lattner63ecc502008-11-23 09:21:17 +0000192static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT,
193 const char *Modifier, unsigned ML,
194 const char *Argument, unsigned ArgLen,
Chris Lattnerc243f292009-10-20 05:25:22 +0000195 const Diagnostic::ArgumentValue *PrevArgs,
196 unsigned NumPrevArgs,
Chris Lattnercf868c42009-02-19 23:53:20 +0000197 llvm::SmallVectorImpl<char> &Output,
198 void *Cookie) {
Chris Lattner63ecc502008-11-23 09:21:17 +0000199 const char *Str = "<can't format argument>";
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000200 Output.append(Str, Str+strlen(Str));
201}
202
203
Ted Kremenek31691ae2008-08-07 17:49:57 +0000204Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
Chris Lattnere007de32009-04-15 07:01:18 +0000205 AllExtensionsSilenced = 0;
Chris Lattner8c800702008-05-29 15:36:45 +0000206 IgnoreAllWarnings = false;
Chris Lattnerae411572006-07-05 00:55:08 +0000207 WarningsAsErrors = false;
Chris Lattner801fda82009-12-22 23:12:53 +0000208 ErrorsAsFatal = false;
Daniel Dunbar84b70f72008-09-12 18:10:20 +0000209 SuppressSystemWarnings = false;
Douglas Gregor2436e712009-09-17 21:32:03 +0000210 SuppressAllDiagnostics = false;
Chris Lattnerb8e73152009-04-16 05:04:32 +0000211 ExtBehavior = Ext_Ignore;
Mike Stump11289f42009-09-09 15:08:12 +0000212
Chris Lattnerc49b9052007-05-28 00:46:44 +0000213 ErrorOccurred = false;
Chris Lattner9e031192009-02-06 04:16:02 +0000214 FatalErrorOccurred = false;
Bill Wendlingda0c8a92007-06-08 19:17:38 +0000215 NumDiagnostics = 0;
Steve Naroff4fb3d9f2009-12-05 02:14:08 +0000216
Bill Wendlingda0c8a92007-06-08 19:17:38 +0000217 NumErrors = 0;
Chris Lattnere6535cf2007-12-02 01:09:57 +0000218 CustomDiagInfo = 0;
Chris Lattner427c9c12008-11-22 00:59:29 +0000219 CurDiagID = ~0U;
Douglas Gregor19367f52009-03-19 18:55:06 +0000220 LastDiagLevel = Ignored;
Mike Stump11289f42009-09-09 15:08:12 +0000221
Chris Lattner63ecc502008-11-23 09:21:17 +0000222 ArgToStringFn = DummyArgToStringFn;
Chris Lattnercf868c42009-02-19 23:53:20 +0000223 ArgToStringCookie = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor85795312010-03-22 15:10:57 +0000225 DelayedDiagID = 0;
226
Chris Lattner411c0ff2009-04-16 04:12:40 +0000227 // Set all mappings to 'unset'.
Chris Lattnerfb42a182009-07-12 21:18:45 +0000228 DiagMappings BlankDiags(diag::DIAG_UPPER_LIMIT/2, 0);
229 DiagMappingsStack.push_back(BlankDiags);
Chris Lattnerae411572006-07-05 00:55:08 +0000230}
231
Chris Lattnere6535cf2007-12-02 01:09:57 +0000232Diagnostic::~Diagnostic() {
233 delete CustomDiagInfo;
234}
235
Chris Lattnerfb42a182009-07-12 21:18:45 +0000236
237void Diagnostic::pushMappings() {
John Thompsond73d7ad2009-10-23 02:21:17 +0000238 // Avoids undefined behavior when the stack has to resize.
239 DiagMappingsStack.reserve(DiagMappingsStack.size() + 1);
Chris Lattnerfb42a182009-07-12 21:18:45 +0000240 DiagMappingsStack.push_back(DiagMappingsStack.back());
241}
242
243bool Diagnostic::popMappings() {
244 if (DiagMappingsStack.size() == 1)
245 return false;
246
247 DiagMappingsStack.pop_back();
248 return true;
249}
250
Chris Lattnere6535cf2007-12-02 01:09:57 +0000251/// getCustomDiagID - Return an ID for a diagnostic with the specified message
252/// and level. If this is the first request for this diagnosic, it is
253/// registered and created, otherwise the existing ID is returned.
Daniel Dunbar4886c812009-12-01 17:42:06 +0000254unsigned Diagnostic::getCustomDiagID(Level L, llvm::StringRef Message) {
Mike Stump11289f42009-09-09 15:08:12 +0000255 if (CustomDiagInfo == 0)
Chris Lattnere6535cf2007-12-02 01:09:57 +0000256 CustomDiagInfo = new diag::CustomDiagInfo();
Chris Lattnerf0a5f842008-10-17 21:24:47 +0000257 return CustomDiagInfo->getOrCreateDiagID(L, Message, *this);
Chris Lattnere6535cf2007-12-02 01:09:57 +0000258}
259
260
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000261/// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
262/// level of the specified diagnostic ID is a Warning or Extension.
263/// This only works on builtin diagnostics, not custom ones, and is not legal to
264/// call on NOTEs.
265bool Diagnostic::isBuiltinWarningOrExtension(unsigned DiagID) {
Chris Lattnere6c831d2009-04-15 16:56:26 +0000266 return DiagID < diag::DIAG_UPPER_LIMIT &&
267 getBuiltinDiagClass(DiagID) != CLASS_ERROR;
Chris Lattner22eb9722006-06-18 05:43:12 +0000268}
269
Douglas Gregor4ea568f2009-03-10 18:03:33 +0000270/// \brief Determine whether the given built-in diagnostic ID is a
271/// Note.
272bool Diagnostic::isBuiltinNote(unsigned DiagID) {
Chris Lattnere6c831d2009-04-15 16:56:26 +0000273 return DiagID < diag::DIAG_UPPER_LIMIT &&
274 getBuiltinDiagClass(DiagID) == CLASS_NOTE;
Douglas Gregor4ea568f2009-03-10 18:03:33 +0000275}
276
Chris Lattnere007de32009-04-15 07:01:18 +0000277/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
278/// ID is for an extension of some sort.
279///
280bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) {
Chris Lattnere6c831d2009-04-15 16:56:26 +0000281 return DiagID < diag::DIAG_UPPER_LIMIT &&
282 getBuiltinDiagClass(DiagID) == CLASS_EXTENSION;
Chris Lattnere007de32009-04-15 07:01:18 +0000283}
284
Chris Lattner22eb9722006-06-18 05:43:12 +0000285
286/// getDescription - Given a diagnostic ID, return a description of the
287/// issue.
Chris Lattner8488c822008-11-18 07:04:44 +0000288const char *Diagnostic::getDescription(unsigned DiagID) const {
Chris Lattner6c440322009-04-16 06:07:15 +0000289 if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
290 return Info->Description;
Chris Lattner7368d582009-01-27 18:30:58 +0000291 return CustomDiagInfo->getDescription(DiagID);
Chris Lattner22eb9722006-06-18 05:43:12 +0000292}
293
Douglas Gregor85795312010-03-22 15:10:57 +0000294void Diagnostic::SetDelayedDiagnostic(unsigned DiagID, llvm::StringRef Arg1,
295 llvm::StringRef Arg2) {
296 if (DelayedDiagID)
297 return;
298
299 DelayedDiagID = DiagID;
Douglas Gregor96380982010-03-22 15:47:45 +0000300 DelayedDiagArg1 = Arg1.str();
301 DelayedDiagArg2 = Arg2.str();
Douglas Gregor85795312010-03-22 15:10:57 +0000302}
303
304void Diagnostic::ReportDelayed() {
305 Report(DelayedDiagID) << DelayedDiagArg1 << DelayedDiagArg2;
306 DelayedDiagID = 0;
307 DelayedDiagArg1.clear();
308 DelayedDiagArg2.clear();
309}
310
Chris Lattner22eb9722006-06-18 05:43:12 +0000311/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
312/// object, classify the specified diagnostic ID into a Level, consumable by
313/// the DiagnosticClient.
314Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
Chris Lattnere6535cf2007-12-02 01:09:57 +0000315 // Handle custom diagnostics, which cannot be mapped.
Chris Lattner4b6713e2009-01-29 17:46:13 +0000316 if (DiagID >= diag::DIAG_UPPER_LIMIT)
Chris Lattnere6535cf2007-12-02 01:09:57 +0000317 return CustomDiagInfo->getLevel(DiagID);
Mike Stump11289f42009-09-09 15:08:12 +0000318
Chris Lattner4431a1b2007-11-30 22:53:43 +0000319 unsigned DiagClass = getBuiltinDiagClass(DiagID);
Chris Lattnere6c831d2009-04-15 16:56:26 +0000320 assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000321 return getDiagnosticLevel(DiagID, DiagClass);
322}
323
324/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
325/// object, classify the specified diagnostic ID into a Level, consumable by
326/// the DiagnosticClient.
327Diagnostic::Level
328Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
Chris Lattnerae411572006-07-05 00:55:08 +0000329 // Specific non-error diagnostics may be mapped to various levels from ignored
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000330 // to error. Errors can only be mapped to fatal.
Chris Lattnere007de32009-04-15 07:01:18 +0000331 Diagnostic::Level Result = Diagnostic::Fatal;
Mike Stump11289f42009-09-09 15:08:12 +0000332
Chris Lattner411c0ff2009-04-16 04:12:40 +0000333 // Get the mapping information, if unset, compute it lazily.
334 unsigned MappingInfo = getDiagnosticMappingInfo((diag::kind)DiagID);
335 if (MappingInfo == 0) {
336 MappingInfo = GetDefaultDiagMapping(DiagID);
337 setDiagnosticMappingInternal(DiagID, MappingInfo, false);
338 }
Mike Stump11289f42009-09-09 15:08:12 +0000339
Chris Lattner411c0ff2009-04-16 04:12:40 +0000340 switch (MappingInfo & 7) {
341 default: assert(0 && "Unknown mapping!");
Chris Lattnere007de32009-04-15 07:01:18 +0000342 case diag::MAP_IGNORE:
Chris Lattnerb8e73152009-04-16 05:04:32 +0000343 // Ignore this, unless this is an extension diagnostic and we're mapping
344 // them onto warnings or errors.
345 if (!isBuiltinExtensionDiag(DiagID) || // Not an extension
346 ExtBehavior == Ext_Ignore || // Extensions ignored anyway
347 (MappingInfo & 8) != 0) // User explicitly mapped it.
348 return Diagnostic::Ignored;
349 Result = Diagnostic::Warning;
350 if (ExtBehavior == Ext_Error) Result = Diagnostic::Error;
Chris Lattner801fda82009-12-22 23:12:53 +0000351 if (Result == Diagnostic::Error && ErrorsAsFatal)
352 Result = Diagnostic::Fatal;
Chris Lattnerb8e73152009-04-16 05:04:32 +0000353 break;
Chris Lattnere007de32009-04-15 07:01:18 +0000354 case diag::MAP_ERROR:
355 Result = Diagnostic::Error;
Chris Lattner801fda82009-12-22 23:12:53 +0000356 if (ErrorsAsFatal)
357 Result = Diagnostic::Fatal;
Chris Lattnere007de32009-04-15 07:01:18 +0000358 break;
359 case diag::MAP_FATAL:
360 Result = Diagnostic::Fatal;
361 break;
362 case diag::MAP_WARNING:
363 // If warnings are globally mapped to ignore or error, do it.
Chris Lattner8c800702008-05-29 15:36:45 +0000364 if (IgnoreAllWarnings)
365 return Diagnostic::Ignored;
Mike Stump11289f42009-09-09 15:08:12 +0000366
Chris Lattnerf9150ba2009-04-16 04:32:54 +0000367 Result = Diagnostic::Warning;
Mike Stump11289f42009-09-09 15:08:12 +0000368
Chris Lattnerb8e73152009-04-16 05:04:32 +0000369 // If this is an extension diagnostic and we're in -pedantic-error mode, and
370 // if the user didn't explicitly map it, upgrade to an error.
371 if (ExtBehavior == Ext_Error &&
372 (MappingInfo & 8) == 0 &&
373 isBuiltinExtensionDiag(DiagID))
374 Result = Diagnostic::Error;
Mike Stump11289f42009-09-09 15:08:12 +0000375
Chris Lattnerf9150ba2009-04-16 04:32:54 +0000376 if (WarningsAsErrors)
377 Result = Diagnostic::Error;
Chris Lattner801fda82009-12-22 23:12:53 +0000378 if (Result == Diagnostic::Error && ErrorsAsFatal)
379 Result = Diagnostic::Fatal;
Chris Lattnerf9150ba2009-04-16 04:32:54 +0000380 break;
Mike Stump11289f42009-09-09 15:08:12 +0000381
Chris Lattnerf9150ba2009-04-16 04:32:54 +0000382 case diag::MAP_WARNING_NO_WERROR:
383 // Diagnostics specified with -Wno-error=foo should be set to warnings, but
384 // not be adjusted by -Werror or -pedantic-errors.
385 Result = Diagnostic::Warning;
Mike Stump11289f42009-09-09 15:08:12 +0000386
Chris Lattnerf9150ba2009-04-16 04:32:54 +0000387 // If warnings are globally mapped to ignore or error, do it.
388 if (IgnoreAllWarnings)
389 return Diagnostic::Ignored;
Mike Stump11289f42009-09-09 15:08:12 +0000390
Chris Lattnere007de32009-04-15 07:01:18 +0000391 break;
Chris Lattner801fda82009-12-22 23:12:53 +0000392
393 case diag::MAP_ERROR_NO_WFATAL:
394 // Diagnostics specified as -Wno-fatal-error=foo should be errors, but
395 // unaffected by -Wfatal-errors.
396 Result = Diagnostic::Error;
397 break;
Chris Lattner8c800702008-05-29 15:36:45 +0000398 }
Chris Lattnere007de32009-04-15 07:01:18 +0000399
400 // Okay, we're about to return this as a "diagnostic to emit" one last check:
401 // if this is any sort of extension warning, and if we're in an __extension__
402 // block, silence it.
403 if (AllExtensionsSilenced && isBuiltinExtensionDiag(DiagID))
404 return Diagnostic::Ignored;
Mike Stump11289f42009-09-09 15:08:12 +0000405
Chris Lattnere007de32009-04-15 07:01:18 +0000406 return Result;
Chris Lattner22eb9722006-06-18 05:43:12 +0000407}
408
Chris Lattnerc6fafed2009-04-19 22:34:23 +0000409struct WarningOption {
410 const char *Name;
411 const short *Members;
412 const char *SubGroups;
413};
414
415#define GET_DIAG_ARRAYS
416#include "clang/Basic/DiagnosticGroups.inc"
417#undef GET_DIAG_ARRAYS
418
419// Second the table of options, sorted by name for fast binary lookup.
420static const WarningOption OptionTable[] = {
421#define GET_DIAG_TABLE
422#include "clang/Basic/DiagnosticGroups.inc"
423#undef GET_DIAG_TABLE
424};
425static const size_t OptionTableSize =
426sizeof(OptionTable) / sizeof(OptionTable[0]);
427
428static bool WarningOptionCompare(const WarningOption &LHS,
429 const WarningOption &RHS) {
430 return strcmp(LHS.Name, RHS.Name) < 0;
431}
432
433static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping,
434 Diagnostic &Diags) {
435 // Option exists, poke all the members of its diagnostic set.
436 if (const short *Member = Group->Members) {
437 for (; *Member != -1; ++Member)
438 Diags.setDiagnosticMapping(*Member, Mapping);
439 }
Mike Stump11289f42009-09-09 15:08:12 +0000440
Chris Lattnerc6fafed2009-04-19 22:34:23 +0000441 // Enable/disable all subgroups along with this one.
442 if (const char *SubGroups = Group->SubGroups) {
443 for (; *SubGroups != (char)-1; ++SubGroups)
444 MapGroupMembers(&OptionTable[(unsigned char)*SubGroups], Mapping, Diags);
445 }
446}
447
448/// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g.
449/// "unknown-pragmas" to have the specified mapping. This returns true and
450/// ignores the request if "Group" was unknown, false otherwise.
451bool Diagnostic::setDiagnosticGroupMapping(const char *Group,
452 diag::Mapping Map) {
Mike Stump11289f42009-09-09 15:08:12 +0000453
Chris Lattnerc6fafed2009-04-19 22:34:23 +0000454 WarningOption Key = { Group, 0, 0 };
455 const WarningOption *Found =
456 std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key,
457 WarningOptionCompare);
458 if (Found == OptionTable + OptionTableSize ||
459 strcmp(Found->Name, Group) != 0)
460 return true; // Option not found.
Mike Stump11289f42009-09-09 15:08:12 +0000461
Chris Lattnerc6fafed2009-04-19 22:34:23 +0000462 MapGroupMembers(Found, Map, *this);
463 return false;
464}
465
466
Chris Lattner8488c822008-11-18 07:04:44 +0000467/// ProcessDiag - This is the method used to report a diagnostic that is
468/// finally fully formed.
Douglas Gregor33834512009-06-14 07:33:30 +0000469bool Diagnostic::ProcessDiag() {
Chris Lattner427c9c12008-11-22 00:59:29 +0000470 DiagnosticInfo Info(this);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregor2436e712009-09-17 21:32:03 +0000472 if (SuppressAllDiagnostics)
473 return false;
474
Chris Lattner22eb9722006-06-18 05:43:12 +0000475 // Figure out the diagnostic level of this message.
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000476 Diagnostic::Level DiagLevel;
477 unsigned DiagID = Info.getID();
Mike Stump11289f42009-09-09 15:08:12 +0000478
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000479 // ShouldEmitInSystemHeader - True if this diagnostic should be produced even
480 // in a system header.
481 bool ShouldEmitInSystemHeader;
Mike Stump11289f42009-09-09 15:08:12 +0000482
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000483 if (DiagID >= diag::DIAG_UPPER_LIMIT) {
484 // Handle custom diagnostics, which cannot be mapped.
485 DiagLevel = CustomDiagInfo->getLevel(DiagID);
Mike Stump11289f42009-09-09 15:08:12 +0000486
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000487 // Custom diagnostics always are emitted in system headers.
488 ShouldEmitInSystemHeader = true;
489 } else {
490 // Get the class of the diagnostic. If this is a NOTE, map it onto whatever
491 // the diagnostic level was for the previous diagnostic so that it is
492 // filtered the same as the previous diagnostic.
493 unsigned DiagClass = getBuiltinDiagClass(DiagID);
Chris Lattnere6c831d2009-04-15 16:56:26 +0000494 if (DiagClass == CLASS_NOTE) {
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000495 DiagLevel = Diagnostic::Note;
496 ShouldEmitInSystemHeader = false; // extra consideration is needed
497 } else {
Mike Stump11289f42009-09-09 15:08:12 +0000498 // If this is not an error and we are in a system header, we ignore it.
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000499 // Check the original Diag ID here, because we also want to ignore
500 // extensions and warnings in -Werror and -pedantic-errors modes, which
501 // *map* warnings/extensions to errors.
Chris Lattnere6c831d2009-04-15 16:56:26 +0000502 ShouldEmitInSystemHeader = DiagClass == CLASS_ERROR;
Mike Stump11289f42009-09-09 15:08:12 +0000503
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000504 DiagLevel = getDiagnosticLevel(DiagID, DiagClass);
505 }
506 }
507
Douglas Gregor19367f52009-03-19 18:55:06 +0000508 if (DiagLevel != Diagnostic::Note) {
509 // Record that a fatal error occurred only when we see a second
510 // non-note diagnostic. This allows notes to be attached to the
511 // fatal error, but suppresses any diagnostics that follow those
512 // notes.
513 if (LastDiagLevel == Diagnostic::Fatal)
514 FatalErrorOccurred = true;
515
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000516 LastDiagLevel = DiagLevel;
Mike Stump11289f42009-09-09 15:08:12 +0000517 }
Douglas Gregor19367f52009-03-19 18:55:06 +0000518
519 // If a fatal error has already been emitted, silence all subsequent
520 // diagnostics.
521 if (FatalErrorOccurred)
Douglas Gregor33834512009-06-14 07:33:30 +0000522 return false;
Douglas Gregor19367f52009-03-19 18:55:06 +0000523
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000524 // If the client doesn't care about this message, don't issue it. If this is
525 // a note and the last real diagnostic was ignored, ignore it too.
526 if (DiagLevel == Diagnostic::Ignored ||
527 (DiagLevel == Diagnostic::Note && LastDiagLevel == Diagnostic::Ignored))
Douglas Gregor33834512009-06-14 07:33:30 +0000528 return false;
Nico Weber4c311642008-08-10 19:59:06 +0000529
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000530 // If this diagnostic is in a system header and is not a clang error, suppress
531 // it.
532 if (SuppressSystemWarnings && !ShouldEmitInSystemHeader &&
Chris Lattner8488c822008-11-18 07:04:44 +0000533 Info.getLocation().isValid() &&
John McCallbe089fa2010-02-11 10:04:29 +0000534 Info.getLocation().getInstantiationLoc().isInSystemHeader() &&
Chris Lattner9ee10ea2009-02-17 06:52:20 +0000535 (DiagLevel != Diagnostic::Note || LastDiagLevel == Diagnostic::Ignored)) {
536 LastDiagLevel = Diagnostic::Ignored;
Douglas Gregor33834512009-06-14 07:33:30 +0000537 return false;
Chris Lattner9ee10ea2009-02-17 06:52:20 +0000538 }
Chris Lattnerd2a2c132009-02-17 06:49:55 +0000539
Bill Wendlingda0c8a92007-06-08 19:17:38 +0000540 if (DiagLevel >= Diagnostic::Error) {
Chris Lattnerc49b9052007-05-28 00:46:44 +0000541 ErrorOccurred = true;
Chris Lattner8488c822008-11-18 07:04:44 +0000542 ++NumErrors;
Bill Wendlingda0c8a92007-06-08 19:17:38 +0000543 }
Mike Stump11289f42009-09-09 15:08:12 +0000544
Chris Lattner22eb9722006-06-18 05:43:12 +0000545 // Finally, report it.
Chris Lattner8488c822008-11-18 07:04:44 +0000546 Client->HandleDiagnostic(DiagLevel, Info);
Ted Kremenekea06ec12009-01-23 20:28:53 +0000547 if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics;
Douglas Gregor4ea568f2009-03-10 18:03:33 +0000548
Douglas Gregor4ea568f2009-03-10 18:03:33 +0000549 CurDiagID = ~0U;
Douglas Gregor33834512009-06-14 07:33:30 +0000550
551 return true;
Chris Lattner22eb9722006-06-18 05:43:12 +0000552}
553
Douglas Gregor85795312010-03-22 15:10:57 +0000554bool DiagnosticBuilder::Emit() {
555 // If DiagObj is null, then its soul was stolen by the copy ctor
556 // or the user called Emit().
557 if (DiagObj == 0) return false;
558
559 // When emitting diagnostics, we set the final argument count into
560 // the Diagnostic object.
561 DiagObj->NumDiagArgs = NumArgs;
562 DiagObj->NumDiagRanges = NumRanges;
563 DiagObj->NumCodeModificationHints = NumCodeModificationHints;
564
565 // Process the diagnostic, sending the accumulated information to the
566 // DiagnosticClient.
567 bool Emitted = DiagObj->ProcessDiag();
568
569 // Clear out the current diagnostic object.
Douglas Gregor96380982010-03-22 15:47:45 +0000570 unsigned DiagID = DiagObj->CurDiagID;
Douglas Gregor85795312010-03-22 15:10:57 +0000571 DiagObj->Clear();
572
573 // If there was a delayed diagnostic, emit it now.
Douglas Gregor96380982010-03-22 15:47:45 +0000574 if (DiagObj->DelayedDiagID && DiagObj->DelayedDiagID != DiagID)
Douglas Gregor85795312010-03-22 15:10:57 +0000575 DiagObj->ReportDelayed();
576
577 // This diagnostic is dead.
578 DiagObj = 0;
579
580 return Emitted;
581}
582
Nico Weber4c311642008-08-10 19:59:06 +0000583
Chris Lattner22eb9722006-06-18 05:43:12 +0000584DiagnosticClient::~DiagnosticClient() {}
Nico Weber4c311642008-08-10 19:59:06 +0000585
Chris Lattner23be0672008-11-19 06:51:40 +0000586
Chris Lattner2b786902008-11-21 07:50:02 +0000587/// ModifierIs - Return true if the specified modifier matches specified string.
588template <std::size_t StrLen>
589static bool ModifierIs(const char *Modifier, unsigned ModifierLen,
590 const char (&Str)[StrLen]) {
591 return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1);
592}
593
John McCall8cb7a8a32010-01-14 20:11:39 +0000594/// ScanForward - Scans forward, looking for the given character, skipping
595/// nested clauses and escaped characters.
596static const char *ScanFormat(const char *I, const char *E, char Target) {
597 unsigned Depth = 0;
598
599 for ( ; I != E; ++I) {
600 if (Depth == 0 && *I == Target) return I;
601 if (Depth != 0 && *I == '}') Depth--;
602
603 if (*I == '%') {
604 I++;
605 if (I == E) break;
606
607 // Escaped characters get implicitly skipped here.
608
609 // Format specifier.
610 if (!isdigit(*I) && !ispunct(*I)) {
611 for (I++; I != E && !isdigit(*I) && *I != '{'; I++) ;
612 if (I == E) break;
613 if (*I == '{')
614 Depth++;
615 }
616 }
617 }
618 return E;
619}
620
Chris Lattner2b786902008-11-21 07:50:02 +0000621/// HandleSelectModifier - Handle the integer 'select' modifier. This is used
622/// like this: %select{foo|bar|baz}2. This means that the integer argument
623/// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'.
624/// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'.
625/// This is very useful for certain classes of variant diagnostics.
John McCalle4d54322010-01-13 23:58:20 +0000626static void HandleSelectModifier(const DiagnosticInfo &DInfo, unsigned ValNo,
Chris Lattner2b786902008-11-21 07:50:02 +0000627 const char *Argument, unsigned ArgumentLen,
628 llvm::SmallVectorImpl<char> &OutStr) {
629 const char *ArgumentEnd = Argument+ArgumentLen;
Mike Stump11289f42009-09-09 15:08:12 +0000630
Chris Lattner2b786902008-11-21 07:50:02 +0000631 // Skip over 'ValNo' |'s.
632 while (ValNo) {
John McCall8cb7a8a32010-01-14 20:11:39 +0000633 const char *NextVal = ScanFormat(Argument, ArgumentEnd, '|');
Chris Lattner2b786902008-11-21 07:50:02 +0000634 assert(NextVal != ArgumentEnd && "Value for integer select modifier was"
635 " larger than the number of options in the diagnostic string!");
636 Argument = NextVal+1; // Skip this string.
637 --ValNo;
638 }
Mike Stump11289f42009-09-09 15:08:12 +0000639
Chris Lattner2b786902008-11-21 07:50:02 +0000640 // Get the end of the value. This is either the } or the |.
John McCall8cb7a8a32010-01-14 20:11:39 +0000641 const char *EndPtr = ScanFormat(Argument, ArgumentEnd, '|');
John McCalle4d54322010-01-13 23:58:20 +0000642
643 // Recursively format the result of the select clause into the output string.
644 DInfo.FormatDiagnostic(Argument, EndPtr, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000645}
646
647/// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the
648/// letter 's' to the string if the value is not 1. This is used in cases like
649/// this: "you idiot, you have %4 parameter%s4!".
650static void HandleIntegerSModifier(unsigned ValNo,
651 llvm::SmallVectorImpl<char> &OutStr) {
652 if (ValNo != 1)
653 OutStr.push_back('s');
654}
655
John McCall9015cde2010-01-14 00:50:32 +0000656/// HandleOrdinalModifier - Handle the integer 'ord' modifier. This
657/// prints the ordinal form of the given integer, with 1 corresponding
658/// to the first ordinal. Currently this is hard-coded to use the
659/// English form.
660static void HandleOrdinalModifier(unsigned ValNo,
661 llvm::SmallVectorImpl<char> &OutStr) {
662 assert(ValNo != 0 && "ValNo must be strictly positive!");
663
664 llvm::raw_svector_ostream Out(OutStr);
665
666 // We could use text forms for the first N ordinals, but the numeric
667 // forms are actually nicer in diagnostics because they stand out.
668 Out << ValNo;
669
670 // It is critically important that we do this perfectly for
671 // user-written sequences with over 100 elements.
672 switch (ValNo % 100) {
673 case 11:
674 case 12:
675 case 13:
676 Out << "th"; return;
677 default:
678 switch (ValNo % 10) {
679 case 1: Out << "st"; return;
680 case 2: Out << "nd"; return;
681 case 3: Out << "rd"; return;
682 default: Out << "th"; return;
683 }
684 }
685}
686
Chris Lattner2b786902008-11-21 07:50:02 +0000687
Sebastian Redl15b02d22008-11-22 13:44:36 +0000688/// PluralNumber - Parse an unsigned integer and advance Start.
Chris Lattner2fe29202009-04-15 17:13:42 +0000689static unsigned PluralNumber(const char *&Start, const char *End) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000690 // Programming 101: Parse a decimal number :-)
691 unsigned Val = 0;
692 while (Start != End && *Start >= '0' && *Start <= '9') {
693 Val *= 10;
694 Val += *Start - '0';
695 ++Start;
696 }
697 return Val;
698}
699
700/// TestPluralRange - Test if Val is in the parsed range. Modifies Start.
Chris Lattner2fe29202009-04-15 17:13:42 +0000701static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000702 if (*Start != '[') {
703 unsigned Ref = PluralNumber(Start, End);
704 return Ref == Val;
705 }
706
707 ++Start;
708 unsigned Low = PluralNumber(Start, End);
709 assert(*Start == ',' && "Bad plural expression syntax: expected ,");
710 ++Start;
711 unsigned High = PluralNumber(Start, End);
712 assert(*Start == ']' && "Bad plural expression syntax: expected )");
713 ++Start;
714 return Low <= Val && Val <= High;
715}
716
717/// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier.
Chris Lattner2fe29202009-04-15 17:13:42 +0000718static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000719 // Empty condition?
720 if (*Start == ':')
721 return true;
722
723 while (1) {
724 char C = *Start;
725 if (C == '%') {
726 // Modulo expression
727 ++Start;
728 unsigned Arg = PluralNumber(Start, End);
729 assert(*Start == '=' && "Bad plural expression syntax: expected =");
730 ++Start;
731 unsigned ValMod = ValNo % Arg;
732 if (TestPluralRange(ValMod, Start, End))
733 return true;
734 } else {
Sebastian Redl3ceaf622008-11-27 07:28:14 +0000735 assert((C == '[' || (C >= '0' && C <= '9')) &&
Sebastian Redl15b02d22008-11-22 13:44:36 +0000736 "Bad plural expression syntax: unexpected character");
737 // Range expression
738 if (TestPluralRange(ValNo, Start, End))
739 return true;
740 }
741
742 // Scan for next or-expr part.
743 Start = std::find(Start, End, ',');
Mike Stump11289f42009-09-09 15:08:12 +0000744 if (Start == End)
Sebastian Redl15b02d22008-11-22 13:44:36 +0000745 break;
746 ++Start;
747 }
748 return false;
749}
750
751/// HandlePluralModifier - Handle the integer 'plural' modifier. This is used
752/// for complex plural forms, or in languages where all plurals are complex.
753/// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are
754/// conditions that are tested in order, the form corresponding to the first
755/// that applies being emitted. The empty condition is always true, making the
756/// last form a default case.
757/// Conditions are simple boolean expressions, where n is the number argument.
758/// Here are the rules.
759/// condition := expression | empty
760/// empty := -> always true
761/// expression := numeric [',' expression] -> logical or
762/// numeric := range -> true if n in range
763/// | '%' number '=' range -> true if n % number in range
764/// range := number
765/// | '[' number ',' number ']' -> ranges are inclusive both ends
766///
767/// Here are some examples from the GNU gettext manual written in this form:
768/// English:
769/// {1:form0|:form1}
770/// Latvian:
771/// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0}
772/// Gaeilge:
773/// {1:form0|2:form1|:form2}
774/// Romanian:
775/// {1:form0|0,%100=[1,19]:form1|:form2}
776/// Lithuanian:
777/// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1}
778/// Russian (requires repeated form):
779/// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2}
780/// Slovak
781/// {1:form0|[2,4]:form1|:form2}
782/// Polish (requires repeated form):
783/// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2}
784static void HandlePluralModifier(unsigned ValNo,
785 const char *Argument, unsigned ArgumentLen,
Chris Lattnerb8e73152009-04-16 05:04:32 +0000786 llvm::SmallVectorImpl<char> &OutStr) {
Sebastian Redl15b02d22008-11-22 13:44:36 +0000787 const char *ArgumentEnd = Argument + ArgumentLen;
788 while (1) {
789 assert(Argument < ArgumentEnd && "Plural expression didn't match.");
790 const char *ExprEnd = Argument;
791 while (*ExprEnd != ':') {
792 assert(ExprEnd != ArgumentEnd && "Plural missing expression end");
793 ++ExprEnd;
794 }
795 if (EvalPluralExpr(ValNo, Argument, ExprEnd)) {
796 Argument = ExprEnd + 1;
John McCall8cb7a8a32010-01-14 20:11:39 +0000797 ExprEnd = ScanFormat(Argument, ArgumentEnd, '|');
Sebastian Redl15b02d22008-11-22 13:44:36 +0000798 OutStr.append(Argument, ExprEnd);
799 return;
800 }
John McCall8cb7a8a32010-01-14 20:11:39 +0000801 Argument = ScanFormat(Argument, ArgumentEnd - 1, '|') + 1;
Sebastian Redl15b02d22008-11-22 13:44:36 +0000802 }
803}
804
805
Chris Lattner23be0672008-11-19 06:51:40 +0000806/// FormatDiagnostic - Format this diagnostic into a string, substituting the
807/// formal arguments into the %0 slots. The result is appended onto the Str
808/// array.
809void DiagnosticInfo::
810FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
811 const char *DiagStr = getDiags()->getDescription(getID());
812 const char *DiagEnd = DiagStr+strlen(DiagStr);
Mike Stump11289f42009-09-09 15:08:12 +0000813
John McCalle4d54322010-01-13 23:58:20 +0000814 FormatDiagnostic(DiagStr, DiagEnd, OutStr);
815}
816
817void DiagnosticInfo::
818FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
819 llvm::SmallVectorImpl<char> &OutStr) const {
820
Chris Lattnerc243f292009-10-20 05:25:22 +0000821 /// FormattedArgs - Keep track of all of the arguments formatted by
822 /// ConvertArgToString and pass them into subsequent calls to
823 /// ConvertArgToString, allowing the implementation to avoid redundancies in
824 /// obvious cases.
825 llvm::SmallVector<Diagnostic::ArgumentValue, 8> FormattedArgs;
826
Chris Lattner23be0672008-11-19 06:51:40 +0000827 while (DiagStr != DiagEnd) {
828 if (DiagStr[0] != '%') {
829 // Append non-%0 substrings to Str if we have one.
830 const char *StrEnd = std::find(DiagStr, DiagEnd, '%');
831 OutStr.append(DiagStr, StrEnd);
832 DiagStr = StrEnd;
Chris Lattner2b786902008-11-21 07:50:02 +0000833 continue;
John McCall8cb7a8a32010-01-14 20:11:39 +0000834 } else if (ispunct(DiagStr[1])) {
835 OutStr.push_back(DiagStr[1]); // %% -> %.
Chris Lattner23be0672008-11-19 06:51:40 +0000836 DiagStr += 2;
Chris Lattner2b786902008-11-21 07:50:02 +0000837 continue;
838 }
Mike Stump11289f42009-09-09 15:08:12 +0000839
Chris Lattner2b786902008-11-21 07:50:02 +0000840 // Skip the %.
841 ++DiagStr;
Mike Stump11289f42009-09-09 15:08:12 +0000842
Chris Lattner2b786902008-11-21 07:50:02 +0000843 // This must be a placeholder for a diagnostic argument. The format for a
844 // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0".
845 // The digit is a number from 0-9 indicating which argument this comes from.
846 // The modifier is a string of digits from the set [-a-z]+, arguments is a
847 // brace enclosed string.
848 const char *Modifier = 0, *Argument = 0;
849 unsigned ModifierLen = 0, ArgumentLen = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000850
Chris Lattner2b786902008-11-21 07:50:02 +0000851 // Check to see if we have a modifier. If so eat it.
852 if (!isdigit(DiagStr[0])) {
853 Modifier = DiagStr;
854 while (DiagStr[0] == '-' ||
855 (DiagStr[0] >= 'a' && DiagStr[0] <= 'z'))
856 ++DiagStr;
857 ModifierLen = DiagStr-Modifier;
Chris Lattner23be0672008-11-19 06:51:40 +0000858
Chris Lattner2b786902008-11-21 07:50:02 +0000859 // If we have an argument, get it next.
860 if (DiagStr[0] == '{') {
861 ++DiagStr; // Skip {.
862 Argument = DiagStr;
Mike Stump11289f42009-09-09 15:08:12 +0000863
John McCall8cb7a8a32010-01-14 20:11:39 +0000864 DiagStr = ScanFormat(DiagStr, DiagEnd, '}');
865 assert(DiagStr != DiagEnd && "Mismatched {}'s in diagnostic string!");
Chris Lattner2b786902008-11-21 07:50:02 +0000866 ArgumentLen = DiagStr-Argument;
867 ++DiagStr; // Skip }.
Chris Lattner23be0672008-11-19 06:51:40 +0000868 }
Chris Lattner2b786902008-11-21 07:50:02 +0000869 }
Mike Stump11289f42009-09-09 15:08:12 +0000870
Chris Lattner2b786902008-11-21 07:50:02 +0000871 assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic");
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000872 unsigned ArgNo = *DiagStr++ - '0';
Chris Lattner2b786902008-11-21 07:50:02 +0000873
Chris Lattnerc243f292009-10-20 05:25:22 +0000874 Diagnostic::ArgumentKind Kind = getArgKind(ArgNo);
875
876 switch (Kind) {
Chris Lattnere3d20d92008-11-23 21:45:46 +0000877 // ---- STRINGS ----
Chris Lattner427c9c12008-11-22 00:59:29 +0000878 case Diagnostic::ak_std_string: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000879 const std::string &S = getArgStdStr(ArgNo);
Chris Lattner2b786902008-11-21 07:50:02 +0000880 assert(ModifierLen == 0 && "No modifiers for strings yet");
881 OutStr.append(S.begin(), S.end());
882 break;
883 }
Chris Lattner427c9c12008-11-22 00:59:29 +0000884 case Diagnostic::ak_c_string: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000885 const char *S = getArgCStr(ArgNo);
Chris Lattner2b786902008-11-21 07:50:02 +0000886 assert(ModifierLen == 0 && "No modifiers for strings yet");
Daniel Dunbar69a79b12009-04-20 06:13:16 +0000887
888 // Don't crash if get passed a null pointer by accident.
889 if (!S)
890 S = "(null)";
Mike Stump11289f42009-09-09 15:08:12 +0000891
Chris Lattner2b786902008-11-21 07:50:02 +0000892 OutStr.append(S, S + strlen(S));
893 break;
894 }
Chris Lattnere3d20d92008-11-23 21:45:46 +0000895 // ---- INTEGERS ----
Chris Lattner427c9c12008-11-22 00:59:29 +0000896 case Diagnostic::ak_sint: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000897 int Val = getArgSInt(ArgNo);
Mike Stump11289f42009-09-09 15:08:12 +0000898
Chris Lattner2b786902008-11-21 07:50:02 +0000899 if (ModifierIs(Modifier, ModifierLen, "select")) {
John McCalle4d54322010-01-13 23:58:20 +0000900 HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000901 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
902 HandleIntegerSModifier(Val, OutStr);
Sebastian Redl15b02d22008-11-22 13:44:36 +0000903 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
904 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
John McCall9015cde2010-01-14 00:50:32 +0000905 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
906 HandleOrdinalModifier((unsigned)Val, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000907 } else {
908 assert(ModifierLen == 0 && "Unknown integer modifier");
Daniel Dunbare3633792009-10-17 18:12:14 +0000909 llvm::raw_svector_ostream(OutStr) << Val;
Chris Lattner91aea712008-11-19 07:22:31 +0000910 }
Chris Lattner2b786902008-11-21 07:50:02 +0000911 break;
912 }
Chris Lattner427c9c12008-11-22 00:59:29 +0000913 case Diagnostic::ak_uint: {
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000914 unsigned Val = getArgUInt(ArgNo);
Mike Stump11289f42009-09-09 15:08:12 +0000915
Chris Lattner2b786902008-11-21 07:50:02 +0000916 if (ModifierIs(Modifier, ModifierLen, "select")) {
John McCalle4d54322010-01-13 23:58:20 +0000917 HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000918 } else if (ModifierIs(Modifier, ModifierLen, "s")) {
919 HandleIntegerSModifier(Val, OutStr);
Sebastian Redl15b02d22008-11-22 13:44:36 +0000920 } else if (ModifierIs(Modifier, ModifierLen, "plural")) {
921 HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
John McCall9015cde2010-01-14 00:50:32 +0000922 } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) {
923 HandleOrdinalModifier(Val, OutStr);
Chris Lattner2b786902008-11-21 07:50:02 +0000924 } else {
925 assert(ModifierLen == 0 && "Unknown integer modifier");
Daniel Dunbare3633792009-10-17 18:12:14 +0000926 llvm::raw_svector_ostream(OutStr) << Val;
Chris Lattner91aea712008-11-19 07:22:31 +0000927 }
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000928 break;
Chris Lattner2b786902008-11-21 07:50:02 +0000929 }
Chris Lattnere3d20d92008-11-23 21:45:46 +0000930 // ---- NAMES and TYPES ----
931 case Diagnostic::ak_identifierinfo: {
Chris Lattnere3d20d92008-11-23 21:45:46 +0000932 const IdentifierInfo *II = getArgIdentifier(ArgNo);
933 assert(ModifierLen == 0 && "No modifiers for strings yet");
Daniel Dunbar69a79b12009-04-20 06:13:16 +0000934
935 // Don't crash if get passed a null pointer by accident.
936 if (!II) {
937 const char *S = "(null)";
938 OutStr.append(S, S + strlen(S));
939 continue;
940 }
941
Daniel Dunbar07d07852009-10-18 21:17:35 +0000942 llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\'';
Chris Lattnere3d20d92008-11-23 21:45:46 +0000943 break;
944 }
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000945 case Diagnostic::ak_qualtype:
Chris Lattnerf7e69d52008-11-23 20:28:15 +0000946 case Diagnostic::ak_declarationname:
Douglas Gregor2ada0482009-02-04 17:27:36 +0000947 case Diagnostic::ak_nameddecl:
Douglas Gregor053f6912009-08-26 00:04:55 +0000948 case Diagnostic::ak_nestednamespec:
Douglas Gregore40876a2009-10-13 21:16:44 +0000949 case Diagnostic::ak_declcontext:
Chris Lattnerc243f292009-10-20 05:25:22 +0000950 getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo),
Chris Lattner63ecc502008-11-23 09:21:17 +0000951 Modifier, ModifierLen,
Chris Lattnerc243f292009-10-20 05:25:22 +0000952 Argument, ArgumentLen,
953 FormattedArgs.data(), FormattedArgs.size(),
954 OutStr);
Chris Lattner6a2ed6f2008-11-23 09:13:29 +0000955 break;
Nico Weber4c311642008-08-10 19:59:06 +0000956 }
Chris Lattnerc243f292009-10-20 05:25:22 +0000957
958 // Remember this argument info for subsequent formatting operations. Turn
959 // std::strings into a null terminated string to make it be the same case as
960 // all the other ones.
961 if (Kind != Diagnostic::ak_std_string)
962 FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo)));
963 else
964 FormattedArgs.push_back(std::make_pair(Diagnostic::ak_c_string,
965 (intptr_t)getArgStdStr(ArgNo).c_str()));
966
Nico Weber4c311642008-08-10 19:59:06 +0000967 }
Nico Weber4c311642008-08-10 19:59:06 +0000968}
Ted Kremenekea06ec12009-01-23 20:28:53 +0000969
Douglas Gregor33cdd812010-02-18 18:08:43 +0000970StoredDiagnostic::StoredDiagnostic() { }
971
972StoredDiagnostic::StoredDiagnostic(Diagnostic::Level Level,
973 llvm::StringRef Message)
Douglas Gregor1e21cc72010-02-18 23:07:20 +0000974 : Level(Level), Loc(), Message(Message) { }
Douglas Gregor33cdd812010-02-18 18:08:43 +0000975
976StoredDiagnostic::StoredDiagnostic(Diagnostic::Level Level,
977 const DiagnosticInfo &Info)
978 : Level(Level), Loc(Info.getLocation())
979{
980 llvm::SmallString<64> Message;
981 Info.FormatDiagnostic(Message);
982 this->Message.assign(Message.begin(), Message.end());
983
984 Ranges.reserve(Info.getNumRanges());
985 for (unsigned I = 0, N = Info.getNumRanges(); I != N; ++I)
986 Ranges.push_back(Info.getRange(I));
987
988 FixIts.reserve(Info.getNumCodeModificationHints());
989 for (unsigned I = 0, N = Info.getNumCodeModificationHints(); I != N; ++I)
990 FixIts.push_back(Info.getCodeModificationHint(I));
991}
992
993StoredDiagnostic::~StoredDiagnostic() { }
994
Douglas Gregorac0605e2010-01-28 06:00:51 +0000995static void WriteUnsigned(llvm::raw_ostream &OS, unsigned Value) {
996 OS.write((const char *)&Value, sizeof(unsigned));
997}
998
999static void WriteString(llvm::raw_ostream &OS, llvm::StringRef String) {
1000 WriteUnsigned(OS, String.size());
1001 OS.write(String.data(), String.size());
1002}
1003
1004static void WriteSourceLocation(llvm::raw_ostream &OS,
1005 SourceManager *SM,
1006 SourceLocation Location) {
1007 if (!SM || Location.isInvalid()) {
1008 // If we don't have a source manager or this location is invalid,
1009 // just write an invalid location.
1010 WriteUnsigned(OS, 0);
1011 WriteUnsigned(OS, 0);
1012 WriteUnsigned(OS, 0);
1013 return;
1014 }
1015
1016 Location = SM->getInstantiationLoc(Location);
1017 std::pair<FileID, unsigned> Decomposed = SM->getDecomposedLoc(Location);
1018
1019 WriteString(OS, SM->getFileEntryForID(Decomposed.first)->getName());
1020 WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second));
1021 WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second));
1022}
1023
Douglas Gregor33cdd812010-02-18 18:08:43 +00001024void StoredDiagnostic::Serialize(llvm::raw_ostream &OS) const {
Douglas Gregorac0605e2010-01-28 06:00:51 +00001025 SourceManager *SM = 0;
1026 if (getLocation().isValid())
1027 SM = &const_cast<SourceManager &>(getLocation().getManager());
1028
Douglas Gregor70127c12010-02-19 00:40:40 +00001029 // Write a short header to help identify diagnostics.
1030 OS << (char)0x06 << (char)0x07;
1031
Douglas Gregorac0605e2010-01-28 06:00:51 +00001032 // Write the diagnostic level and location.
Douglas Gregor33cdd812010-02-18 18:08:43 +00001033 WriteUnsigned(OS, (unsigned)Level);
Douglas Gregorac0605e2010-01-28 06:00:51 +00001034 WriteSourceLocation(OS, SM, getLocation());
1035
1036 // Write the diagnostic message.
1037 llvm::SmallString<64> Message;
Douglas Gregor33cdd812010-02-18 18:08:43 +00001038 WriteString(OS, getMessage());
Douglas Gregorac0605e2010-01-28 06:00:51 +00001039
1040 // Count the number of ranges that don't point into macros, since
1041 // only simple file ranges serialize well.
1042 unsigned NumNonMacroRanges = 0;
Douglas Gregor33cdd812010-02-18 18:08:43 +00001043 for (range_iterator R = range_begin(), REnd = range_end(); R != REnd; ++R) {
1044 if (R->getBegin().isMacroID() || R->getEnd().isMacroID())
Douglas Gregorac0605e2010-01-28 06:00:51 +00001045 continue;
1046
1047 ++NumNonMacroRanges;
1048 }
1049
1050 // Write the ranges.
1051 WriteUnsigned(OS, NumNonMacroRanges);
1052 if (NumNonMacroRanges) {
Douglas Gregor33cdd812010-02-18 18:08:43 +00001053 for (range_iterator R = range_begin(), REnd = range_end(); R != REnd; ++R) {
1054 if (R->getBegin().isMacroID() || R->getEnd().isMacroID())
Douglas Gregorac0605e2010-01-28 06:00:51 +00001055 continue;
1056
Douglas Gregor33cdd812010-02-18 18:08:43 +00001057 WriteSourceLocation(OS, SM, R->getBegin());
1058 WriteSourceLocation(OS, SM, R->getEnd());
Douglas Gregorac0605e2010-01-28 06:00:51 +00001059 }
1060 }
1061
1062 // Determine if all of the fix-its involve rewrites with simple file
1063 // locations (not in macro instantiations). If so, we can write
1064 // fix-it information.
Douglas Gregor33cdd812010-02-18 18:08:43 +00001065 unsigned NumFixIts = 0;
1066 for (fixit_iterator F = fixit_begin(), FEnd = fixit_end(); F != FEnd; ++F) {
1067 if (F->RemoveRange.isValid() &&
1068 (F->RemoveRange.getBegin().isMacroID() ||
1069 F->RemoveRange.getEnd().isMacroID())) {
Douglas Gregorac0605e2010-01-28 06:00:51 +00001070 NumFixIts = 0;
1071 break;
1072 }
1073
Douglas Gregor33cdd812010-02-18 18:08:43 +00001074 if (F->InsertionLoc.isValid() && F->InsertionLoc.isMacroID()) {
Douglas Gregorac0605e2010-01-28 06:00:51 +00001075 NumFixIts = 0;
1076 break;
1077 }
Douglas Gregor33cdd812010-02-18 18:08:43 +00001078
1079 ++NumFixIts;
Douglas Gregorac0605e2010-01-28 06:00:51 +00001080 }
1081
1082 // Write the fix-its.
1083 WriteUnsigned(OS, NumFixIts);
Douglas Gregor33cdd812010-02-18 18:08:43 +00001084 for (fixit_iterator F = fixit_begin(), FEnd = fixit_end(); F != FEnd; ++F) {
1085 WriteSourceLocation(OS, SM, F->RemoveRange.getBegin());
1086 WriteSourceLocation(OS, SM, F->RemoveRange.getEnd());
1087 WriteSourceLocation(OS, SM, F->InsertionLoc);
1088 WriteString(OS, F->CodeToInsert);
Douglas Gregorac0605e2010-01-28 06:00:51 +00001089 }
1090}
1091
Douglas Gregor33cdd812010-02-18 18:08:43 +00001092static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd,
1093 unsigned &Value) {
1094 if (Memory + sizeof(unsigned) > MemoryEnd)
1095 return true;
1096
1097 memmove(&Value, Memory, sizeof(unsigned));
1098 Memory += sizeof(unsigned);
1099 return false;
1100}
1101
1102static bool ReadSourceLocation(FileManager &FM, SourceManager &SM,
1103 const char *&Memory, const char *MemoryEnd,
1104 SourceLocation &Location) {
1105 // Read the filename.
1106 unsigned FileNameLen = 0;
1107 if (ReadUnsigned(Memory, MemoryEnd, FileNameLen) ||
1108 Memory + FileNameLen > MemoryEnd)
1109 return true;
1110
1111 llvm::StringRef FileName(Memory, FileNameLen);
1112 Memory += FileNameLen;
1113
1114 // Read the line, column.
1115 unsigned Line = 0, Column = 0;
1116 if (ReadUnsigned(Memory, MemoryEnd, Line) ||
1117 ReadUnsigned(Memory, MemoryEnd, Column))
1118 return true;
1119
1120 if (FileName.empty()) {
1121 Location = SourceLocation();
1122 return false;
1123 }
1124
1125 const FileEntry *File = FM.getFile(FileName);
1126 if (!File)
1127 return true;
1128
1129 // Make sure that this file has an entry in the source manager.
1130 if (!SM.hasFileInfo(File))
1131 SM.createFileID(File, SourceLocation(), SrcMgr::C_User);
1132
1133 Location = SM.getLocation(File, Line, Column);
1134 return false;
1135}
1136
1137StoredDiagnostic
1138StoredDiagnostic::Deserialize(FileManager &FM, SourceManager &SM,
1139 const char *&Memory, const char *MemoryEnd) {
Douglas Gregor70127c12010-02-19 00:40:40 +00001140 while (true) {
1141 if (Memory == MemoryEnd)
1142 return StoredDiagnostic();
1143
1144 if (*Memory != 0x06) {
1145 ++Memory;
1146 continue;
1147 }
1148
1149 ++Memory;
1150 if (Memory == MemoryEnd)
1151 return StoredDiagnostic();
1152
1153 if (*Memory != 0x07) {
1154 ++Memory;
1155 continue;
1156 }
1157
1158 // We found the header. We're done.
1159 ++Memory;
1160 break;
1161 }
1162
Douglas Gregor33cdd812010-02-18 18:08:43 +00001163 // Read the severity level.
1164 unsigned Level = 0;
1165 if (ReadUnsigned(Memory, MemoryEnd, Level) || Level > Diagnostic::Fatal)
1166 return StoredDiagnostic();
1167
1168 // Read the source location.
1169 SourceLocation Location;
1170 if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Location))
1171 return StoredDiagnostic();
1172
1173 // Read the diagnostic text.
1174 if (Memory == MemoryEnd)
1175 return StoredDiagnostic();
1176
1177 unsigned MessageLen = 0;
1178 if (ReadUnsigned(Memory, MemoryEnd, MessageLen) ||
1179 Memory + MessageLen > MemoryEnd)
1180 return StoredDiagnostic();
1181
1182 llvm::StringRef Message(Memory, MessageLen);
1183 Memory += MessageLen;
1184
1185
1186 // At this point, we have enough information to form a diagnostic. Do so.
1187 StoredDiagnostic Diag;
1188 Diag.Level = (Diagnostic::Level)Level;
1189 Diag.Loc = FullSourceLoc(Location, SM);
1190 Diag.Message = Message;
1191 if (Memory == MemoryEnd)
1192 return Diag;
1193
1194 // Read the source ranges.
1195 unsigned NumSourceRanges = 0;
1196 if (ReadUnsigned(Memory, MemoryEnd, NumSourceRanges))
1197 return Diag;
1198 for (unsigned I = 0; I != NumSourceRanges; ++I) {
1199 SourceLocation Begin, End;
1200 if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Begin) ||
1201 ReadSourceLocation(FM, SM, Memory, MemoryEnd, End))
1202 return Diag;
1203
1204 Diag.Ranges.push_back(SourceRange(Begin, End));
1205 }
1206
1207 // Read the fix-it hints.
1208 unsigned NumFixIts = 0;
1209 if (ReadUnsigned(Memory, MemoryEnd, NumFixIts))
1210 return Diag;
1211 for (unsigned I = 0; I != NumFixIts; ++I) {
1212 SourceLocation RemoveBegin, RemoveEnd, InsertionLoc;
1213 unsigned InsertLen = 0;
1214 if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveBegin) ||
1215 ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveEnd) ||
1216 ReadSourceLocation(FM, SM, Memory, MemoryEnd, InsertionLoc) ||
1217 ReadUnsigned(Memory, MemoryEnd, InsertLen) ||
1218 Memory + InsertLen > MemoryEnd) {
1219 Diag.FixIts.clear();
1220 return Diag;
1221 }
1222
1223 CodeModificationHint Hint;
1224 Hint.RemoveRange = SourceRange(RemoveBegin, RemoveEnd);
1225 Hint.InsertionLoc = InsertionLoc;
1226 Hint.CodeToInsert.assign(Memory, Memory + InsertLen);
1227 Memory += InsertLen;
1228 Diag.FixIts.push_back(Hint);
1229 }
1230
1231 return Diag;
1232}
1233
Ted Kremenekea06ec12009-01-23 20:28:53 +00001234/// IncludeInDiagnosticCounts - This method (whose default implementation
1235/// returns true) indicates whether the diagnostics handled by this
1236/// DiagnosticClient should be included in the number of diagnostics
1237/// reported by Diagnostic.
1238bool DiagnosticClient::IncludeInDiagnosticCounts() const { return true; }