HomePhabricator

[ASTMatchers] Enhanced support for matchers taking Regex arguments

Authored by njames93 on Jul 2 2020, 6:52 AM.

Description

[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