This is an archive of the discontinued LLVM Phabricator instance.

[clangd] DefineOutline: removes static token from static CXXMethodDecl
ClosedPublic

Authored by njames93 on Apr 6 2020, 3:05 AM.

Details

Summary

Removes the static token when defining a function out of line if the function is a CXXMethodDecl

Diff Detail

Event Timeline

njames93 created this revision.Apr 6 2020, 3:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2020, 3:05 AM
njames93 added a project: Restricted Project.Apr 6 2020, 3:06 AM

thanks for the patch!

this is quite similar to handling kw_virtual even handling multiple static keywords. Could you rather factor the search for kw, generate an edit to delete specifier part into a DelKeyword lambda similar to DelAttr and call it with kw_static and kw_virtual?

p.s. you can make use of tok::getKeywordSpelling for error messages.

njames93 updated this revision to Diff 255298.Apr 6 2020, 5:29 AM
  • Moved keyword removing logic into a lambda.
kadircet added inline comments.Apr 6 2020, 12:13 PM
clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
242–245

nit, AllowMultiple is always false(see my comment below) maybe just drop that parameter and add a comment to lambda saying that it deletes all occurences of the keyword in range.

242–245

nit: s/DeleteKeyword/DelKeyword/

to be consistent with DelAttr

247

this condition becomes obsolete once you get rid of AllowMultiple.

255
llvm::formatv("define outline: couldn't remove `{0}` keyword.", tok::getKeywordSpelling(Kind))
265

nit: put braces here as statement spans multiple lines

284

please use formatv here as well, while dropping can't move outline

289

nit: this also needs to be a methoddecl, so you can combine the two checks:

if(const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {

if(MD->isvirt...) delKeyword(virt);
if(MD->isStatic) delKeyword(static);

}

293

sorry if I miscommunicated, I was trying to say that multiple static keywords are also allowed by clang. So we should be dropping all of them, as we do for virtual

clang-tools-extra/clangd/unittests/TweakTests.cpp
2152

please also add a test with multiple static keywords

njames93 marked 9 inline comments as done.Apr 6 2020, 1:31 PM
njames93 added inline comments.
clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
293

Yeah sorry, I checked and it was rejected. I just realised I was checking against gcc...

njames93 updated this revision to Diff 255472.Apr 6 2020, 1:34 PM
njames93 marked an inline comment as done.
  • Address comments
njames93 updated this revision to Diff 255473.Apr 6 2020, 1:38 PM
  • Fix issue with last revision
kadircet accepted this revision.Apr 7 2020, 12:02 AM

thanks LGTM!

This revision is now accepted and ready to land.Apr 7 2020, 12:02 AM
This revision was automatically updated to reflect the committed changes.