Skip to content

Commit

Permalink
Update mode used in traverse() examples
Browse files Browse the repository at this point in the history
traverse() predates the IgnoreUnlessSpelledInSource mode. Update example
and test code to use the newer mode.

Differential Revision: https://reviews.llvm.org/D91917
  • Loading branch information
steveire committed Nov 23, 2020
1 parent 72a9f36 commit f052cf4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion clang/docs/LibASTMatchersReference.html
Expand Up @@ -5567,7 +5567,7 @@ <h2 id="traversal-matchers">AST Traversal Matchers</h2>
int i = 3.0;
}
The matcher
traverse(TK_IgnoreImplicitCastsAndParentheses,
traverse(TK_IgnoreUnlessSpelledInSource,
varDecl(hasInitializer(floatLiteral().bind("init")))
)
matches the variable declaration with "init" bound to the "3.0".
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/ASTMatchers/ASTMatchers.h
Expand Up @@ -782,7 +782,7 @@ AST_POLYMORPHIC_MATCHER_P(
/// \endcode
/// The matcher
/// \code
/// traverse(TK_IgnoreImplicitCastsAndParentheses,
/// traverse(TK_IgnoreUnlessSpelledInSource,
/// varDecl(hasInitializer(floatLiteral().bind("init")))
/// )
/// \endcode
Expand Down
13 changes: 6 additions & 7 deletions clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Expand Up @@ -1873,8 +1873,8 @@ void foo()
auto Matcher = varDecl(hasInitializer(floatLiteral()));

EXPECT_TRUE(notMatches(VarDeclCode, traverse(TK_AsIs, Matcher)));
EXPECT_TRUE(matches(VarDeclCode,
traverse(TK_IgnoreImplicitCastsAndParentheses, Matcher)));
EXPECT_TRUE(
matches(VarDeclCode, traverse(TK_IgnoreUnlessSpelledInSource, Matcher)));

auto ParentMatcher = floatLiteral(hasParent(varDecl(hasName("i"))));

Expand Down Expand Up @@ -2715,14 +2715,14 @@ void foo()
)cpp";

EXPECT_TRUE(
matches(Code, traverse(TK_IgnoreImplicitCastsAndParentheses,
matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
callExpr(has(callExpr(traverse(
TK_AsIs, callExpr(has(implicitCastExpr(
has(floatLiteral())))))))))));

EXPECT_TRUE(matches(
Code,
traverse(TK_IgnoreImplicitCastsAndParentheses,
traverse(TK_IgnoreUnlessSpelledInSource,
traverse(TK_AsIs, implicitCastExpr(has(floatLiteral()))))));
}

Expand All @@ -2738,8 +2738,7 @@ void constructImplicit() {
}
)cpp";

auto Matcher =
traverse(TK_IgnoreImplicitCastsAndParentheses, implicitCastExpr());
auto Matcher = traverse(TK_IgnoreUnlessSpelledInSource, implicitCastExpr());

// Verfiy that it does not segfault
EXPECT_FALSE(matches(Code, Matcher));
Expand All @@ -2766,7 +2765,7 @@ void foo()
EXPECT_TRUE(matches(
Code,
functionDecl(anyOf(hasDescendant(Matcher),
traverse(TK_IgnoreImplicitCastsAndParentheses,
traverse(TK_IgnoreUnlessSpelledInSource,
functionDecl(hasDescendant(Matcher)))))));
}

Expand Down

0 comments on commit f052cf4

Please sign in to comment.