The most significant encoding bit of GPR:$src or GPR:$dst was over-specified in
[oota-llvm.git] / lib / Support / Regex.cpp
index 285e01f02b16b58d1475c08fe4d659e0416851c8..618ca0524a04f5f996da3de4c26363f97ab41c28 100644 (file)
@@ -25,21 +25,20 @@ Regex::Regex(const StringRef &regex, unsigned Flags) {
   preg->re_endp = regex.end();
   if (Flags & IgnoreCase) 
     flags |= REG_ICASE;
-  if (Flags & NoSub) {
-    flags |= REG_NOSUB;
-    sub = false;
-  } else {
-    sub = true;
-  }
   if (Flags & Newline)
     flags |= REG_NEWLINE;
   error = llvm_regcomp(preg, regex.data(), flags|REG_EXTENDED|REG_PEND);
 }
 
+Regex::~Regex() {
+  llvm_regfree(preg);
+  delete preg;
+}
+
 bool Regex::isValid(std::string &Error) {
   if (!error)
     return true;
-
+  
   size_t len = llvm_regerror(error, preg, NULL, 0);
   
   Error.resize(len);
@@ -47,19 +46,15 @@ bool Regex::isValid(std::string &Error) {
   return false;
 }
 
-Regex::~Regex() {
-  llvm_regfree(preg);
-  delete preg;
+/// getNumMatches - In a valid regex, return the number of parenthesized
+/// matches it contains.
+unsigned Regex::getNumMatches() const {
+  return preg->re_nsub;
 }
 
 bool Regex::match(const StringRef &String, SmallVectorImpl<StringRef> *Matches){
   unsigned nmatch = Matches ? preg->re_nsub+1 : 0;
 
-  if (Matches) {
-    assert(sub && "Substring matching requested but pattern compiled without");
-    Matches->clear();
-  }
-
   // pmatch needs to have at least one element.
   SmallVector<llvm_regmatch_t, 8> pm;
   pm.resize(nmatch > 0 ? nmatch : 1);
@@ -79,6 +74,8 @@ bool Regex::match(const StringRef &String, SmallVectorImpl<StringRef> *Matches){
   // There was a match.
 
   if (Matches) { // match position requested
+    Matches->clear();
+    
     for (unsigned i = 0; i != nmatch; ++i) {
       if (pm[i].rm_so == -1) {
         // this group didn't match