[PATCH] D51258: Extract parseBindID method

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 30 16:12:21 PDT 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341141: Extract parseBindID method (authored by steveire, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51258?vs=162552&id=163441#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51258

Files:
  cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
  cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp


Index: cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
===================================================================
--- cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
+++ cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
@@ -234,6 +234,7 @@
          const NamedValueMap *NamedValues,
          Diagnostics *Error);
 
+  bool parseBindID(std::string &BindID);
   bool parseExpressionImpl(VariantValue *Value);
   bool parseMatcherExpressionImpl(const TokenInfo &NameToken,
                                   VariantValue *Value);
Index: cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
===================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -359,6 +359,43 @@
   return parseMatcherExpressionImpl(NameToken, Value);
 }
 
+bool Parser::parseBindID(std::string &BindID) {
+  // Parse .bind("foo")
+  assert(Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period);
+  Tokenizer->consumeNextToken(); // consume the period.
+  const TokenInfo BindToken = Tokenizer->consumeNextToken();
+  if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
+    addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
+    return false;
+  }
+
+  const TokenInfo OpenToken = Tokenizer->consumeNextToken();
+  const TokenInfo IDToken = Tokenizer->consumeNextToken();
+  const TokenInfo CloseToken = Tokenizer->consumeNextToken();
+
+  // TODO: We could use different error codes for each/some to be more
+  //       explicit about the syntax error.
+  if (BindToken.Kind != TokenInfo::TK_Ident ||
+      BindToken.Text != TokenInfo::ID_Bind) {
+    Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
+    return false;
+  }
+  if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
+    Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr);
+    return false;
+  }
+  if (IDToken.Kind != TokenInfo::TK_Literal || !IDToken.Value.isString()) {
+    Error->addError(IDToken.Range, Error->ET_ParserMalformedBindExpr);
+    return false;
+  }
+  if (CloseToken.Kind != TokenInfo::TK_CloseParen) {
+    Error->addError(CloseToken.Range, Error->ET_ParserMalformedBindExpr);
+    return false;
+  }
+  BindID = IDToken.Value.getString();
+  return true;
+}
+
 /// Parse and validate a matcher expression.
 /// \return \c true on success, in which case \c Value has the matcher parsed.
 ///   If the input is malformed, or some argument has an error, it
@@ -425,38 +462,8 @@
 
   std::string BindID;
   if (Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period) {
-    // Parse .bind("foo")
-    Tokenizer->consumeNextToken();  // consume the period.
-    const TokenInfo BindToken = Tokenizer->consumeNextToken();
-    if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
-      addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
+    if (!parseBindID(BindID))
       return false;
-    }
-
-    const TokenInfo OpenToken = Tokenizer->consumeNextToken();
-    const TokenInfo IDToken = Tokenizer->consumeNextToken();
-    const TokenInfo CloseToken = Tokenizer->consumeNextToken();
-
-    // TODO: We could use different error codes for each/some to be more
-    //       explicit about the syntax error.
-    if (BindToken.Kind != TokenInfo::TK_Ident ||
-        BindToken.Text != TokenInfo::ID_Bind) {
-      Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
-      return false;
-    }
-    if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
-      Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr);
-      return false;
-    }
-    if (IDToken.Kind != TokenInfo::TK_Literal || !IDToken.Value.isString()) {
-      Error->addError(IDToken.Range, Error->ET_ParserMalformedBindExpr);
-      return false;
-    }
-    if (CloseToken.Kind != TokenInfo::TK_CloseParen) {
-      Error->addError(CloseToken.Range, Error->ET_ParserMalformedBindExpr);
-      return false;
-    }
-    BindID = IDToken.Value.getString();
   }
 
   if (!Ctor)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51258.163441.patch
Type: text/x-patch
Size: 4030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180830/b29d2b83/attachment.bin>


More information about the cfe-commits mailing list