This revision was automatically updated to reflect the committed changes. Closed by commit rGd2e32fa493a2: [libTooling] Add support for implicit `this` to `buildAddressOf`. (authored by ymandel).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D105551/new/ https://reviews.llvm.org/D105551 Files: clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp clang/unittests/Tooling/SourceCodeBuildersTest.cpp Index: clang/unittests/Tooling/SourceCodeBuildersTest.cpp =================================================================== --- clang/unittests/Tooling/SourceCodeBuildersTest.cpp +++ clang/unittests/Tooling/SourceCodeBuildersTest.cpp @@ -172,6 +172,24 @@ testBuilder(buildAddressOf, "S x; x + x;", "&(x + x)"); } +TEST(SourceCodeBuildersTest, BuildAddressOfImplicitThis) { + StringRef Snippet = R"cc( + struct Struct { + void foo() {} + void bar() { + foo(); + } + }; + )cc"; + auto StmtMatch = matchStmt( + Snippet, + cxxMemberCallExpr(onImplicitObjectArgument(cxxThisExpr().bind("expr")))); + ASSERT_TRUE(StmtMatch); + EXPECT_THAT(buildAddressOf(*StmtMatch->Result.Nodes.getNodeAs<Expr>("expr"), + *StmtMatch->Result.Context), + ValueIs(std::string("this"))); +} + TEST(SourceCodeBuildersTest, BuildDereferencePointer) { testBuilder(buildDereference, "S *x; x;", "*x"); } Index: clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp =================================================================== --- clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp +++ clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp @@ -93,6 +93,8 @@ llvm::Optional<std::string> tooling::buildAddressOf(const Expr &E, const ASTContext &Context) { + if (E.isImplicitCXXThis()) + return std::string("this"); if (const auto *Op = dyn_cast<UnaryOperator>(&E)) if (Op->getOpcode() == UO_Deref) { // Strip leading '*'.
Index: clang/unittests/Tooling/SourceCodeBuildersTest.cpp =================================================================== --- clang/unittests/Tooling/SourceCodeBuildersTest.cpp +++ clang/unittests/Tooling/SourceCodeBuildersTest.cpp @@ -172,6 +172,24 @@ testBuilder(buildAddressOf, "S x; x + x;", "&(x + x)"); } +TEST(SourceCodeBuildersTest, BuildAddressOfImplicitThis) { + StringRef Snippet = R"cc( + struct Struct { + void foo() {} + void bar() { + foo(); + } + }; + )cc"; + auto StmtMatch = matchStmt( + Snippet, + cxxMemberCallExpr(onImplicitObjectArgument(cxxThisExpr().bind("expr")))); + ASSERT_TRUE(StmtMatch); + EXPECT_THAT(buildAddressOf(*StmtMatch->Result.Nodes.getNodeAs<Expr>("expr"), + *StmtMatch->Result.Context), + ValueIs(std::string("this"))); +} + TEST(SourceCodeBuildersTest, BuildDereferencePointer) { testBuilder(buildDereference, "S *x; x;", "*x"); } Index: clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp =================================================================== --- clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp +++ clang/lib/Tooling/Transformer/SourceCodeBuilders.cpp @@ -93,6 +93,8 @@ llvm::Optional<std::string> tooling::buildAddressOf(const Expr &E, const ASTContext &Context) { + if (E.isImplicitCXXThis()) + return std::string("this"); if (const auto *Op = dyn_cast<UnaryOperator>(&E)) if (Op->getOpcode() == UO_Deref) { // Strip leading '*'.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits