AST Matcher Reference
- -This document shows all currently implemented matchers. The matchers are grouped -by category and node type they match. You can click on matcher names to show the -matcher's source documentation.
- -There are three different basic categories of matchers: -
-
-
- Node Matchers: Matchers that match a specific type of AST node. -
- Narrowing Matchers: Matchers that match attributes on AST nodes. -
- Traversal Matchers: Matchers that allow traversal between AST nodes. -
Within each category the matchers are ordered by node type they match on. -Note that if a matcher can match multiple node types, it will it will appear -multiple times. This means that by searching for Matcher<Stmt> you can -find all matchers that can be used to match on Stmt nodes.
- -The exception to that rule are matchers that can match on any node. Those -are marked with a * and are listed in the beginning of each category.
- -Note that the categorization of matchers is a great help when you combine -them into matcher expressions. You will usually want to form matcher expressions -that read like english sentences by alternating between node matchers and -narrowing or traversal matchers, like this: -
-recordDecl(hasDescendant( - ifStmt(hasTrueExpression( - expr(hasDescendant( - ifStmt())))))) -- - - -
Node Matchers
- - -Node matchers are at the core of matcher expressions - they specify the type -of node that is expected. Every match expression starts with a node matcher, -which can then be further refined with a narrowing or traversal matcher. All -traversal matchers take node matchers as their arguments.
- -For convenience, all node matchers take an arbitrary number of arguments -and implicitly act as allOf matchers.
- -Node matchers are the only matchers that support the bind("id") call to -bind the matched node to the given string, to be later retrieved from the -match callback.
- -It is important to remember that the arguments to node matchers are -predicates on the same node, just with additional information about the type. -This is often useful to make matcher expression more readable by inlining bind -calls into redundant node matchers inside another node matcher: -
-// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on -// the same node. -recordDecl(decl().bind("id"), hasName("::MyClass")) -- - -
Return type | Name | Parameters |
---|
Return type | Name | Parameters |
---|---|---|
Matcher<CXXCtorInitializer> | cxxCtorInitializer | Matcher<CXXCtorInitializer>... |
Narrowing Matchers
- - -Narrowing matchers match certain attributes on the current node, thus -narrowing down the set of nodes of the current type to match on.
- -There are special logical narrowing matchers (allOf, anyOf, anything and unless) -which allow users to create more powerful match expressions.
- -Return type | Name | Parameters |
---|
Narrowing Matchers
+ + +Narrowing matchers match certain attributes on the current node, thus +narrowing down the set of nodes of the current type to match on.
+ +There are special logical narrowing matchers (allOf, anyOf, anything and unless) +which allow users to create more powerful match expressions.
+ +Return type | Name | Parameters |
---|---|---|
Matcher<*> | allOf | Matcher<*>, ..., Matcher<*> |
AST Traversal Matchers
- - -Traversal matchers specify the relationship to other nodes that are -reachable from the current node.
- -Note that there are special traversal matchers (has, hasDescendant, forEach and -forEachDescendant) which work on all nodes and allow users to write more generic -match expressions.
- -Return type | Name | Parameters |
---|
AST Traversal Matchers
+ + +Traversal matchers specify the relationship to other nodes that are +reachable from the current node.
+ +Note that there are special traversal matchers (has, hasDescendant, forEach and +forEachDescendant) which work on all nodes and allow users to write more generic +match expressions.
+ +Return type | Name | Parameters |
---|---|---|
Matcher<*> | eachOf | Matcher<*>, ..., Matcher<*> |