[PATCH] D91872: [libTooling] Update Transformer's `node` combinator to include the trailing semicolon for decls.
Yitzhak Mandelbaum via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 20 10:12:19 PST 2020
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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91872.306729.patch
Type: text/x-patch
Size: 4087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201120/177449e6/attachment-0001.bin>
More information about the cfe-commits
mailing list