ymandel updated this revision to Diff 306707. ymandel added a comment. Clarified that semicolons are only removed if present. Fixed test.
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 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/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