[PATCH] D77534: [clangd] DefineOutline: removes static token from static CXXMethodDecl
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 6 03:13:21 PDT 2020
njames93 created this revision.
njames93 added reviewers: sammccall, kadircet, hokein.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
njames93 added a project: clang-tools-extra.
Removes the `static` token when defining a function out of line if the function is a `CXXMethodDecl`
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77534
Files:
clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2142,6 +2142,17 @@
};)cpp",
"void B::foo() {}\n",
},
+ {
+ R"cpp(
+ struct A {
+ static void fo^o() {}
+ };)cpp",
+ R"cpp(
+ struct A {
+ static void foo() ;
+ };)cpp",
+ " void A::foo() {}\n",
+ },
};
for (const auto &Case : Cases) {
SCOPED_TRACE(Case.Test);
@@ -2236,6 +2247,24 @@
STUPID_MACRO(sizeof sizeof int) void foo() ;
};)cpp",
" void A::foo() {}\n"},
+ {R"cpp(#define STAT static
+ struct A {
+ STAT void f^oo() {}
+ };)cpp",
+ R"cpp(#define STAT static
+ struct A {
+ STAT void foo() ;
+ };)cpp",
+ " void A::foo() {}\n"},
+ {R"cpp(#define STUPID_MACRO(X) static
+ struct A {
+ STUPID_MACRO(sizeof sizeof int) void f^oo() {}
+ };)cpp",
+ R"cpp(#define STUPID_MACRO(X) static
+ struct A {
+ STUPID_MACRO(sizeof sizeof int) void foo() ;
+ };)cpp",
+ " void A::foo() {}\n"},
};
for (const auto &Case : Cases) {
SCOPED_TRACE(Case.Test);
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -270,6 +270,41 @@
}
}
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
+ if (MD->isStatic()) {
+ SourceRange SpecRange{FD->getBeginLoc(), FD->getLocation()};
+ bool FoundTok = false;
+ for (const auto &Tok : TokBuf.expandedTokens(SpecRange)) {
+ if (Tok.kind() != tok::kw_static)
+ continue;
+ FoundTok = true;
+ auto Spelling = TokBuf.spelledForExpanded(llvm::makeArrayRef(Tok));
+ if (!Spelling) {
+ Errors =
+ llvm::joinErrors(std::move(Errors),
+ llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "define outline: Can't move out of line as "
+ "function has a macro `static` specifier."));
+ break;
+ }
+ CharSourceRange DelRange =
+ syntax::Token::range(SM, Spelling->front(), Spelling->back())
+ .toCharRange(SM);
+ if (auto Err =
+ DeclarationCleanups.add(tooling::Replacement(SM, DelRange, "")))
+ Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
+ break;
+ }
+ if (!FoundTok)
+ Errors = llvm::joinErrors(
+ std::move(Errors),
+ llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "define outline: Couldn't remove methods `static` keyword"));
+ }
+ }
+
if (Errors)
return std::move(Errors);
return getFunctionSourceAfterReplacements(FD, DeclarationCleanups);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77534.255269.patch
Type: text/x-patch
Size: 3284 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200406/67a22606/attachment.bin>
More information about the cfe-commits
mailing list