This is an archive of the discontinued LLVM Phabricator instance.

[include-fixer] Refactor include fixer to be usable as a plugin
ClosedPublic

Authored by bkramer on Nov 16 2016, 10:17 AM.

Details

Summary
  • Refactor the external sema source into a visible class
  • Add support for emitting FixIts
  • Wrap up include fixer as a plugin as I did with clang-tidy

Test case will follow as soon as I wire this up in libclang.

Diff Detail

Repository
rL LLVM

Event Timeline

bkramer updated this revision to Diff 78210.Nov 16 2016, 10:17 AM
bkramer retitled this revision from to [include-fixer] Refactor include fixer to be usable as a plugin.
bkramer updated this object.
bkramer added reviewers: klimek, hokein, ioeric.
bkramer added a subscriber: cfe-commits.
hokein added inline comments.Nov 17 2016, 1:54 AM
include-fixer/IncludeFixer.cpp
64 ↗(On Diff #78210)

also make it const?

124 ↗(On Diff #78210)

nit: /*AddQualifiers=*/false.

136 ↗(On Diff #78210)

I have a concern that Placed here might be not the replacement for inserting the new header, becuase the Reps returned from createIncludeFixerReplacements may have some replacements for cleanup.

To make it more correct, maybe we can check whether Placed.getReplacementText() is equal to "#include" + Context.getHeaderInfos().front().Header?

283 ↗(On Diff #78210)

You can use SM directly here since you have created a SM variable for SourceManager above? The same below.

include-fixer/IncludeFixer.h
119 ↗(On Diff #78210)

Make it a const member function?

124 ↗(On Diff #78210)

A blank line below.

include-fixer/plugin/IncludeFixerPlugin.cpp
1 ↗(On Diff #78210)

nit: IncludeFixerPlugin

91 ↗(On Diff #78210)

nit: clang-tidy=>include-fixer

bkramer updated this revision to Diff 78345.Nov 17 2016, 3:51 AM
bkramer marked 7 inline comments as done.
  • Address review comments.
include-fixer/IncludeFixer.cpp
136 ↗(On Diff #78210)

I don't think that will work. We do want to put the replacement into the right position so we have to apply the full cleanup, right? Just comparing with the header path doesn't work because the cleanup is larger than that.

ioeric added inline comments.Nov 17 2016, 5:16 AM
include-fixer/IncludeFixer.cpp
136 ↗(On Diff #78210)

Yep, createIncludeFixerReplacements also sorts #includes with formatReplacements, so the returned replacements can be larger than header insertion.

hokein added inline comments.Nov 17 2016, 5:27 AM
include-fixer/IncludeFixer.cpp
136 ↗(On Diff #78210)

I see. What I concern is that the behavior won't be correct if there are multiple replacements in *Reps. But looks like if we pass only one Replacement for inserting the new header to createIncludeFixerReplacements, the Reps only has a Replacement inside, which is correct.

Maybe add an assert here?

ioeric added inline comments.Nov 17 2016, 5:38 AM
include-fixer/IncludeFixer.cpp
136 ↗(On Diff #78210)

This is implementation detail; the interface does not guarantee that. And I guess there might still be cases where more than one replacement is generated.

bkramer updated this revision to Diff 78354.Nov 17 2016, 5:55 AM
  • Turn loop into an assertions, there should never be more than one replacement coming back.
bkramer added inline comments.Nov 17 2016, 5:56 AM
include-fixer/IncludeFixer.cpp
136 ↗(On Diff #78210)

We'll see if this comes up. The current implementation wouldn't deal well with multiple replacements as it would format them as alternatives. I'll do the assert for now.

hokein accepted this revision.Nov 17 2016, 6:16 AM
hokein edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Nov 17 2016, 6:16 AM
This revision was automatically updated to reflect the committed changes.