2009-07-08 20:44:05 +02:00
|
|
|
//===- FileCheck.cpp - Check that File's Contents match what is expected --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// FileCheck does a line-by line check of a file that validates whether it
|
|
|
|
// contains the expected content. This is useful for regression tests etc.
|
|
|
|
//
|
|
|
|
// This program exits with an error status of 2 on error, exit status of 0 if
|
|
|
|
// the file matched the expected contents, and exit status of 1 if it did not
|
|
|
|
// contain the expected contents.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2009-09-24 23:47:32 +02:00
|
|
|
#include "llvm/Support/Regex.h"
|
2009-07-08 20:44:05 +02:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/System/Signals.h"
|
2009-11-22 23:08:06 +01:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2009-09-27 09:56:52 +02:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include <algorithm>
|
2009-07-08 20:44:05 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static cl::opt<std::string>
|
|
|
|
CheckFilename(cl::Positional, cl::desc("<check-file>"), cl::Required);
|
|
|
|
|
|
|
|
static cl::opt<std::string>
|
|
|
|
InputFilename("input-file", cl::desc("File to check (defaults to stdin)"),
|
|
|
|
cl::init("-"), cl::value_desc("filename"));
|
|
|
|
|
|
|
|
static cl::opt<std::string>
|
|
|
|
CheckPrefix("check-prefix", cl::init("CHECK"),
|
|
|
|
cl::desc("Prefix to use from check file (defaults to 'CHECK')"));
|
|
|
|
|
2009-07-11 20:58:15 +02:00
|
|
|
static cl::opt<bool>
|
|
|
|
NoCanonicalizeWhiteSpace("strict-whitespace",
|
|
|
|
cl::desc("Do not treat all horizontal whitespace as equivalent"));
|
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pattern Handling Code.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-09-24 22:25:55 +02:00
|
|
|
class Pattern {
|
2009-09-25 19:29:36 +02:00
|
|
|
SMLoc PatternLoc;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
/// FixedStr - If non-empty, this pattern is a fixed string match with the
|
|
|
|
/// specified fixed string.
|
2009-09-25 19:09:12 +02:00
|
|
|
StringRef FixedStr;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
/// RegEx - If non-empty, this is a regex pattern.
|
|
|
|
std::string RegExStr;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
/// VariableUses - Entries in this vector map to uses of a variable in the
|
|
|
|
/// pattern, e.g. "foo[[bar]]baz". In this case, the RegExStr will contain
|
|
|
|
/// "foobaz" and we'll get an entry in this vector that tells us to insert the
|
|
|
|
/// value of bar at offset 3.
|
|
|
|
std::vector<std::pair<StringRef, unsigned> > VariableUses;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
/// VariableDefs - Entries in this vector map to definitions of a variable in
|
|
|
|
/// the pattern, e.g. "foo[[bar:.*]]baz". In this case, the RegExStr will
|
|
|
|
/// contain "foo(.*)baz" and VariableDefs will contain the pair "bar",1. The
|
|
|
|
/// index indicates what parenthesized value captures the variable value.
|
|
|
|
std::vector<std::pair<StringRef, unsigned> > VariableDefs;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:25:55 +02:00
|
|
|
public:
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
Pattern() { }
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
bool ParsePattern(StringRef PatternStr, SourceMgr &SM);
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:25:55 +02:00
|
|
|
/// Match - Match the pattern string against the input buffer Buffer. This
|
|
|
|
/// returns the position that is matched or npos if there is no match. If
|
|
|
|
/// there is a match, the size of the matched string is returned in MatchLen.
|
2009-09-27 09:56:52 +02:00
|
|
|
///
|
|
|
|
/// The VariableTable StringMap provides the current values of filecheck
|
|
|
|
/// variables and is updated if this match defines new values.
|
|
|
|
size_t Match(StringRef Buffer, size_t &MatchLen,
|
|
|
|
StringMap<StringRef> &VariableTable) const;
|
2009-11-22 23:08:06 +01:00
|
|
|
|
|
|
|
/// PrintFailureInfo - Print additional information about a failure to match
|
|
|
|
/// involving this pattern.
|
|
|
|
void PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,
|
|
|
|
const StringMap<StringRef> &VariableTable) const;
|
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
private:
|
2009-09-27 09:56:52 +02:00
|
|
|
static void AddFixedStringToRegEx(StringRef FixedStr, std::string &TheStr);
|
|
|
|
bool AddRegExToRegEx(StringRef RegExStr, unsigned &CurParen, SourceMgr &SM);
|
2009-11-22 23:59:26 +01:00
|
|
|
|
|
|
|
/// ComputeMatchDistance - Compute an arbitrary estimate for the quality of
|
|
|
|
/// matching this pattern at the start of \arg Buffer; a distance of zero
|
|
|
|
/// should correspond to a perfect match.
|
|
|
|
unsigned ComputeMatchDistance(StringRef Buffer,
|
|
|
|
const StringMap<StringRef> &VariableTable) const;
|
2009-09-24 22:25:55 +02:00
|
|
|
};
|
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
|
2009-09-25 19:29:36 +02:00
|
|
|
PatternLoc = SMLoc::getFromPointer(PatternStr.data());
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
// Ignore trailing whitespace.
|
|
|
|
while (!PatternStr.empty() &&
|
|
|
|
(PatternStr.back() == ' ' || PatternStr.back() == '\t'))
|
|
|
|
PatternStr = PatternStr.substr(0, PatternStr.size()-1);
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
// Check that there is something on the line.
|
|
|
|
if (PatternStr.empty()) {
|
2009-09-25 19:29:36 +02:00
|
|
|
SM.PrintMessage(PatternLoc, "found empty check string with prefix '" +
|
|
|
|
CheckPrefix+":'", "error");
|
2009-09-24 22:39:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-25 19:09:12 +02:00
|
|
|
// Check to see if this is a fixed string, or if it has regex pieces.
|
2009-09-27 09:56:52 +02:00
|
|
|
if (PatternStr.size() < 2 ||
|
|
|
|
(PatternStr.find("{{") == StringRef::npos &&
|
|
|
|
PatternStr.find("[[") == StringRef::npos)) {
|
2009-09-25 19:09:12 +02:00
|
|
|
FixedStr = PatternStr;
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Paren value #0 is for the fully matched string. Any new parenthesized
|
|
|
|
// values add from their.
|
|
|
|
unsigned CurParen = 1;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
// Otherwise, there is at least one regex piece. Build up the regex pattern
|
|
|
|
// by escaping scary characters in fixed strings, building up one big regex.
|
2009-09-24 23:47:32 +02:00
|
|
|
while (!PatternStr.empty()) {
|
2009-09-27 09:56:52 +02:00
|
|
|
// RegEx matches.
|
|
|
|
if (PatternStr.size() >= 2 &&
|
|
|
|
PatternStr[0] == '{' && PatternStr[1] == '{') {
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Otherwise, this is the start of a regex match. Scan for the }}.
|
|
|
|
size_t End = PatternStr.find("}}");
|
|
|
|
if (End == StringRef::npos) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
|
|
|
|
"found start of regex string with no end '}}'", "error");
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
if (AddRegExToRegEx(PatternStr.substr(2, End-2), CurParen, SM))
|
|
|
|
return true;
|
|
|
|
PatternStr = PatternStr.substr(End+2);
|
2009-09-24 23:47:32 +02:00
|
|
|
continue;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Named RegEx matches. These are of two forms: [[foo:.*]] which matches .*
|
|
|
|
// (or some other regex) and assigns it to the FileCheck variable 'foo'. The
|
|
|
|
// second form is [[foo]] which is a reference to foo. The variable name
|
2009-11-22 23:07:50 +01:00
|
|
|
// itself must be of the form "[a-zA-Z_][0-9a-zA-Z_]*", otherwise we reject
|
2009-09-27 09:56:52 +02:00
|
|
|
// it. This is to catch some common errors.
|
|
|
|
if (PatternStr.size() >= 2 &&
|
|
|
|
PatternStr[0] == '[' && PatternStr[1] == '[') {
|
|
|
|
// Verify that it is terminated properly.
|
|
|
|
size_t End = PatternStr.find("]]");
|
|
|
|
if (End == StringRef::npos) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
|
|
|
|
"invalid named regex reference, no ]] found", "error");
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
StringRef MatchStr = PatternStr.substr(2, End-2);
|
|
|
|
PatternStr = PatternStr.substr(End+2);
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Get the regex name (e.g. "foo").
|
|
|
|
size_t NameEnd = MatchStr.find(':');
|
|
|
|
StringRef Name = MatchStr.substr(0, NameEnd);
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
if (Name.empty()) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
|
|
|
|
"invalid name in named regex: empty name", "error");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that the name is well formed.
|
|
|
|
for (unsigned i = 0, e = Name.size(); i != e; ++i)
|
2009-11-22 23:07:50 +01:00
|
|
|
if (Name[i] != '_' &&
|
|
|
|
(Name[i] < 'a' || Name[i] > 'z') &&
|
2009-09-27 09:56:52 +02:00
|
|
|
(Name[i] < 'A' || Name[i] > 'Z') &&
|
|
|
|
(Name[i] < '0' || Name[i] > '9')) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Name.data()+i),
|
|
|
|
"invalid name in named regex", "error");
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Name can't start with a digit.
|
|
|
|
if (isdigit(Name[0])) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
|
|
|
|
"invalid name in named regex", "error");
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Handle [[foo]].
|
|
|
|
if (NameEnd == StringRef::npos) {
|
|
|
|
VariableUses.push_back(std::make_pair(Name, RegExStr.size()));
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Handle [[foo:.*]].
|
|
|
|
VariableDefs.push_back(std::make_pair(Name, CurParen));
|
|
|
|
RegExStr += '(';
|
|
|
|
++CurParen;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
if (AddRegExToRegEx(MatchStr.substr(NameEnd+1), CurParen, SM))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
RegExStr += ')';
|
2009-09-24 23:47:32 +02:00
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Handle fixed string matches.
|
|
|
|
// Find the end, which is the start of the next regex.
|
|
|
|
size_t FixedMatchEnd = PatternStr.find("{{");
|
|
|
|
FixedMatchEnd = std::min(FixedMatchEnd, PatternStr.find("[["));
|
|
|
|
AddFixedStringToRegEx(PatternStr.substr(0, FixedMatchEnd), RegExStr);
|
|
|
|
PatternStr = PatternStr.substr(FixedMatchEnd);
|
|
|
|
continue;
|
2009-09-24 23:47:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-24 22:45:07 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
void Pattern::AddFixedStringToRegEx(StringRef FixedStr, std::string &TheStr) {
|
2009-09-25 19:23:43 +02:00
|
|
|
// Add the characters from FixedStr to the regex, escaping as needed. This
|
|
|
|
// avoids "leaning toothpicks" in common patterns.
|
|
|
|
for (unsigned i = 0, e = FixedStr.size(); i != e; ++i) {
|
|
|
|
switch (FixedStr[i]) {
|
|
|
|
// These are the special characters matched in "p_ere_exp".
|
|
|
|
case '(':
|
|
|
|
case ')':
|
|
|
|
case '^':
|
|
|
|
case '$':
|
|
|
|
case '|':
|
|
|
|
case '*':
|
|
|
|
case '+':
|
|
|
|
case '?':
|
|
|
|
case '.':
|
|
|
|
case '[':
|
|
|
|
case '\\':
|
|
|
|
case '{':
|
2009-09-27 09:56:52 +02:00
|
|
|
TheStr += '\\';
|
2009-09-25 19:23:43 +02:00
|
|
|
// FALL THROUGH.
|
|
|
|
default:
|
2009-09-27 09:56:52 +02:00
|
|
|
TheStr += FixedStr[i];
|
2009-09-25 19:23:43 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
bool Pattern::AddRegExToRegEx(StringRef RegexStr, unsigned &CurParen,
|
|
|
|
SourceMgr &SM) {
|
|
|
|
Regex R(RegexStr);
|
|
|
|
std::string Error;
|
|
|
|
if (!R.isValid(Error)) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(RegexStr.data()),
|
|
|
|
"invalid regex: " + Error, "error");
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
RegExStr += RegexStr.str();
|
|
|
|
CurParen += R.getNumMatches();
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-25 19:23:43 +02:00
|
|
|
|
2009-09-24 23:47:32 +02:00
|
|
|
/// Match - Match the pattern string against the input buffer Buffer. This
|
|
|
|
/// returns the position that is matched or npos if there is no match. If
|
|
|
|
/// there is a match, the size of the matched string is returned in MatchLen.
|
2009-09-27 09:56:52 +02:00
|
|
|
size_t Pattern::Match(StringRef Buffer, size_t &MatchLen,
|
|
|
|
StringMap<StringRef> &VariableTable) const {
|
2009-09-25 19:09:12 +02:00
|
|
|
// If this is a fixed string pattern, just match it now.
|
|
|
|
if (!FixedStr.empty()) {
|
|
|
|
MatchLen = FixedStr.size();
|
|
|
|
return Buffer.find(FixedStr);
|
|
|
|
}
|
2009-09-27 09:56:52 +02:00
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
// Regex match.
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// If there are variable uses, we need to create a temporary string with the
|
|
|
|
// actual value.
|
|
|
|
StringRef RegExToMatch = RegExStr;
|
|
|
|
std::string TmpStr;
|
|
|
|
if (!VariableUses.empty()) {
|
|
|
|
TmpStr = RegExStr;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
unsigned InsertOffset = 0;
|
|
|
|
for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
|
2009-11-22 23:08:06 +01:00
|
|
|
StringMap<StringRef>::iterator it =
|
|
|
|
VariableTable.find(VariableUses[i].first);
|
|
|
|
// If the variable is undefined, return an error.
|
|
|
|
if (it == VariableTable.end())
|
|
|
|
return StringRef::npos;
|
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Look up the value and escape it so that we can plop it into the regex.
|
|
|
|
std::string Value;
|
2009-11-22 23:08:06 +01:00
|
|
|
AddFixedStringToRegEx(it->second, Value);
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Plop it into the regex at the adjusted offset.
|
|
|
|
TmpStr.insert(TmpStr.begin()+VariableUses[i].second+InsertOffset,
|
|
|
|
Value.begin(), Value.end());
|
|
|
|
InsertOffset += Value.size();
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// Match the newly constructed regex.
|
|
|
|
RegExToMatch = TmpStr;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
SmallVector<StringRef, 4> MatchInfo;
|
2009-09-27 09:56:52 +02:00
|
|
|
if (!Regex(RegExToMatch, Regex::Newline).match(Buffer, &MatchInfo))
|
2009-09-25 19:23:43 +02:00
|
|
|
return StringRef::npos;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
// Successful regex match.
|
|
|
|
assert(!MatchInfo.empty() && "Didn't get any match");
|
|
|
|
StringRef FullMatch = MatchInfo[0];
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
// If this defines any variables, remember their values.
|
|
|
|
for (unsigned i = 0, e = VariableDefs.size(); i != e; ++i) {
|
|
|
|
assert(VariableDefs[i].second < MatchInfo.size() &&
|
|
|
|
"Internal paren error");
|
|
|
|
VariableTable[VariableDefs[i].first] = MatchInfo[VariableDefs[i].second];
|
2009-09-25 19:29:36 +02:00
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-25 19:23:43 +02:00
|
|
|
MatchLen = FullMatch.size();
|
|
|
|
return FullMatch.data()-Buffer.data();
|
2009-09-24 22:39:13 +02:00
|
|
|
}
|
|
|
|
|
2009-11-22 23:59:26 +01:00
|
|
|
unsigned Pattern::ComputeMatchDistance(StringRef Buffer,
|
|
|
|
const StringMap<StringRef> &VariableTable) const {
|
|
|
|
// Just compute the number of matching characters. For regular expressions, we
|
|
|
|
// just compare against the regex itself and hope for the best.
|
|
|
|
//
|
|
|
|
// FIXME: One easy improvement here is have the regex lib generate a single
|
|
|
|
// example regular expression which matches, and use that as the example
|
|
|
|
// string.
|
|
|
|
StringRef ExampleString(FixedStr);
|
|
|
|
if (ExampleString.empty())
|
|
|
|
ExampleString = RegExStr;
|
|
|
|
|
2010-01-30 01:24:06 +01:00
|
|
|
// Only compare up to the first line in the buffer, or the string size.
|
|
|
|
StringRef BufferPrefix = Buffer.substr(0, ExampleString.size());
|
|
|
|
BufferPrefix = BufferPrefix.split('\n').first;
|
|
|
|
return BufferPrefix.edit_distance(ExampleString);
|
2009-11-22 23:59:26 +01:00
|
|
|
}
|
|
|
|
|
2009-11-22 23:08:06 +01:00
|
|
|
void Pattern::PrintFailureInfo(const SourceMgr &SM, StringRef Buffer,
|
|
|
|
const StringMap<StringRef> &VariableTable) const{
|
|
|
|
// If this was a regular expression using variables, print the current
|
|
|
|
// variable values.
|
|
|
|
if (!VariableUses.empty()) {
|
|
|
|
for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
|
|
|
|
StringRef Var = VariableUses[i].first;
|
|
|
|
StringMap<StringRef>::const_iterator it = VariableTable.find(Var);
|
|
|
|
SmallString<256> Msg;
|
|
|
|
raw_svector_ostream OS(Msg);
|
|
|
|
|
|
|
|
// Check for undefined variable references.
|
|
|
|
if (it == VariableTable.end()) {
|
|
|
|
OS << "uses undefined variable \"";
|
|
|
|
OS.write_escaped(Var) << "\"";;
|
|
|
|
} else {
|
|
|
|
OS << "with variable \"";
|
|
|
|
OS.write_escaped(Var) << "\" equal to \"";
|
|
|
|
OS.write_escaped(it->second) << "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), OS.str(), "note",
|
|
|
|
/*ShowLine=*/false);
|
|
|
|
}
|
|
|
|
}
|
2009-11-22 23:59:26 +01:00
|
|
|
|
|
|
|
// Attempt to find the closest/best fuzzy match. Usually an error happens
|
|
|
|
// because some string in the output didn't exactly match. In these cases, we
|
|
|
|
// would like to show the user a best guess at what "should have" matched, to
|
|
|
|
// save them having to actually check the input manually.
|
|
|
|
size_t NumLinesForward = 0;
|
|
|
|
size_t Best = StringRef::npos;
|
|
|
|
double BestQuality = 0;
|
|
|
|
|
|
|
|
// Use an arbitrary 4k limit on how far we will search.
|
2010-01-29 22:57:46 +01:00
|
|
|
for (size_t i = 0, e = std::min(size_t(4096), Buffer.size()); i != e; ++i) {
|
2009-11-22 23:59:26 +01:00
|
|
|
if (Buffer[i] == '\n')
|
|
|
|
++NumLinesForward;
|
|
|
|
|
2010-01-29 22:55:16 +01:00
|
|
|
// Patterns have leading whitespace stripped, so skip whitespace when
|
|
|
|
// looking for something which looks like a pattern.
|
|
|
|
if (Buffer[i] == ' ' || Buffer[i] == '\t')
|
|
|
|
continue;
|
|
|
|
|
2009-11-22 23:59:26 +01:00
|
|
|
// Compute the "quality" of this match as an arbitrary combination of the
|
|
|
|
// match distance and the number of lines skipped to get to this match.
|
|
|
|
unsigned Distance = ComputeMatchDistance(Buffer.substr(i), VariableTable);
|
|
|
|
double Quality = Distance + (NumLinesForward / 100.);
|
|
|
|
|
|
|
|
if (Quality < BestQuality || Best == StringRef::npos) {
|
|
|
|
Best = i;
|
|
|
|
BestQuality = Quality;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-19 19:07:43 +01:00
|
|
|
// Print the "possible intended match here" line if we found something
|
|
|
|
// reasonable and not equal to what we showed in the "scanning from here"
|
|
|
|
// line.
|
|
|
|
if (Best && Best != StringRef::npos && BestQuality < 50) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data() + Best),
|
|
|
|
"possible intended match here", "note");
|
2009-11-22 23:59:26 +01:00
|
|
|
|
|
|
|
// FIXME: If we wanted to be really friendly we would show why the match
|
|
|
|
// failed, as it can be hard to spot simple one character differences.
|
|
|
|
}
|
2009-11-22 23:08:06 +01:00
|
|
|
}
|
2009-09-24 22:39:13 +02:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Check Strings.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-24 22:25:55 +02:00
|
|
|
|
|
|
|
/// CheckString - This is a check that we found in the input file.
|
|
|
|
struct CheckString {
|
|
|
|
/// Pat - The pattern to match.
|
|
|
|
Pattern Pat;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 19:41:04 +02:00
|
|
|
/// Loc - The location in the match file that the check string was specified.
|
|
|
|
SMLoc Loc;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
/// IsCheckNext - This is true if this is a CHECK-NEXT: directive (as opposed
|
|
|
|
/// to a CHECK: directive.
|
|
|
|
bool IsCheckNext;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:35:26 +02:00
|
|
|
/// NotStrings - These are all of the strings that are disallowed from
|
|
|
|
/// occurring between this match string and the previous one (or start of
|
|
|
|
/// file).
|
2009-09-24 22:39:13 +02:00
|
|
|
std::vector<std::pair<SMLoc, Pattern> > NotStrings;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:25:55 +02:00
|
|
|
CheckString(const Pattern &P, SMLoc L, bool isCheckNext)
|
|
|
|
: Pat(P), Loc(L), IsCheckNext(isCheckNext) {}
|
2009-08-15 19:41:04 +02:00
|
|
|
};
|
|
|
|
|
2009-09-24 22:45:07 +02:00
|
|
|
/// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
|
|
|
|
/// memory buffer, free it, and return a new one.
|
|
|
|
static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
|
2010-04-06 00:42:30 +02:00
|
|
|
SmallString<128> NewFile;
|
2009-09-24 22:45:07 +02:00
|
|
|
NewFile.reserve(MB->getBufferSize());
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:45:07 +02:00
|
|
|
for (const char *Ptr = MB->getBufferStart(), *End = MB->getBufferEnd();
|
|
|
|
Ptr != End; ++Ptr) {
|
|
|
|
// If C is not a horizontal whitespace, skip it.
|
|
|
|
if (*Ptr != ' ' && *Ptr != '\t') {
|
|
|
|
NewFile.push_back(*Ptr);
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:45:07 +02:00
|
|
|
// Otherwise, add one space and advance over neighboring space.
|
|
|
|
NewFile.push_back(' ');
|
|
|
|
while (Ptr+1 != End &&
|
|
|
|
(Ptr[1] == ' ' || Ptr[1] == '\t'))
|
|
|
|
++Ptr;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:45:07 +02:00
|
|
|
// Free the old buffer and return a new one.
|
|
|
|
MemoryBuffer *MB2 =
|
2010-04-06 00:42:30 +02:00
|
|
|
MemoryBuffer::getMemBufferCopy(NewFile.str(), MB->getBufferIdentifier());
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:45:07 +02:00
|
|
|
delete MB;
|
|
|
|
return MB2;
|
|
|
|
}
|
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
|
|
|
|
/// ReadCheckFile - Read the check file, which specifies the sequence of
|
|
|
|
/// expected strings. The strings are added to the CheckStrings vector.
|
|
|
|
static bool ReadCheckFile(SourceMgr &SM,
|
2009-08-15 19:41:04 +02:00
|
|
|
std::vector<CheckString> &CheckStrings) {
|
2009-07-08 20:44:05 +02:00
|
|
|
// Open the check file, and tell SourceMgr about it.
|
|
|
|
std::string ErrorStr;
|
|
|
|
MemoryBuffer *F =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(CheckFilename.c_str(), &ErrorStr);
|
|
|
|
if (F == 0) {
|
2010-08-20 19:38:38 +02:00
|
|
|
errs() << "Could not open check file '" << CheckFilename << "': "
|
2009-07-08 20:44:05 +02:00
|
|
|
<< ErrorStr << '\n';
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:45:07 +02:00
|
|
|
// If we want to canonicalize whitespace, strip excess whitespace from the
|
|
|
|
// buffer containing the CHECK lines.
|
|
|
|
if (!NoCanonicalizeWhiteSpace)
|
|
|
|
F = CanonicalizeInputFile(F);
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
SM.AddNewSourceBuffer(F, SMLoc());
|
|
|
|
|
2009-08-15 20:00:42 +02:00
|
|
|
// Find all instances of CheckPrefix followed by : in the file.
|
2009-09-21 00:11:44 +02:00
|
|
|
StringRef Buffer = F->getBuffer();
|
2009-07-08 20:44:05 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
std::vector<std::pair<SMLoc, Pattern> > NotMatches;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
while (1) {
|
|
|
|
// See if Prefix occurs in the memory buffer.
|
2009-09-21 00:11:44 +02:00
|
|
|
Buffer = Buffer.substr(Buffer.find(CheckPrefix));
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
// If we didn't find a match, we're done.
|
2009-09-21 00:11:44 +02:00
|
|
|
if (Buffer.empty())
|
2009-07-08 20:44:05 +02:00
|
|
|
break;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:11:44 +02:00
|
|
|
const char *CheckPrefixStart = Buffer.data();
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
// When we find a check prefix, keep track of whether we find CHECK: or
|
|
|
|
// CHECK-NEXT:
|
2009-09-21 00:35:26 +02:00
|
|
|
bool IsCheckNext = false, IsCheckNot = false;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:00:42 +02:00
|
|
|
// Verify that the : is present after the prefix.
|
2009-09-21 00:11:44 +02:00
|
|
|
if (Buffer[CheckPrefix.size()] == ':') {
|
|
|
|
Buffer = Buffer.substr(CheckPrefix.size()+1);
|
|
|
|
} else if (Buffer.size() > CheckPrefix.size()+6 &&
|
|
|
|
memcmp(Buffer.data()+CheckPrefix.size(), "-NEXT:", 6) == 0) {
|
|
|
|
Buffer = Buffer.substr(CheckPrefix.size()+7);
|
2009-08-15 20:32:21 +02:00
|
|
|
IsCheckNext = true;
|
2009-09-21 00:35:26 +02:00
|
|
|
} else if (Buffer.size() > CheckPrefix.size()+5 &&
|
|
|
|
memcmp(Buffer.data()+CheckPrefix.size(), "-NOT:", 5) == 0) {
|
|
|
|
Buffer = Buffer.substr(CheckPrefix.size()+6);
|
|
|
|
IsCheckNot = true;
|
2009-08-15 20:32:21 +02:00
|
|
|
} else {
|
2009-09-21 00:11:44 +02:00
|
|
|
Buffer = Buffer.substr(1);
|
2009-08-15 20:00:42 +02:00
|
|
|
continue;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
// Okay, we found the prefix, yay. Remember the rest of the line, but
|
|
|
|
// ignore leading and trailing whitespace.
|
2009-09-21 00:35:26 +02:00
|
|
|
Buffer = Buffer.substr(Buffer.find_first_not_of(" \t"));
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
// Scan ahead to the end of line.
|
2009-09-21 00:11:44 +02:00
|
|
|
size_t EOL = Buffer.find_first_of("\n\r");
|
2009-09-24 22:39:13 +02:00
|
|
|
|
2010-01-29 22:53:18 +01:00
|
|
|
// Remember the location of the start of the pattern, for diagnostics.
|
|
|
|
SMLoc PatternLoc = SMLoc::getFromPointer(Buffer.data());
|
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
// Parse the pattern.
|
|
|
|
Pattern P;
|
|
|
|
if (P.ParsePattern(Buffer.substr(0, EOL), SM))
|
2009-07-08 20:44:05 +02:00
|
|
|
return true;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
Buffer = Buffer.substr(EOL);
|
|
|
|
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
// Verify that CHECK-NEXT lines have at least one CHECK line before them.
|
|
|
|
if (IsCheckNext && CheckStrings.empty()) {
|
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(CheckPrefixStart),
|
|
|
|
"found '"+CheckPrefix+"-NEXT:' without previous '"+
|
|
|
|
CheckPrefix+ ": line", "error");
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-24 22:39:13 +02:00
|
|
|
// Handle CHECK-NOT.
|
|
|
|
if (IsCheckNot) {
|
|
|
|
NotMatches.push_back(std::make_pair(SMLoc::getFromPointer(Buffer.data()),
|
|
|
|
P));
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
// Okay, add the string we captured to the output vector and move on.
|
2009-09-24 22:25:55 +02:00
|
|
|
CheckStrings.push_back(CheckString(P,
|
2010-01-29 22:53:18 +01:00
|
|
|
PatternLoc,
|
2009-08-15 20:32:21 +02:00
|
|
|
IsCheckNext));
|
2009-09-21 00:35:26 +02:00
|
|
|
std::swap(NotMatches, CheckStrings.back().NotStrings);
|
2009-07-08 20:44:05 +02:00
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
if (CheckStrings.empty()) {
|
2009-08-15 20:00:42 +02:00
|
|
|
errs() << "error: no check strings found with prefix '" << CheckPrefix
|
|
|
|
<< ":'\n";
|
2009-07-08 20:44:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:35:26 +02:00
|
|
|
if (!NotMatches.empty()) {
|
|
|
|
errs() << "error: '" << CheckPrefix
|
|
|
|
<< "-NOT:' not supported after last check line.\n";
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
static void PrintCheckFailed(const SourceMgr &SM, const CheckString &CheckStr,
|
2009-11-22 23:08:06 +01:00
|
|
|
StringRef Buffer,
|
|
|
|
StringMap<StringRef> &VariableTable) {
|
2009-08-15 20:32:21 +02:00
|
|
|
// Otherwise, we have an error, emit an error message.
|
|
|
|
SM.PrintMessage(CheckStr.Loc, "expected string not found in input",
|
|
|
|
"error");
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
// Print the "scanning from here" line. If the current position is at the
|
|
|
|
// end of a line, advance to the start of the next line.
|
2009-09-21 00:11:44 +02:00
|
|
|
Buffer = Buffer.substr(Buffer.find_first_not_of(" \t\n\r"));
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:11:44 +02:00
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), "scanning from here",
|
2009-08-15 20:32:21 +02:00
|
|
|
"note");
|
2009-11-22 23:08:06 +01:00
|
|
|
|
|
|
|
// Allow the pattern to print additional information if desired.
|
|
|
|
CheckStr.Pat.PrintFailureInfo(SM, Buffer, VariableTable);
|
2009-08-15 20:32:21 +02:00
|
|
|
}
|
|
|
|
|
2009-09-21 00:42:44 +02:00
|
|
|
/// CountNumNewlinesBetween - Count the number of newlines in the specified
|
|
|
|
/// range.
|
|
|
|
static unsigned CountNumNewlinesBetween(StringRef Range) {
|
2009-08-15 20:32:21 +02:00
|
|
|
unsigned NumNewLines = 0;
|
2009-09-21 00:42:44 +02:00
|
|
|
while (1) {
|
2009-08-15 20:32:21 +02:00
|
|
|
// Scan for newline.
|
2009-09-21 00:42:44 +02:00
|
|
|
Range = Range.substr(Range.find_first_of("\n\r"));
|
|
|
|
if (Range.empty()) return NumNewLines;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
++NumNewLines;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
// Handle \n\r and \r\n as a single newline.
|
2009-09-21 00:42:44 +02:00
|
|
|
if (Range.size() > 1 &&
|
|
|
|
(Range[1] == '\n' || Range[1] == '\r') &&
|
|
|
|
(Range[0] != Range[1]))
|
|
|
|
Range = Range.substr(1);
|
|
|
|
Range = Range.substr(1);
|
2009-08-15 20:32:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
sys::PrintStackTraceOnErrorSignal();
|
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
|
|
cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
|
|
|
|
SourceMgr SM;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
// Read the expected strings from the check file.
|
2009-08-15 19:41:04 +02:00
|
|
|
std::vector<CheckString> CheckStrings;
|
2009-07-08 20:44:05 +02:00
|
|
|
if (ReadCheckFile(SM, CheckStrings))
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
// Open the file to check and add it to SourceMgr.
|
|
|
|
std::string ErrorStr;
|
|
|
|
MemoryBuffer *F =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), &ErrorStr);
|
|
|
|
if (F == 0) {
|
2010-08-20 19:38:38 +02:00
|
|
|
errs() << "Could not open input file '" << InputFilename << "': "
|
2009-07-08 20:44:05 +02:00
|
|
|
<< ErrorStr << '\n';
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-11 20:58:15 +02:00
|
|
|
// Remove duplicate spaces in the input file if requested.
|
|
|
|
if (!NoCanonicalizeWhiteSpace)
|
|
|
|
F = CanonicalizeInputFile(F);
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
SM.AddNewSourceBuffer(F, SMLoc());
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-27 09:56:52 +02:00
|
|
|
/// VariableTable - This holds all the current filecheck variables.
|
|
|
|
StringMap<StringRef> VariableTable;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
// Check that we have all of the expected strings, in order, in the input
|
|
|
|
// file.
|
2009-09-21 00:11:44 +02:00
|
|
|
StringRef Buffer = F->getBuffer();
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:35:26 +02:00
|
|
|
const char *LastMatch = Buffer.data();
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
for (unsigned StrNo = 0, e = CheckStrings.size(); StrNo != e; ++StrNo) {
|
2009-08-15 19:41:04 +02:00
|
|
|
const CheckString &CheckStr = CheckStrings[StrNo];
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:11:44 +02:00
|
|
|
StringRef SearchFrom = Buffer;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
// Find StrNo in the file.
|
2009-09-24 22:25:55 +02:00
|
|
|
size_t MatchLen = 0;
|
2009-09-27 09:56:52 +02:00
|
|
|
Buffer = Buffer.substr(CheckStr.Pat.Match(Buffer, MatchLen, VariableTable));
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
// If we didn't find a match, reject the input.
|
2009-09-21 00:11:44 +02:00
|
|
|
if (Buffer.empty()) {
|
2009-11-22 23:08:06 +01:00
|
|
|
PrintCheckFailed(SM, CheckStr, SearchFrom, VariableTable);
|
2009-08-15 20:32:21 +02:00
|
|
|
return 1;
|
2009-07-08 20:44:05 +02:00
|
|
|
}
|
2009-09-21 00:42:44 +02:00
|
|
|
|
|
|
|
StringRef SkippedRegion(LastMatch, Buffer.data()-LastMatch);
|
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
// If this check is a "CHECK-NEXT", verify that the previous match was on
|
|
|
|
// the previous line (i.e. that there is one newline between them).
|
|
|
|
if (CheckStr.IsCheckNext) {
|
|
|
|
// Count the number of newlines between the previous match and this one.
|
2009-09-21 00:35:26 +02:00
|
|
|
assert(LastMatch != F->getBufferStart() &&
|
|
|
|
"CHECK-NEXT can't be the first check in a file");
|
2009-08-15 20:32:21 +02:00
|
|
|
|
2009-09-21 00:42:44 +02:00
|
|
|
unsigned NumNewLines = CountNumNewlinesBetween(SkippedRegion);
|
2009-08-15 20:32:21 +02:00
|
|
|
if (NumNewLines == 0) {
|
2009-08-16 04:22:31 +02:00
|
|
|
SM.PrintMessage(CheckStr.Loc,
|
2009-08-15 20:32:21 +02:00
|
|
|
CheckPrefix+"-NEXT: is on the same line as previous match",
|
|
|
|
"error");
|
2009-09-21 00:11:44 +02:00
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
|
2009-08-16 04:22:31 +02:00
|
|
|
"'next' match was here", "note");
|
2009-08-15 20:32:21 +02:00
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(LastMatch),
|
|
|
|
"previous match was here", "note");
|
|
|
|
return 1;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
if (NumNewLines != 1) {
|
2009-08-16 04:22:31 +02:00
|
|
|
SM.PrintMessage(CheckStr.Loc,
|
2009-08-15 20:32:21 +02:00
|
|
|
CheckPrefix+
|
|
|
|
"-NEXT: is not on the line after the previous match",
|
|
|
|
"error");
|
2009-09-21 00:11:44 +02:00
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
|
2009-08-16 04:22:31 +02:00
|
|
|
"'next' match was here", "note");
|
2009-08-15 20:32:21 +02:00
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(LastMatch),
|
|
|
|
"previous match was here", "note");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:35:26 +02:00
|
|
|
// If this match had "not strings", verify that they don't exist in the
|
|
|
|
// skipped region.
|
2009-09-27 09:56:52 +02:00
|
|
|
for (unsigned ChunkNo = 0, e = CheckStr.NotStrings.size();
|
|
|
|
ChunkNo != e; ++ChunkNo) {
|
2009-09-24 22:39:13 +02:00
|
|
|
size_t MatchLen = 0;
|
2009-09-27 09:56:52 +02:00
|
|
|
size_t Pos = CheckStr.NotStrings[ChunkNo].second.Match(SkippedRegion,
|
|
|
|
MatchLen,
|
|
|
|
VariableTable);
|
2009-09-21 00:35:26 +02:00
|
|
|
if (Pos == StringRef::npos) continue;
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-09-21 00:35:26 +02:00
|
|
|
SM.PrintMessage(SMLoc::getFromPointer(LastMatch+Pos),
|
|
|
|
CheckPrefix+"-NOT: string occurred!", "error");
|
2009-09-24 23:47:32 +02:00
|
|
|
SM.PrintMessage(CheckStr.NotStrings[ChunkNo].first,
|
2009-09-21 00:35:26 +02:00
|
|
|
CheckPrefix+"-NOT: pattern specified here", "note");
|
|
|
|
return 1;
|
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-08-15 20:32:21 +02:00
|
|
|
|
2009-09-21 04:30:42 +02:00
|
|
|
// Otherwise, everything is good. Step over the matched text and remember
|
|
|
|
// the position after the match as the end of the last match.
|
2009-09-24 22:25:55 +02:00
|
|
|
Buffer = Buffer.substr(MatchLen);
|
2009-09-21 04:30:42 +02:00
|
|
|
LastMatch = Buffer.data();
|
2009-07-08 20:44:05 +02:00
|
|
|
}
|
2010-08-20 19:38:38 +02:00
|
|
|
|
2009-07-08 20:44:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|