diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3007,7 +3007,7 @@
-
Matcher<Decl> | isExpansionInFileMatching | std::string RegExp |
+Matcher<Decl> | isExpansionInFileMatching | StringRef RegExp, Regex::RegexFlags Flags = NoFlags |
Matches AST nodes that were expanded within files whose name is
partially matching a given regex.
@@ -3019,6 +3019,10 @@
class Y {};
Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
+If the matcher is used in clang-query, RegexFlags parameter
+should be passed as a quoted string. e.g: "NoFlags".
+Flags can be combined with '|' example "IgnoreCase | BasicRegex"
|
@@ -3725,7 +3729,7 @@
-Matcher<NamedDecl> | matchesName | std::string RegExp |
+Matcher<NamedDecl> | matchesName | StringRef RegExp, Regex::RegexFlags Flags = NoFlags |
Matches NamedDecl nodes whose fully qualified names contain
a substring matched by the given RegExp.
@@ -3738,6 +3742,10 @@
Example matches X (regexp is one of "::X", "^foo::.*X", among others)
namespace foo { namespace bar { class X; } }
+
+If the matcher is used in clang-query, RegexFlags parameter
+should be passed as a quoted string. e.g: "NoFlags".
+Flags can be combined with '|' example "IgnoreCase | BasicRegex"
|
@@ -3932,12 +3940,16 @@
-Matcher<ObjCMessageExpr> | matchesSelector | std::string RegExp |
+Matcher<ObjCMessageExpr> | matchesSelector | StringRef RegExp, Regex::RegexFlags Flags = NoFlags |
Matches ObjC selectors whose name contains
a substring matched by the given RegExp.
matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message
invocation for self.bodyView.
[self.bodyView loadHTMLString:html baseURL:NULL];
+
+If the matcher is used in clang-query, RegexFlags parameter
+should be passed as a quoted string. e.g: "NoFlags".
+Flags can be combined with '|' example "IgnoreCase | BasicRegex"
|
@@ -4228,7 +4240,7 @@
-Matcher<Stmt> | isExpansionInFileMatching | std::string RegExp |
+Matcher<Stmt> | isExpansionInFileMatching | StringRef RegExp, Regex::RegexFlags Flags = NoFlags |
Matches AST nodes that were expanded within files whose name is
partially matching a given regex.
@@ -4240,6 +4252,10 @@
class Y {};
Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
+If the matcher is used in clang-query, RegexFlags parameter
+should be passed as a quoted string. e.g: "NoFlags".
+Flags can be combined with '|' example "IgnoreCase | BasicRegex"
|
@@ -4410,7 +4426,7 @@
-Matcher<TypeLoc> | isExpansionInFileMatching | std::string RegExp |
+Matcher<TypeLoc> | isExpansionInFileMatching | StringRef RegExp, Regex::RegexFlags Flags = NoFlags |
Matches AST nodes that were expanded within files whose name is
partially matching a given regex.
@@ -4422,6 +4438,10 @@
class Y {};
Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
+If the matcher is used in clang-query, RegexFlags parameter
+should be passed as a quoted string. e.g: "NoFlags".
+Flags can be combined with '|' example "IgnoreCase | BasicRegex"
|
diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -230,6 +230,28 @@
add_matcher(result_type, name, args, comment)
return
+ m = re.match(r"""^\s*AST_POLYMORPHIC_MATCHER_REGEX(?:_OVERLOAD)?\(
+ \s*([^\s,]+)\s*,
+ \s*AST_POLYMORPHIC_SUPPORTED_TYPES\(([^)]*)\),
+ \s*([^\s,]+)\s*
+ (?:,\s*\d+\s*)?
+ \)\s*{\s*$""", declaration, flags=re.X)
+
+ if m:
+ name, results, arg_name = m.groups()[0:3]
+ result_types = [r.strip() for r in results.split(',')]
+ if allowed_types and allowed_types != result_types:
+ raise Exception('Inconsistent documentation for: %s' % name)
+ arg = "StringRef %s, Regex::RegexFlags Flags = NoFlags" % arg_name
+ comment += """
+If the matcher is used in clang-query, RegexFlags parameter
+should be passed as a quoted string. e.g: "NoFlags".
+Flags can be combined with '|' example \"IgnoreCase | BasicRegex\"
+"""
+ for result_type in result_types:
+ add_matcher(result_type, name, arg, comment)
+ return
+
m = re.match(r"""^\s*AST_MATCHER_FUNCTION(_P)?(.?)(?:_OVERLOAD)?\(
(?:\s*([^\s,]+)\s*,)?
\s*([^\s,]+)\s*
@@ -275,6 +297,31 @@
add_matcher(result_type, name, args, comment)
return
+ m = re.match(r"""^\s*AST_MATCHER_REGEX(?:_OVERLOAD)?\(
+ \s*([^\s,]+)\s*,
+ \s*([^\s,]+)\s*,
+ \s*([^\s,]+)\s*
+ (?:,\s*\d+\s*)?
+ \)\s*{""", declaration, flags=re.X)
+ if m:
+ result, name, arg_name = m.groups()[0:3]
+ if not result:
+ if not allowed_types:
+ raise Exception('Did not find allowed result types for: %s' % name)
+ result_types = allowed_types
+ else:
+ result_types = [result]
+ arg = "StringRef %s, Regex::RegexFlags Flags = NoFlags" % arg_name
+ comment += """
+If the matcher is used in clang-query, RegexFlags parameter
+should be passed as a quoted string. e.g: "NoFlags".
+Flags can be combined with '|' example \"IgnoreCase | BasicRegex\"
+"""
+
+ for result_type in result_types:
+ add_matcher(result_type, name, arg, comment)
+ return
+
# Parse ArgumentAdapting matchers.
m = re.match(
r"""^.*ArgumentAdaptingMatcherFunc<.*>\s*
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -283,9 +283,10 @@
/// \endcode
///
/// Usable as: Matcher, Matcher, Matcher
-AST_POLYMORPHIC_MATCHER_P(isExpansionInFileMatching,
- AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc),
- std::string, RegExp) {
+AST_POLYMORPHIC_MATCHER_REGEX(isExpansionInFileMatching,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt,
+ TypeLoc),
+ RegExp) {
auto &SourceManager = Finder->getASTContext().getSourceManager();
auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
if (ExpansionLoc.isInvalid()) {
@@ -298,8 +299,7 @@
}
auto Filename = FileEntry->getName();
- llvm::Regex RE(RegExp);
- return RE.match(Filename);
+ return RegExp->match(Filename);
}
/// Matches statements that are (transitively) expanded from the named macro.
@@ -2748,11 +2748,9 @@
/// \code
/// namespace foo { namespace bar { class X; } }
/// \endcode
-AST_MATCHER_P(NamedDecl, matchesName, std::string, RegExp) {
- assert(!RegExp.empty());
+AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp) {
std::string FullNameString = "::" + Node.getQualifiedNameAsString();
- llvm::Regex RE(RegExp);
- return RE.match(FullNameString);
+ return RegExp->match(FullNameString);
}
/// Matches overloaded operator names.
@@ -3373,11 +3371,9 @@
/// \code
/// [self.bodyView loadHTMLString:html baseURL:NULL];
/// \endcode
-AST_MATCHER_P(ObjCMessageExpr, matchesSelector, std::string, RegExp) {
- assert(!RegExp.empty());
+AST_MATCHER_REGEX(ObjCMessageExpr, matchesSelector, RegExp) {
std::string SelectorString = Node.getSelector().getAsString();
- llvm::Regex RE(RegExp);
- return RE.match(SelectorString);
+ return RegExp->match(SelectorString);
}
/// Matches when the selector is the empty selector
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -40,7 +40,6 @@
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/ExprObjC.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/NestedNameSpecifier.h"
@@ -61,11 +60,13 @@
#include "llvm/ADT/iterator.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/Regex.h"
#include
#include
#include
#include
#include