oontvoo created this revision. Herald added subscribers: cfe-commits, danielkiss, kristof.beyls. Herald added a project: clang. oontvoo added reviewers: gribozavr, ymandel.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80603 Files: clang/include/clang/ASTMatchers/ASTMatchers.h clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2643,6 +2643,13 @@ parmVarDecl(hasDefaultArgument()))); } +TEST(IsAtPosition, Basic) { + EXPECT_TRUE(matches("void x(int a) {}", parmVarDecl(isAtPosition(0)))); + EXPECT_TRUE(matches("void x(int a, int b) {}", parmVarDecl(isAtPosition(1)))); + EXPECT_TRUE(matches("void x(int a, int b) {}", parmVarDecl(isAtPosition(1)))); + EXPECT_TRUE(notMatches("void x(int val) {}", parmVarDecl(isAtPosition(1)))); +} + TEST(IsArray, Basic) { EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];", cxxNewExpr(isArray()))); Index: clang/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- clang/include/clang/ASTMatchers/ASTMatchers.h +++ clang/include/clang/ASTMatchers/ASTMatchers.h @@ -7001,6 +7001,26 @@ return InnerMatcher.matches(Node, Finder, Builder); } +/// Matches the ParmVarDecl nodes that are at the N'th position in the parameter +/// list. +/// +/// Given +/// +/// \code +/// void f(int a, int b, int c) { +/// } +/// \endcode +/// +/// ``parmVarDecl(isAtPosition(0))``` matches `int a`. +/// +/// ``parmVarDecl(isAtPosition(1))`` matches `int b`. +AST_MATCHER_P(clang::ParmVarDecl, isAtPosition, unsigned, N) { + return parmVarDecl(hasAncestor(functionDecl( + hasParameter(N, parmVarDecl().bind("this_decl")))), + equalsBoundNode("this_decl")) + .matches(Node, Finder, Builder); +} + //----------------------------------------------------------------------------// // OpenMP handling. //----------------------------------------------------------------------------//
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2643,6 +2643,13 @@ parmVarDecl(hasDefaultArgument()))); } +TEST(IsAtPosition, Basic) { + EXPECT_TRUE(matches("void x(int a) {}", parmVarDecl(isAtPosition(0)))); + EXPECT_TRUE(matches("void x(int a, int b) {}", parmVarDecl(isAtPosition(1)))); + EXPECT_TRUE(matches("void x(int a, int b) {}", parmVarDecl(isAtPosition(1)))); + EXPECT_TRUE(notMatches("void x(int val) {}", parmVarDecl(isAtPosition(1)))); +} + TEST(IsArray, Basic) { EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];", cxxNewExpr(isArray()))); Index: clang/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- clang/include/clang/ASTMatchers/ASTMatchers.h +++ clang/include/clang/ASTMatchers/ASTMatchers.h @@ -7001,6 +7001,26 @@ return InnerMatcher.matches(Node, Finder, Builder); } +/// Matches the ParmVarDecl nodes that are at the N'th position in the parameter +/// list. +/// +/// Given +/// +/// \code +/// void f(int a, int b, int c) { +/// } +/// \endcode +/// +/// ``parmVarDecl(isAtPosition(0))``` matches `int a`. +/// +/// ``parmVarDecl(isAtPosition(1))`` matches `int b`. +AST_MATCHER_P(clang::ParmVarDecl, isAtPosition, unsigned, N) { + return parmVarDecl(hasAncestor(functionDecl( + hasParameter(N, parmVarDecl().bind("this_decl")))), + equalsBoundNode("this_decl")) + .matches(Node, Finder, Builder); +} + //----------------------------------------------------------------------------// // OpenMP handling. //----------------------------------------------------------------------------//
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits