Index: lib/Frontend/VerifyDiagnosticConsumer.cpp =================================================================== --- lib/Frontend/VerifyDiagnosticConsumer.cpp +++ lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -19,6 +19,7 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/ParseHelper.h" #include "llvm/Support/Regex.h" #include "llvm/Support/raw_ostream.h" @@ -198,108 +199,6 @@ llvm::Regex Regex; }; -class ParseHelper -{ -public: - ParseHelper(StringRef S) - : Begin(S.begin()), End(S.end()), C(Begin), P(Begin), PEnd(nullptr) {} - - // Return true if string literal is next. - bool Next(StringRef S) { - P = C; - PEnd = C + S.size(); - if (PEnd > End) - return false; - return !memcmp(P, S.data(), S.size()); - } - - // Return true if number is next. - // Output N only if number is next. - bool Next(unsigned &N) { - unsigned TMP = 0; - P = C; - for (; P < End && P[0] >= '0' && P[0] <= '9'; ++P) { - TMP *= 10; - TMP += P[0] - '0'; - } - if (P == C) - return false; - PEnd = P; - N = TMP; - return true; - } - - // Return true if string literal is found. - // When true, P marks begin-position of S in content. - bool Search(StringRef S, bool EnsureStartOfWord = false) { - do { - P = std::search(C, End, S.begin(), S.end()); - PEnd = P + S.size(); - if (P == End) - break; - if (!EnsureStartOfWord - // Check if string literal starts a new word. - || P == Begin || isWhitespace(P[-1]) - // Or it could be preceded by the start of a comment. - || (P > (Begin + 1) && (P[-1] == '/' || P[-1] == '*') - && P[-2] == '/')) - return true; - // Otherwise, skip and search again. - } while (Advance()); - return false; - } - - // Return true if a CloseBrace that closes the OpenBrace at the current nest - // level is found. When true, P marks begin-position of CloseBrace. - bool SearchClosingBrace(StringRef OpenBrace, StringRef CloseBrace) { - unsigned Depth = 1; - P = C; - while (P < End) { - StringRef S(P, End - P); - if (S.startswith(OpenBrace)) { - ++Depth; - P += OpenBrace.size(); - } else if (S.startswith(CloseBrace)) { - --Depth; - if (Depth == 0) { - PEnd = P + CloseBrace.size(); - return true; - } - P += CloseBrace.size(); - } else { - ++P; - } - } - return false; - } - - // Advance 1-past previous next/search. - // Behavior is undefined if previous next/search failed. - bool Advance() { - C = PEnd; - return C < End; - } - - // Skip zero or more whitespace. - void SkipWhitespace() { - for (; C < End && isWhitespace(*C); ++C) - ; - } - - // Return true if EOF reached. - bool Done() { - return !(C < End); - } - - const char * const Begin; // beginning of expected content - const char * const End; // end of expected content (1-past) - const char *C; // position of next char in content - const char *P; - -private: - const char *PEnd; // previous next/search subject end (1-past) -}; - } // namespace anonymous /// ParseDirective - Go through the comment and see if it indicates expected @@ -313,7 +212,7 @@ // A single comment may contain multiple directives. bool FoundDirective = false; - for (ParseHelper PH(S); !PH.Done();) { + for (llvm::ParseHelper PH(S); !PH.Done();) { // Search for token: expected if (!PH.Search("expected", true)) break;