summaryrefslogtreecommitdiffstats
path: root/utils/FileCheck
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-09-24 20:45:07 +0000
committerChris Lattner <sabre@nondot.org>2009-09-24 20:45:07 +0000
commitadea46ed617982ea07fc3266d52717496c0076ce (patch)
treeccf3c938802a76138e0ca4b5cb746d67d5ec6528 /utils/FileCheck
parenta29703e8426763fa5232f9a91e6a5fce4d4244d6 (diff)
downloadexternal_llvm-adea46ed617982ea07fc3266d52717496c0076ce.zip
external_llvm-adea46ed617982ea07fc3266d52717496c0076ce.tar.gz
external_llvm-adea46ed617982ea07fc3266d52717496c0076ce.tar.bz2
Use CanonicalizeInputFile to canonicalize the entire buffer containing the
CHECK strings, instead of canonicalizing the patterns directly. This allows Pattern to just contain a StringRef instead of std::string. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82713 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/FileCheck')
-rw-r--r--utils/FileCheck/FileCheck.cpp97
1 files changed, 40 insertions, 57 deletions
diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp
index cab37fb..cd62870 100644
--- a/utils/FileCheck/FileCheck.cpp
+++ b/utils/FileCheck/FileCheck.cpp
@@ -45,7 +45,7 @@ NoCanonicalizeWhiteSpace("strict-whitespace",
class Pattern {
/// Str - The string to match.
- std::string Str;
+ StringRef Str;
public:
Pattern() { }
@@ -59,25 +59,6 @@ public:
MatchLen = Str.size();
return Buffer.find(Str);
}
-
-private:
- /// CanonicalizeCheckString - Replace all sequences of horizontal whitespace
- /// in the check strings with a single space.
- void CanonicalizeCheckString() {
- for (unsigned C = 0; C != Str.size(); ++C) {
- // If C is not a horizontal whitespace, skip it.
- if (Str[C] != ' ' && Str[C] != '\t')
- continue;
-
- // Replace the character with space, then remove any other space
- // characters after it.
- Str[C] = ' ';
-
- while (C+1 != Str.size() &&
- (Str[C+1] == ' ' || Str[C+1] == '\t'))
- Str.erase(Str.begin()+C+1);
- }
- }
};
bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
@@ -93,13 +74,10 @@ bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
"error");
return true;
}
+
- Str = PatternStr.str();
-
- // Remove duplicate spaces in the check strings if requested.
- if (!NoCanonicalizeWhiteSpace)
- CanonicalizeCheckString();
+ Str = PatternStr;
return false;
}
@@ -129,6 +107,37 @@ struct CheckString {
: Pat(P), Loc(L), IsCheckNext(isCheckNext) {}
};
+/// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
+/// memory buffer, free it, and return a new one.
+static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
+ SmallVector<char, 16> NewFile;
+ NewFile.reserve(MB->getBufferSize());
+
+ 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;
+ }
+
+ // Otherwise, add one space and advance over neighboring space.
+ NewFile.push_back(' ');
+ while (Ptr+1 != End &&
+ (Ptr[1] == ' ' || Ptr[1] == '\t'))
+ ++Ptr;
+ }
+
+ // Free the old buffer and return a new one.
+ MemoryBuffer *MB2 =
+ MemoryBuffer::getMemBufferCopy(NewFile.data(),
+ NewFile.data() + NewFile.size(),
+ MB->getBufferIdentifier());
+
+ delete MB;
+ return MB2;
+}
+
/// ReadCheckFile - Read the check file, which specifies the sequence of
/// expected strings. The strings are added to the CheckStrings vector.
@@ -143,6 +152,12 @@ static bool ReadCheckFile(SourceMgr &SM,
<< ErrorStr << '\n';
return true;
}
+
+ // If we want to canonicalize whitespace, strip excess whitespace from the
+ // buffer containing the CHECK lines.
+ if (!NoCanonicalizeWhiteSpace)
+ F = CanonicalizeInputFile(F);
+
SM.AddNewSourceBuffer(F, SMLoc());
// Find all instances of CheckPrefix followed by : in the file.
@@ -233,38 +248,6 @@ static bool ReadCheckFile(SourceMgr &SM,
return false;
}
-/// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
-/// memory buffer, free it, and return a new one.
-static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
- SmallVector<char, 16> NewFile;
- NewFile.reserve(MB->getBufferSize());
-
- 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;
- }
-
- // Otherwise, add one space and advance over neighboring space.
- NewFile.push_back(' ');
- while (Ptr+1 != End &&
- (Ptr[1] == ' ' || Ptr[1] == '\t'))
- ++Ptr;
- }
-
- // Free the old buffer and return a new one.
- MemoryBuffer *MB2 =
- MemoryBuffer::getMemBufferCopy(NewFile.data(),
- NewFile.data() + NewFile.size(),
- MB->getBufferIdentifier());
-
- delete MB;
- return MB2;
-}
-
-
static void PrintCheckFailed(const SourceMgr &SM, const CheckString &CheckStr,
StringRef Buffer) {
// Otherwise, we have an error, emit an error message.