This is an archive of the discontinued LLVM Phabricator instance.

[clang-move] Make the output code look more pretty.
ClosedPublic

Authored by hokein on Nov 9 2016, 9:53 PM.

Details

Summary

Add decent blank lines between declarations:

  • Add extra blank line after #define or #includes.
  • Add extra blank line between declarations.
  • Add extra blank line in front of #endif.

Previously, the new generated code is quite tight:

#ifndef FOO_H
#define FOO_H
namespace a {
class A { public: int f(); };
int A::f() { return 0; }
} // namespace a
#endif // FOO_H

After this patch, the code looks like:

#ifndef FOO_H
#define FOO_H

namespace a {
class A { public: int f(); };

int A::f() { return 0; }
} // namespace a

#endif // FOO_H

Diff Detail

Repository
rL LLVM

Event Timeline

hokein updated this revision to Diff 77449.Nov 9 2016, 9:53 PM
hokein retitled this revision from to [clang-move] Make the output code look more pretty..
hokein updated this object.
hokein added a reviewer: ioeric.
hokein added a subscriber: cfe-commits.
ioeric added inline comments.Nov 10 2016, 10:48 AM
clang-move/ClangMove.cpp
273 ↗(On Diff #77449)

It's been a while since the last time I reviewed this, and I need to struggle to understand what CurrentNamespaces, NextNamespaces, and IsNamespaceStart are... some comments for them are really appreciated.

hokein updated this revision to Diff 77794.Nov 14 2016, 5:12 AM

Add comments and update patch descriptions.

hokein updated this object.Nov 14 2016, 5:13 AM
hokein updated this object.
hokein marked an inline comment as done.Nov 14 2016, 5:15 AM
ioeric edited edge metadata.Nov 14 2016, 6:29 AM

Lg with one nit.

clang-move/ClangMove.cpp
280 ↗(On Diff #77794)

Wouldn't this create something like:

namespace x {
namespace y {
...
} // namespace y
  <----------------------------extra \n.
} // namespace x
ioeric accepted this revision.Nov 14 2016, 6:30 AM
ioeric edited edge metadata.
This revision is now accepted and ready to land.Nov 14 2016, 6:30 AM
hokein added inline comments.Nov 14 2016, 7:37 AM
clang-move/ClangMove.cpp
280 ↗(On Diff #77794)

No. This code is for nested namespace. In your case, there should be a declaration after } // namespace y like:

namespace x {
namespace y {
...
} // namespace y

int A::f() {}
} // namespace x
hokein added inline comments.Nov 14 2016, 7:43 AM
clang-move/ClangMove.cpp
280 ↗(On Diff #77794)

Oh, I see your meaning here. This case could be happened if the loop runs multiple times. Looking to it.

hokein updated this revision to Diff 77820.Nov 14 2016, 8:52 AM
hokein marked an inline comment as done.
hokein edited edge metadata.

Fix a corner case, and add a test.

hokein updated this object.Nov 14 2016, 8:52 AM
hokein updated this revision to Diff 77821.Nov 14 2016, 8:53 AM

Remove a trailing blank line.

This revision was automatically updated to reflect the committed changes.