[llvm-commits] [llvm] r82713 - /llvm/trunk/utils/FileCheck/FileCheck.cpp
Chris Lattner
sabre at nondot.org
Thu Sep 24 13:45:08 PDT 2009
Author: lattner
Date: Thu Sep 24 15:45:07 2009
New Revision: 82713
URL: http://llvm.org/viewvc/llvm-project?rev=82713&view=rev
Log:
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.
Modified:
llvm/trunk/utils/FileCheck/FileCheck.cpp
Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=82713&r1=82712&r2=82713&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Thu Sep 24 15:45:07 2009
@@ -45,7 +45,7 @@
class Pattern {
/// Str - The string to match.
- std::string Str;
+ StringRef Str;
public:
Pattern() { }
@@ -59,25 +59,6 @@
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 @@
"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 @@
: 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 @@
<< 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 @@
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.
More information about the llvm-commits
mailing list