summaryrefslogtreecommitdiffstats
path: root/clang/unittests/AST
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2019-12-18 22:35:46 +0000
committerStephen Kelly <steveire@gmail.com>2019-12-21 11:02:11 +0000
commit5a79cfa32d62f018607438a30b7acb49c2ab97f3 (patch)
tree0968857245022ac33971450dbea8fa42bd02d7ec /clang/unittests/AST
parent1805d1f87d7835b237f85bfb0595d1f411ebf1bf (diff)
downloadbcm5719-llvm-5a79cfa32d62f018607438a30b7acb49c2ab97f3.tar.gz
bcm5719-llvm-5a79cfa32d62f018607438a30b7acb49c2ab97f3.zip
Customize simplified dumping and matching of LambdaExpr
Reviewers: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71680
Diffstat (limited to 'clang/unittests/AST')
-rw-r--r--clang/unittests/AST/ASTTraverserTest.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/clang/unittests/AST/ASTTraverserTest.cpp b/clang/unittests/AST/ASTTraverserTest.cpp
index c995f55d3c8..4b982431297 100644
--- a/clang/unittests/AST/ASTTraverserTest.cpp
+++ b/clang/unittests/AST/ASTTraverserTest.cpp
@@ -479,4 +479,123 @@ FunctionDecl 'func12'
)cpp");
}
+TEST(Traverse, LambdaUnlessSpelledInSource) {
+
+ auto AST =
+ buildASTFromCodeWithArgs(R"cpp(
+
+void captures() {
+ int a = 0;
+ int b = 0;
+ int d = 0;
+ int f = 0;
+
+ [a, &b, c = d, &e = f](int g, int h = 42) {};
+}
+
+void templated() {
+ int a = 0;
+ [a]<typename T>(T t) {};
+}
+
+struct SomeStruct {
+ int a = 0;
+ void capture_this() {
+ [this]() {};
+ }
+ void capture_this_copy() {
+ [self = *this]() {};
+ }
+};
+)cpp",
+ {"-Wno-unused-value", "-Wno-c++2a-extensions"});
+
+ auto getLambdaNode = [&AST](const std::string &name) {
+ auto BN = ast_matchers::match(
+ lambdaExpr(hasAncestor(functionDecl(hasName(name)))).bind("lambda"),
+ AST->getASTContext());
+ EXPECT_EQ(BN.size(), 1u);
+ return BN[0].getNodeAs<LambdaExpr>("lambda");
+ };
+
+ {
+ auto L = getLambdaNode("captures");
+
+ EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
+ R"cpp(
+LambdaExpr
+|-DeclRefExpr 'a'
+|-DeclRefExpr 'b'
+|-VarDecl 'c'
+| `-DeclRefExpr 'd'
+|-VarDecl 'e'
+| `-DeclRefExpr 'f'
+|-ParmVarDecl 'g'
+|-ParmVarDecl 'h'
+| `-IntegerLiteral
+`-CompoundStmt
+)cpp");
+
+ EXPECT_EQ(dumpASTString(ast_type_traits::TK_AsIs, L),
+ R"cpp(
+LambdaExpr
+|-CXXRecordDecl ''
+| |-CXXMethodDecl 'operator()'
+| | |-ParmVarDecl 'g'
+| | |-ParmVarDecl 'h'
+| | | `-IntegerLiteral
+| | `-CompoundStmt
+| |-FieldDecl ''
+| |-FieldDecl ''
+| |-FieldDecl ''
+| |-FieldDecl ''
+| `-CXXDestructorDecl '~'
+|-ImplicitCastExpr
+| `-DeclRefExpr 'a'
+|-DeclRefExpr 'b'
+|-ImplicitCastExpr
+| `-DeclRefExpr 'd'
+|-DeclRefExpr 'f'
+`-CompoundStmt
+)cpp");
+ }
+
+ {
+ auto L = getLambdaNode("templated");
+
+ EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
+ R"cpp(
+LambdaExpr
+|-DeclRefExpr 'a'
+|-TemplateTypeParmDecl 'T'
+|-ParmVarDecl 't'
+`-CompoundStmt
+)cpp");
+ }
+
+ {
+ auto L = getLambdaNode("capture_this");
+
+ EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
+ R"cpp(
+LambdaExpr
+|-CXXThisExpr
+`-CompoundStmt
+)cpp");
+ }
+
+ {
+ auto L = getLambdaNode("capture_this_copy");
+
+ EXPECT_EQ(dumpASTString(ast_type_traits::TK_IgnoreUnlessSpelledInSource, L),
+ R"cpp(
+LambdaExpr
+|-VarDecl 'self'
+| `-UnaryOperator
+| `-CXXThisExpr
+`-CompoundStmt
+)cpp");
+ }
+}
+
} // namespace clang
OpenPOWER on IntegriCloud