diff options
author | Rihan Yang <adam@air20.com> | 2020-01-08 14:09:29 -0500 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2020-01-08 14:10:11 -0500 |
commit | 2823e91d55891e33a7a8b9a4016db4ec9e2765ae (patch) | |
tree | 3cff8a06b1f09001bd0c7d252e61307851e8d490 /clang/docs/LibASTMatchersReference.html | |
parent | b675a7628ce6a21b1e4a71c079a67badfb8b073d (diff) | |
download | bcm5719-llvm-2823e91d55891e33a7a8b9a4016db4ec9e2765ae.tar.gz bcm5719-llvm-2823e91d55891e33a7a8b9a4016db4ec9e2765ae.zip |
Add a new AST matcher 'optionally'.
This matcher matches any node and at the same time executes all its
inner matchers to produce any possbile result bindings.
This is useful when a user wants certain supplementary information
that's not always present along with the main match result.
Diffstat (limited to 'clang/docs/LibASTMatchersReference.html')
-rw-r--r-- | clang/docs/LibASTMatchersReference.html | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 338399976f4..05562c543c4 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -4689,6 +4689,32 @@ Usable as: Any Matcher </pre></td></tr> +<tr><td>Matcher<*></td><td class="name" onclick="toggle('optionally0')"><a name="optionally0Anchor">optionally</a></td><td>Matcher<*>, ..., Matcher<*></td></tr> +<tr><td colspan="4" class="doc" id="optionally0"><pre>Matches any node regardless of the submatchers. + +However, optionally will generate a result binding for each matching +submatcher. + +Useful when additional information which may or may not present about a +main matching node is desired. + +For example, in: + class Foo { + int bar; + } +The matcher: + cxxRecordDecl( + optionally(has( + fieldDecl(hasName("bar")).bind("var") + ))).bind("record") +will produce a result binding for both "record" and "var". +The matcher will produce a "record" binding for even if there is no data +member named "bar" in that class. + +Usable as: Any Matcher +</pre></td></tr> + + <tr><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1AbstractConditionalOperator.html">AbstractConditionalOperator</a>></td><td class="name" onclick="toggle('hasCondition5')"><a name="hasCondition5Anchor">hasCondition</a></td><td>Matcher<<a href="https://clang.llvm.org/doxygen/classclang_1_1Expr.html">Expr</a>> InnerMatcher</td></tr> <tr><td colspan="4" class="doc" id="hasCondition5"><pre>Matches the condition expression of an if statement, for loop, switch statement or conditional operator. @@ -5098,15 +5124,15 @@ with compoundStmt() <tr><td colspan="4" class="doc" id="hasInitStatement2"><pre>Matches selection statements with initializer. Given: - void foo() { + void foo() { if (int i = foobar(); i > 0) {} switch (int i = foobar(); i) {} - for (auto& a = get_range(); auto& x : a) {} + for (auto& a = get_range(); auto& x : a) {} } - void bar() { + void bar() { if (foobar() > 0) {} switch (foobar()) {} - for (auto& x : get_range()) {} + for (auto& x : get_range()) {} } ifStmt(hasInitStatement(anything())) matches the if statement in foo but not in bar. @@ -6245,15 +6271,15 @@ Examples matches the if statement <tr><td colspan="4" class="doc" id="hasInitStatement0"><pre>Matches selection statements with initializer. Given: - void foo() { + void foo() { if (int i = foobar(); i > 0) {} switch (int i = foobar(); i) {} - for (auto& a = get_range(); auto& x : a) {} + for (auto& a = get_range(); auto& x : a) {} } - void bar() { + void bar() { if (foobar() > 0) {} switch (foobar()) {} - for (auto& x : get_range()) {} + for (auto& x : get_range()) {} } ifStmt(hasInitStatement(anything())) matches the if statement in foo but not in bar. @@ -7005,15 +7031,15 @@ Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) <tr><td colspan="4" class="doc" id="hasInitStatement1"><pre>Matches selection statements with initializer. Given: - void foo() { + void foo() { if (int i = foobar(); i > 0) {} switch (int i = foobar(); i) {} - for (auto& a = get_range(); auto& x : a) {} + for (auto& a = get_range(); auto& x : a) {} } - void bar() { + void bar() { if (foobar() > 0) {} switch (foobar()) {} - for (auto& x : get_range()) {} + for (auto& x : get_range()) {} } ifStmt(hasInitStatement(anything())) matches the if statement in foo but not in bar. |