blob: c6b2ff7c60e73f513a8de899f0d83f7909bd5b7e [file] [log] [blame]
Chris Lattner81cb8ca2009-07-08 18:44:05 +00001//===- FileCheck.cpp - Check that File's Contents match what is expected --===//
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// FileCheck does a line-by line check of a file that validates whether it
11// contains the expected content. This is useful for regression tests etc.
12//
13// This program exits with an error status of 2 on error, exit status of 0 if
14// the file matched the expected contents, and exit status of 1 if it did not
15// contain the expected contents.
16//
17//===----------------------------------------------------------------------===//
18
19#include "llvm/Support/CommandLine.h"
20#include "llvm/Support/MemoryBuffer.h"
21#include "llvm/Support/PrettyStackTrace.h"
Chris Lattner52870082009-09-24 21:47:32 +000022#include "llvm/Support/Regex.h"
Chris Lattner81cb8ca2009-07-08 18:44:05 +000023#include "llvm/Support/SourceMgr.h"
24#include "llvm/Support/raw_ostream.h"
25#include "llvm/System/Signals.h"
Daniel Dunbarfafe93c2009-11-22 22:08:06 +000026#include "llvm/ADT/SmallString.h"
Chris Lattnereec96952009-09-27 07:56:52 +000027#include "llvm/ADT/StringMap.h"
28#include <algorithm>
Chris Lattner81cb8ca2009-07-08 18:44:05 +000029using namespace llvm;
30
31static cl::opt<std::string>
32CheckFilename(cl::Positional, cl::desc("<check-file>"), cl::Required);
33
34static cl::opt<std::string>
35InputFilename("input-file", cl::desc("File to check (defaults to stdin)"),
36 cl::init("-"), cl::value_desc("filename"));
37
38static cl::opt<std::string>
39CheckPrefix("check-prefix", cl::init("CHECK"),
40 cl::desc("Prefix to use from check file (defaults to 'CHECK')"));
41
Chris Lattner88a7e9e2009-07-11 18:58:15 +000042static cl::opt<bool>
43NoCanonicalizeWhiteSpace("strict-whitespace",
44 cl::desc("Do not treat all horizontal whitespace as equivalent"));
45
Chris Lattnera29703e2009-09-24 20:39:13 +000046//===----------------------------------------------------------------------===//
47// Pattern Handling Code.
48//===----------------------------------------------------------------------===//
49
Chris Lattner9fc66782009-09-24 20:25:55 +000050class Pattern {
Chris Lattner94638f02009-09-25 17:29:36 +000051 SMLoc PatternLoc;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000052
Jakob Stoklund Olesen824c10e2010-10-15 17:47:12 +000053 /// MatchEOF - When set, this pattern only matches the end of file. This is
54 /// used for trailing CHECK-NOTs.
55 bool MatchEOF;
56
Chris Lattner5d6a05f2009-09-25 17:23:43 +000057 /// FixedStr - If non-empty, this pattern is a fixed string match with the
58 /// specified fixed string.
Chris Lattner2702e6a2009-09-25 17:09:12 +000059 StringRef FixedStr;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000060
Chris Lattner5d6a05f2009-09-25 17:23:43 +000061 /// RegEx - If non-empty, this is a regex pattern.
62 std::string RegExStr;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000063
Chris Lattnereec96952009-09-27 07:56:52 +000064 /// VariableUses - Entries in this vector map to uses of a variable in the
65 /// pattern, e.g. "foo[[bar]]baz". In this case, the RegExStr will contain
66 /// "foobaz" and we'll get an entry in this vector that tells us to insert the
67 /// value of bar at offset 3.
68 std::vector<std::pair<StringRef, unsigned> > VariableUses;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000069
Chris Lattnereec96952009-09-27 07:56:52 +000070 /// VariableDefs - Entries in this vector map to definitions of a variable in
71 /// the pattern, e.g. "foo[[bar:.*]]baz". In this case, the RegExStr will
72 /// contain "foo(.*)baz" and VariableDefs will contain the pair "bar",1. The
73 /// index indicates what parenthesized value captures the variable value.
74 std::vector<std::pair<StringRef, unsigned> > VariableDefs;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000075
Chris Lattner9fc66782009-09-24 20:25:55 +000076public:
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000077
Jakob Stoklund Olesen824c10e2010-10-15 17:47:12 +000078 Pattern(bool matchEOF = false) : MatchEOF(matchEOF) { }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000079
Chris Lattnera29703e2009-09-24 20:39:13 +000080 bool ParsePattern(StringRef PatternStr, SourceMgr &SM);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +000081
Chris Lattner9fc66782009-09-24 20:25:55 +000082 /// Match - Match the pattern string against the input buffer Buffer. This
83 /// returns the position that is matched or npos if there is no match. If
84 /// there is a match, the size of the matched string is returned in MatchLen.
Chris Lattnereec96952009-09-27 07:56:52 +000085 ///
86 /// The VariableTable StringMap provides the current values of filecheck
87 /// variables and is updated if this match defines new values.
88 size_t Match(StringRef Buffer, size_t &MatchLen,
89 StringMap<StringRef> &VariableTable) const;
Daniel Dunbarfafe93c2009-11-22 22:08:06 +000090
91 /// PrintFailureInfo - Print additional information about a failure to match
92 /// involving this pattern.
93 void PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,
94 const StringMap<StringRef> &VariableTable) const;
95
Chris Lattner5d6a05f2009-09-25 17:23:43 +000096private:
Chris Lattnereec96952009-09-27 07:56:52 +000097 static void AddFixedStringToRegEx(StringRef FixedStr, std::string &TheStr);
98 bool AddRegExToRegEx(StringRef RegExStr, unsigned &CurParen, SourceMgr &SM);
Daniel Dunbaread2dac2009-11-22 22:59:26 +000099
100 /// ComputeMatchDistance - Compute an arbitrary estimate for the quality of
101 /// matching this pattern at the start of \arg Buffer; a distance of zero
102 /// should correspond to a perfect match.
103 unsigned ComputeMatchDistance(StringRef Buffer,
104 const StringMap<StringRef> &VariableTable) const;
Chris Lattner9fc66782009-09-24 20:25:55 +0000105};
106
Chris Lattnereec96952009-09-27 07:56:52 +0000107
Chris Lattnera29703e2009-09-24 20:39:13 +0000108bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
Chris Lattner94638f02009-09-25 17:29:36 +0000109 PatternLoc = SMLoc::getFromPointer(PatternStr.data());
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000110
Chris Lattnera29703e2009-09-24 20:39:13 +0000111 // Ignore trailing whitespace.
112 while (!PatternStr.empty() &&
113 (PatternStr.back() == ' ' || PatternStr.back() == '\t'))
114 PatternStr = PatternStr.substr(0, PatternStr.size()-1);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000115
Chris Lattnera29703e2009-09-24 20:39:13 +0000116 // Check that there is something on the line.
117 if (PatternStr.empty()) {
Chris Lattner94638f02009-09-25 17:29:36 +0000118 SM.PrintMessage(PatternLoc, "found empty check string with prefix '" +
119 CheckPrefix+":'", "error");
Chris Lattnera29703e2009-09-24 20:39:13 +0000120 return true;
121 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000122
Chris Lattner2702e6a2009-09-25 17:09:12 +0000123 // Check to see if this is a fixed string, or if it has regex pieces.
Chris Lattnereec96952009-09-27 07:56:52 +0000124 if (PatternStr.size() < 2 ||
125 (PatternStr.find("{{") == StringRef::npos &&
126 PatternStr.find("[[") == StringRef::npos)) {
Chris Lattner2702e6a2009-09-25 17:09:12 +0000127 FixedStr = PatternStr;
128 return false;
129 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000130
Chris Lattnereec96952009-09-27 07:56:52 +0000131 // Paren value #0 is for the fully matched string. Any new parenthesized
132 // values add from their.
133 unsigned CurParen = 1;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000134
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000135 // Otherwise, there is at least one regex piece. Build up the regex pattern
136 // by escaping scary characters in fixed strings, building up one big regex.
Chris Lattner52870082009-09-24 21:47:32 +0000137 while (!PatternStr.empty()) {
Chris Lattnereec96952009-09-27 07:56:52 +0000138 // RegEx matches.
139 if (PatternStr.size() >= 2 &&
140 PatternStr[0] == '{' && PatternStr[1] == '{') {
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000141
Chris Lattnereec96952009-09-27 07:56:52 +0000142 // Otherwise, this is the start of a regex match. Scan for the }}.
143 size_t End = PatternStr.find("}}");
144 if (End == StringRef::npos) {
145 SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
146 "found start of regex string with no end '}}'", "error");
147 return true;
148 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000149
Chris Lattnereec96952009-09-27 07:56:52 +0000150 if (AddRegExToRegEx(PatternStr.substr(2, End-2), CurParen, SM))
151 return true;
152 PatternStr = PatternStr.substr(End+2);
Chris Lattner52870082009-09-24 21:47:32 +0000153 continue;
154 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000155
Chris Lattnereec96952009-09-27 07:56:52 +0000156 // Named RegEx matches. These are of two forms: [[foo:.*]] which matches .*
157 // (or some other regex) and assigns it to the FileCheck variable 'foo'. The
158 // second form is [[foo]] which is a reference to foo. The variable name
Daniel Dunbar964ac012009-11-22 22:07:50 +0000159 // itself must be of the form "[a-zA-Z_][0-9a-zA-Z_]*", otherwise we reject
Chris Lattnereec96952009-09-27 07:56:52 +0000160 // it. This is to catch some common errors.
161 if (PatternStr.size() >= 2 &&
162 PatternStr[0] == '[' && PatternStr[1] == '[') {
163 // Verify that it is terminated properly.
164 size_t End = PatternStr.find("]]");
165 if (End == StringRef::npos) {
166 SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
167 "invalid named regex reference, no ]] found", "error");
168 return true;
169 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000170
Chris Lattnereec96952009-09-27 07:56:52 +0000171 StringRef MatchStr = PatternStr.substr(2, End-2);
172 PatternStr = PatternStr.substr(End+2);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000173
Chris Lattnereec96952009-09-27 07:56:52 +0000174 // Get the regex name (e.g. "foo").
175 size_t NameEnd = MatchStr.find(':');
176 StringRef Name = MatchStr.substr(0, NameEnd);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000177
Chris Lattnereec96952009-09-27 07:56:52 +0000178 if (Name.empty()) {
179 SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
180 "invalid name in named regex: empty name", "error");
181 return true;
182 }
183
184 // Verify that the name is well formed.
185 for (unsigned i = 0, e = Name.size(); i != e; ++i)
Daniel Dunbar964ac012009-11-22 22:07:50 +0000186 if (Name[i] != '_' &&
187 (Name[i] < 'a' || Name[i] > 'z') &&
Chris Lattnereec96952009-09-27 07:56:52 +0000188 (Name[i] < 'A' || Name[i] > 'Z') &&
189 (Name[i] < '0' || Name[i] > '9')) {
190 SM.PrintMessage(SMLoc::getFromPointer(Name.data()+i),
191 "invalid name in named regex", "error");
192 return true;
193 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000194
Chris Lattnereec96952009-09-27 07:56:52 +0000195 // Name can't start with a digit.
196 if (isdigit(Name[0])) {
197 SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
198 "invalid name in named regex", "error");
199 return true;
200 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000201
Chris Lattnereec96952009-09-27 07:56:52 +0000202 // Handle [[foo]].
203 if (NameEnd == StringRef::npos) {
204 VariableUses.push_back(std::make_pair(Name, RegExStr.size()));
205 continue;
206 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000207
Chris Lattnereec96952009-09-27 07:56:52 +0000208 // Handle [[foo:.*]].
209 VariableDefs.push_back(std::make_pair(Name, CurParen));
210 RegExStr += '(';
211 ++CurParen;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000212
Chris Lattnereec96952009-09-27 07:56:52 +0000213 if (AddRegExToRegEx(MatchStr.substr(NameEnd+1), CurParen, SM))
214 return true;
215
216 RegExStr += ')';
Chris Lattner52870082009-09-24 21:47:32 +0000217 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000218
Chris Lattnereec96952009-09-27 07:56:52 +0000219 // Handle fixed string matches.
220 // Find the end, which is the start of the next regex.
221 size_t FixedMatchEnd = PatternStr.find("{{");
222 FixedMatchEnd = std::min(FixedMatchEnd, PatternStr.find("[["));
223 AddFixedStringToRegEx(PatternStr.substr(0, FixedMatchEnd), RegExStr);
224 PatternStr = PatternStr.substr(FixedMatchEnd);
225 continue;
Chris Lattner52870082009-09-24 21:47:32 +0000226 }
Chris Lattneradea46e2009-09-24 20:45:07 +0000227
Chris Lattnera29703e2009-09-24 20:39:13 +0000228 return false;
229}
230
Chris Lattnereec96952009-09-27 07:56:52 +0000231void Pattern::AddFixedStringToRegEx(StringRef FixedStr, std::string &TheStr) {
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000232 // Add the characters from FixedStr to the regex, escaping as needed. This
233 // avoids "leaning toothpicks" in common patterns.
234 for (unsigned i = 0, e = FixedStr.size(); i != e; ++i) {
235 switch (FixedStr[i]) {
236 // These are the special characters matched in "p_ere_exp".
237 case '(':
238 case ')':
239 case '^':
240 case '$':
241 case '|':
242 case '*':
243 case '+':
244 case '?':
245 case '.':
246 case '[':
247 case '\\':
248 case '{':
Chris Lattnereec96952009-09-27 07:56:52 +0000249 TheStr += '\\';
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000250 // FALL THROUGH.
251 default:
Chris Lattnereec96952009-09-27 07:56:52 +0000252 TheStr += FixedStr[i];
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000253 break;
254 }
255 }
256}
257
Chris Lattnereec96952009-09-27 07:56:52 +0000258bool Pattern::AddRegExToRegEx(StringRef RegexStr, unsigned &CurParen,
259 SourceMgr &SM) {
260 Regex R(RegexStr);
261 std::string Error;
262 if (!R.isValid(Error)) {
263 SM.PrintMessage(SMLoc::getFromPointer(RegexStr.data()),
264 "invalid regex: " + Error, "error");
265 return true;
266 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000267
Chris Lattnereec96952009-09-27 07:56:52 +0000268 RegExStr += RegexStr.str();
269 CurParen += R.getNumMatches();
270 return false;
271}
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000272
Chris Lattner52870082009-09-24 21:47:32 +0000273/// Match - Match the pattern string against the input buffer Buffer. This
274/// returns the position that is matched or npos if there is no match. If
275/// there is a match, the size of the matched string is returned in MatchLen.
Chris Lattnereec96952009-09-27 07:56:52 +0000276size_t Pattern::Match(StringRef Buffer, size_t &MatchLen,
277 StringMap<StringRef> &VariableTable) const {
Jakob Stoklund Olesen824c10e2010-10-15 17:47:12 +0000278 // If this is the EOF pattern, match it immediately.
279 if (MatchEOF) {
280 MatchLen = 0;
281 return Buffer.size();
282 }
283
Chris Lattner2702e6a2009-09-25 17:09:12 +0000284 // If this is a fixed string pattern, just match it now.
285 if (!FixedStr.empty()) {
286 MatchLen = FixedStr.size();
287 return Buffer.find(FixedStr);
288 }
Chris Lattnereec96952009-09-27 07:56:52 +0000289
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000290 // Regex match.
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000291
Chris Lattnereec96952009-09-27 07:56:52 +0000292 // If there are variable uses, we need to create a temporary string with the
293 // actual value.
294 StringRef RegExToMatch = RegExStr;
295 std::string TmpStr;
296 if (!VariableUses.empty()) {
297 TmpStr = RegExStr;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000298
Chris Lattnereec96952009-09-27 07:56:52 +0000299 unsigned InsertOffset = 0;
300 for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000301 StringMap<StringRef>::iterator it =
302 VariableTable.find(VariableUses[i].first);
303 // If the variable is undefined, return an error.
304 if (it == VariableTable.end())
305 return StringRef::npos;
306
Chris Lattnereec96952009-09-27 07:56:52 +0000307 // Look up the value and escape it so that we can plop it into the regex.
308 std::string Value;
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000309 AddFixedStringToRegEx(it->second, Value);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000310
Chris Lattnereec96952009-09-27 07:56:52 +0000311 // Plop it into the regex at the adjusted offset.
312 TmpStr.insert(TmpStr.begin()+VariableUses[i].second+InsertOffset,
313 Value.begin(), Value.end());
314 InsertOffset += Value.size();
315 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000316
Chris Lattnereec96952009-09-27 07:56:52 +0000317 // Match the newly constructed regex.
318 RegExToMatch = TmpStr;
319 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000320
321
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000322 SmallVector<StringRef, 4> MatchInfo;
Chris Lattnereec96952009-09-27 07:56:52 +0000323 if (!Regex(RegExToMatch, Regex::Newline).match(Buffer, &MatchInfo))
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000324 return StringRef::npos;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000325
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000326 // Successful regex match.
327 assert(!MatchInfo.empty() && "Didn't get any match");
328 StringRef FullMatch = MatchInfo[0];
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000329
Chris Lattnereec96952009-09-27 07:56:52 +0000330 // If this defines any variables, remember their values.
331 for (unsigned i = 0, e = VariableDefs.size(); i != e; ++i) {
332 assert(VariableDefs[i].second < MatchInfo.size() &&
333 "Internal paren error");
334 VariableTable[VariableDefs[i].first] = MatchInfo[VariableDefs[i].second];
Chris Lattner94638f02009-09-25 17:29:36 +0000335 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000336
Chris Lattner5d6a05f2009-09-25 17:23:43 +0000337 MatchLen = FullMatch.size();
338 return FullMatch.data()-Buffer.data();
Chris Lattner52870082009-09-24 21:47:32 +0000339}
340
Daniel Dunbaread2dac2009-11-22 22:59:26 +0000341unsigned Pattern::ComputeMatchDistance(StringRef Buffer,
342 const StringMap<StringRef> &VariableTable) const {
343 // Just compute the number of matching characters. For regular expressions, we
344 // just compare against the regex itself and hope for the best.
345 //
346 // FIXME: One easy improvement here is have the regex lib generate a single
347 // example regular expression which matches, and use that as the example
348 // string.
349 StringRef ExampleString(FixedStr);
350 if (ExampleString.empty())
351 ExampleString = RegExStr;
352
Daniel Dunbar0806f9f2010-01-30 00:24:06 +0000353 // Only compare up to the first line in the buffer, or the string size.
354 StringRef BufferPrefix = Buffer.substr(0, ExampleString.size());
355 BufferPrefix = BufferPrefix.split('\n').first;
356 return BufferPrefix.edit_distance(ExampleString);
Daniel Dunbaread2dac2009-11-22 22:59:26 +0000357}
358
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000359void Pattern::PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,
360 const StringMap<StringRef> &VariableTable) const{
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000361 // If this was a regular expression using variables, print the current
362 // variable values.
363 if (!VariableUses.empty()) {
364 for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
365 StringRef Var = VariableUses[i].first;
366 StringMap<StringRef>::const_iterator it = VariableTable.find(Var);
367 SmallString<256> Msg;
368 raw_svector_ostream OS(Msg);
369
370 // Check for undefined variable references.
371 if (it == VariableTable.end()) {
372 OS << "uses undefined variable \"";
373 OS.write_escaped(Var) << "\"";;
374 } else {
375 OS << "with variable \"";
376 OS.write_escaped(Var) << "\" equal to \"";
377 OS.write_escaped(it->second) << "\"";
378 }
379
380 SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), OS.str(), "note",
381 /*ShowLine=*/false);
382 }
383 }
Daniel Dunbaread2dac2009-11-22 22:59:26 +0000384
385 // Attempt to find the closest/best fuzzy match. Usually an error happens
386 // because some string in the output didn't exactly match. In these cases, we
387 // would like to show the user a best guess at what "should have" matched, to
388 // save them having to actually check the input manually.
389 size_t NumLinesForward = 0;
390 size_t Best = StringRef::npos;
391 double BestQuality = 0;
392
393 // Use an arbitrary 4k limit on how far we will search.
Dan Gohmane3a1e502010-01-29 21:57:46 +0000394 for (size_t i = 0, e = std::min(size_t(4096), Buffer.size()); i != e; ++i) {
Daniel Dunbaread2dac2009-11-22 22:59:26 +0000395 if (Buffer[i] == '\n')
396 ++NumLinesForward;
397
Dan Gohmand8a55412010-01-29 21:55:16 +0000398 // Patterns have leading whitespace stripped, so skip whitespace when
399 // looking for something which looks like a pattern.
400 if (Buffer[i] == ' ' || Buffer[i] == '\t')
401 continue;
402
Daniel Dunbaread2dac2009-11-22 22:59:26 +0000403 // Compute the "quality" of this match as an arbitrary combination of the
404 // match distance and the number of lines skipped to get to this match.
405 unsigned Distance = ComputeMatchDistance(Buffer.substr(i), VariableTable);
406 double Quality = Distance + (NumLinesForward / 100.);
407
408 if (Quality < BestQuality || Best == StringRef::npos) {
409 Best = i;
410 BestQuality = Quality;
411 }
412 }
413
Daniel Dunbar7a68e0d2010-03-19 18:07:43 +0000414 // Print the "possible intended match here" line if we found something
415 // reasonable and not equal to what we showed in the "scanning from here"
416 // line.
417 if (Best && Best != StringRef::npos && BestQuality < 50) {
418 SM.PrintMessage(SMLoc::getFromPointer(Buffer.data() + Best),
419 "possible intended match here", "note");
Daniel Dunbaread2dac2009-11-22 22:59:26 +0000420
421 // FIXME: If we wanted to be really friendly we would show why the match
422 // failed, as it can be hard to spot simple one character differences.
423 }
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000424}
Chris Lattnera29703e2009-09-24 20:39:13 +0000425
426//===----------------------------------------------------------------------===//
427// Check Strings.
428//===----------------------------------------------------------------------===//
Chris Lattner9fc66782009-09-24 20:25:55 +0000429
430/// CheckString - This is a check that we found in the input file.
431struct CheckString {
432 /// Pat - The pattern to match.
433 Pattern Pat;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000434
Chris Lattner207e1bc2009-08-15 17:41:04 +0000435 /// Loc - The location in the match file that the check string was specified.
436 SMLoc Loc;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000437
Chris Lattner5dafafd2009-08-15 18:32:21 +0000438 /// IsCheckNext - This is true if this is a CHECK-NEXT: directive (as opposed
439 /// to a CHECK: directive.
440 bool IsCheckNext;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000441
Chris Lattnerf15380b2009-09-20 22:35:26 +0000442 /// NotStrings - These are all of the strings that are disallowed from
443 /// occurring between this match string and the previous one (or start of
444 /// file).
Chris Lattnera29703e2009-09-24 20:39:13 +0000445 std::vector<std::pair<SMLoc, Pattern> > NotStrings;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000446
Chris Lattner9fc66782009-09-24 20:25:55 +0000447 CheckString(const Pattern &P, SMLoc L, bool isCheckNext)
448 : Pat(P), Loc(L), IsCheckNext(isCheckNext) {}
Chris Lattner207e1bc2009-08-15 17:41:04 +0000449};
450
Chris Lattneradea46e2009-09-24 20:45:07 +0000451/// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
452/// memory buffer, free it, and return a new one.
453static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
Chris Lattner4c842dd2010-04-05 22:42:30 +0000454 SmallString<128> NewFile;
Chris Lattneradea46e2009-09-24 20:45:07 +0000455 NewFile.reserve(MB->getBufferSize());
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000456
Chris Lattneradea46e2009-09-24 20:45:07 +0000457 for (const char *Ptr = MB->getBufferStart(), *End = MB->getBufferEnd();
458 Ptr != End; ++Ptr) {
459 // If C is not a horizontal whitespace, skip it.
460 if (*Ptr != ' ' && *Ptr != '\t') {
461 NewFile.push_back(*Ptr);
462 continue;
463 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000464
Chris Lattneradea46e2009-09-24 20:45:07 +0000465 // Otherwise, add one space and advance over neighboring space.
466 NewFile.push_back(' ');
467 while (Ptr+1 != End &&
468 (Ptr[1] == ' ' || Ptr[1] == '\t'))
469 ++Ptr;
470 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000471
Chris Lattneradea46e2009-09-24 20:45:07 +0000472 // Free the old buffer and return a new one.
473 MemoryBuffer *MB2 =
Chris Lattner4c842dd2010-04-05 22:42:30 +0000474 MemoryBuffer::getMemBufferCopy(NewFile.str(), MB->getBufferIdentifier());
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000475
Chris Lattneradea46e2009-09-24 20:45:07 +0000476 delete MB;
477 return MB2;
478}
479
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000480
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000481/// ReadCheckFile - Read the check file, which specifies the sequence of
482/// expected strings. The strings are added to the CheckStrings vector.
483static bool ReadCheckFile(SourceMgr &SM,
Chris Lattner207e1bc2009-08-15 17:41:04 +0000484 std::vector<CheckString> &CheckStrings) {
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000485 // Open the check file, and tell SourceMgr about it.
486 std::string ErrorStr;
487 MemoryBuffer *F =
488 MemoryBuffer::getFileOrSTDIN(CheckFilename.c_str(), &ErrorStr);
489 if (F == 0) {
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000490 errs() << "Could not open check file '" << CheckFilename << "': "
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000491 << ErrorStr << '\n';
492 return true;
493 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000494
Chris Lattneradea46e2009-09-24 20:45:07 +0000495 // If we want to canonicalize whitespace, strip excess whitespace from the
496 // buffer containing the CHECK lines.
497 if (!NoCanonicalizeWhiteSpace)
498 F = CanonicalizeInputFile(F);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000499
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000500 SM.AddNewSourceBuffer(F, SMLoc());
501
Chris Lattnerd7e25052009-08-15 18:00:42 +0000502 // Find all instances of CheckPrefix followed by : in the file.
Chris Lattner96077032009-09-20 22:11:44 +0000503 StringRef Buffer = F->getBuffer();
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000504
Chris Lattnera29703e2009-09-24 20:39:13 +0000505 std::vector<std::pair<SMLoc, Pattern> > NotMatches;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000506
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000507 while (1) {
508 // See if Prefix occurs in the memory buffer.
Chris Lattner96077032009-09-20 22:11:44 +0000509 Buffer = Buffer.substr(Buffer.find(CheckPrefix));
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000510
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000511 // If we didn't find a match, we're done.
Chris Lattner96077032009-09-20 22:11:44 +0000512 if (Buffer.empty())
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000513 break;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000514
Chris Lattner96077032009-09-20 22:11:44 +0000515 const char *CheckPrefixStart = Buffer.data();
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000516
Chris Lattner5dafafd2009-08-15 18:32:21 +0000517 // When we find a check prefix, keep track of whether we find CHECK: or
518 // CHECK-NEXT:
Chris Lattnerf15380b2009-09-20 22:35:26 +0000519 bool IsCheckNext = false, IsCheckNot = false;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000520
Chris Lattnerd7e25052009-08-15 18:00:42 +0000521 // Verify that the : is present after the prefix.
Chris Lattner96077032009-09-20 22:11:44 +0000522 if (Buffer[CheckPrefix.size()] == ':') {
523 Buffer = Buffer.substr(CheckPrefix.size()+1);
Chris Lattner96077032009-09-20 22:11:44 +0000524 } else if (Buffer.size() > CheckPrefix.size()+6 &&
525 memcmp(Buffer.data()+CheckPrefix.size(), "-NEXT:", 6) == 0) {
526 Buffer = Buffer.substr(CheckPrefix.size()+7);
Chris Lattner5dafafd2009-08-15 18:32:21 +0000527 IsCheckNext = true;
Chris Lattnerf15380b2009-09-20 22:35:26 +0000528 } else if (Buffer.size() > CheckPrefix.size()+5 &&
529 memcmp(Buffer.data()+CheckPrefix.size(), "-NOT:", 5) == 0) {
530 Buffer = Buffer.substr(CheckPrefix.size()+6);
531 IsCheckNot = true;
Chris Lattner5dafafd2009-08-15 18:32:21 +0000532 } else {
Chris Lattner96077032009-09-20 22:11:44 +0000533 Buffer = Buffer.substr(1);
Chris Lattnerd7e25052009-08-15 18:00:42 +0000534 continue;
535 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000536
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000537 // Okay, we found the prefix, yay. Remember the rest of the line, but
538 // ignore leading and trailing whitespace.
Chris Lattnerf15380b2009-09-20 22:35:26 +0000539 Buffer = Buffer.substr(Buffer.find_first_not_of(" \t"));
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000540
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000541 // Scan ahead to the end of line.
Chris Lattner96077032009-09-20 22:11:44 +0000542 size_t EOL = Buffer.find_first_of("\n\r");
Chris Lattnera29703e2009-09-24 20:39:13 +0000543
Dan Gohmane5463432010-01-29 21:53:18 +0000544 // Remember the location of the start of the pattern, for diagnostics.
545 SMLoc PatternLoc = SMLoc::getFromPointer(Buffer.data());
546
Chris Lattnera29703e2009-09-24 20:39:13 +0000547 // Parse the pattern.
548 Pattern P;
549 if (P.ParsePattern(Buffer.substr(0, EOL), SM))
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000550 return true;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000551
Chris Lattnera29703e2009-09-24 20:39:13 +0000552 Buffer = Buffer.substr(EOL);
553
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000554
Chris Lattner5dafafd2009-08-15 18:32:21 +0000555 // Verify that CHECK-NEXT lines have at least one CHECK line before them.
556 if (IsCheckNext && CheckStrings.empty()) {
557 SM.PrintMessage(SMLoc::getFromPointer(CheckPrefixStart),
558 "found '"+CheckPrefix+"-NEXT:' without previous '"+
559 CheckPrefix+ ": line", "error");
560 return true;
561 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000562
Chris Lattnera29703e2009-09-24 20:39:13 +0000563 // Handle CHECK-NOT.
564 if (IsCheckNot) {
565 NotMatches.push_back(std::make_pair(SMLoc::getFromPointer(Buffer.data()),
566 P));
567 continue;
568 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000569
570
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000571 // Okay, add the string we captured to the output vector and move on.
Chris Lattner9fc66782009-09-24 20:25:55 +0000572 CheckStrings.push_back(CheckString(P,
Dan Gohmane5463432010-01-29 21:53:18 +0000573 PatternLoc,
Chris Lattner5dafafd2009-08-15 18:32:21 +0000574 IsCheckNext));
Chris Lattnerf15380b2009-09-20 22:35:26 +0000575 std::swap(NotMatches, CheckStrings.back().NotStrings);
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000576 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000577
Jakob Stoklund Olesen824c10e2010-10-15 17:47:12 +0000578 // Add an EOF pattern for any trailing CHECK-NOTs.
579 if (!NotMatches.empty()) {
580 CheckStrings.push_back(CheckString(Pattern(true),
581 SMLoc::getFromPointer(Buffer.data()),
582 false));
583 std::swap(NotMatches, CheckStrings.back().NotStrings);
584 }
585
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000586 if (CheckStrings.empty()) {
Chris Lattnerd7e25052009-08-15 18:00:42 +0000587 errs() << "error: no check strings found with prefix '" << CheckPrefix
588 << ":'\n";
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000589 return true;
590 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000591
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000592 return false;
593}
594
Chris Lattner5dafafd2009-08-15 18:32:21 +0000595static void PrintCheckFailed(const SourceMgr &SM, const CheckString &CheckStr,
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000596 StringRef Buffer,
597 StringMap<StringRef> &VariableTable) {
Chris Lattner5dafafd2009-08-15 18:32:21 +0000598 // Otherwise, we have an error, emit an error message.
599 SM.PrintMessage(CheckStr.Loc, "expected string not found in input",
600 "error");
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000601
Chris Lattner5dafafd2009-08-15 18:32:21 +0000602 // Print the "scanning from here" line. If the current position is at the
603 // end of a line, advance to the start of the next line.
Chris Lattner96077032009-09-20 22:11:44 +0000604 Buffer = Buffer.substr(Buffer.find_first_not_of(" \t\n\r"));
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000605
Chris Lattner96077032009-09-20 22:11:44 +0000606 SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), "scanning from here",
Chris Lattner5dafafd2009-08-15 18:32:21 +0000607 "note");
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000608
609 // Allow the pattern to print additional information if desired.
610 CheckStr.Pat.PrintFailureInfo(SM, Buffer, VariableTable);
Chris Lattner5dafafd2009-08-15 18:32:21 +0000611}
612
Chris Lattner3711b7a2009-09-20 22:42:44 +0000613/// CountNumNewlinesBetween - Count the number of newlines in the specified
614/// range.
615static unsigned CountNumNewlinesBetween(StringRef Range) {
Chris Lattner5dafafd2009-08-15 18:32:21 +0000616 unsigned NumNewLines = 0;
Chris Lattner3711b7a2009-09-20 22:42:44 +0000617 while (1) {
Chris Lattner5dafafd2009-08-15 18:32:21 +0000618 // Scan for newline.
Chris Lattner3711b7a2009-09-20 22:42:44 +0000619 Range = Range.substr(Range.find_first_of("\n\r"));
620 if (Range.empty()) return NumNewLines;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000621
Chris Lattner5dafafd2009-08-15 18:32:21 +0000622 ++NumNewLines;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000623
Chris Lattner5dafafd2009-08-15 18:32:21 +0000624 // Handle \n\r and \r\n as a single newline.
Chris Lattner3711b7a2009-09-20 22:42:44 +0000625 if (Range.size() > 1 &&
626 (Range[1] == '\n' || Range[1] == '\r') &&
627 (Range[0] != Range[1]))
628 Range = Range.substr(1);
629 Range = Range.substr(1);
Chris Lattner5dafafd2009-08-15 18:32:21 +0000630 }
Chris Lattner5dafafd2009-08-15 18:32:21 +0000631}
632
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000633int main(int argc, char **argv) {
634 sys::PrintStackTraceOnErrorSignal();
635 PrettyStackTraceProgram X(argc, argv);
636 cl::ParseCommandLineOptions(argc, argv);
637
638 SourceMgr SM;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000639
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000640 // Read the expected strings from the check file.
Chris Lattner207e1bc2009-08-15 17:41:04 +0000641 std::vector<CheckString> CheckStrings;
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000642 if (ReadCheckFile(SM, CheckStrings))
643 return 2;
644
645 // Open the file to check and add it to SourceMgr.
646 std::string ErrorStr;
647 MemoryBuffer *F =
648 MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), &ErrorStr);
649 if (F == 0) {
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000650 errs() << "Could not open input file '" << InputFilename << "': "
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000651 << ErrorStr << '\n';
652 return true;
653 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000654
Chris Lattner88a7e9e2009-07-11 18:58:15 +0000655 // Remove duplicate spaces in the input file if requested.
656 if (!NoCanonicalizeWhiteSpace)
657 F = CanonicalizeInputFile(F);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000658
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000659 SM.AddNewSourceBuffer(F, SMLoc());
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000660
Chris Lattnereec96952009-09-27 07:56:52 +0000661 /// VariableTable - This holds all the current filecheck variables.
662 StringMap<StringRef> VariableTable;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000663
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000664 // Check that we have all of the expected strings, in order, in the input
665 // file.
Chris Lattner96077032009-09-20 22:11:44 +0000666 StringRef Buffer = F->getBuffer();
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000667
Chris Lattnerf15380b2009-09-20 22:35:26 +0000668 const char *LastMatch = Buffer.data();
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000669
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000670 for (unsigned StrNo = 0, e = CheckStrings.size(); StrNo != e; ++StrNo) {
Chris Lattner207e1bc2009-08-15 17:41:04 +0000671 const CheckString &CheckStr = CheckStrings[StrNo];
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000672
Chris Lattner96077032009-09-20 22:11:44 +0000673 StringRef SearchFrom = Buffer;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000674
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000675 // Find StrNo in the file.
Chris Lattner9fc66782009-09-24 20:25:55 +0000676 size_t MatchLen = 0;
Jakob Stoklund Olesen824c10e2010-10-15 17:47:12 +0000677 size_t MatchPos = CheckStr.Pat.Match(Buffer, MatchLen, VariableTable);
678 Buffer = Buffer.substr(MatchPos);
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000679
Chris Lattner5dafafd2009-08-15 18:32:21 +0000680 // If we didn't find a match, reject the input.
Jakob Stoklund Olesen824c10e2010-10-15 17:47:12 +0000681 if (MatchPos == StringRef::npos) {
Daniel Dunbarfafe93c2009-11-22 22:08:06 +0000682 PrintCheckFailed(SM, CheckStr, SearchFrom, VariableTable);
Chris Lattner5dafafd2009-08-15 18:32:21 +0000683 return 1;
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000684 }
Chris Lattner3711b7a2009-09-20 22:42:44 +0000685
686 StringRef SkippedRegion(LastMatch, Buffer.data()-LastMatch);
687
Chris Lattner5dafafd2009-08-15 18:32:21 +0000688 // If this check is a "CHECK-NEXT", verify that the previous match was on
689 // the previous line (i.e. that there is one newline between them).
690 if (CheckStr.IsCheckNext) {
691 // Count the number of newlines between the previous match and this one.
Chris Lattnerf15380b2009-09-20 22:35:26 +0000692 assert(LastMatch != F->getBufferStart() &&
693 "CHECK-NEXT can't be the first check in a file");
Chris Lattner5dafafd2009-08-15 18:32:21 +0000694
Chris Lattner3711b7a2009-09-20 22:42:44 +0000695 unsigned NumNewLines = CountNumNewlinesBetween(SkippedRegion);
Chris Lattner5dafafd2009-08-15 18:32:21 +0000696 if (NumNewLines == 0) {
Chris Lattner0b2353f2009-08-16 02:22:31 +0000697 SM.PrintMessage(CheckStr.Loc,
Chris Lattner5dafafd2009-08-15 18:32:21 +0000698 CheckPrefix+"-NEXT: is on the same line as previous match",
699 "error");
Chris Lattner96077032009-09-20 22:11:44 +0000700 SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
Chris Lattner0b2353f2009-08-16 02:22:31 +0000701 "'next' match was here", "note");
Chris Lattner5dafafd2009-08-15 18:32:21 +0000702 SM.PrintMessage(SMLoc::getFromPointer(LastMatch),
703 "previous match was here", "note");
704 return 1;
705 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000706
Chris Lattner5dafafd2009-08-15 18:32:21 +0000707 if (NumNewLines != 1) {
Chris Lattner0b2353f2009-08-16 02:22:31 +0000708 SM.PrintMessage(CheckStr.Loc,
Chris Lattner5dafafd2009-08-15 18:32:21 +0000709 CheckPrefix+
710 "-NEXT: is not on the line after the previous match",
711 "error");
Chris Lattner96077032009-09-20 22:11:44 +0000712 SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
Chris Lattner0b2353f2009-08-16 02:22:31 +0000713 "'next' match was here", "note");
Chris Lattner5dafafd2009-08-15 18:32:21 +0000714 SM.PrintMessage(SMLoc::getFromPointer(LastMatch),
715 "previous match was here", "note");
716 return 1;
717 }
718 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000719
Chris Lattnerf15380b2009-09-20 22:35:26 +0000720 // If this match had "not strings", verify that they don't exist in the
721 // skipped region.
Chris Lattnereec96952009-09-27 07:56:52 +0000722 for (unsigned ChunkNo = 0, e = CheckStr.NotStrings.size();
723 ChunkNo != e; ++ChunkNo) {
Chris Lattnera29703e2009-09-24 20:39:13 +0000724 size_t MatchLen = 0;
Chris Lattnereec96952009-09-27 07:56:52 +0000725 size_t Pos = CheckStr.NotStrings[ChunkNo].second.Match(SkippedRegion,
726 MatchLen,
727 VariableTable);
Chris Lattnerf15380b2009-09-20 22:35:26 +0000728 if (Pos == StringRef::npos) continue;
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000729
Chris Lattnerf15380b2009-09-20 22:35:26 +0000730 SM.PrintMessage(SMLoc::getFromPointer(LastMatch+Pos),
731 CheckPrefix+"-NOT: string occurred!", "error");
Chris Lattner52870082009-09-24 21:47:32 +0000732 SM.PrintMessage(CheckStr.NotStrings[ChunkNo].first,
Chris Lattnerf15380b2009-09-20 22:35:26 +0000733 CheckPrefix+"-NOT: pattern specified here", "note");
734 return 1;
735 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000736
Chris Lattner5dafafd2009-08-15 18:32:21 +0000737
Chris Lattner81115762009-09-21 02:30:42 +0000738 // Otherwise, everything is good. Step over the matched text and remember
739 // the position after the match as the end of the last match.
Chris Lattner9fc66782009-09-24 20:25:55 +0000740 Buffer = Buffer.substr(MatchLen);
Chris Lattner81115762009-09-21 02:30:42 +0000741 LastMatch = Buffer.data();
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000742 }
Mikhail Glushenkov7112c862010-08-20 17:38:38 +0000743
Chris Lattner81cb8ca2009-07-08 18:44:05 +0000744 return 0;
745}