Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 1 | //===- 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 Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Regex.h" |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 23 | #include "llvm/Support/SourceMgr.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | #include "llvm/System/Signals.h" |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringMap.h" |
| 27 | #include <algorithm> |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 28 | using namespace llvm; |
| 29 | |
| 30 | static cl::opt<std::string> |
| 31 | CheckFilename(cl::Positional, cl::desc("<check-file>"), cl::Required); |
| 32 | |
| 33 | static cl::opt<std::string> |
| 34 | InputFilename("input-file", cl::desc("File to check (defaults to stdin)"), |
| 35 | cl::init("-"), cl::value_desc("filename")); |
| 36 | |
| 37 | static cl::opt<std::string> |
| 38 | CheckPrefix("check-prefix", cl::init("CHECK"), |
| 39 | cl::desc("Prefix to use from check file (defaults to 'CHECK')")); |
| 40 | |
Chris Lattner | 88a7e9e | 2009-07-11 18:58:15 +0000 | [diff] [blame] | 41 | static cl::opt<bool> |
| 42 | NoCanonicalizeWhiteSpace("strict-whitespace", |
| 43 | cl::desc("Do not treat all horizontal whitespace as equivalent")); |
| 44 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 45 | //===----------------------------------------------------------------------===// |
| 46 | // Pattern Handling Code. |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 49 | class Pattern { |
Chris Lattner | 94638f0 | 2009-09-25 17:29:36 +0000 | [diff] [blame] | 50 | SMLoc PatternLoc; |
| 51 | |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 52 | /// FixedStr - If non-empty, this pattern is a fixed string match with the |
| 53 | /// specified fixed string. |
Chris Lattner | 2702e6a | 2009-09-25 17:09:12 +0000 | [diff] [blame] | 54 | StringRef FixedStr; |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 55 | |
| 56 | /// RegEx - If non-empty, this is a regex pattern. |
| 57 | std::string RegExStr; |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 58 | |
| 59 | /// VariableUses - Entries in this vector map to uses of a variable in the |
| 60 | /// pattern, e.g. "foo[[bar]]baz". In this case, the RegExStr will contain |
| 61 | /// "foobaz" and we'll get an entry in this vector that tells us to insert the |
| 62 | /// value of bar at offset 3. |
| 63 | std::vector<std::pair<StringRef, unsigned> > VariableUses; |
| 64 | |
| 65 | /// VariableDefs - Entries in this vector map to definitions of a variable in |
| 66 | /// the pattern, e.g. "foo[[bar:.*]]baz". In this case, the RegExStr will |
| 67 | /// contain "foo(.*)baz" and VariableDefs will contain the pair "bar",1. The |
| 68 | /// index indicates what parenthesized value captures the variable value. |
| 69 | std::vector<std::pair<StringRef, unsigned> > VariableDefs; |
| 70 | |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 71 | public: |
| 72 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 73 | Pattern() { } |
| 74 | |
| 75 | bool ParsePattern(StringRef PatternStr, SourceMgr &SM); |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 76 | |
| 77 | /// Match - Match the pattern string against the input buffer Buffer. This |
| 78 | /// returns the position that is matched or npos if there is no match. If |
| 79 | /// there is a match, the size of the matched string is returned in MatchLen. |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 80 | /// |
| 81 | /// The VariableTable StringMap provides the current values of filecheck |
| 82 | /// variables and is updated if this match defines new values. |
| 83 | size_t Match(StringRef Buffer, size_t &MatchLen, |
| 84 | StringMap<StringRef> &VariableTable) const; |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 85 | |
| 86 | private: |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 87 | static void AddFixedStringToRegEx(StringRef FixedStr, std::string &TheStr); |
| 88 | bool AddRegExToRegEx(StringRef RegExStr, unsigned &CurParen, SourceMgr &SM); |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 91 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 92 | bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) { |
Chris Lattner | 94638f0 | 2009-09-25 17:29:36 +0000 | [diff] [blame] | 93 | PatternLoc = SMLoc::getFromPointer(PatternStr.data()); |
| 94 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 95 | // Ignore trailing whitespace. |
| 96 | while (!PatternStr.empty() && |
| 97 | (PatternStr.back() == ' ' || PatternStr.back() == '\t')) |
| 98 | PatternStr = PatternStr.substr(0, PatternStr.size()-1); |
| 99 | |
| 100 | // Check that there is something on the line. |
| 101 | if (PatternStr.empty()) { |
Chris Lattner | 94638f0 | 2009-09-25 17:29:36 +0000 | [diff] [blame] | 102 | SM.PrintMessage(PatternLoc, "found empty check string with prefix '" + |
| 103 | CheckPrefix+":'", "error"); |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 104 | return true; |
| 105 | } |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 106 | |
Chris Lattner | 2702e6a | 2009-09-25 17:09:12 +0000 | [diff] [blame] | 107 | // Check to see if this is a fixed string, or if it has regex pieces. |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 108 | if (PatternStr.size() < 2 || |
| 109 | (PatternStr.find("{{") == StringRef::npos && |
| 110 | PatternStr.find("[[") == StringRef::npos)) { |
Chris Lattner | 2702e6a | 2009-09-25 17:09:12 +0000 | [diff] [blame] | 111 | FixedStr = PatternStr; |
| 112 | return false; |
| 113 | } |
| 114 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 115 | // Paren value #0 is for the fully matched string. Any new parenthesized |
| 116 | // values add from their. |
| 117 | unsigned CurParen = 1; |
| 118 | |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 119 | // Otherwise, there is at least one regex piece. Build up the regex pattern |
| 120 | // by escaping scary characters in fixed strings, building up one big regex. |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 121 | while (!PatternStr.empty()) { |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 122 | // RegEx matches. |
| 123 | if (PatternStr.size() >= 2 && |
| 124 | PatternStr[0] == '{' && PatternStr[1] == '{') { |
| 125 | |
| 126 | // Otherwise, this is the start of a regex match. Scan for the }}. |
| 127 | size_t End = PatternStr.find("}}"); |
| 128 | if (End == StringRef::npos) { |
| 129 | SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()), |
| 130 | "found start of regex string with no end '}}'", "error"); |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | if (AddRegExToRegEx(PatternStr.substr(2, End-2), CurParen, SM)) |
| 135 | return true; |
| 136 | PatternStr = PatternStr.substr(End+2); |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 137 | continue; |
| 138 | } |
| 139 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 140 | // Named RegEx matches. These are of two forms: [[foo:.*]] which matches .* |
| 141 | // (or some other regex) and assigns it to the FileCheck variable 'foo'. The |
| 142 | // second form is [[foo]] which is a reference to foo. The variable name |
Daniel Dunbar | 964ac01 | 2009-11-22 22:07:50 +0000 | [diff] [blame] | 143 | // itself must be of the form "[a-zA-Z_][0-9a-zA-Z_]*", otherwise we reject |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 144 | // it. This is to catch some common errors. |
| 145 | if (PatternStr.size() >= 2 && |
| 146 | PatternStr[0] == '[' && PatternStr[1] == '[') { |
| 147 | // Verify that it is terminated properly. |
| 148 | size_t End = PatternStr.find("]]"); |
| 149 | if (End == StringRef::npos) { |
| 150 | SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()), |
| 151 | "invalid named regex reference, no ]] found", "error"); |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | StringRef MatchStr = PatternStr.substr(2, End-2); |
| 156 | PatternStr = PatternStr.substr(End+2); |
| 157 | |
| 158 | // Get the regex name (e.g. "foo"). |
| 159 | size_t NameEnd = MatchStr.find(':'); |
| 160 | StringRef Name = MatchStr.substr(0, NameEnd); |
| 161 | |
| 162 | if (Name.empty()) { |
| 163 | SM.PrintMessage(SMLoc::getFromPointer(Name.data()), |
| 164 | "invalid name in named regex: empty name", "error"); |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | // Verify that the name is well formed. |
| 169 | for (unsigned i = 0, e = Name.size(); i != e; ++i) |
Daniel Dunbar | 964ac01 | 2009-11-22 22:07:50 +0000 | [diff] [blame] | 170 | if (Name[i] != '_' && |
| 171 | (Name[i] < 'a' || Name[i] > 'z') && |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 172 | (Name[i] < 'A' || Name[i] > 'Z') && |
| 173 | (Name[i] < '0' || Name[i] > '9')) { |
| 174 | SM.PrintMessage(SMLoc::getFromPointer(Name.data()+i), |
| 175 | "invalid name in named regex", "error"); |
| 176 | return true; |
| 177 | } |
| 178 | |
| 179 | // Name can't start with a digit. |
| 180 | if (isdigit(Name[0])) { |
| 181 | SM.PrintMessage(SMLoc::getFromPointer(Name.data()), |
| 182 | "invalid name in named regex", "error"); |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | // Handle [[foo]]. |
| 187 | if (NameEnd == StringRef::npos) { |
| 188 | VariableUses.push_back(std::make_pair(Name, RegExStr.size())); |
| 189 | continue; |
| 190 | } |
| 191 | |
| 192 | // Handle [[foo:.*]]. |
| 193 | VariableDefs.push_back(std::make_pair(Name, CurParen)); |
| 194 | RegExStr += '('; |
| 195 | ++CurParen; |
| 196 | |
| 197 | if (AddRegExToRegEx(MatchStr.substr(NameEnd+1), CurParen, SM)) |
| 198 | return true; |
| 199 | |
| 200 | RegExStr += ')'; |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 203 | // Handle fixed string matches. |
| 204 | // Find the end, which is the start of the next regex. |
| 205 | size_t FixedMatchEnd = PatternStr.find("{{"); |
| 206 | FixedMatchEnd = std::min(FixedMatchEnd, PatternStr.find("[[")); |
| 207 | AddFixedStringToRegEx(PatternStr.substr(0, FixedMatchEnd), RegExStr); |
| 208 | PatternStr = PatternStr.substr(FixedMatchEnd); |
| 209 | continue; |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 210 | } |
Chris Lattner | adea46e | 2009-09-24 20:45:07 +0000 | [diff] [blame] | 211 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 212 | return false; |
| 213 | } |
| 214 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 215 | void Pattern::AddFixedStringToRegEx(StringRef FixedStr, std::string &TheStr) { |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 216 | // Add the characters from FixedStr to the regex, escaping as needed. This |
| 217 | // avoids "leaning toothpicks" in common patterns. |
| 218 | for (unsigned i = 0, e = FixedStr.size(); i != e; ++i) { |
| 219 | switch (FixedStr[i]) { |
| 220 | // These are the special characters matched in "p_ere_exp". |
| 221 | case '(': |
| 222 | case ')': |
| 223 | case '^': |
| 224 | case '$': |
| 225 | case '|': |
| 226 | case '*': |
| 227 | case '+': |
| 228 | case '?': |
| 229 | case '.': |
| 230 | case '[': |
| 231 | case '\\': |
| 232 | case '{': |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 233 | TheStr += '\\'; |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 234 | // FALL THROUGH. |
| 235 | default: |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 236 | TheStr += FixedStr[i]; |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 242 | bool Pattern::AddRegExToRegEx(StringRef RegexStr, unsigned &CurParen, |
| 243 | SourceMgr &SM) { |
| 244 | Regex R(RegexStr); |
| 245 | std::string Error; |
| 246 | if (!R.isValid(Error)) { |
| 247 | SM.PrintMessage(SMLoc::getFromPointer(RegexStr.data()), |
| 248 | "invalid regex: " + Error, "error"); |
| 249 | return true; |
| 250 | } |
| 251 | |
| 252 | RegExStr += RegexStr.str(); |
| 253 | CurParen += R.getNumMatches(); |
| 254 | return false; |
| 255 | } |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 257 | /// Match - Match the pattern string against the input buffer Buffer. This |
| 258 | /// returns the position that is matched or npos if there is no match. If |
| 259 | /// there is a match, the size of the matched string is returned in MatchLen. |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 260 | size_t Pattern::Match(StringRef Buffer, size_t &MatchLen, |
| 261 | StringMap<StringRef> &VariableTable) const { |
Chris Lattner | 2702e6a | 2009-09-25 17:09:12 +0000 | [diff] [blame] | 262 | // If this is a fixed string pattern, just match it now. |
| 263 | if (!FixedStr.empty()) { |
| 264 | MatchLen = FixedStr.size(); |
| 265 | return Buffer.find(FixedStr); |
| 266 | } |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 267 | |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 268 | // Regex match. |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 269 | |
| 270 | // If there are variable uses, we need to create a temporary string with the |
| 271 | // actual value. |
| 272 | StringRef RegExToMatch = RegExStr; |
| 273 | std::string TmpStr; |
| 274 | if (!VariableUses.empty()) { |
| 275 | TmpStr = RegExStr; |
| 276 | |
| 277 | unsigned InsertOffset = 0; |
| 278 | for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) { |
| 279 | // Look up the value and escape it so that we can plop it into the regex. |
| 280 | std::string Value; |
| 281 | AddFixedStringToRegEx(VariableTable[VariableUses[i].first], Value); |
| 282 | |
| 283 | // Plop it into the regex at the adjusted offset. |
| 284 | TmpStr.insert(TmpStr.begin()+VariableUses[i].second+InsertOffset, |
| 285 | Value.begin(), Value.end()); |
| 286 | InsertOffset += Value.size(); |
| 287 | } |
| 288 | |
| 289 | // Match the newly constructed regex. |
| 290 | RegExToMatch = TmpStr; |
| 291 | } |
| 292 | |
| 293 | |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 294 | SmallVector<StringRef, 4> MatchInfo; |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 295 | if (!Regex(RegExToMatch, Regex::Newline).match(Buffer, &MatchInfo)) |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 296 | return StringRef::npos; |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 297 | |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 298 | // Successful regex match. |
| 299 | assert(!MatchInfo.empty() && "Didn't get any match"); |
| 300 | StringRef FullMatch = MatchInfo[0]; |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 301 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 302 | // If this defines any variables, remember their values. |
| 303 | for (unsigned i = 0, e = VariableDefs.size(); i != e; ++i) { |
| 304 | assert(VariableDefs[i].second < MatchInfo.size() && |
| 305 | "Internal paren error"); |
| 306 | VariableTable[VariableDefs[i].first] = MatchInfo[VariableDefs[i].second]; |
Chris Lattner | 94638f0 | 2009-09-25 17:29:36 +0000 | [diff] [blame] | 307 | } |
Chris Lattner | 94638f0 | 2009-09-25 17:29:36 +0000 | [diff] [blame] | 308 | |
Chris Lattner | 5d6a05f | 2009-09-25 17:23:43 +0000 | [diff] [blame] | 309 | MatchLen = FullMatch.size(); |
| 310 | return FullMatch.data()-Buffer.data(); |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 313 | |
| 314 | //===----------------------------------------------------------------------===// |
| 315 | // Check Strings. |
| 316 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 317 | |
| 318 | /// CheckString - This is a check that we found in the input file. |
| 319 | struct CheckString { |
| 320 | /// Pat - The pattern to match. |
| 321 | Pattern Pat; |
Chris Lattner | 207e1bc | 2009-08-15 17:41:04 +0000 | [diff] [blame] | 322 | |
| 323 | /// Loc - The location in the match file that the check string was specified. |
| 324 | SMLoc Loc; |
| 325 | |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 326 | /// IsCheckNext - This is true if this is a CHECK-NEXT: directive (as opposed |
| 327 | /// to a CHECK: directive. |
| 328 | bool IsCheckNext; |
| 329 | |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 330 | /// NotStrings - These are all of the strings that are disallowed from |
| 331 | /// occurring between this match string and the previous one (or start of |
| 332 | /// file). |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 333 | std::vector<std::pair<SMLoc, Pattern> > NotStrings; |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 334 | |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 335 | CheckString(const Pattern &P, SMLoc L, bool isCheckNext) |
| 336 | : Pat(P), Loc(L), IsCheckNext(isCheckNext) {} |
Chris Lattner | 207e1bc | 2009-08-15 17:41:04 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
Chris Lattner | adea46e | 2009-09-24 20:45:07 +0000 | [diff] [blame] | 339 | /// CanonicalizeInputFile - Remove duplicate horizontal space from the specified |
| 340 | /// memory buffer, free it, and return a new one. |
| 341 | static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) { |
| 342 | SmallVector<char, 16> NewFile; |
| 343 | NewFile.reserve(MB->getBufferSize()); |
| 344 | |
| 345 | for (const char *Ptr = MB->getBufferStart(), *End = MB->getBufferEnd(); |
| 346 | Ptr != End; ++Ptr) { |
| 347 | // If C is not a horizontal whitespace, skip it. |
| 348 | if (*Ptr != ' ' && *Ptr != '\t') { |
| 349 | NewFile.push_back(*Ptr); |
| 350 | continue; |
| 351 | } |
| 352 | |
| 353 | // Otherwise, add one space and advance over neighboring space. |
| 354 | NewFile.push_back(' '); |
| 355 | while (Ptr+1 != End && |
| 356 | (Ptr[1] == ' ' || Ptr[1] == '\t')) |
| 357 | ++Ptr; |
| 358 | } |
| 359 | |
| 360 | // Free the old buffer and return a new one. |
| 361 | MemoryBuffer *MB2 = |
| 362 | MemoryBuffer::getMemBufferCopy(NewFile.data(), |
| 363 | NewFile.data() + NewFile.size(), |
| 364 | MB->getBufferIdentifier()); |
| 365 | |
| 366 | delete MB; |
| 367 | return MB2; |
| 368 | } |
| 369 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 370 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 371 | /// ReadCheckFile - Read the check file, which specifies the sequence of |
| 372 | /// expected strings. The strings are added to the CheckStrings vector. |
| 373 | static bool ReadCheckFile(SourceMgr &SM, |
Chris Lattner | 207e1bc | 2009-08-15 17:41:04 +0000 | [diff] [blame] | 374 | std::vector<CheckString> &CheckStrings) { |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 375 | // Open the check file, and tell SourceMgr about it. |
| 376 | std::string ErrorStr; |
| 377 | MemoryBuffer *F = |
| 378 | MemoryBuffer::getFileOrSTDIN(CheckFilename.c_str(), &ErrorStr); |
| 379 | if (F == 0) { |
| 380 | errs() << "Could not open check file '" << CheckFilename << "': " |
| 381 | << ErrorStr << '\n'; |
| 382 | return true; |
| 383 | } |
Chris Lattner | adea46e | 2009-09-24 20:45:07 +0000 | [diff] [blame] | 384 | |
| 385 | // If we want to canonicalize whitespace, strip excess whitespace from the |
| 386 | // buffer containing the CHECK lines. |
| 387 | if (!NoCanonicalizeWhiteSpace) |
| 388 | F = CanonicalizeInputFile(F); |
| 389 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 390 | SM.AddNewSourceBuffer(F, SMLoc()); |
| 391 | |
Chris Lattner | d7e2505 | 2009-08-15 18:00:42 +0000 | [diff] [blame] | 392 | // Find all instances of CheckPrefix followed by : in the file. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 393 | StringRef Buffer = F->getBuffer(); |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 394 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 395 | std::vector<std::pair<SMLoc, Pattern> > NotMatches; |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 396 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 397 | while (1) { |
| 398 | // See if Prefix occurs in the memory buffer. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 399 | Buffer = Buffer.substr(Buffer.find(CheckPrefix)); |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 400 | |
| 401 | // If we didn't find a match, we're done. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 402 | if (Buffer.empty()) |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 403 | break; |
| 404 | |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 405 | const char *CheckPrefixStart = Buffer.data(); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 406 | |
| 407 | // When we find a check prefix, keep track of whether we find CHECK: or |
| 408 | // CHECK-NEXT: |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 409 | bool IsCheckNext = false, IsCheckNot = false; |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 410 | |
Chris Lattner | d7e2505 | 2009-08-15 18:00:42 +0000 | [diff] [blame] | 411 | // Verify that the : is present after the prefix. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 412 | if (Buffer[CheckPrefix.size()] == ':') { |
| 413 | Buffer = Buffer.substr(CheckPrefix.size()+1); |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 414 | } else if (Buffer.size() > CheckPrefix.size()+6 && |
| 415 | memcmp(Buffer.data()+CheckPrefix.size(), "-NEXT:", 6) == 0) { |
| 416 | Buffer = Buffer.substr(CheckPrefix.size()+7); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 417 | IsCheckNext = true; |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 418 | } else if (Buffer.size() > CheckPrefix.size()+5 && |
| 419 | memcmp(Buffer.data()+CheckPrefix.size(), "-NOT:", 5) == 0) { |
| 420 | Buffer = Buffer.substr(CheckPrefix.size()+6); |
| 421 | IsCheckNot = true; |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 422 | } else { |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 423 | Buffer = Buffer.substr(1); |
Chris Lattner | d7e2505 | 2009-08-15 18:00:42 +0000 | [diff] [blame] | 424 | continue; |
| 425 | } |
| 426 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 427 | // Okay, we found the prefix, yay. Remember the rest of the line, but |
| 428 | // ignore leading and trailing whitespace. |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 429 | Buffer = Buffer.substr(Buffer.find_first_not_of(" \t")); |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 430 | |
| 431 | // Scan ahead to the end of line. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 432 | size_t EOL = Buffer.find_first_of("\n\r"); |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 433 | |
| 434 | // Parse the pattern. |
| 435 | Pattern P; |
| 436 | if (P.ParsePattern(Buffer.substr(0, EOL), SM)) |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 437 | return true; |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 438 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 439 | Buffer = Buffer.substr(EOL); |
| 440 | |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 441 | |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 442 | // Verify that CHECK-NEXT lines have at least one CHECK line before them. |
| 443 | if (IsCheckNext && CheckStrings.empty()) { |
| 444 | SM.PrintMessage(SMLoc::getFromPointer(CheckPrefixStart), |
| 445 | "found '"+CheckPrefix+"-NEXT:' without previous '"+ |
| 446 | CheckPrefix+ ": line", "error"); |
| 447 | return true; |
| 448 | } |
| 449 | |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 450 | // Handle CHECK-NOT. |
| 451 | if (IsCheckNot) { |
| 452 | NotMatches.push_back(std::make_pair(SMLoc::getFromPointer(Buffer.data()), |
| 453 | P)); |
| 454 | continue; |
| 455 | } |
| 456 | |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 457 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 458 | // Okay, add the string we captured to the output vector and move on. |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 459 | CheckStrings.push_back(CheckString(P, |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 460 | SMLoc::getFromPointer(Buffer.data()), |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 461 | IsCheckNext)); |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 462 | std::swap(NotMatches, CheckStrings.back().NotStrings); |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | if (CheckStrings.empty()) { |
Chris Lattner | d7e2505 | 2009-08-15 18:00:42 +0000 | [diff] [blame] | 466 | errs() << "error: no check strings found with prefix '" << CheckPrefix |
| 467 | << ":'\n"; |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 468 | return true; |
| 469 | } |
| 470 | |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 471 | if (!NotMatches.empty()) { |
| 472 | errs() << "error: '" << CheckPrefix |
| 473 | << "-NOT:' not supported after last check line.\n"; |
| 474 | return true; |
| 475 | } |
| 476 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 477 | return false; |
| 478 | } |
| 479 | |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 480 | static void PrintCheckFailed(const SourceMgr &SM, const CheckString &CheckStr, |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 481 | StringRef Buffer) { |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 482 | // Otherwise, we have an error, emit an error message. |
| 483 | SM.PrintMessage(CheckStr.Loc, "expected string not found in input", |
| 484 | "error"); |
| 485 | |
| 486 | // Print the "scanning from here" line. If the current position is at the |
| 487 | // end of a line, advance to the start of the next line. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 488 | Buffer = Buffer.substr(Buffer.find_first_not_of(" \t\n\r")); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 489 | |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 490 | SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), "scanning from here", |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 491 | "note"); |
| 492 | } |
| 493 | |
Chris Lattner | 3711b7a | 2009-09-20 22:42:44 +0000 | [diff] [blame] | 494 | /// CountNumNewlinesBetween - Count the number of newlines in the specified |
| 495 | /// range. |
| 496 | static unsigned CountNumNewlinesBetween(StringRef Range) { |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 497 | unsigned NumNewLines = 0; |
Chris Lattner | 3711b7a | 2009-09-20 22:42:44 +0000 | [diff] [blame] | 498 | while (1) { |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 499 | // Scan for newline. |
Chris Lattner | 3711b7a | 2009-09-20 22:42:44 +0000 | [diff] [blame] | 500 | Range = Range.substr(Range.find_first_of("\n\r")); |
| 501 | if (Range.empty()) return NumNewLines; |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 502 | |
| 503 | ++NumNewLines; |
| 504 | |
| 505 | // Handle \n\r and \r\n as a single newline. |
Chris Lattner | 3711b7a | 2009-09-20 22:42:44 +0000 | [diff] [blame] | 506 | if (Range.size() > 1 && |
| 507 | (Range[1] == '\n' || Range[1] == '\r') && |
| 508 | (Range[0] != Range[1])) |
| 509 | Range = Range.substr(1); |
| 510 | Range = Range.substr(1); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 511 | } |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 514 | int main(int argc, char **argv) { |
| 515 | sys::PrintStackTraceOnErrorSignal(); |
| 516 | PrettyStackTraceProgram X(argc, argv); |
| 517 | cl::ParseCommandLineOptions(argc, argv); |
| 518 | |
| 519 | SourceMgr SM; |
| 520 | |
| 521 | // Read the expected strings from the check file. |
Chris Lattner | 207e1bc | 2009-08-15 17:41:04 +0000 | [diff] [blame] | 522 | std::vector<CheckString> CheckStrings; |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 523 | if (ReadCheckFile(SM, CheckStrings)) |
| 524 | return 2; |
| 525 | |
| 526 | // Open the file to check and add it to SourceMgr. |
| 527 | std::string ErrorStr; |
| 528 | MemoryBuffer *F = |
| 529 | MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), &ErrorStr); |
| 530 | if (F == 0) { |
| 531 | errs() << "Could not open input file '" << InputFilename << "': " |
| 532 | << ErrorStr << '\n'; |
| 533 | return true; |
| 534 | } |
Chris Lattner | 88a7e9e | 2009-07-11 18:58:15 +0000 | [diff] [blame] | 535 | |
| 536 | // Remove duplicate spaces in the input file if requested. |
| 537 | if (!NoCanonicalizeWhiteSpace) |
| 538 | F = CanonicalizeInputFile(F); |
| 539 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 540 | SM.AddNewSourceBuffer(F, SMLoc()); |
| 541 | |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 542 | /// VariableTable - This holds all the current filecheck variables. |
| 543 | StringMap<StringRef> VariableTable; |
| 544 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 545 | // Check that we have all of the expected strings, in order, in the input |
| 546 | // file. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 547 | StringRef Buffer = F->getBuffer(); |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 548 | |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 549 | const char *LastMatch = Buffer.data(); |
| 550 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 551 | for (unsigned StrNo = 0, e = CheckStrings.size(); StrNo != e; ++StrNo) { |
Chris Lattner | 207e1bc | 2009-08-15 17:41:04 +0000 | [diff] [blame] | 552 | const CheckString &CheckStr = CheckStrings[StrNo]; |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 553 | |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 554 | StringRef SearchFrom = Buffer; |
| 555 | |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 556 | // Find StrNo in the file. |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 557 | size_t MatchLen = 0; |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 558 | Buffer = Buffer.substr(CheckStr.Pat.Match(Buffer, MatchLen, VariableTable)); |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 559 | |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 560 | // If we didn't find a match, reject the input. |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 561 | if (Buffer.empty()) { |
| 562 | PrintCheckFailed(SM, CheckStr, SearchFrom); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 563 | return 1; |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 564 | } |
Chris Lattner | 3711b7a | 2009-09-20 22:42:44 +0000 | [diff] [blame] | 565 | |
| 566 | StringRef SkippedRegion(LastMatch, Buffer.data()-LastMatch); |
| 567 | |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 568 | // If this check is a "CHECK-NEXT", verify that the previous match was on |
| 569 | // the previous line (i.e. that there is one newline between them). |
| 570 | if (CheckStr.IsCheckNext) { |
| 571 | // Count the number of newlines between the previous match and this one. |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 572 | assert(LastMatch != F->getBufferStart() && |
| 573 | "CHECK-NEXT can't be the first check in a file"); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 574 | |
Chris Lattner | 3711b7a | 2009-09-20 22:42:44 +0000 | [diff] [blame] | 575 | unsigned NumNewLines = CountNumNewlinesBetween(SkippedRegion); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 576 | if (NumNewLines == 0) { |
Chris Lattner | 0b2353f | 2009-08-16 02:22:31 +0000 | [diff] [blame] | 577 | SM.PrintMessage(CheckStr.Loc, |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 578 | CheckPrefix+"-NEXT: is on the same line as previous match", |
| 579 | "error"); |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 580 | SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), |
Chris Lattner | 0b2353f | 2009-08-16 02:22:31 +0000 | [diff] [blame] | 581 | "'next' match was here", "note"); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 582 | SM.PrintMessage(SMLoc::getFromPointer(LastMatch), |
| 583 | "previous match was here", "note"); |
| 584 | return 1; |
| 585 | } |
| 586 | |
| 587 | if (NumNewLines != 1) { |
Chris Lattner | 0b2353f | 2009-08-16 02:22:31 +0000 | [diff] [blame] | 588 | SM.PrintMessage(CheckStr.Loc, |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 589 | CheckPrefix+ |
| 590 | "-NEXT: is not on the line after the previous match", |
| 591 | "error"); |
Chris Lattner | 9607703 | 2009-09-20 22:11:44 +0000 | [diff] [blame] | 592 | SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), |
Chris Lattner | 0b2353f | 2009-08-16 02:22:31 +0000 | [diff] [blame] | 593 | "'next' match was here", "note"); |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 594 | SM.PrintMessage(SMLoc::getFromPointer(LastMatch), |
| 595 | "previous match was here", "note"); |
| 596 | return 1; |
| 597 | } |
| 598 | } |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 599 | |
| 600 | // If this match had "not strings", verify that they don't exist in the |
| 601 | // skipped region. |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 602 | for (unsigned ChunkNo = 0, e = CheckStr.NotStrings.size(); |
| 603 | ChunkNo != e; ++ChunkNo) { |
Chris Lattner | a29703e | 2009-09-24 20:39:13 +0000 | [diff] [blame] | 604 | size_t MatchLen = 0; |
Chris Lattner | eec9695 | 2009-09-27 07:56:52 +0000 | [diff] [blame] | 605 | size_t Pos = CheckStr.NotStrings[ChunkNo].second.Match(SkippedRegion, |
| 606 | MatchLen, |
| 607 | VariableTable); |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 608 | if (Pos == StringRef::npos) continue; |
| 609 | |
| 610 | SM.PrintMessage(SMLoc::getFromPointer(LastMatch+Pos), |
| 611 | CheckPrefix+"-NOT: string occurred!", "error"); |
Chris Lattner | 5287008 | 2009-09-24 21:47:32 +0000 | [diff] [blame] | 612 | SM.PrintMessage(CheckStr.NotStrings[ChunkNo].first, |
Chris Lattner | f15380b | 2009-09-20 22:35:26 +0000 | [diff] [blame] | 613 | CheckPrefix+"-NOT: pattern specified here", "note"); |
| 614 | return 1; |
| 615 | } |
| 616 | |
Chris Lattner | 5dafafd | 2009-08-15 18:32:21 +0000 | [diff] [blame] | 617 | |
Chris Lattner | 8111576 | 2009-09-21 02:30:42 +0000 | [diff] [blame] | 618 | // Otherwise, everything is good. Step over the matched text and remember |
| 619 | // the position after the match as the end of the last match. |
Chris Lattner | 9fc6678 | 2009-09-24 20:25:55 +0000 | [diff] [blame] | 620 | Buffer = Buffer.substr(MatchLen); |
Chris Lattner | 8111576 | 2009-09-21 02:30:42 +0000 | [diff] [blame] | 621 | LastMatch = Buffer.data(); |
Chris Lattner | 81cb8ca | 2009-07-08 18:44:05 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | return 0; |
| 625 | } |