This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG88e62085624e: [libTooling] Update Transformer's `node` combinator to include the trailing… (authored by ymandel).
Changed prior to commit: https://reviews.llvm.org/D91872?vs=306707&id=306729#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91872/new/ https://reviews.llvm.org/D91872 Files: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp clang/include/clang/Tooling/Transformer/RangeSelector.h clang/lib/Tooling/Transformer/RangeSelector.cpp clang/unittests/Tooling/TransformerTest.cpp Index: clang/unittests/Tooling/TransformerTest.cpp =================================================================== --- clang/unittests/Tooling/TransformerTest.cpp +++ clang/unittests/Tooling/TransformerTest.cpp @@ -1353,7 +1353,7 @@ // Changes the 'int' in 'S', but not the 'T' in 'TemplStruct': testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedField), - changeTo(cat("safe_int ", name("theField")))), + changeTo(cat("safe_int ", name("theField"), ";"))), NonTemplatesInput + TemplatesInput, NonTemplatesExpected + TemplatesInput); @@ -1378,7 +1378,7 @@ // Changes the 'int' in 'S', and (incorrectly) the 'T' in 'TemplStruct': testRule(makeRule(traverse(TK_AsIs, MatchedField), - changeTo(cat("safe_int ", name("theField")))), + changeTo(cat("safe_int ", name("theField"), ";"))), NonTemplatesInput + TemplatesInput, NonTemplatesExpected + IncorrectTemplatesExpected); @@ -1589,7 +1589,7 @@ Changes[0].getReplacements()); ASSERT_TRUE(static_cast<bool>(UpdatedCode)) << "Could not update code: " << llvm::toString(UpdatedCode.takeError()); - EXPECT_EQ(format(*UpdatedCode), format(R"cc(;)cc")); + EXPECT_EQ(format(*UpdatedCode), ""); ASSERT_EQ(Changes[1].getFilePath(), "input.cc"); EXPECT_THAT(Changes[1].getInsertedHeaders(), IsEmpty()); @@ -1598,8 +1598,7 @@ Source, Changes[1].getReplacements()); ASSERT_TRUE(static_cast<bool>(UpdatedCode)) << "Could not update code: " << llvm::toString(UpdatedCode.takeError()); - EXPECT_EQ(format(*UpdatedCode), format(R"cc(#include "input.h" - ;)cc")); + EXPECT_EQ(format(*UpdatedCode), format("#include \"input.h\"\n")); } TEST_F(TransformerTest, AddIncludeMultipleFiles) { Index: clang/lib/Tooling/Transformer/RangeSelector.cpp =================================================================== --- clang/lib/Tooling/Transformer/RangeSelector.cpp +++ clang/lib/Tooling/Transformer/RangeSelector.cpp @@ -142,7 +142,8 @@ Expected<DynTypedNode> Node = getNode(Result.Nodes, ID); if (!Node) return Node.takeError(); - return Node->get<Stmt>() != nullptr && Node->get<Expr>() == nullptr + return (Node->get<Decl>() != nullptr || + (Node->get<Stmt>() != nullptr && Node->get<Expr>() == nullptr)) ? tooling::getExtendedRange(*Node, tok::TokenKind::semi, *Result.Context) : CharSourceRange::getTokenRange(Node->getSourceRange()); Index: clang/include/clang/Tooling/Transformer/RangeSelector.h =================================================================== --- clang/include/clang/Tooling/Transformer/RangeSelector.h +++ clang/include/clang/Tooling/Transformer/RangeSelector.h @@ -61,8 +61,8 @@ return enclose(after(std::move(R1)), before(std::move(R2))); } -/// Selects a node, including trailing semicolon (for non-expression -/// statements). \p ID is the node's binding in the match result. +/// Selects a node, including trailing semicolon, if any (for declarations and +/// non-expression statements). \p ID is the node's binding in the match result. RangeSelector node(std::string ID); /// Selects a node, including trailing semicolon (always). Useful for selecting Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp +++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp @@ -148,7 +148,7 @@ if (Options.get("Skip", "false") == "true") return None; return tooling::makeRule(clang::ast_matchers::functionDecl(), - change(cat("void nothing()")), cat("no message")); + changeTo(cat("void nothing();")), cat("no message")); } class ConfigurableCheck : public TransformerClangTidyCheck {
Index: clang/unittests/Tooling/TransformerTest.cpp =================================================================== --- clang/unittests/Tooling/TransformerTest.cpp +++ clang/unittests/Tooling/TransformerTest.cpp @@ -1353,7 +1353,7 @@ // Changes the 'int' in 'S', but not the 'T' in 'TemplStruct': testRule(makeRule(traverse(TK_IgnoreUnlessSpelledInSource, MatchedField), - changeTo(cat("safe_int ", name("theField")))), + changeTo(cat("safe_int ", name("theField"), ";"))), NonTemplatesInput + TemplatesInput, NonTemplatesExpected + TemplatesInput); @@ -1378,7 +1378,7 @@ // Changes the 'int' in 'S', and (incorrectly) the 'T' in 'TemplStruct': testRule(makeRule(traverse(TK_AsIs, MatchedField), - changeTo(cat("safe_int ", name("theField")))), + changeTo(cat("safe_int ", name("theField"), ";"))), NonTemplatesInput + TemplatesInput, NonTemplatesExpected + IncorrectTemplatesExpected); @@ -1589,7 +1589,7 @@ Changes[0].getReplacements()); ASSERT_TRUE(static_cast<bool>(UpdatedCode)) << "Could not update code: " << llvm::toString(UpdatedCode.takeError()); - EXPECT_EQ(format(*UpdatedCode), format(R"cc(;)cc")); + EXPECT_EQ(format(*UpdatedCode), ""); ASSERT_EQ(Changes[1].getFilePath(), "input.cc"); EXPECT_THAT(Changes[1].getInsertedHeaders(), IsEmpty()); @@ -1598,8 +1598,7 @@ Source, Changes[1].getReplacements()); ASSERT_TRUE(static_cast<bool>(UpdatedCode)) << "Could not update code: " << llvm::toString(UpdatedCode.takeError()); - EXPECT_EQ(format(*UpdatedCode), format(R"cc(#include "input.h" - ;)cc")); + EXPECT_EQ(format(*UpdatedCode), format("#include \"input.h\"\n")); } TEST_F(TransformerTest, AddIncludeMultipleFiles) { Index: clang/lib/Tooling/Transformer/RangeSelector.cpp =================================================================== --- clang/lib/Tooling/Transformer/RangeSelector.cpp +++ clang/lib/Tooling/Transformer/RangeSelector.cpp @@ -142,7 +142,8 @@ Expected<DynTypedNode> Node = getNode(Result.Nodes, ID); if (!Node) return Node.takeError(); - return Node->get<Stmt>() != nullptr && Node->get<Expr>() == nullptr + return (Node->get<Decl>() != nullptr || + (Node->get<Stmt>() != nullptr && Node->get<Expr>() == nullptr)) ? tooling::getExtendedRange(*Node, tok::TokenKind::semi, *Result.Context) : CharSourceRange::getTokenRange(Node->getSourceRange()); Index: clang/include/clang/Tooling/Transformer/RangeSelector.h =================================================================== --- clang/include/clang/Tooling/Transformer/RangeSelector.h +++ clang/include/clang/Tooling/Transformer/RangeSelector.h @@ -61,8 +61,8 @@ return enclose(after(std::move(R1)), before(std::move(R2))); } -/// Selects a node, including trailing semicolon (for non-expression -/// statements). \p ID is the node's binding in the match result. +/// Selects a node, including trailing semicolon, if any (for declarations and +/// non-expression statements). \p ID is the node's binding in the match result. RangeSelector node(std::string ID); /// Selects a node, including trailing semicolon (always). Useful for selecting Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp =================================================================== --- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp +++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp @@ -148,7 +148,7 @@ if (Options.get("Skip", "false") == "true") return None; return tooling::makeRule(clang::ast_matchers::functionDecl(), - change(cat("void nothing()")), cat("no message")); + changeTo(cat("void nothing();")), cat("no message")); } class ConfigurableCheck : public TransformerClangTidyCheck {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits