Chris Lattner | 22eb972 | 2006-06-18 05:43:12 +0000 | [diff] [blame] | 1 | //===--- Diagnostic.cpp - C Language Family Diagnostic Handling -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 22eb972 | 2006-06-18 05:43:12 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Diagnostic-related interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 14 | #include "clang/Basic/CharInfo.h" |
Ted Kremenek | 39a7665 | 2010-04-12 19:54:17 +0000 | [diff] [blame] | 15 | #include "clang/Basic/Diagnostic.h" |
Douglas Gregor | 811db4e | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 16 | #include "clang/Basic/DiagnosticOptions.h" |
Chris Lattner | b91fd17 | 2008-11-19 07:32:16 +0000 | [diff] [blame] | 17 | #include "clang/Basic/IdentifierTable.h" |
Ted Kremenek | 39a7665 | 2010-04-12 19:54:17 +0000 | [diff] [blame] | 18 | #include "clang/Basic/PartialDiagnostic.h" |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 19 | #include "clang/Basic/SourceManager.h" |
Benjamin Kramer | 4903802 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallString.h" |
Jordan Rose | c102b35 | 2012-09-22 01:24:42 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringExtras.h" |
Ted Kremenek | 84de4a1 | 2011-03-21 18:40:07 +0000 | [diff] [blame] | 22 | #include "llvm/Support/CrashRecoveryContext.h" |
Richard Trieu | b3b8bb0 | 2015-01-08 01:27:03 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Locale.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 84de4a1 | 2011-03-21 18:40:07 +0000 | [diff] [blame] | 25 | |
Chris Lattner | 22eb972 | 2006-06-18 05:43:12 +0000 | [diff] [blame] | 26 | using namespace clang; |
| 27 | |
Douglas Gregor | aea7afd | 2015-06-24 22:02:08 +0000 | [diff] [blame] | 28 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 29 | DiagNullabilityKind nullability) { |
| 30 | StringRef string; |
| 31 | switch (nullability.first) { |
| 32 | case NullabilityKind::NonNull: |
| 33 | string = nullability.second ? "'nonnull'" : "'_Nonnull'"; |
| 34 | break; |
| 35 | |
| 36 | case NullabilityKind::Nullable: |
| 37 | string = nullability.second ? "'nullable'" : "'_Nullable'"; |
| 38 | break; |
| 39 | |
| 40 | case NullabilityKind::Unspecified: |
| 41 | string = nullability.second ? "'null_unspecified'" : "'_Null_unspecified'"; |
| 42 | break; |
| 43 | } |
| 44 | |
| 45 | DB.AddString(string); |
| 46 | return DB; |
| 47 | } |
| 48 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 49 | static void DummyArgToStringFn(DiagnosticsEngine::ArgumentKind AK, intptr_t QT, |
Craig Topper | 3aa4fb3 | 2014-06-12 05:32:35 +0000 | [diff] [blame] | 50 | StringRef Modifier, StringRef Argument, |
Craig Topper | e475350 | 2014-06-12 05:32:27 +0000 | [diff] [blame] | 51 | ArrayRef<DiagnosticsEngine::ArgumentValue> PrevArgs, |
| 52 | SmallVectorImpl<char> &Output, |
| 53 | void *Cookie, |
| 54 | ArrayRef<intptr_t> QualTypeVals) { |
| 55 | StringRef Str = "<can't format argument>"; |
| 56 | Output.append(Str.begin(), Str.end()); |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Benjamin Kramer | 018b6d4 | 2016-07-21 15:06:51 +0000 | [diff] [blame] | 59 | DiagnosticsEngine::DiagnosticsEngine(IntrusiveRefCntPtr<DiagnosticIDs> diags, |
| 60 | DiagnosticOptions *DiagOpts, |
| 61 | DiagnosticConsumer *client, |
| 62 | bool ShouldOwnClient) |
| 63 | : Diags(std::move(diags)), DiagOpts(DiagOpts), Client(nullptr), |
| 64 | SourceMgr(nullptr) { |
Alexander Kornienko | 41c247a | 2014-11-17 23:46:02 +0000 | [diff] [blame] | 65 | setClient(client, ShouldOwnClient); |
Chris Lattner | 63ecc50 | 2008-11-23 09:21:17 +0000 | [diff] [blame] | 66 | ArgToStringFn = DummyArgToStringFn; |
Craig Topper | f1186c5 | 2014-05-08 06:41:40 +0000 | [diff] [blame] | 67 | ArgToStringCookie = nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | |
Douglas Gregor | 0e11955 | 2010-07-31 00:40:00 +0000 | [diff] [blame] | 69 | AllExtensionsSilenced = 0; |
| 70 | IgnoreAllWarnings = false; |
| 71 | WarningsAsErrors = false; |
Ted Kremenek | fbbdced | 2011-08-18 01:12:56 +0000 | [diff] [blame] | 72 | EnableAllWarnings = false; |
Douglas Gregor | 0e11955 | 2010-07-31 00:40:00 +0000 | [diff] [blame] | 73 | ErrorsAsFatal = false; |
Manuel Klimek | 016c024 | 2016-03-01 10:56:19 +0000 | [diff] [blame] | 74 | FatalsAsError = false; |
Douglas Gregor | 0e11955 | 2010-07-31 00:40:00 +0000 | [diff] [blame] | 75 | SuppressSystemWarnings = false; |
| 76 | SuppressAllDiagnostics = false; |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 77 | ElideType = true; |
| 78 | PrintTemplateTree = false; |
| 79 | ShowColors = false; |
Douglas Gregor | 0e11955 | 2010-07-31 00:40:00 +0000 | [diff] [blame] | 80 | ShowOverloads = Ovl_All; |
Alp Toker | ac4e8e5 | 2014-06-22 21:58:33 +0000 | [diff] [blame] | 81 | ExtBehavior = diag::Severity::Ignored; |
Douglas Gregor | 0e11955 | 2010-07-31 00:40:00 +0000 | [diff] [blame] | 82 | |
| 83 | ErrorLimit = 0; |
| 84 | TemplateBacktraceLimit = 0; |
Richard Smith | f6f003a | 2011-12-16 19:06:07 +0000 | [diff] [blame] | 85 | ConstexprBacktraceLimit = 0; |
Douglas Gregor | 0e11955 | 2010-07-31 00:40:00 +0000 | [diff] [blame] | 86 | |
Douglas Gregor | aa21cc4 | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 87 | Reset(); |
Chris Lattner | ae41157 | 2006-07-05 00:55:08 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Reid Kleckner | dccbabf | 2014-12-17 20:23:11 +0000 | [diff] [blame] | 90 | DiagnosticsEngine::~DiagnosticsEngine() { |
| 91 | // If we own the diagnostic client, destroy it first so that it can access the |
| 92 | // engine from its destructor. |
| 93 | setClient(nullptr); |
| 94 | } |
| 95 | |
David Blaikie | e2eefae | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 96 | void DiagnosticsEngine::setClient(DiagnosticConsumer *client, |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 97 | bool ShouldOwnClient) { |
Alexander Kornienko | 41c247a | 2014-11-17 23:46:02 +0000 | [diff] [blame] | 98 | Owner.reset(ShouldOwnClient ? client : nullptr); |
Douglas Gregor | 7a964ad | 2011-01-31 22:04:05 +0000 | [diff] [blame] | 99 | Client = client; |
Douglas Gregor | 7a964ad | 2011-01-31 22:04:05 +0000 | [diff] [blame] | 100 | } |
Chris Lattner | fb42a18 | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 101 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 102 | void DiagnosticsEngine::pushMappings(SourceLocation Loc) { |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 103 | DiagStateOnPushStack.push_back(GetCurDiagState()); |
Chris Lattner | fb42a18 | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 104 | } |
| 105 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 106 | bool DiagnosticsEngine::popMappings(SourceLocation Loc) { |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 107 | if (DiagStateOnPushStack.empty()) |
Chris Lattner | fb42a18 | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 108 | return false; |
| 109 | |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 110 | if (DiagStateOnPushStack.back() != GetCurDiagState()) { |
| 111 | // State changed at some point between push/pop. |
| 112 | PushDiagStatePoint(DiagStateOnPushStack.back(), Loc); |
| 113 | } |
| 114 | DiagStateOnPushStack.pop_back(); |
Chris Lattner | fb42a18 | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 115 | return true; |
| 116 | } |
| 117 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 118 | void DiagnosticsEngine::Reset() { |
Douglas Gregor | aa21cc4 | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 119 | ErrorOccurred = false; |
DeLesley Hutchins | 8ecd491 | 2012-12-07 22:53:48 +0000 | [diff] [blame] | 120 | UncompilableErrorOccurred = false; |
Douglas Gregor | aa21cc4 | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 121 | FatalErrorOccurred = false; |
Douglas Gregor | 8a60bbe | 2011-07-06 17:40:26 +0000 | [diff] [blame] | 122 | UnrecoverableErrorOccurred = false; |
Douglas Gregor | aa21cc4 | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 123 | |
| 124 | NumWarnings = 0; |
| 125 | NumErrors = 0; |
Argyrios Kyrtzidis | 1fa8b4b | 2011-07-29 01:25:44 +0000 | [diff] [blame] | 126 | TrapNumErrorsOccurred = 0; |
| 127 | TrapNumUnrecoverableErrorsOccurred = 0; |
Douglas Gregor | 8a60bbe | 2011-07-06 17:40:26 +0000 | [diff] [blame] | 128 | |
Douglas Gregor | aa21cc4 | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 129 | CurDiagID = ~0U; |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 130 | LastDiagLevel = DiagnosticIDs::Ignored; |
Douglas Gregor | aa21cc4 | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 131 | DelayedDiagID = 0; |
Argyrios Kyrtzidis | bbbeea1 | 2011-03-26 18:58:17 +0000 | [diff] [blame] | 132 | |
| 133 | // Clear state related to #pragma diagnostic. |
| 134 | DiagStates.clear(); |
| 135 | DiagStatePoints.clear(); |
| 136 | DiagStateOnPushStack.clear(); |
| 137 | |
| 138 | // Create a DiagState and DiagStatePoint representing diagnostic changes |
| 139 | // through command-line. |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 140 | DiagStates.emplace_back(); |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 141 | DiagStatePoints.emplace_back(&DiagStates.back(), SourceLocation()); |
Douglas Gregor | aa21cc4 | 2010-07-19 21:46:24 +0000 | [diff] [blame] | 142 | } |
Chris Lattner | 22eb972 | 2006-06-18 05:43:12 +0000 | [diff] [blame] | 143 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 144 | void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1, |
Chad Rosier | 849a67b | 2012-02-07 23:24:49 +0000 | [diff] [blame] | 145 | StringRef Arg2) { |
Douglas Gregor | 8579531 | 2010-03-22 15:10:57 +0000 | [diff] [blame] | 146 | if (DelayedDiagID) |
| 147 | return; |
| 148 | |
| 149 | DelayedDiagID = DiagID; |
Douglas Gregor | 9638098 | 2010-03-22 15:47:45 +0000 | [diff] [blame] | 150 | DelayedDiagArg1 = Arg1.str(); |
| 151 | DelayedDiagArg2 = Arg2.str(); |
Douglas Gregor | 8579531 | 2010-03-22 15:10:57 +0000 | [diff] [blame] | 152 | } |
| 153 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 154 | void DiagnosticsEngine::ReportDelayed() { |
Douglas Gregor | 8579531 | 2010-03-22 15:10:57 +0000 | [diff] [blame] | 155 | Report(DelayedDiagID) << DelayedDiagArg1 << DelayedDiagArg2; |
| 156 | DelayedDiagID = 0; |
| 157 | DelayedDiagArg1.clear(); |
| 158 | DelayedDiagArg2.clear(); |
| 159 | } |
| 160 | |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 161 | void DiagnosticsEngine::PushDiagStatePoint(DiagState *State, |
| 162 | SourceLocation Loc) { |
| 163 | // Make sure that DiagStatePoints is always sorted according to Loc. |
| 164 | assert(Loc.isValid() && "Adding invalid loc point"); |
| 165 | assert(!DiagStatePoints.empty() && |
| 166 | (DiagStatePoints.back().Loc.isInvalid() || |
| 167 | getSourceManager().isBeforeInTranslationUnit( |
| 168 | DiagStatePoints.back().Loc, Loc)) && |
| 169 | "Previous point loc comes after or is the same as new one"); |
| 170 | DiagStatePoints.push_back(DiagStatePoint(State, Loc)); |
| 171 | } |
| 172 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 173 | DiagnosticsEngine::DiagStatePointsTy::iterator |
| 174 | DiagnosticsEngine::GetDiagStatePointForLoc(SourceLocation L) const { |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 175 | assert(!DiagStatePoints.empty()); |
| 176 | assert(DiagStatePoints.front().Loc.isInvalid() && |
| 177 | "Should have created a DiagStatePoint for command-line"); |
| 178 | |
Richard Smith | 99eff01 | 2012-08-17 00:55:32 +0000 | [diff] [blame] | 179 | if (!SourceMgr) |
| 180 | return DiagStatePoints.end() - 1; |
| 181 | |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 182 | FullSourceLoc Loc(L, *SourceMgr); |
| 183 | if (Loc.isInvalid()) |
| 184 | return DiagStatePoints.end() - 1; |
| 185 | |
| 186 | DiagStatePointsTy::iterator Pos = DiagStatePoints.end(); |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 187 | SourceLocation LastStateChangePos = DiagStatePoints.back().Loc; |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 188 | if (LastStateChangePos.isValid() && |
| 189 | Loc.isBeforeInTranslationUnitThan(LastStateChangePos)) |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 190 | Pos = std::upper_bound( |
| 191 | DiagStatePoints.begin(), DiagStatePoints.end(), |
| 192 | DiagStatePoint(nullptr, Loc), |
| 193 | [this](const DiagStatePoint &LHS, const DiagStatePoint &RHS) { |
| 194 | // If Loc is invalid it means it came from <command-line>, in which |
| 195 | // case we regard it as coming before any valid source location. |
| 196 | if (RHS.Loc.isInvalid()) |
| 197 | return false; |
| 198 | if (LHS.Loc.isInvalid()) |
| 199 | return true; |
| 200 | return SourceMgr->isBeforeInTranslationUnit(LHS.Loc, RHS.Loc); |
| 201 | }); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 202 | --Pos; |
| 203 | return Pos; |
| 204 | } |
| 205 | |
Alp Toker | d576e00 | 2014-06-12 11:13:52 +0000 | [diff] [blame] | 206 | void DiagnosticsEngine::setSeverity(diag::kind Diag, diag::Severity Map, |
| 207 | SourceLocation L) { |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 208 | assert(Diag < diag::DIAG_UPPER_LIMIT && |
| 209 | "Can only map builtin diagnostics"); |
| 210 | assert((Diags->isBuiltinWarningOrExtension(Diag) || |
Alp Toker | 46df1c0 | 2014-06-12 10:15:20 +0000 | [diff] [blame] | 211 | (Map == diag::Severity::Fatal || Map == diag::Severity::Error)) && |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 212 | "Cannot map errors into warnings!"); |
| 213 | assert(!DiagStatePoints.empty()); |
Richard Smith | 8a0527d | 2012-08-14 22:37:22 +0000 | [diff] [blame] | 214 | assert((L.isInvalid() || SourceMgr) && "No SourceMgr for valid location"); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 215 | |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 216 | SourceLocation Loc = SourceMgr ? L : SourceLocation(); |
| 217 | SourceLocation LastStateChangePos = DiagStatePoints.back().Loc; |
Chad Rosier | d1956e4 | 2012-02-03 01:49:51 +0000 | [diff] [blame] | 218 | // Don't allow a mapping to a warning override an error/fatal mapping. |
Alp Toker | 46df1c0 | 2014-06-12 10:15:20 +0000 | [diff] [blame] | 219 | if (Map == diag::Severity::Warning) { |
Alp Toker | c726c36 | 2014-06-10 09:31:37 +0000 | [diff] [blame] | 220 | DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); |
Alp Toker | 46df1c0 | 2014-06-12 10:15:20 +0000 | [diff] [blame] | 221 | if (Info.getSeverity() == diag::Severity::Error || |
| 222 | Info.getSeverity() == diag::Severity::Fatal) |
Alp Toker | c726c36 | 2014-06-10 09:31:37 +0000 | [diff] [blame] | 223 | Map = Info.getSeverity(); |
Chad Rosier | d1956e4 | 2012-02-03 01:49:51 +0000 | [diff] [blame] | 224 | } |
Alp Toker | c726c36 | 2014-06-10 09:31:37 +0000 | [diff] [blame] | 225 | DiagnosticMapping Mapping = makeUserMapping(Map, L); |
Daniel Dunbar | 2fba097 | 2011-10-04 21:17:24 +0000 | [diff] [blame] | 226 | |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 227 | // Common case; setting all the diagnostics of a group in one place. |
| 228 | if (Loc.isInvalid() || Loc == LastStateChangePos) { |
Alp Toker | c726c36 | 2014-06-10 09:31:37 +0000 | [diff] [blame] | 229 | GetCurDiagState()->setMapping(Diag, Mapping); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 230 | return; |
| 231 | } |
| 232 | |
| 233 | // Another common case; modifying diagnostic state in a source location |
| 234 | // after the previous one. |
| 235 | if ((Loc.isValid() && LastStateChangePos.isInvalid()) || |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 236 | SourceMgr->isBeforeInTranslationUnit(LastStateChangePos, Loc)) { |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 237 | // A diagnostic pragma occurred, create a new DiagState initialized with |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 238 | // the current one and a new DiagStatePoint to record at which location |
| 239 | // the new state became active. |
| 240 | DiagStates.push_back(*GetCurDiagState()); |
| 241 | PushDiagStatePoint(&DiagStates.back(), Loc); |
Alp Toker | c726c36 | 2014-06-10 09:31:37 +0000 | [diff] [blame] | 242 | GetCurDiagState()->setMapping(Diag, Mapping); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 243 | return; |
| 244 | } |
| 245 | |
| 246 | // We allow setting the diagnostic state in random source order for |
| 247 | // completeness but it should not be actually happening in normal practice. |
| 248 | |
| 249 | DiagStatePointsTy::iterator Pos = GetDiagStatePointForLoc(Loc); |
| 250 | assert(Pos != DiagStatePoints.end()); |
| 251 | |
| 252 | // Update all diagnostic states that are active after the given location. |
| 253 | for (DiagStatePointsTy::iterator |
| 254 | I = Pos+1, E = DiagStatePoints.end(); I != E; ++I) { |
Craig Topper | 5e35e66 | 2015-11-26 05:51:54 +0000 | [diff] [blame] | 255 | I->State->setMapping(Diag, Mapping); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // If the location corresponds to an existing point, just update its state. |
| 259 | if (Pos->Loc == Loc) { |
Craig Topper | 5e35e66 | 2015-11-26 05:51:54 +0000 | [diff] [blame] | 260 | Pos->State->setMapping(Diag, Mapping); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 261 | return; |
| 262 | } |
| 263 | |
| 264 | // Create a new state/point and fit it into the vector of DiagStatePoints |
| 265 | // so that the vector is always ordered according to location. |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 266 | assert(SourceMgr->isBeforeInTranslationUnit(Pos->Loc, Loc)); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 267 | DiagStates.push_back(*Pos->State); |
| 268 | DiagState *NewState = &DiagStates.back(); |
Craig Topper | 5e35e66 | 2015-11-26 05:51:54 +0000 | [diff] [blame] | 269 | NewState->setMapping(Diag, Mapping); |
Benjamin Kramer | bc9ef59 | 2017-01-18 15:50:26 +0000 | [diff] [blame^] | 270 | DiagStatePoints.insert(Pos + 1, DiagStatePoint(NewState, Loc)); |
Argyrios Kyrtzidis | 1cb0de1 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 273 | bool DiagnosticsEngine::setSeverityForGroup(diag::Flavor Flavor, |
| 274 | StringRef Group, diag::Severity Map, |
Alp Toker | d576e00 | 2014-06-12 11:13:52 +0000 | [diff] [blame] | 275 | SourceLocation Loc) { |
Daniel Dunbar | d908c12 | 2011-09-29 01:47:16 +0000 | [diff] [blame] | 276 | // Get the diagnostics in this group. |
Hans Wennborg | eb7cd66 | 2014-08-11 16:05:54 +0000 | [diff] [blame] | 277 | SmallVector<diag::kind, 256> GroupDiags; |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 278 | if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags)) |
Daniel Dunbar | d908c12 | 2011-09-29 01:47:16 +0000 | [diff] [blame] | 279 | return true; |
| 280 | |
| 281 | // Set the mapping. |
Hans Wennborg | eb7cd66 | 2014-08-11 16:05:54 +0000 | [diff] [blame] | 282 | for (diag::kind Diag : GroupDiags) |
| 283 | setSeverity(Diag, Map, Loc); |
Daniel Dunbar | d908c12 | 2011-09-29 01:47:16 +0000 | [diff] [blame] | 284 | |
| 285 | return false; |
| 286 | } |
| 287 | |
Daniel Dunbar | c2e5ca6 | 2011-09-29 00:53:47 +0000 | [diff] [blame] | 288 | bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group, |
| 289 | bool Enabled) { |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 290 | // If we are enabling this feature, just set the diagnostic mappings to map to |
| 291 | // errors. |
| 292 | if (Enabled) |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 293 | return setSeverityForGroup(diag::Flavor::WarningOrError, Group, |
| 294 | diag::Severity::Error); |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 295 | |
| 296 | // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and |
| 297 | // potentially downgrade anything already mapped to be a warning. |
| 298 | |
| 299 | // Get the diagnostics in this group. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 300 | SmallVector<diag::kind, 8> GroupDiags; |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 301 | if (Diags->getDiagnosticsInGroup(diag::Flavor::WarningOrError, Group, |
| 302 | GroupDiags)) |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 303 | return true; |
| 304 | |
| 305 | // Perform the mapping change. |
Craig Topper | a52e2b2 | 2015-11-26 05:10:07 +0000 | [diff] [blame] | 306 | for (diag::kind Diag : GroupDiags) { |
| 307 | DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 308 | |
Alp Toker | 46df1c0 | 2014-06-12 10:15:20 +0000 | [diff] [blame] | 309 | if (Info.getSeverity() == diag::Severity::Error || |
| 310 | Info.getSeverity() == diag::Severity::Fatal) |
| 311 | Info.setSeverity(diag::Severity::Warning); |
Daniel Dunbar | 58d0af6 | 2011-09-29 01:58:05 +0000 | [diff] [blame] | 312 | |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 313 | Info.setNoWarningAsError(true); |
| 314 | } |
| 315 | |
| 316 | return false; |
Daniel Dunbar | c2e5ca6 | 2011-09-29 00:53:47 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group, |
| 320 | bool Enabled) { |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 321 | // If we are enabling this feature, just set the diagnostic mappings to map to |
| 322 | // fatal errors. |
| 323 | if (Enabled) |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 324 | return setSeverityForGroup(diag::Flavor::WarningOrError, Group, |
| 325 | diag::Severity::Fatal); |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 326 | |
| 327 | // Otherwise, we want to set the diagnostic mapping's "no Werror" bit, and |
| 328 | // potentially downgrade anything already mapped to be an error. |
| 329 | |
| 330 | // Get the diagnostics in this group. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 331 | SmallVector<diag::kind, 8> GroupDiags; |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 332 | if (Diags->getDiagnosticsInGroup(diag::Flavor::WarningOrError, Group, |
| 333 | GroupDiags)) |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 334 | return true; |
| 335 | |
| 336 | // Perform the mapping change. |
Craig Topper | a52e2b2 | 2015-11-26 05:10:07 +0000 | [diff] [blame] | 337 | for (diag::kind Diag : GroupDiags) { |
| 338 | DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 339 | |
Alp Toker | 46df1c0 | 2014-06-12 10:15:20 +0000 | [diff] [blame] | 340 | if (Info.getSeverity() == diag::Severity::Fatal) |
| 341 | Info.setSeverity(diag::Severity::Error); |
Daniel Dunbar | 58d0af6 | 2011-09-29 01:58:05 +0000 | [diff] [blame] | 342 | |
Daniel Dunbar | fffcf21 | 2011-09-29 01:52:06 +0000 | [diff] [blame] | 343 | Info.setNoErrorAsFatal(true); |
| 344 | } |
| 345 | |
| 346 | return false; |
Daniel Dunbar | c2e5ca6 | 2011-09-29 00:53:47 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 349 | void DiagnosticsEngine::setSeverityForAll(diag::Flavor Flavor, |
| 350 | diag::Severity Map, |
Alp Toker | d576e00 | 2014-06-12 11:13:52 +0000 | [diff] [blame] | 351 | SourceLocation Loc) { |
Argyrios Kyrtzidis | 9ffada9 | 2012-01-27 06:15:43 +0000 | [diff] [blame] | 352 | // Get all the diagnostics. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 353 | SmallVector<diag::kind, 64> AllDiags; |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 354 | Diags->getAllDiagnostics(Flavor, AllDiags); |
Argyrios Kyrtzidis | 9ffada9 | 2012-01-27 06:15:43 +0000 | [diff] [blame] | 355 | |
| 356 | // Set the mapping. |
Craig Topper | a52e2b2 | 2015-11-26 05:10:07 +0000 | [diff] [blame] | 357 | for (diag::kind Diag : AllDiags) |
| 358 | if (Diags->isBuiltinWarningOrExtension(Diag)) |
| 359 | setSeverity(Diag, Map, Loc); |
Argyrios Kyrtzidis | 9ffada9 | 2012-01-27 06:15:43 +0000 | [diff] [blame] | 360 | } |
| 361 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 362 | void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) { |
Argyrios Kyrtzidis | e9af37d | 2011-05-05 07:54:59 +0000 | [diff] [blame] | 363 | assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!"); |
| 364 | |
| 365 | CurDiagLoc = storedDiag.getLocation(); |
| 366 | CurDiagID = storedDiag.getID(); |
| 367 | NumDiagArgs = 0; |
| 368 | |
Alexander Kornienko | d3b4e08 | 2014-05-22 19:56:11 +0000 | [diff] [blame] | 369 | DiagRanges.clear(); |
Benjamin Kramer | f367dd9 | 2015-06-12 15:31:50 +0000 | [diff] [blame] | 370 | DiagRanges.append(storedDiag.range_begin(), storedDiag.range_end()); |
Argyrios Kyrtzidis | e9af37d | 2011-05-05 07:54:59 +0000 | [diff] [blame] | 371 | |
Alexander Kornienko | d3b4e08 | 2014-05-22 19:56:11 +0000 | [diff] [blame] | 372 | DiagFixItHints.clear(); |
Benjamin Kramer | f367dd9 | 2015-06-12 15:31:50 +0000 | [diff] [blame] | 373 | DiagFixItHints.append(storedDiag.fixit_begin(), storedDiag.fixit_end()); |
Argyrios Kyrtzidis | e9af37d | 2011-05-05 07:54:59 +0000 | [diff] [blame] | 374 | |
David Blaikie | e2eefae | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 375 | assert(Client && "DiagnosticConsumer not set!"); |
Argyrios Kyrtzidis | e9af37d | 2011-05-05 07:54:59 +0000 | [diff] [blame] | 376 | Level DiagLevel = storedDiag.getLevel(); |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 377 | Diagnostic Info(this, storedDiag.getMessage()); |
Argyrios Kyrtzidis | e9af37d | 2011-05-05 07:54:59 +0000 | [diff] [blame] | 378 | Client->HandleDiagnostic(DiagLevel, Info); |
| 379 | if (Client->IncludeInDiagnosticCounts()) { |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 380 | if (DiagLevel == DiagnosticsEngine::Warning) |
Argyrios Kyrtzidis | e9af37d | 2011-05-05 07:54:59 +0000 | [diff] [blame] | 381 | ++NumWarnings; |
| 382 | } |
| 383 | |
| 384 | CurDiagID = ~0U; |
| 385 | } |
| 386 | |
Jordan Rose | 6f524ac | 2012-07-11 16:50:36 +0000 | [diff] [blame] | 387 | bool DiagnosticsEngine::EmitCurrentDiagnostic(bool Force) { |
| 388 | assert(getClient() && "DiagnosticClient not set!"); |
| 389 | |
| 390 | bool Emitted; |
| 391 | if (Force) { |
| 392 | Diagnostic Info(this); |
| 393 | |
| 394 | // Figure out the diagnostic level of this message. |
| 395 | DiagnosticIDs::Level DiagLevel |
| 396 | = Diags->getDiagnosticLevel(Info.getID(), Info.getLocation(), *this); |
| 397 | |
| 398 | Emitted = (DiagLevel != DiagnosticIDs::Ignored); |
| 399 | if (Emitted) { |
| 400 | // Emit the diagnostic regardless of suppression level. |
| 401 | Diags->EmitDiag(*this, DiagLevel); |
| 402 | } |
| 403 | } else { |
| 404 | // Process the diagnostic, sending the accumulated information to the |
| 405 | // DiagnosticConsumer. |
| 406 | Emitted = ProcessDiag(); |
| 407 | } |
Douglas Gregor | 8579531 | 2010-03-22 15:10:57 +0000 | [diff] [blame] | 408 | |
| 409 | // Clear out the current diagnostic object. |
Daniel Dunbar | c7c0089 | 2012-03-13 21:02:14 +0000 | [diff] [blame] | 410 | unsigned DiagID = CurDiagID; |
| 411 | Clear(); |
Douglas Gregor | 8579531 | 2010-03-22 15:10:57 +0000 | [diff] [blame] | 412 | |
| 413 | // If there was a delayed diagnostic, emit it now. |
Jordan Rose | 6f524ac | 2012-07-11 16:50:36 +0000 | [diff] [blame] | 414 | if (!Force && DelayedDiagID && DelayedDiagID != DiagID) |
Daniel Dunbar | c7c0089 | 2012-03-13 21:02:14 +0000 | [diff] [blame] | 415 | ReportDelayed(); |
Douglas Gregor | 8579531 | 2010-03-22 15:10:57 +0000 | [diff] [blame] | 416 | |
| 417 | return Emitted; |
| 418 | } |
| 419 | |
Nico Weber | 4c31164 | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 420 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 421 | DiagnosticConsumer::~DiagnosticConsumer() {} |
Nico Weber | 4c31164 | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 422 | |
David Blaikie | e2eefae | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 423 | void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 424 | const Diagnostic &Info) { |
Argyrios Kyrtzidis | c79346a | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 425 | if (!IncludeInDiagnosticCounts()) |
| 426 | return; |
| 427 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 428 | if (DiagLevel == DiagnosticsEngine::Warning) |
Argyrios Kyrtzidis | c79346a | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 429 | ++NumWarnings; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 430 | else if (DiagLevel >= DiagnosticsEngine::Error) |
Argyrios Kyrtzidis | c79346a | 2010-11-18 20:06:46 +0000 | [diff] [blame] | 431 | ++NumErrors; |
| 432 | } |
Chris Lattner | 23be067 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 433 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 434 | /// ModifierIs - Return true if the specified modifier matches specified string. |
| 435 | template <std::size_t StrLen> |
| 436 | static bool ModifierIs(const char *Modifier, unsigned ModifierLen, |
| 437 | const char (&Str)[StrLen]) { |
| 438 | return StrLen-1 == ModifierLen && !memcmp(Modifier, Str, StrLen-1); |
| 439 | } |
| 440 | |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 441 | /// ScanForward - Scans forward, looking for the given character, skipping |
| 442 | /// nested clauses and escaped characters. |
| 443 | static const char *ScanFormat(const char *I, const char *E, char Target) { |
| 444 | unsigned Depth = 0; |
| 445 | |
| 446 | for ( ; I != E; ++I) { |
| 447 | if (Depth == 0 && *I == Target) return I; |
| 448 | if (Depth != 0 && *I == '}') Depth--; |
| 449 | |
| 450 | if (*I == '%') { |
| 451 | I++; |
| 452 | if (I == E) break; |
| 453 | |
| 454 | // Escaped characters get implicitly skipped here. |
| 455 | |
| 456 | // Format specifier. |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 457 | if (!isDigit(*I) && !isPunctuation(*I)) { |
| 458 | for (I++; I != E && !isDigit(*I) && *I != '{'; I++) ; |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 459 | if (I == E) break; |
| 460 | if (*I == '{') |
| 461 | Depth++; |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | return E; |
| 466 | } |
| 467 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 468 | /// HandleSelectModifier - Handle the integer 'select' modifier. This is used |
| 469 | /// like this: %select{foo|bar|baz}2. This means that the integer argument |
| 470 | /// "%2" has a value from 0-2. If the value is 0, the diagnostic prints 'foo'. |
| 471 | /// If the value is 1, it prints 'bar'. If it has the value 2, it prints 'baz'. |
| 472 | /// This is very useful for certain classes of variant diagnostics. |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 473 | static void HandleSelectModifier(const Diagnostic &DInfo, unsigned ValNo, |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 474 | const char *Argument, unsigned ArgumentLen, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 475 | SmallVectorImpl<char> &OutStr) { |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 476 | const char *ArgumentEnd = Argument+ArgumentLen; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 477 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 478 | // Skip over 'ValNo' |'s. |
| 479 | while (ValNo) { |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 480 | const char *NextVal = ScanFormat(Argument, ArgumentEnd, '|'); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 481 | assert(NextVal != ArgumentEnd && "Value for integer select modifier was" |
| 482 | " larger than the number of options in the diagnostic string!"); |
| 483 | Argument = NextVal+1; // Skip this string. |
| 484 | --ValNo; |
| 485 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 487 | // Get the end of the value. This is either the } or the |. |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 488 | const char *EndPtr = ScanFormat(Argument, ArgumentEnd, '|'); |
John McCall | e4d5432 | 2010-01-13 23:58:20 +0000 | [diff] [blame] | 489 | |
| 490 | // Recursively format the result of the select clause into the output string. |
| 491 | DInfo.FormatDiagnostic(Argument, EndPtr, OutStr); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /// HandleIntegerSModifier - Handle the integer 's' modifier. This adds the |
| 495 | /// letter 's' to the string if the value is not 1. This is used in cases like |
| 496 | /// this: "you idiot, you have %4 parameter%s4!". |
| 497 | static void HandleIntegerSModifier(unsigned ValNo, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 498 | SmallVectorImpl<char> &OutStr) { |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 499 | if (ValNo != 1) |
| 500 | OutStr.push_back('s'); |
| 501 | } |
| 502 | |
John McCall | 9015cde | 2010-01-14 00:50:32 +0000 | [diff] [blame] | 503 | /// HandleOrdinalModifier - Handle the integer 'ord' modifier. This |
| 504 | /// prints the ordinal form of the given integer, with 1 corresponding |
| 505 | /// to the first ordinal. Currently this is hard-coded to use the |
| 506 | /// English form. |
| 507 | static void HandleOrdinalModifier(unsigned ValNo, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 508 | SmallVectorImpl<char> &OutStr) { |
John McCall | 9015cde | 2010-01-14 00:50:32 +0000 | [diff] [blame] | 509 | assert(ValNo != 0 && "ValNo must be strictly positive!"); |
| 510 | |
| 511 | llvm::raw_svector_ostream Out(OutStr); |
| 512 | |
| 513 | // We could use text forms for the first N ordinals, but the numeric |
| 514 | // forms are actually nicer in diagnostics because they stand out. |
Jordan Rose | c102b35 | 2012-09-22 01:24:42 +0000 | [diff] [blame] | 515 | Out << ValNo << llvm::getOrdinalSuffix(ValNo); |
John McCall | 9015cde | 2010-01-14 00:50:32 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 518 | |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 519 | /// PluralNumber - Parse an unsigned integer and advance Start. |
Chris Lattner | 2fe2920 | 2009-04-15 17:13:42 +0000 | [diff] [blame] | 520 | static unsigned PluralNumber(const char *&Start, const char *End) { |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 521 | // Programming 101: Parse a decimal number :-) |
| 522 | unsigned Val = 0; |
| 523 | while (Start != End && *Start >= '0' && *Start <= '9') { |
| 524 | Val *= 10; |
| 525 | Val += *Start - '0'; |
| 526 | ++Start; |
| 527 | } |
| 528 | return Val; |
| 529 | } |
| 530 | |
| 531 | /// TestPluralRange - Test if Val is in the parsed range. Modifies Start. |
Chris Lattner | 2fe2920 | 2009-04-15 17:13:42 +0000 | [diff] [blame] | 532 | static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) { |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 533 | if (*Start != '[') { |
| 534 | unsigned Ref = PluralNumber(Start, End); |
| 535 | return Ref == Val; |
| 536 | } |
| 537 | |
| 538 | ++Start; |
| 539 | unsigned Low = PluralNumber(Start, End); |
| 540 | assert(*Start == ',' && "Bad plural expression syntax: expected ,"); |
| 541 | ++Start; |
| 542 | unsigned High = PluralNumber(Start, End); |
| 543 | assert(*Start == ']' && "Bad plural expression syntax: expected )"); |
| 544 | ++Start; |
| 545 | return Low <= Val && Val <= High; |
| 546 | } |
| 547 | |
| 548 | /// EvalPluralExpr - Actual expression evaluator for HandlePluralModifier. |
Chris Lattner | 2fe2920 | 2009-04-15 17:13:42 +0000 | [diff] [blame] | 549 | static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) { |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 550 | // Empty condition? |
| 551 | if (*Start == ':') |
| 552 | return true; |
| 553 | |
| 554 | while (1) { |
| 555 | char C = *Start; |
| 556 | if (C == '%') { |
| 557 | // Modulo expression |
| 558 | ++Start; |
| 559 | unsigned Arg = PluralNumber(Start, End); |
| 560 | assert(*Start == '=' && "Bad plural expression syntax: expected ="); |
| 561 | ++Start; |
| 562 | unsigned ValMod = ValNo % Arg; |
| 563 | if (TestPluralRange(ValMod, Start, End)) |
| 564 | return true; |
| 565 | } else { |
Sebastian Redl | 3ceaf62 | 2008-11-27 07:28:14 +0000 | [diff] [blame] | 566 | assert((C == '[' || (C >= '0' && C <= '9')) && |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 567 | "Bad plural expression syntax: unexpected character"); |
| 568 | // Range expression |
| 569 | if (TestPluralRange(ValNo, Start, End)) |
| 570 | return true; |
| 571 | } |
| 572 | |
| 573 | // Scan for next or-expr part. |
| 574 | Start = std::find(Start, End, ','); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 575 | if (Start == End) |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 576 | break; |
| 577 | ++Start; |
| 578 | } |
| 579 | return false; |
| 580 | } |
| 581 | |
| 582 | /// HandlePluralModifier - Handle the integer 'plural' modifier. This is used |
| 583 | /// for complex plural forms, or in languages where all plurals are complex. |
| 584 | /// The syntax is: %plural{cond1:form1|cond2:form2|:form3}, where condn are |
| 585 | /// conditions that are tested in order, the form corresponding to the first |
| 586 | /// that applies being emitted. The empty condition is always true, making the |
| 587 | /// last form a default case. |
| 588 | /// Conditions are simple boolean expressions, where n is the number argument. |
| 589 | /// Here are the rules. |
| 590 | /// condition := expression | empty |
| 591 | /// empty := -> always true |
| 592 | /// expression := numeric [',' expression] -> logical or |
| 593 | /// numeric := range -> true if n in range |
| 594 | /// | '%' number '=' range -> true if n % number in range |
| 595 | /// range := number |
| 596 | /// | '[' number ',' number ']' -> ranges are inclusive both ends |
| 597 | /// |
| 598 | /// Here are some examples from the GNU gettext manual written in this form: |
| 599 | /// English: |
| 600 | /// {1:form0|:form1} |
| 601 | /// Latvian: |
| 602 | /// {0:form2|%100=11,%10=0,%10=[2,9]:form1|:form0} |
| 603 | /// Gaeilge: |
| 604 | /// {1:form0|2:form1|:form2} |
| 605 | /// Romanian: |
| 606 | /// {1:form0|0,%100=[1,19]:form1|:form2} |
| 607 | /// Lithuanian: |
| 608 | /// {%10=0,%100=[10,19]:form2|%10=1:form0|:form1} |
| 609 | /// Russian (requires repeated form): |
| 610 | /// {%100=[11,14]:form2|%10=1:form0|%10=[2,4]:form1|:form2} |
| 611 | /// Slovak |
| 612 | /// {1:form0|[2,4]:form1|:form2} |
| 613 | /// Polish (requires repeated form): |
| 614 | /// {1:form0|%100=[10,20]:form2|%10=[2,4]:form1|:form2} |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 615 | static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo, |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 616 | const char *Argument, unsigned ArgumentLen, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 617 | SmallVectorImpl<char> &OutStr) { |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 618 | const char *ArgumentEnd = Argument + ArgumentLen; |
| 619 | while (1) { |
| 620 | assert(Argument < ArgumentEnd && "Plural expression didn't match."); |
| 621 | const char *ExprEnd = Argument; |
| 622 | while (*ExprEnd != ':') { |
| 623 | assert(ExprEnd != ArgumentEnd && "Plural missing expression end"); |
| 624 | ++ExprEnd; |
| 625 | } |
| 626 | if (EvalPluralExpr(ValNo, Argument, ExprEnd)) { |
| 627 | Argument = ExprEnd + 1; |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 628 | ExprEnd = ScanFormat(Argument, ArgumentEnd, '|'); |
John McCall | 43b6168 | 2010-10-14 01:55:31 +0000 | [diff] [blame] | 629 | |
| 630 | // Recursively format the result of the plural clause into the |
| 631 | // output string. |
| 632 | DInfo.FormatDiagnostic(Argument, ExprEnd, OutStr); |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 633 | return; |
| 634 | } |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 635 | Argument = ScanFormat(Argument, ArgumentEnd - 1, '|') + 1; |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
Alp Toker | a231ad2 | 2014-01-06 12:54:18 +0000 | [diff] [blame] | 639 | /// \brief Returns the friendly description for a token kind that will appear |
| 640 | /// without quotes in diagnostic messages. These strings may be translatable in |
| 641 | /// future. |
| 642 | static const char *getTokenDescForDiagnostic(tok::TokenKind Kind) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 643 | switch (Kind) { |
| 644 | case tok::identifier: |
| 645 | return "identifier"; |
| 646 | default: |
Craig Topper | f1186c5 | 2014-05-08 06:41:40 +0000 | [diff] [blame] | 647 | return nullptr; |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 648 | } |
| 649 | } |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 650 | |
Chris Lattner | 23be067 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 651 | /// FormatDiagnostic - Format this diagnostic into a string, substituting the |
| 652 | /// formal arguments into the %0 slots. The result is appended onto the Str |
| 653 | /// array. |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 654 | void Diagnostic:: |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 655 | FormatDiagnostic(SmallVectorImpl<char> &OutStr) const { |
Argyrios Kyrtzidis | e9af37d | 2011-05-05 07:54:59 +0000 | [diff] [blame] | 656 | if (!StoredDiagMessage.empty()) { |
| 657 | OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end()); |
| 658 | return; |
| 659 | } |
| 660 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 661 | StringRef Diag = |
Argyrios Kyrtzidis | 0e37afa | 2011-05-25 05:05:01 +0000 | [diff] [blame] | 662 | getDiags()->getDiagnosticIDs()->getDescription(getID()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | |
Argyrios Kyrtzidis | 0e37afa | 2011-05-25 05:05:01 +0000 | [diff] [blame] | 664 | FormatDiagnostic(Diag.begin(), Diag.end(), OutStr); |
John McCall | e4d5432 | 2010-01-13 23:58:20 +0000 | [diff] [blame] | 665 | } |
| 666 | |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 667 | void Diagnostic:: |
John McCall | e4d5432 | 2010-01-13 23:58:20 +0000 | [diff] [blame] | 668 | FormatDiagnostic(const char *DiagStr, const char *DiagEnd, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 669 | SmallVectorImpl<char> &OutStr) const { |
John McCall | e4d5432 | 2010-01-13 23:58:20 +0000 | [diff] [blame] | 670 | |
Richard Trieu | b3b8bb0 | 2015-01-08 01:27:03 +0000 | [diff] [blame] | 671 | // When the diagnostic string is only "%0", the entire string is being given |
| 672 | // by an outside source. Remove unprintable characters from this string |
| 673 | // and skip all the other string processing. |
Richard Trieu | dcd7bb0 | 2015-01-17 00:56:10 +0000 | [diff] [blame] | 674 | if (DiagEnd - DiagStr == 2 && |
| 675 | StringRef(DiagStr, DiagEnd - DiagStr).equals("%0") && |
Richard Trieu | b3b8bb0 | 2015-01-08 01:27:03 +0000 | [diff] [blame] | 676 | getArgKind(0) == DiagnosticsEngine::ak_std_string) { |
| 677 | const std::string &S = getArgStdStr(0); |
| 678 | for (char c : S) { |
| 679 | if (llvm::sys::locale::isPrint(c) || c == '\t') { |
| 680 | OutStr.push_back(c); |
| 681 | } |
| 682 | } |
| 683 | return; |
| 684 | } |
| 685 | |
Chris Lattner | c243f29 | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 686 | /// FormattedArgs - Keep track of all of the arguments formatted by |
| 687 | /// ConvertArgToString and pass them into subsequent calls to |
| 688 | /// ConvertArgToString, allowing the implementation to avoid redundancies in |
| 689 | /// obvious cases. |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 690 | SmallVector<DiagnosticsEngine::ArgumentValue, 8> FormattedArgs; |
Chandler Carruth | d517395 | 2011-07-11 17:49:21 +0000 | [diff] [blame] | 691 | |
| 692 | /// QualTypeVals - Pass a vector of arrays so that QualType names can be |
| 693 | /// compared to see if more information is needed to be printed. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 694 | SmallVector<intptr_t, 2> QualTypeVals; |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 695 | SmallVector<char, 64> Tree; |
| 696 | |
Chandler Carruth | d517395 | 2011-07-11 17:49:21 +0000 | [diff] [blame] | 697 | for (unsigned i = 0, e = getNumArgs(); i < e; ++i) |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 698 | if (getArgKind(i) == DiagnosticsEngine::ak_qualtype) |
Chandler Carruth | d517395 | 2011-07-11 17:49:21 +0000 | [diff] [blame] | 699 | QualTypeVals.push_back(getRawArg(i)); |
| 700 | |
Chris Lattner | 23be067 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 701 | while (DiagStr != DiagEnd) { |
| 702 | if (DiagStr[0] != '%') { |
| 703 | // Append non-%0 substrings to Str if we have one. |
| 704 | const char *StrEnd = std::find(DiagStr, DiagEnd, '%'); |
| 705 | OutStr.append(DiagStr, StrEnd); |
| 706 | DiagStr = StrEnd; |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 707 | continue; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 708 | } else if (isPunctuation(DiagStr[1])) { |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 709 | OutStr.push_back(DiagStr[1]); // %% -> %. |
Chris Lattner | 23be067 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 710 | DiagStr += 2; |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 711 | continue; |
| 712 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 714 | // Skip the %. |
| 715 | ++DiagStr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 716 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 717 | // This must be a placeholder for a diagnostic argument. The format for a |
| 718 | // placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0". |
| 719 | // The digit is a number from 0-9 indicating which argument this comes from. |
| 720 | // The modifier is a string of digits from the set [-a-z]+, arguments is a |
| 721 | // brace enclosed string. |
Craig Topper | f1186c5 | 2014-05-08 06:41:40 +0000 | [diff] [blame] | 722 | const char *Modifier = nullptr, *Argument = nullptr; |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 723 | unsigned ModifierLen = 0, ArgumentLen = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 725 | // Check to see if we have a modifier. If so eat it. |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 726 | if (!isDigit(DiagStr[0])) { |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 727 | Modifier = DiagStr; |
| 728 | while (DiagStr[0] == '-' || |
| 729 | (DiagStr[0] >= 'a' && DiagStr[0] <= 'z')) |
| 730 | ++DiagStr; |
| 731 | ModifierLen = DiagStr-Modifier; |
Chris Lattner | 23be067 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 732 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 733 | // If we have an argument, get it next. |
| 734 | if (DiagStr[0] == '{') { |
| 735 | ++DiagStr; // Skip {. |
| 736 | Argument = DiagStr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 737 | |
John McCall | 8cb7a8a3 | 2010-01-14 20:11:39 +0000 | [diff] [blame] | 738 | DiagStr = ScanFormat(DiagStr, DiagEnd, '}'); |
| 739 | assert(DiagStr != DiagEnd && "Mismatched {}'s in diagnostic string!"); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 740 | ArgumentLen = DiagStr-Argument; |
| 741 | ++DiagStr; // Skip }. |
Chris Lattner | 23be067 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 742 | } |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 743 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 744 | |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 745 | assert(isDigit(*DiagStr) && "Invalid format for argument in diagnostic"); |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 746 | unsigned ArgNo = *DiagStr++ - '0'; |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 747 | |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 748 | // Only used for type diffing. |
| 749 | unsigned ArgNo2 = ArgNo; |
| 750 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 751 | DiagnosticsEngine::ArgumentKind Kind = getArgKind(ArgNo); |
Richard Trieu | 90c31f5 | 2013-01-30 20:04:31 +0000 | [diff] [blame] | 752 | if (ModifierIs(Modifier, ModifierLen, "diff")) { |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 753 | assert(*DiagStr == ',' && isDigit(*(DiagStr + 1)) && |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 754 | "Invalid format for diff modifier"); |
| 755 | ++DiagStr; // Comma. |
| 756 | ArgNo2 = *DiagStr++ - '0'; |
Richard Trieu | 90c31f5 | 2013-01-30 20:04:31 +0000 | [diff] [blame] | 757 | DiagnosticsEngine::ArgumentKind Kind2 = getArgKind(ArgNo2); |
| 758 | if (Kind == DiagnosticsEngine::ak_qualtype && |
| 759 | Kind2 == DiagnosticsEngine::ak_qualtype) |
| 760 | Kind = DiagnosticsEngine::ak_qualtype_pair; |
| 761 | else { |
| 762 | // %diff only supports QualTypes. For other kinds of arguments, |
| 763 | // use the default printing. For example, if the modifier is: |
| 764 | // "%diff{compare $ to $|other text}1,2" |
| 765 | // treat it as: |
| 766 | // "compare %1 to %2" |
Chandler Carruth | 8df65e4 | 2016-12-23 05:19:47 +0000 | [diff] [blame] | 767 | const char *ArgumentEnd = Argument + ArgumentLen; |
| 768 | const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|'); |
| 769 | assert(ScanFormat(Pipe + 1, ArgumentEnd, '|') == ArgumentEnd && |
| 770 | "Found too many '|'s in a %diff modifier!"); |
Richard Trieu | 90c31f5 | 2013-01-30 20:04:31 +0000 | [diff] [blame] | 771 | const char *FirstDollar = ScanFormat(Argument, Pipe, '$'); |
| 772 | const char *SecondDollar = ScanFormat(FirstDollar + 1, Pipe, '$'); |
Filipe Cabecinhas | ed4a00c | 2013-01-30 22:03:24 +0000 | [diff] [blame] | 773 | const char ArgStr1[] = { '%', static_cast<char>('0' + ArgNo) }; |
| 774 | const char ArgStr2[] = { '%', static_cast<char>('0' + ArgNo2) }; |
Richard Trieu | 90c31f5 | 2013-01-30 20:04:31 +0000 | [diff] [blame] | 775 | FormatDiagnostic(Argument, FirstDollar, OutStr); |
| 776 | FormatDiagnostic(ArgStr1, ArgStr1 + 2, OutStr); |
| 777 | FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr); |
| 778 | FormatDiagnostic(ArgStr2, ArgStr2 + 2, OutStr); |
| 779 | FormatDiagnostic(SecondDollar + 1, Pipe, OutStr); |
| 780 | continue; |
| 781 | } |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 782 | } |
Chris Lattner | c243f29 | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 783 | |
| 784 | switch (Kind) { |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 785 | // ---- STRINGS ---- |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 786 | case DiagnosticsEngine::ak_std_string: { |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 787 | const std::string &S = getArgStdStr(ArgNo); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 788 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
| 789 | OutStr.append(S.begin(), S.end()); |
| 790 | break; |
| 791 | } |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 792 | case DiagnosticsEngine::ak_c_string: { |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 793 | const char *S = getArgCStr(ArgNo); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 794 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
Daniel Dunbar | 69a79b1 | 2009-04-20 06:13:16 +0000 | [diff] [blame] | 795 | |
| 796 | // Don't crash if get passed a null pointer by accident. |
| 797 | if (!S) |
| 798 | S = "(null)"; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 799 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 800 | OutStr.append(S, S + strlen(S)); |
| 801 | break; |
| 802 | } |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 803 | // ---- INTEGERS ---- |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 804 | case DiagnosticsEngine::ak_sint: { |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 805 | int Val = getArgSInt(ArgNo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 807 | if (ModifierIs(Modifier, ModifierLen, "select")) { |
John McCall | 43b6168 | 2010-10-14 01:55:31 +0000 | [diff] [blame] | 808 | HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen, |
| 809 | OutStr); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 810 | } else if (ModifierIs(Modifier, ModifierLen, "s")) { |
| 811 | HandleIntegerSModifier(Val, OutStr); |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 812 | } else if (ModifierIs(Modifier, ModifierLen, "plural")) { |
John McCall | 43b6168 | 2010-10-14 01:55:31 +0000 | [diff] [blame] | 813 | HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen, |
| 814 | OutStr); |
John McCall | 9015cde | 2010-01-14 00:50:32 +0000 | [diff] [blame] | 815 | } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) { |
| 816 | HandleOrdinalModifier((unsigned)Val, OutStr); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 817 | } else { |
| 818 | assert(ModifierLen == 0 && "Unknown integer modifier"); |
Daniel Dunbar | e363379 | 2009-10-17 18:12:14 +0000 | [diff] [blame] | 819 | llvm::raw_svector_ostream(OutStr) << Val; |
Chris Lattner | 91aea71 | 2008-11-19 07:22:31 +0000 | [diff] [blame] | 820 | } |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 821 | break; |
| 822 | } |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 823 | case DiagnosticsEngine::ak_uint: { |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 824 | unsigned Val = getArgUInt(ArgNo); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 826 | if (ModifierIs(Modifier, ModifierLen, "select")) { |
John McCall | e4d5432 | 2010-01-13 23:58:20 +0000 | [diff] [blame] | 827 | HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 828 | } else if (ModifierIs(Modifier, ModifierLen, "s")) { |
| 829 | HandleIntegerSModifier(Val, OutStr); |
Sebastian Redl | 15b02d2 | 2008-11-22 13:44:36 +0000 | [diff] [blame] | 830 | } else if (ModifierIs(Modifier, ModifierLen, "plural")) { |
John McCall | 43b6168 | 2010-10-14 01:55:31 +0000 | [diff] [blame] | 831 | HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen, |
| 832 | OutStr); |
John McCall | 9015cde | 2010-01-14 00:50:32 +0000 | [diff] [blame] | 833 | } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) { |
| 834 | HandleOrdinalModifier(Val, OutStr); |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 835 | } else { |
| 836 | assert(ModifierLen == 0 && "Unknown integer modifier"); |
Daniel Dunbar | e363379 | 2009-10-17 18:12:14 +0000 | [diff] [blame] | 837 | llvm::raw_svector_ostream(OutStr) << Val; |
Chris Lattner | 91aea71 | 2008-11-19 07:22:31 +0000 | [diff] [blame] | 838 | } |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 839 | break; |
Chris Lattner | 2b78690 | 2008-11-21 07:50:02 +0000 | [diff] [blame] | 840 | } |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 841 | // ---- TOKEN SPELLINGS ---- |
| 842 | case DiagnosticsEngine::ak_tokenkind: { |
| 843 | tok::TokenKind Kind = static_cast<tok::TokenKind>(getRawArg(ArgNo)); |
| 844 | assert(ModifierLen == 0 && "No modifiers for token kinds yet"); |
| 845 | |
| 846 | llvm::raw_svector_ostream Out(OutStr); |
Alp Toker | a231ad2 | 2014-01-06 12:54:18 +0000 | [diff] [blame] | 847 | if (const char *S = tok::getPunctuatorSpelling(Kind)) |
| 848 | // Quoted token spelling for punctuators. |
| 849 | Out << '\'' << S << '\''; |
| 850 | else if (const char *S = tok::getKeywordSpelling(Kind)) |
| 851 | // Unquoted token spelling for keywords. |
| 852 | Out << S; |
| 853 | else if (const char *S = getTokenDescForDiagnostic(Kind)) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 854 | // Unquoted translatable token name. |
| 855 | Out << S; |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 856 | else if (const char *S = tok::getTokenName(Kind)) |
| 857 | // Debug name, shouldn't appear in user-facing diagnostics. |
| 858 | Out << '<' << S << '>'; |
| 859 | else |
| 860 | Out << "(null)"; |
| 861 | break; |
| 862 | } |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 863 | // ---- NAMES and TYPES ---- |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 864 | case DiagnosticsEngine::ak_identifierinfo: { |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 865 | const IdentifierInfo *II = getArgIdentifier(ArgNo); |
| 866 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
Daniel Dunbar | 69a79b1 | 2009-04-20 06:13:16 +0000 | [diff] [blame] | 867 | |
| 868 | // Don't crash if get passed a null pointer by accident. |
| 869 | if (!II) { |
| 870 | const char *S = "(null)"; |
| 871 | OutStr.append(S, S + strlen(S)); |
| 872 | continue; |
| 873 | } |
| 874 | |
Daniel Dunbar | 07d0785 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 875 | llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\''; |
Chris Lattner | e3d20d9 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 876 | break; |
| 877 | } |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 878 | case DiagnosticsEngine::ak_qualtype: |
| 879 | case DiagnosticsEngine::ak_declarationname: |
| 880 | case DiagnosticsEngine::ak_nameddecl: |
| 881 | case DiagnosticsEngine::ak_nestednamespec: |
| 882 | case DiagnosticsEngine::ak_declcontext: |
Aaron Ballman | 3e424b5 | 2013-12-26 18:30:57 +0000 | [diff] [blame] | 883 | case DiagnosticsEngine::ak_attr: |
Chris Lattner | c243f29 | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 884 | getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo), |
Craig Topper | 3aa4fb3 | 2014-06-12 05:32:35 +0000 | [diff] [blame] | 885 | StringRef(Modifier, ModifierLen), |
| 886 | StringRef(Argument, ArgumentLen), |
Craig Topper | e475350 | 2014-06-12 05:32:27 +0000 | [diff] [blame] | 887 | FormattedArgs, |
Chandler Carruth | d517395 | 2011-07-11 17:49:21 +0000 | [diff] [blame] | 888 | OutStr, QualTypeVals); |
Chris Lattner | 6a2ed6f | 2008-11-23 09:13:29 +0000 | [diff] [blame] | 889 | break; |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 890 | case DiagnosticsEngine::ak_qualtype_pair: |
| 891 | // Create a struct with all the info needed for printing. |
| 892 | TemplateDiffTypes TDT; |
| 893 | TDT.FromType = getRawArg(ArgNo); |
| 894 | TDT.ToType = getRawArg(ArgNo2); |
| 895 | TDT.ElideType = getDiags()->ElideType; |
| 896 | TDT.ShowColors = getDiags()->ShowColors; |
Richard Trieu | 50f5f46 | 2012-07-10 01:46:04 +0000 | [diff] [blame] | 897 | TDT.TemplateDiffUsed = false; |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 898 | intptr_t val = reinterpret_cast<intptr_t>(&TDT); |
| 899 | |
Richard Trieu | c605844 | 2012-06-29 21:12:16 +0000 | [diff] [blame] | 900 | const char *ArgumentEnd = Argument + ArgumentLen; |
| 901 | const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|'); |
| 902 | |
Richard Trieu | a405600 | 2012-07-13 21:18:32 +0000 | [diff] [blame] | 903 | // Print the tree. If this diagnostic already has a tree, skip the |
| 904 | // second tree. |
| 905 | if (getDiags()->PrintTemplateTree && Tree.empty()) { |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 906 | TDT.PrintFromType = true; |
| 907 | TDT.PrintTree = true; |
| 908 | getDiags()->ConvertArgToString(Kind, val, |
Craig Topper | 3aa4fb3 | 2014-06-12 05:32:35 +0000 | [diff] [blame] | 909 | StringRef(Modifier, ModifierLen), |
| 910 | StringRef(Argument, ArgumentLen), |
Craig Topper | e475350 | 2014-06-12 05:32:27 +0000 | [diff] [blame] | 911 | FormattedArgs, |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 912 | Tree, QualTypeVals); |
| 913 | // If there is no tree information, fall back to regular printing. |
Richard Trieu | c605844 | 2012-06-29 21:12:16 +0000 | [diff] [blame] | 914 | if (!Tree.empty()) { |
| 915 | FormatDiagnostic(Pipe + 1, ArgumentEnd, OutStr); |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 916 | break; |
Richard Trieu | c605844 | 2012-06-29 21:12:16 +0000 | [diff] [blame] | 917 | } |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | // Non-tree printing, also the fall-back when tree printing fails. |
| 921 | // The fall-back is triggered when the types compared are not templates. |
Richard Trieu | c605844 | 2012-06-29 21:12:16 +0000 | [diff] [blame] | 922 | const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$'); |
| 923 | const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$'); |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 924 | |
| 925 | // Append before text |
Richard Trieu | c605844 | 2012-06-29 21:12:16 +0000 | [diff] [blame] | 926 | FormatDiagnostic(Argument, FirstDollar, OutStr); |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 927 | |
| 928 | // Append first type |
| 929 | TDT.PrintTree = false; |
| 930 | TDT.PrintFromType = true; |
| 931 | getDiags()->ConvertArgToString(Kind, val, |
Craig Topper | 3aa4fb3 | 2014-06-12 05:32:35 +0000 | [diff] [blame] | 932 | StringRef(Modifier, ModifierLen), |
| 933 | StringRef(Argument, ArgumentLen), |
Craig Topper | e475350 | 2014-06-12 05:32:27 +0000 | [diff] [blame] | 934 | FormattedArgs, |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 935 | OutStr, QualTypeVals); |
Richard Trieu | 50f5f46 | 2012-07-10 01:46:04 +0000 | [diff] [blame] | 936 | if (!TDT.TemplateDiffUsed) |
| 937 | FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype, |
| 938 | TDT.FromType)); |
| 939 | |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 940 | // Append middle text |
Richard Trieu | c605844 | 2012-06-29 21:12:16 +0000 | [diff] [blame] | 941 | FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr); |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 942 | |
| 943 | // Append second type |
| 944 | TDT.PrintFromType = false; |
| 945 | getDiags()->ConvertArgToString(Kind, val, |
Craig Topper | 3aa4fb3 | 2014-06-12 05:32:35 +0000 | [diff] [blame] | 946 | StringRef(Modifier, ModifierLen), |
| 947 | StringRef(Argument, ArgumentLen), |
Craig Topper | e475350 | 2014-06-12 05:32:27 +0000 | [diff] [blame] | 948 | FormattedArgs, |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 949 | OutStr, QualTypeVals); |
Richard Trieu | 50f5f46 | 2012-07-10 01:46:04 +0000 | [diff] [blame] | 950 | if (!TDT.TemplateDiffUsed) |
| 951 | FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype, |
| 952 | TDT.ToType)); |
| 953 | |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 954 | // Append end text |
Richard Trieu | c605844 | 2012-06-29 21:12:16 +0000 | [diff] [blame] | 955 | FormatDiagnostic(SecondDollar + 1, Pipe, OutStr); |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 956 | break; |
Nico Weber | 4c31164 | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 957 | } |
Chris Lattner | c243f29 | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 958 | |
| 959 | // Remember this argument info for subsequent formatting operations. Turn |
| 960 | // std::strings into a null terminated string to make it be the same case as |
| 961 | // all the other ones. |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 962 | if (Kind == DiagnosticsEngine::ak_qualtype_pair) |
| 963 | continue; |
| 964 | else if (Kind != DiagnosticsEngine::ak_std_string) |
Chris Lattner | c243f29 | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 965 | FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo))); |
| 966 | else |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 967 | FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_c_string, |
Chris Lattner | c243f29 | 2009-10-20 05:25:22 +0000 | [diff] [blame] | 968 | (intptr_t)getArgStdStr(ArgNo).c_str())); |
| 969 | |
Nico Weber | 4c31164 | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 970 | } |
Richard Trieu | 9184423 | 2012-06-26 18:18:47 +0000 | [diff] [blame] | 971 | |
| 972 | // Append the type tree to the end of the diagnostics. |
| 973 | OutStr.append(Tree.begin(), Tree.end()); |
Nico Weber | 4c31164 | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 974 | } |
Ted Kremenek | ea06ec1 | 2009-01-23 20:28:53 +0000 | [diff] [blame] | 975 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 976 | StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 977 | StringRef Message) |
Benjamin Kramer | 929bd68 | 2010-11-19 17:36:51 +0000 | [diff] [blame] | 978 | : ID(ID), Level(Level), Loc(), Message(Message) { } |
Douglas Gregor | 33cdd81 | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 979 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 980 | StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, |
David Blaikie | b578432 | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 981 | const Diagnostic &Info) |
Douglas Gregor | a750e8e | 2010-11-19 16:18:16 +0000 | [diff] [blame] | 982 | : ID(Info.getID()), Level(Level) |
| 983 | { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 984 | assert((Info.getLocation().isInvalid() || Info.hasSourceManager()) && |
| 985 | "Valid source location without setting a source manager for diagnostic"); |
| 986 | if (Info.getLocation().isValid()) |
| 987 | Loc = FullSourceLoc(Info.getLocation(), Info.getSourceManager()); |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 988 | SmallString<64> Message; |
Douglas Gregor | 33cdd81 | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 989 | Info.FormatDiagnostic(Message); |
| 990 | this->Message.assign(Message.begin(), Message.end()); |
Benjamin Kramer | f989042 | 2015-02-17 16:48:30 +0000 | [diff] [blame] | 991 | this->Ranges.assign(Info.getRanges().begin(), Info.getRanges().end()); |
| 992 | this->FixIts.assign(Info.getFixItHints().begin(), Info.getFixItHints().end()); |
Douglas Gregor | 33cdd81 | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 993 | } |
| 994 | |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 995 | StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 996 | StringRef Message, FullSourceLoc Loc, |
Chris Lattner | 54b1677 | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 997 | ArrayRef<CharSourceRange> Ranges, |
Aaron Ballman | 234ebd7 | 2013-02-24 19:08:10 +0000 | [diff] [blame] | 998 | ArrayRef<FixItHint> FixIts) |
| 999 | : ID(ID), Level(Level), Loc(Loc), Message(Message), |
| 1000 | Ranges(Ranges.begin(), Ranges.end()), FixIts(FixIts.begin(), FixIts.end()) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1001 | { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Ted Kremenek | ea06ec1 | 2009-01-23 20:28:53 +0000 | [diff] [blame] | 1004 | /// IncludeInDiagnosticCounts - This method (whose default implementation |
| 1005 | /// returns true) indicates whether the diagnostics handled by this |
David Blaikie | e2eefae | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 1006 | /// DiagnosticConsumer should be included in the number of diagnostics |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1007 | /// reported by DiagnosticsEngine. |
David Blaikie | e2eefae | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 1008 | bool DiagnosticConsumer::IncludeInDiagnosticCounts() const { return true; } |
Douglas Gregor | 8933623 | 2010-03-29 23:34:08 +0000 | [diff] [blame] | 1009 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1010 | void IgnoringDiagConsumer::anchor() { } |
| 1011 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 1012 | ForwardingDiagnosticConsumer::~ForwardingDiagnosticConsumer() {} |
Douglas Gregor | 6b93096 | 2013-05-03 22:58:43 +0000 | [diff] [blame] | 1013 | |
| 1014 | void ForwardingDiagnosticConsumer::HandleDiagnostic( |
| 1015 | DiagnosticsEngine::Level DiagLevel, |
| 1016 | const Diagnostic &Info) { |
| 1017 | Target.HandleDiagnostic(DiagLevel, Info); |
| 1018 | } |
| 1019 | |
| 1020 | void ForwardingDiagnosticConsumer::clear() { |
| 1021 | DiagnosticConsumer::clear(); |
| 1022 | Target.clear(); |
| 1023 | } |
| 1024 | |
| 1025 | bool ForwardingDiagnosticConsumer::IncludeInDiagnosticCounts() const { |
| 1026 | return Target.IncludeInDiagnosticCounts(); |
| 1027 | } |
| 1028 | |
Benjamin Kramer | 7ec12c9 | 2012-02-07 22:29:24 +0000 | [diff] [blame] | 1029 | PartialDiagnostic::StorageAllocator::StorageAllocator() { |
Douglas Gregor | 8933623 | 2010-03-29 23:34:08 +0000 | [diff] [blame] | 1030 | for (unsigned I = 0; I != NumCached; ++I) |
| 1031 | FreeList[I] = Cached + I; |
| 1032 | NumFreeListEntries = NumCached; |
| 1033 | } |
| 1034 | |
Benjamin Kramer | 7ec12c9 | 2012-02-07 22:29:24 +0000 | [diff] [blame] | 1035 | PartialDiagnostic::StorageAllocator::~StorageAllocator() { |
Chad Rosier | 849a67b | 2012-02-07 23:24:49 +0000 | [diff] [blame] | 1036 | // Don't assert if we are in a CrashRecovery context, as this invariant may |
| 1037 | // be invalidated during a crash. |
Justin Lebar | bf16db1 | 2016-08-10 01:09:07 +0000 | [diff] [blame] | 1038 | assert((NumFreeListEntries == NumCached || |
| 1039 | llvm::CrashRecoveryContext::isRecoveringFromCrash()) && |
| 1040 | "A partial is on the lam"); |
Douglas Gregor | 8933623 | 2010-03-29 23:34:08 +0000 | [diff] [blame] | 1041 | } |