This is an archive of the discontinued LLVM Phabricator instance.

[clang-move] Move all code from old.h/cc directly when moving all class declarations from old.h.
ClosedPublic

Authored by hokein on Nov 2 2016, 4:05 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

hokein updated this revision to Diff 76687.Nov 2 2016, 4:05 AM
hokein retitled this revision from to [clang-move] Move all codes from old.h/cc if old.h only contains one moved declarations..
hokein updated this object.
hokein updated this revision to Diff 77062.Nov 7 2016, 10:44 AM

Update.

hokein retitled this revision from [clang-move] Move all codes from old.h/cc if old.h only contains one moved declarations. to [clang-move] Move all codes from old.h/cc if old.h only contains one moved declaration..
hokein added a subscriber: cfe-commits.
ioeric edited edge metadata.Nov 7 2016, 11:28 AM

First round of comments.

The patch summary says "one moved declaration." Why it is just one moved declaration? Doesn't this also support moving all classes in one file?

Maybe also mention the new behavior in the class comment.

clang-move/ClangMove.h
72 ↗(On Diff #77062)

It took me a while to understand this comment...

IIUC, this is the source range of the #include directive of old.h (i.e. #include "old.h") in old.cc?

109 ↗(On Diff #77062)

What about trailing comments or whitespaces?

test/clang-move/Inputs/test.h
3 ↗(On Diff #77062)

Maybe add some white spaces or something in the file to demonstrate that the file is copied over.

unittests/clang-move/ClangMoveTests.cpp
267 ↗(On Diff #77062)

Can you add tests for move all (multiple) classes in file?

Not related to this patch...but it seems that we are missing test case for moving template class?

278 ↗(On Diff #77062)

Maybe just insert or push back?

280 ↗(On Diff #77062)

Where is foo.cc?

299 ↗(On Diff #77062)

I think using namespace decl should also be ignored?

hokein retitled this revision from [clang-move] Move all codes from old.h/cc if old.h only contains one moved declaration. to [clang-move] Move all code from old.h/cc directly when moving all class declarations from old.h..Nov 7 2016, 1:33 PM
hokein updated this object.
hokein edited edge metadata.
hokein updated this revision to Diff 77093.Nov 7 2016, 1:35 PM
hokein marked 5 inline comments as done.

Address review comments.

hokein added a comment.Nov 7 2016, 1:36 PM

The patch summary says "one moved declaration." Why it is just one moved declaration? Doesn't this also support moving all classes in one file?

Oh, the patch summary is not totally correct. It actually does what you mention above. Have updated the summary.

clang-move/ClangMove.h
72 ↗(On Diff #77062)

Sorry for the confusion.

Indeed this a range for the written file name of #include, i.e. if the #include is #include "old.h", then the range here is for "old.h". Have updated the comment.

109 ↗(On Diff #77062)

The trailing comments or whitespaces will be ignored here. We just copy this field from InclusionDirective interface, and seems there is no explicit way to retrieve the comments or whitespaces.

unittests/clang-move/ClangMoveTests.cpp
267 ↗(On Diff #77062)

Not related to this patch...but it seems that we are missing test case for moving template class?

Yeah, moving template classes doesn't support perfectly right now.

278 ↗(On Diff #77062)

I think using insert or push_back doesn't make the code as clear as initialization here. Code readers might pull up the source file to find the code for the initialized value of this variable.

280 ↗(On Diff #77062)

The Code variable above represents the source code of foo.cc.

299 ↗(On Diff #77062)

This case should rarely happen in source code, as many code styles prohibit using-namespace decls in headers.
I'd like to keep the current behavior because the using-namespace decl will populate the namespace in all the files which include this header. Ignoring it might break a lot of code.

ioeric added inline comments.Nov 7 2016, 2:24 PM
unittests/clang-move/ClangMoveTests.cpp
278 ↗(On Diff #77062)

But you have only one element here right? With those, you wouldn't need std::string(...) I guess.

299 ↗(On Diff #77062)

But if you are moving the whole file, using namespace would also be moved so that code would not break?

hokein updated this revision to Diff 77208.Nov 8 2016, 9:42 AM
hokein marked 2 inline comments as done.

Fix remaining comments.

ioeric accepted this revision.Nov 8 2016, 9:54 AM
ioeric edited edge metadata.

Lg with a few nits.

clang-move/ClangMove.cpp
539 ↗(On Diff #77208)

I'd probably pull this out as an inline function to save some typing.

inline std::string ClangMoveTool::MakeAbsolute(Path) {
    return MakeAbsolutePath(OriginalRunningDirectory, OldFile));
}
unittests/clang-move/ClangMoveTests.cpp
286 ↗(On Diff #77208)

Please also check old header is removed or empty.

329 ↗(On Diff #77208)

Please also check old headers.

This revision is now accepted and ready to land.Nov 8 2016, 9:54 AM
hokein updated this revision to Diff 77223.Nov 8 2016, 11:38 AM
hokein marked 2 inline comments as done.
hokein edited edge metadata.

Update test to check old header.

hokein marked an inline comment as done.Nov 8 2016, 11:39 AM
This revision was automatically updated to reflect the committed changes.