[llvm-commits] [llvm] r82712 - /llvm/trunk/utils/FileCheck/FileCheck.cpp

Chris Lattner sabre at nondot.org
Thu Sep 24 15:39:13 CDT 2009


Author: lattner
Date: Thu Sep 24 15:39:13 2009
New Revision: 82712

URL: http://llvm.org/viewvc/llvm-project?rev=82712&view=rev
Log:
change 'not' matching to use Pattern, move pattern parsing logic into
the Pattern class.

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=82712&r1=82711&r2=82712&view=diff

==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Thu Sep 24 15:39:13 2009
@@ -39,16 +39,18 @@
 NoCanonicalizeWhiteSpace("strict-whitespace",
               cl::desc("Do not treat all horizontal whitespace as equivalent"));
 
+//===----------------------------------------------------------------------===//
+// Pattern Handling Code.
+//===----------------------------------------------------------------------===//
+
 class Pattern {
   /// Str - The string to match.
   std::string Str;
 public:
   
-  Pattern(StringRef S) : Str(S.str()) {
-    // Remove duplicate spaces in the check strings if requested.
-    if (!NoCanonicalizeWhiteSpace)
-      CanonicalizeCheckString();
-  }
+  Pattern() { }
+  
+  bool ParsePattern(StringRef PatternStr, SourceMgr &SM);
   
   /// 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
@@ -78,6 +80,33 @@
   }
 };
 
+bool Pattern::ParsePattern(StringRef PatternStr, SourceMgr &SM) {
+  // Ignore trailing whitespace.
+  while (!PatternStr.empty() &&
+         (PatternStr.back() == ' ' || PatternStr.back() == '\t'))
+    PatternStr = PatternStr.substr(0, PatternStr.size()-1);
+  
+  // Check that there is something on the line.
+  if (PatternStr.empty()) {
+    SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
+                    "found empty check string with prefix '"+CheckPrefix+":'",
+                    "error");
+    return true;
+  }
+  
+  Str = PatternStr.str();
+  
+  // Remove duplicate spaces in the check strings if requested.
+  if (!NoCanonicalizeWhiteSpace)
+    CanonicalizeCheckString();
+  
+  return false;
+}
+
+
+//===----------------------------------------------------------------------===//
+// Check Strings.
+//===----------------------------------------------------------------------===//
 
 /// CheckString - This is a check that we found in the input file.
 struct CheckString {
@@ -94,7 +123,7 @@
   /// NotStrings - These are all of the strings that are disallowed from
   /// occurring between this match string and the previous one (or start of
   /// file).
-  std::vector<std::pair<SMLoc, std::string> > NotStrings;
+  std::vector<std::pair<SMLoc, Pattern> > NotStrings;
   
   CheckString(const Pattern &P, SMLoc L, bool isCheckNext)
     : Pat(P), Loc(L), IsCheckNext(isCheckNext) {}
@@ -119,7 +148,7 @@
   // Find all instances of CheckPrefix followed by : in the file.
   StringRef Buffer = F->getBuffer();
 
-  std::vector<std::pair<SMLoc, std::string> > NotMatches;
+  std::vector<std::pair<SMLoc, Pattern> > NotMatches;
   
   while (1) {
     // See if Prefix occurs in the memory buffer.
@@ -157,29 +186,14 @@
     
     // Scan ahead to the end of line.
     size_t EOL = Buffer.find_first_of("\n\r");
-    if (EOL == StringRef::npos) EOL = Buffer.size();
-    
-    // Ignore trailing whitespace.
-    while (EOL && (Buffer[EOL-1] == ' ' || Buffer[EOL-1] == '\t'))
-      --EOL;
-    
-    // Check that there is something on the line.
-    if (EOL == 0) {
-      SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
-                      "found empty check string with prefix '"+CheckPrefix+":'",
-                      "error");
+
+    // Parse the pattern.
+    Pattern P;
+    if (P.ParsePattern(Buffer.substr(0, EOL), SM))
       return true;
-    }
     
-    StringRef PatternStr = Buffer.substr(0, EOL);
-    
-    // Handle CHECK-NOT.
-    if (IsCheckNot) {
-      NotMatches.push_back(std::make_pair(SMLoc::getFromPointer(Buffer.data()),
-                                          PatternStr.str()));
-      Buffer = Buffer.substr(EOL);
-      continue;
-    }
+    Buffer = Buffer.substr(EOL);
+
     
     // Verify that CHECK-NEXT lines have at least one CHECK line before them.
     if (IsCheckNext && CheckStrings.empty()) {
@@ -189,15 +203,19 @@
       return true;
     }
     
-    Pattern P(PatternStr);
+    // Handle CHECK-NOT.
+    if (IsCheckNot) {
+      NotMatches.push_back(std::make_pair(SMLoc::getFromPointer(Buffer.data()),
+                                          P));
+      continue;
+    }
+    
     
     // Okay, add the string we captured to the output vector and move on.
     CheckStrings.push_back(CheckString(P,
                                        SMLoc::getFromPointer(Buffer.data()),
                                        IsCheckNext));
     std::swap(NotMatches, CheckStrings.back().NotStrings);
-    
-    Buffer = Buffer.substr(EOL);
   }
   
   if (CheckStrings.empty()) {
@@ -367,7 +385,8 @@
     // If this match had "not strings", verify that they don't exist in the
     // skipped region.
     for (unsigned i = 0, e = CheckStr.NotStrings.size(); i != e; ++i) {
-      size_t Pos = SkippedRegion.find(CheckStr.NotStrings[i].second);
+      size_t MatchLen = 0;
+      size_t Pos = CheckStr.NotStrings[i].second.Match(SkippedRegion, MatchLen);
       if (Pos == StringRef::npos) continue;
      
       SM.PrintMessage(SMLoc::getFromPointer(LastMatch+Pos),





More information about the llvm-commits mailing list