r184538 - Improve documentation for AST matchers.
Manuel Klimek
klimek at google.com
Fri Jun 21 03:00:00 PDT 2013
Author: klimek
Date: Fri Jun 21 04:59:59 2013
New Revision: 184538
URL: http://llvm.org/viewvc/llvm-project?rev=184538&view=rev
Log:
Improve documentation for AST matchers.
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=184538&r1=184537&r2=184538&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri Jun 21 04:59:59 2013
@@ -57,6 +57,18 @@ find all matchers that can be used to ma
<p>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.</p>
+<p>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:
+<pre>
+recordDecl(hasDescendant(
+ ifStmt(hasTrueExpression(
+ expr(hasDescendant(
+ ifStmt()))))))
+</pre>
+</p>
+
<!-- ======================================================================= -->
<h2 id="decl-matchers">Node Matchers</h2>
<!-- ======================================================================= -->
@@ -73,6 +85,17 @@ and implicitly act as allOf matchers.</p
bind the matched node to the given string, to be later retrieved from the
match callback.</p>
+<p>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:
+<pre>
+// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on
+// the same node.
+recordDecl(decl().bind("id"), hasName("::MyClass"))
+</pre>
+</p>
+
<table>
<tr style="text-align:left"><th>Return type</th><th>Name</th><th>Parameters</th></tr>
<!-- START_DECL_MATCHERS -->
More information about the cfe-commits
mailing list