[ASTMatchers] Enhanced support for matchers taking Regex arguments
authorNathan James <n.james93@hotmail.co.uk>
Thu, 2 Jul 2020 13:52:24 +0000 (14:52 +0100)
committerNathan James <n.james93@hotmail.co.uk>
Thu, 2 Jul 2020 13:52:25 +0000 (14:52 +0100)
commitf51a319cacd44819b4fb9fa9f005c2445bcee984
tree1a76fb5c59f0fd09aa0cdf0c6a61d02fce1b41b5
parentc1f1db8502f1fc788eefeafd3dc225bd287ee4b9
[ASTMatchers] Enhanced support for matchers taking Regex arguments

Added new Macros `AST(_POLYMORPHIC)_MATCHER_REGEX(_OVERLOAD)` that define a matchers that take a regular expression string and optionally regular expression flags. This lets users match against nodes while ignoring the case without having to manually use `[Aa]` or `[A-Fa-f]` in their regex. The other point this addresses is in the current state, matchers that use regular expressions have to compile them for each node they try to match on, Now the regular expression is compiled once when you define the matcher and used for every node that it tries to match against. If there is an error while compiling the regular expression an error will be logged to stderr showing the bad regex string and the reason it couldn't be compiled. The old behaviour of this was down to the Matcher implementation and some would assert, whereas others just would never match. Support for this has been added to the documentation script as well. Support for this has been added to dynamic matchers ensuring functionality is the same between the 2 use cases.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82706
13 files changed:
clang/docs/LibASTMatchersReference.html
clang/docs/tools/dump_ast_matchers.py
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/include/clang/ASTMatchers/ASTMatchersMacros.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
llvm/include/llvm/Support/Regex.h
llvm/lib/Support/Regex.cpp