David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 1 | //===---- VerifyDiagnosticConsumer.cpp - Verifying Diagnostic Client ------===// |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is a concrete diagnostic client, which buffers the diagnostic messages. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 14 | #include "clang/Basic/FileManager.h" |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 15 | #include "clang/Frontend/VerifyDiagnosticConsumer.h" |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 16 | #include "clang/Frontend/FrontendDiagnostic.h" |
| 17 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
| 18 | #include "clang/Lex/Preprocessor.h" |
| 19 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Regex.h" |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Anna Zaks | c035e09 | 2011-12-15 02:58:00 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 23 | using namespace clang; |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 24 | typedef VerifyDiagnosticConsumer::Directive Directive; |
| 25 | typedef VerifyDiagnosticConsumer::DirectiveList DirectiveList; |
| 26 | typedef VerifyDiagnosticConsumer::ExpectedData ExpectedData; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 27 | |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 28 | VerifyDiagnosticConsumer::VerifyDiagnosticConsumer(DiagnosticsEngine &_Diags) |
Douglas Gregor | 7824365 | 2011-09-13 01:26:44 +0000 | [diff] [blame] | 29 | : Diags(_Diags), PrimaryClient(Diags.getClient()), |
| 30 | OwnsPrimaryClient(Diags.ownsClient()), |
| 31 | Buffer(new TextDiagnosticBuffer()), CurrentPreprocessor(0) |
| 32 | { |
| 33 | Diags.takeClient(); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 34 | } |
| 35 | |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 36 | VerifyDiagnosticConsumer::~VerifyDiagnosticConsumer() { |
Douglas Gregor | 7824365 | 2011-09-13 01:26:44 +0000 | [diff] [blame] | 37 | CheckDiagnostics(); |
| 38 | Diags.takeClient(); |
| 39 | if (OwnsPrimaryClient) |
| 40 | delete PrimaryClient; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 41 | } |
| 42 | |
David Blaikie | 78ad0b9 | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 43 | // DiagnosticConsumer interface. |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 44 | |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 45 | void VerifyDiagnosticConsumer::BeginSourceFile(const LangOptions &LangOpts, |
Douglas Gregor | 1f6b2b5 | 2012-01-20 16:28:04 +0000 | [diff] [blame] | 46 | const Preprocessor *PP) { |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 47 | CurrentPreprocessor = PP; |
| 48 | if (PP) const_cast<Preprocessor*>(PP)->addCommentHandler(this); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 49 | |
| 50 | PrimaryClient->BeginSourceFile(LangOpts, PP); |
| 51 | } |
| 52 | |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 53 | void VerifyDiagnosticConsumer::EndSourceFile() { |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 54 | if (CurrentPreprocessor) |
| 55 | const_cast<Preprocessor*>(CurrentPreprocessor)->removeCommentHandler(this); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 56 | CheckDiagnostics(); |
| 57 | |
| 58 | PrimaryClient->EndSourceFile(); |
| 59 | |
| 60 | CurrentPreprocessor = 0; |
| 61 | } |
Daniel Dunbar | 221c721 | 2009-11-14 07:53:24 +0000 | [diff] [blame] | 62 | |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 63 | void VerifyDiagnosticConsumer::HandleDiagnostic( |
David Blaikie | 40847cf | 2011-09-26 01:18:08 +0000 | [diff] [blame] | 64 | DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) { |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 65 | if (Info.hasSourceManager()) { |
Axel Naumann | 0123161 | 2011-07-25 19:18:12 +0000 | [diff] [blame] | 66 | const SourceManager &SM = Info.getSourceManager(); |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 67 | FilesWithDiagnostics.insert(SM.getFileID(Info.getLocation())); |
Axel Naumann | 0123161 | 2011-07-25 19:18:12 +0000 | [diff] [blame] | 68 | } |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 69 | // Send the diagnostic to the buffer, we will check it once we reach the end |
| 70 | // of the source file (or are destructed). |
| 71 | Buffer->HandleDiagnostic(DiagLevel, Info); |
| 72 | } |
| 73 | |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 74 | //===----------------------------------------------------------------------===// |
| 75 | // Checking diagnostics implementation. |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | |
| 78 | typedef TextDiagnosticBuffer::DiagList DiagList; |
| 79 | typedef TextDiagnosticBuffer::const_iterator const_diag_iterator; |
| 80 | |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 81 | namespace { |
| 82 | |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 83 | /// StandardDirective - Directive with string matching. |
| 84 | /// |
| 85 | class StandardDirective : public Directive { |
| 86 | public: |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 87 | StandardDirective(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc, |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 88 | StringRef Text, unsigned Min, unsigned Max) |
| 89 | : Directive(DirectiveLoc, DiagnosticLoc, Text, Min, Max) { } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 90 | |
| 91 | virtual bool isValid(std::string &Error) { |
| 92 | // all strings are considered valid; even empty ones |
| 93 | return true; |
| 94 | } |
| 95 | |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 96 | virtual bool match(StringRef S) { |
| 97 | return S.find(Text) != StringRef::npos; |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 98 | } |
| 99 | }; |
| 100 | |
| 101 | /// RegexDirective - Directive with regular-expression matching. |
| 102 | /// |
| 103 | class RegexDirective : public Directive { |
| 104 | public: |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 105 | RegexDirective(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc, |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 106 | StringRef Text, unsigned Min, unsigned Max) |
| 107 | : Directive(DirectiveLoc, DiagnosticLoc, Text, Min, Max), Regex(Text) { } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 108 | |
| 109 | virtual bool isValid(std::string &Error) { |
| 110 | if (Regex.isValid(Error)) |
| 111 | return true; |
| 112 | return false; |
| 113 | } |
| 114 | |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 115 | virtual bool match(StringRef S) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 116 | return Regex.match(S); |
| 117 | } |
| 118 | |
| 119 | private: |
| 120 | llvm::Regex Regex; |
| 121 | }; |
| 122 | |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 123 | class ParseHelper |
| 124 | { |
| 125 | public: |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 126 | ParseHelper(StringRef S) |
| 127 | : Begin(S.begin()), End(S.end()), C(Begin), P(Begin), PEnd(NULL) { } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 128 | |
| 129 | // Return true if string literal is next. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 130 | bool Next(StringRef S) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 131 | P = C; |
Benjamin Kramer | 0080f0c | 2010-09-01 17:28:48 +0000 | [diff] [blame] | 132 | PEnd = C + S.size(); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 133 | if (PEnd > End) |
| 134 | return false; |
Benjamin Kramer | 0080f0c | 2010-09-01 17:28:48 +0000 | [diff] [blame] | 135 | return !memcmp(P, S.data(), S.size()); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // Return true if number is next. |
| 139 | // Output N only if number is next. |
| 140 | bool Next(unsigned &N) { |
| 141 | unsigned TMP = 0; |
| 142 | P = C; |
| 143 | for (; P < End && P[0] >= '0' && P[0] <= '9'; ++P) { |
| 144 | TMP *= 10; |
| 145 | TMP += P[0] - '0'; |
| 146 | } |
| 147 | if (P == C) |
| 148 | return false; |
| 149 | PEnd = P; |
| 150 | N = TMP; |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | // Return true if string literal is found. |
| 155 | // When true, P marks begin-position of S in content. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 156 | bool Search(StringRef S) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 157 | P = std::search(C, End, S.begin(), S.end()); |
Benjamin Kramer | 0080f0c | 2010-09-01 17:28:48 +0000 | [diff] [blame] | 158 | PEnd = P + S.size(); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 159 | return P != End; |
| 160 | } |
| 161 | |
| 162 | // Advance 1-past previous next/search. |
| 163 | // Behavior is undefined if previous next/search failed. |
| 164 | bool Advance() { |
| 165 | C = PEnd; |
| 166 | return C < End; |
| 167 | } |
| 168 | |
| 169 | // Skip zero or more whitespace. |
| 170 | void SkipWhitespace() { |
| 171 | for (; C < End && isspace(*C); ++C) |
| 172 | ; |
| 173 | } |
| 174 | |
| 175 | // Return true if EOF reached. |
| 176 | bool Done() { |
| 177 | return !(C < End); |
| 178 | } |
| 179 | |
| 180 | const char * const Begin; // beginning of expected content |
| 181 | const char * const End; // end of expected content (1-past) |
| 182 | const char *C; // position of next char in content |
| 183 | const char *P; |
| 184 | |
| 185 | private: |
| 186 | const char *PEnd; // previous next/search subject end (1-past) |
| 187 | }; |
| 188 | |
| 189 | } // namespace anonymous |
| 190 | |
| 191 | /// ParseDirective - Go through the comment and see if it indicates expected |
| 192 | /// diagnostics. If so, then put them in the appropriate directive list. |
| 193 | /// |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 194 | /// Returns true if any valid directives were found. |
| 195 | static bool ParseDirective(StringRef S, ExpectedData &ED, SourceManager &SM, |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 196 | SourceLocation Pos, DiagnosticsEngine &Diags) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 197 | // A single comment may contain multiple directives. |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 198 | bool FoundDirective = false; |
| 199 | for (ParseHelper PH(S); !PH.Done();) { |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 200 | // Search for token: expected |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 201 | if (!PH.Search("expected")) |
| 202 | break; |
| 203 | PH.Advance(); |
| 204 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 205 | // Next token: - |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 206 | if (!PH.Next("-")) |
| 207 | continue; |
| 208 | PH.Advance(); |
| 209 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 210 | // Next token: { error | warning | note } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 211 | DirectiveList* DL = NULL; |
| 212 | if (PH.Next("error")) |
| 213 | DL = &ED.Errors; |
| 214 | else if (PH.Next("warning")) |
| 215 | DL = &ED.Warnings; |
| 216 | else if (PH.Next("note")) |
| 217 | DL = &ED.Notes; |
| 218 | else |
| 219 | continue; |
| 220 | PH.Advance(); |
| 221 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 222 | // Default directive kind. |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 223 | bool RegexKind = false; |
| 224 | const char* KindStr = "string"; |
| 225 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 226 | // Next optional token: - |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 227 | if (PH.Next("-re")) { |
| 228 | PH.Advance(); |
| 229 | RegexKind = true; |
| 230 | KindStr = "regex"; |
| 231 | } |
| 232 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 233 | // Next optional token: @ |
| 234 | SourceLocation ExpectedLoc; |
| 235 | if (!PH.Next("@")) { |
| 236 | ExpectedLoc = Pos; |
| 237 | } else { |
| 238 | PH.Advance(); |
| 239 | unsigned Line = 0; |
| 240 | bool FoundPlus = PH.Next("+"); |
| 241 | if (FoundPlus || PH.Next("-")) { |
| 242 | // Relative to current line. |
| 243 | PH.Advance(); |
| 244 | bool Invalid = false; |
| 245 | unsigned ExpectedLine = SM.getSpellingLineNumber(Pos, &Invalid); |
| 246 | if (!Invalid && PH.Next(Line) && (FoundPlus || Line < ExpectedLine)) { |
| 247 | if (FoundPlus) ExpectedLine += Line; |
| 248 | else ExpectedLine -= Line; |
| 249 | ExpectedLoc = SM.translateLineCol(SM.getFileID(Pos), ExpectedLine, 1); |
| 250 | } |
| 251 | } else { |
| 252 | // Absolute line number. |
| 253 | if (PH.Next(Line) && Line > 0) |
| 254 | ExpectedLoc = SM.translateLineCol(SM.getFileID(Pos), Line, 1); |
| 255 | } |
| 256 | |
| 257 | if (ExpectedLoc.isInvalid()) { |
| 258 | Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin), |
| 259 | diag::err_verify_missing_line) << KindStr; |
| 260 | continue; |
| 261 | } |
| 262 | PH.Advance(); |
| 263 | } |
| 264 | |
| 265 | // Skip optional whitespace. |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 266 | PH.SkipWhitespace(); |
| 267 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 268 | // Next optional token: positive integer or a '+'. |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 269 | unsigned Min = 1; |
| 270 | unsigned Max = 1; |
| 271 | if (PH.Next(Min)) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 272 | PH.Advance(); |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 273 | // A positive integer can be followed by a '+' meaning min |
| 274 | // or more, or by a '-' meaning a range from min to max. |
| 275 | if (PH.Next("+")) { |
| 276 | Max = Directive::MaxCount; |
| 277 | PH.Advance(); |
| 278 | } else if (PH.Next("-")) { |
| 279 | PH.Advance(); |
| 280 | if (!PH.Next(Max) || Max < Min) { |
| 281 | Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin), |
| 282 | diag::err_verify_invalid_range) << KindStr; |
| 283 | continue; |
| 284 | } |
| 285 | PH.Advance(); |
| 286 | } else { |
| 287 | Max = Min; |
| 288 | } |
| 289 | } else if (PH.Next("+")) { |
| 290 | // '+' on its own means "1 or more". |
| 291 | Max = Directive::MaxCount; |
Anna Zaks | 2135ebb | 2011-12-15 02:28:16 +0000 | [diff] [blame] | 292 | PH.Advance(); |
| 293 | } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 294 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 295 | // Skip optional whitespace. |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 296 | PH.SkipWhitespace(); |
| 297 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 298 | // Next token: {{ |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 299 | if (!PH.Next("{{")) { |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 300 | Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin), |
| 301 | diag::err_verify_missing_start) << KindStr; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 302 | continue; |
| 303 | } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 304 | PH.Advance(); |
| 305 | const char* const ContentBegin = PH.C; // mark content begin |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 306 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 307 | // Search for token: }} |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 308 | if (!PH.Search("}}")) { |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 309 | Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin), |
| 310 | diag::err_verify_missing_end) << KindStr; |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 311 | continue; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 312 | } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 313 | const char* const ContentEnd = PH.P; // mark content end |
| 314 | PH.Advance(); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 315 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 316 | // Build directive text; convert \n to newlines. |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 317 | std::string Text; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 318 | StringRef NewlineStr = "\\n"; |
| 319 | StringRef Content(ContentBegin, ContentEnd-ContentBegin); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 320 | size_t CPos = 0; |
| 321 | size_t FPos; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 322 | while ((FPos = Content.find(NewlineStr, CPos)) != StringRef::npos) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 323 | Text += Content.substr(CPos, FPos-CPos); |
| 324 | Text += '\n'; |
| 325 | CPos = FPos + NewlineStr.size(); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 326 | } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 327 | if (Text.empty()) |
| 328 | Text.assign(ContentBegin, ContentEnd); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 329 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 330 | // Construct new directive. |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 331 | Directive *D = Directive::create(RegexKind, Pos, ExpectedLoc, Text, |
| 332 | Min, Max); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 333 | std::string Error; |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 334 | if (D->isValid(Error)) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 335 | DL->push_back(D); |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 336 | FoundDirective = true; |
| 337 | } else { |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 338 | Diags.Report(Pos.getLocWithOffset(ContentBegin-PH.Begin), |
| 339 | diag::err_verify_invalid_content) |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 340 | << KindStr << Error; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 341 | } |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 342 | } |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 343 | |
| 344 | return FoundDirective; |
| 345 | } |
| 346 | |
| 347 | /// HandleComment - Hook into the preprocessor and extract comments containing |
| 348 | /// expected errors and warnings. |
| 349 | bool VerifyDiagnosticConsumer::HandleComment(Preprocessor &PP, |
| 350 | SourceRange Comment) { |
| 351 | SourceManager &SM = PP.getSourceManager(); |
| 352 | SourceLocation CommentBegin = Comment.getBegin(); |
| 353 | |
| 354 | const char *CommentRaw = SM.getCharacterData(CommentBegin); |
| 355 | StringRef C(CommentRaw, SM.getCharacterData(Comment.getEnd()) - CommentRaw); |
| 356 | |
| 357 | if (C.empty()) |
| 358 | return false; |
| 359 | |
| 360 | // Fold any "\<EOL>" sequences |
| 361 | size_t loc = C.find('\\'); |
| 362 | if (loc == StringRef::npos) { |
| 363 | if (ParseDirective(C, ED, SM, CommentBegin, PP.getDiagnostics())) |
| 364 | if (const FileEntry *E = SM.getFileEntryForID(SM.getFileID(CommentBegin))) |
| 365 | FilesWithDirectives.insert(E); |
| 366 | return false; |
| 367 | } |
| 368 | |
| 369 | std::string C2; |
| 370 | C2.reserve(C.size()); |
| 371 | |
| 372 | for (size_t last = 0;; loc = C.find('\\', last)) { |
| 373 | if (loc == StringRef::npos || loc == C.size()) { |
| 374 | C2 += C.substr(last); |
| 375 | break; |
| 376 | } |
| 377 | C2 += C.substr(last, loc-last); |
| 378 | last = loc + 1; |
| 379 | |
| 380 | if (C[last] == '\n' || C[last] == '\r') { |
| 381 | ++last; |
| 382 | |
| 383 | // Escape \r\n or \n\r, but not \n\n. |
| 384 | if (last < C.size()) |
| 385 | if (C[last] == '\n' || C[last] == '\r') |
| 386 | if (C[last] != C[last-1]) |
| 387 | ++last; |
| 388 | } else { |
| 389 | // This was just a normal backslash. |
| 390 | C2 += '\\'; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if (!C2.empty()) |
| 395 | if (ParseDirective(C2, ED, SM, CommentBegin, PP.getDiagnostics())) |
| 396 | if (const FileEntry *E = SM.getFileEntryForID(SM.getFileID(CommentBegin))) |
| 397 | FilesWithDirectives.insert(E); |
| 398 | return false; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /// FindExpectedDiags - Lex the main source file to find all of the |
| 402 | // expected errors and warnings. |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 403 | static void FindExpectedDiags(const Preprocessor &PP, ExpectedData &ED, |
| 404 | FileID FID) { |
Axel Naumann | 0123161 | 2011-07-25 19:18:12 +0000 | [diff] [blame] | 405 | // Create a raw lexer to pull all the comments out of FID. |
| 406 | if (FID.isInvalid()) |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 407 | return; |
| 408 | |
Axel Naumann | 0123161 | 2011-07-25 19:18:12 +0000 | [diff] [blame] | 409 | SourceManager& SM = PP.getSourceManager(); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 410 | // Create a lexer to lex all the tokens of the main file in raw mode. |
Chris Lattner | 6e29014 | 2009-11-30 04:18:44 +0000 | [diff] [blame] | 411 | const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID); |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 412 | Lexer RawLex(FID, FromFile, SM, PP.getLangOpts()); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 413 | |
| 414 | // Return comments as tokens, this is how we find expected diagnostics. |
| 415 | RawLex.SetCommentRetentionState(true); |
| 416 | |
| 417 | Token Tok; |
| 418 | Tok.setKind(tok::comment); |
| 419 | while (Tok.isNot(tok::eof)) { |
| 420 | RawLex.Lex(Tok); |
| 421 | if (!Tok.is(tok::comment)) continue; |
| 422 | |
| 423 | std::string Comment = PP.getSpelling(Tok); |
| 424 | if (Comment.empty()) continue; |
| 425 | |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 426 | // Find all expected errors/warnings/notes. |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 427 | ParseDirective(Comment, ED, SM, Tok.getLocation(), PP.getDiagnostics()); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 428 | }; |
| 429 | } |
| 430 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 431 | /// \brief Takes a list of diagnostics that have been generated but not matched |
| 432 | /// by an expected-* directive and produces a diagnostic to the user from this. |
| 433 | static unsigned PrintUnexpected(DiagnosticsEngine &Diags, SourceManager *SourceMgr, |
| 434 | const_diag_iterator diag_begin, |
| 435 | const_diag_iterator diag_end, |
| 436 | const char *Kind) { |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 437 | if (diag_begin == diag_end) return 0; |
| 438 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 439 | SmallString<256> Fmt; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 440 | llvm::raw_svector_ostream OS(Fmt); |
| 441 | for (const_diag_iterator I = diag_begin, E = diag_end; I != E; ++I) { |
Daniel Dunbar | 221c721 | 2009-11-14 07:53:24 +0000 | [diff] [blame] | 442 | if (I->first.isInvalid() || !SourceMgr) |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 443 | OS << "\n (frontend)"; |
| 444 | else |
Chandler Carruth | 5ef04ee | 2011-02-23 00:47:48 +0000 | [diff] [blame] | 445 | OS << "\n Line " << SourceMgr->getPresumedLineNumber(I->first); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 446 | OS << ": " << I->second; |
| 447 | } |
| 448 | |
Jordan Rose | c6d64a2 | 2012-07-11 16:50:36 +0000 | [diff] [blame] | 449 | Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit() |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 450 | << Kind << /*Unexpected=*/true << OS.str(); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 451 | return std::distance(diag_begin, diag_end); |
| 452 | } |
| 453 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 454 | /// \brief Takes a list of diagnostics that were expected to have been generated |
| 455 | /// but were not and produces a diagnostic to the user from this. |
| 456 | static unsigned PrintExpected(DiagnosticsEngine &Diags, SourceManager &SourceMgr, |
| 457 | DirectiveList &DL, const char *Kind) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 458 | if (DL.empty()) |
| 459 | return 0; |
| 460 | |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 461 | SmallString<256> Fmt; |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 462 | llvm::raw_svector_ostream OS(Fmt); |
| 463 | for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) { |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 464 | Directive &D = **I; |
| 465 | OS << "\n Line " << SourceMgr.getPresumedLineNumber(D.DiagnosticLoc); |
| 466 | if (D.DirectiveLoc != D.DiagnosticLoc) |
| 467 | OS << " (directive at " |
| 468 | << SourceMgr.getFilename(D.DirectiveLoc) << ":" |
| 469 | << SourceMgr.getPresumedLineNumber(D.DirectiveLoc) << ")"; |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 470 | OS << ": " << D.Text; |
| 471 | } |
| 472 | |
Jordan Rose | c6d64a2 | 2012-07-11 16:50:36 +0000 | [diff] [blame] | 473 | Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit() |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 474 | << Kind << /*Unexpected=*/false << OS.str(); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 475 | return DL.size(); |
| 476 | } |
| 477 | |
| 478 | /// CheckLists - Compare expected to seen diagnostic lists and return the |
| 479 | /// the difference between them. |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 480 | /// |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 481 | static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr, |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 482 | const char *Label, |
| 483 | DirectiveList &Left, |
| 484 | const_diag_iterator d2_begin, |
| 485 | const_diag_iterator d2_end) { |
| 486 | DirectiveList LeftOnly; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 487 | DiagList Right(d2_begin, d2_end); |
| 488 | |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 489 | for (DirectiveList::iterator I = Left.begin(), E = Left.end(); I != E; ++I) { |
| 490 | Directive& D = **I; |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 491 | unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.DiagnosticLoc); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 492 | |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 493 | for (unsigned i = 0; i < D.Max; ++i) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 494 | DiagList::iterator II, IE; |
| 495 | for (II = Right.begin(), IE = Right.end(); II != IE; ++II) { |
Chandler Carruth | 5ef04ee | 2011-02-23 00:47:48 +0000 | [diff] [blame] | 496 | unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 497 | if (LineNo1 != LineNo2) |
| 498 | continue; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 499 | |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 500 | const std::string &RightText = II->second; |
Jordan Rose | 4313c01 | 2012-07-10 02:56:15 +0000 | [diff] [blame] | 501 | if (D.match(RightText)) |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 502 | break; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 503 | } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 504 | if (II == IE) { |
| 505 | // Not found. |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 506 | if (i >= D.Min) break; |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 507 | LeftOnly.push_back(*I); |
| 508 | } else { |
| 509 | // Found. The same cannot be found twice. |
| 510 | Right.erase(II); |
| 511 | } |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | // Now all that's left in Right are those that were not matched. |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 515 | unsigned num = PrintExpected(Diags, SourceMgr, LeftOnly, Label); |
| 516 | num += PrintUnexpected(Diags, &SourceMgr, Right.begin(), Right.end(), Label); |
NAKAMURA Takumi | ad64684 | 2011-12-17 13:00:31 +0000 | [diff] [blame] | 517 | return num; |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /// CheckResults - This compares the expected results to those that |
| 521 | /// were actually reported. It emits any discrepencies. Return "true" if there |
| 522 | /// were problems. Return "false" otherwise. |
| 523 | /// |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 524 | static unsigned CheckResults(DiagnosticsEngine &Diags, SourceManager &SourceMgr, |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 525 | const TextDiagnosticBuffer &Buffer, |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 526 | ExpectedData &ED) { |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 527 | // We want to capture the delta between what was expected and what was |
| 528 | // seen. |
| 529 | // |
| 530 | // Expected \ Seen - set expected but not seen |
| 531 | // Seen \ Expected - set seen but not expected |
| 532 | unsigned NumProblems = 0; |
| 533 | |
| 534 | // See if there are error mismatches. |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 535 | NumProblems += CheckLists(Diags, SourceMgr, "error", ED.Errors, |
| 536 | Buffer.err_begin(), Buffer.err_end()); |
Daniel Dunbar | 221c721 | 2009-11-14 07:53:24 +0000 | [diff] [blame] | 537 | |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 538 | // See if there are warning mismatches. |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 539 | NumProblems += CheckLists(Diags, SourceMgr, "warning", ED.Warnings, |
| 540 | Buffer.warn_begin(), Buffer.warn_end()); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 541 | |
| 542 | // See if there are note mismatches. |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 543 | NumProblems += CheckLists(Diags, SourceMgr, "note", ED.Notes, |
| 544 | Buffer.note_begin(), Buffer.note_end()); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 545 | |
| 546 | return NumProblems; |
| 547 | } |
| 548 | |
David Blaikie | 621bc69 | 2011-09-26 00:38:03 +0000 | [diff] [blame] | 549 | void VerifyDiagnosticConsumer::CheckDiagnostics() { |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 550 | // Ensure any diagnostics go to the primary client. |
Douglas Gregor | 7824365 | 2011-09-13 01:26:44 +0000 | [diff] [blame] | 551 | bool OwnsCurClient = Diags.ownsClient(); |
David Blaikie | 78ad0b9 | 2011-09-25 23:39:51 +0000 | [diff] [blame] | 552 | DiagnosticConsumer *CurClient = Diags.takeClient(); |
Douglas Gregor | 7824365 | 2011-09-13 01:26:44 +0000 | [diff] [blame] | 553 | Diags.setClient(PrimaryClient, false); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 554 | |
| 555 | // If we have a preprocessor, scan the source for expected diagnostic |
| 556 | // markers. If not then any diagnostics are unexpected. |
| 557 | if (CurrentPreprocessor) { |
Axel Naumann | 0123161 | 2011-07-25 19:18:12 +0000 | [diff] [blame] | 558 | SourceManager &SM = CurrentPreprocessor->getSourceManager(); |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 559 | // Only check for expectations in other diagnostic locations not |
| 560 | // captured during normal parsing. |
| 561 | // FIXME: This check is currently necessary while synthesized files may |
| 562 | // not have their expected-* directives captured during parsing. These |
| 563 | // cases should be fixed and the following loop replaced with one which |
| 564 | // checks only during a debug build and asserts on a mismatch. |
| 565 | for (FilesWithDiagnosticsSet::iterator I = FilesWithDiagnostics.begin(), |
| 566 | End = FilesWithDiagnostics.end(); |
| 567 | I != End; ++I) { |
| 568 | const FileEntry *E = SM.getFileEntryForID(*I); |
| 569 | if (!E || !FilesWithDirectives.count(E)) { |
| 570 | if (E) |
| 571 | FilesWithDirectives.insert(E); |
| 572 | FindExpectedDiags(*CurrentPreprocessor, ED, *I); |
| 573 | } |
Axel Naumann | 84c05e3 | 2011-08-24 13:36:19 +0000 | [diff] [blame] | 574 | } |
Daniel Dunbar | 221c721 | 2009-11-14 07:53:24 +0000 | [diff] [blame] | 575 | |
| 576 | // Check that the expected diagnostics occurred. |
Axel Naumann | 0123161 | 2011-07-25 19:18:12 +0000 | [diff] [blame] | 577 | NumErrors += CheckResults(Diags, SM, *Buffer, ED); |
Daniel Dunbar | 221c721 | 2009-11-14 07:53:24 +0000 | [diff] [blame] | 578 | } else { |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 579 | NumErrors += (PrintUnexpected(Diags, 0, Buffer->err_begin(), |
| 580 | Buffer->err_end(), "error") + |
| 581 | PrintUnexpected(Diags, 0, Buffer->warn_begin(), |
| 582 | Buffer->warn_end(), "warn") + |
| 583 | PrintUnexpected(Diags, 0, Buffer->note_begin(), |
| 584 | Buffer->note_end(), "note")); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Douglas Gregor | bdbb004 | 2010-08-18 22:29:43 +0000 | [diff] [blame] | 587 | Diags.takeClient(); |
Douglas Gregor | 7824365 | 2011-09-13 01:26:44 +0000 | [diff] [blame] | 588 | Diags.setClient(CurClient, OwnsCurClient); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 589 | |
| 590 | // Reset the buffer, we have processed all the diagnostics in it. |
| 591 | Buffer.reset(new TextDiagnosticBuffer()); |
Axel Naumann | e445e5d | 2012-07-10 16:24:07 +0000 | [diff] [blame] | 592 | ED.Errors.clear(); |
| 593 | ED.Warnings.clear(); |
| 594 | ED.Notes.clear(); |
Daniel Dunbar | 81f5a1e | 2009-11-14 03:23:19 +0000 | [diff] [blame] | 595 | } |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 596 | |
Douglas Gregor | aee526e | 2011-09-29 00:38:00 +0000 | [diff] [blame] | 597 | DiagnosticConsumer * |
| 598 | VerifyDiagnosticConsumer::clone(DiagnosticsEngine &Diags) const { |
| 599 | if (!Diags.getClient()) |
| 600 | Diags.setClient(PrimaryClient->clone(Diags)); |
| 601 | |
| 602 | return new VerifyDiagnosticConsumer(Diags); |
| 603 | } |
| 604 | |
Jordan Rose | aa48fe8 | 2012-07-10 02:57:03 +0000 | [diff] [blame] | 605 | Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc, |
| 606 | SourceLocation DiagnosticLoc, StringRef Text, |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 607 | unsigned Min, unsigned Max) { |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 608 | if (RegexKind) |
Jordan Rose | 3b81b7d | 2012-07-10 02:57:26 +0000 | [diff] [blame] | 609 | return new RegexDirective(DirectiveLoc, DiagnosticLoc, Text, Min, Max); |
| 610 | return new StandardDirective(DirectiveLoc, DiagnosticLoc, Text, Min, Max); |
Chris Lattner | 60909e1 | 2010-04-28 20:02:30 +0000 | [diff] [blame] | 611 | } |