This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Support sorting using declarations
ClosedPublic

Authored by krasimir on Jun 2 2017, 3:52 AM.

Details

Summary

This patch adds UsingDeclarationsSorter, a TokenAnalyzer that sorts consecutive
using declarations.

Event Timeline

krasimir created this revision.Jun 2 2017, 3:52 AM
krasimir updated this revision to Diff 101188.Jun 2 2017, 4:35 AM
  • Fix comments
djasper edited reviewers, added: klimek; removed: djasper.Jun 6 2017, 5:29 AM
djasper added subscribers: cfe-commits, djasper.
Typz added a subscriber: Typz.Jun 16 2017, 5:44 AM
Typz added inline comments.
lib/Format/UsingDeclarationsSorter.cpp
67

could also be followed by an assignment, in case of type alias:

using foo = bar::foo;
klimek added inline comments.Jun 19 2017, 2:00 AM
lib/Format/UsingDeclarationsSorter.cpp
42–43

Use either:

  • an empty label to indicate that there is no more label, and thus we couldn't compute one
  • use an llvm::ErrorOr as return value
60

I'd invert this if - the happy case is in the if here. That way, you also don't need a continue.

krasimir updated this revision to Diff 103031.Jun 19 2017, 6:05 AM
krasimir marked 3 inline comments as done.
  • Address review comments
krasimir updated this revision to Diff 103032.Jun 19 2017, 6:06 AM
  • Update test case
lib/Format/UsingDeclarationsSorter.cpp
67

Type aliases are in general not safe to permute, as in:

struct C {
  struct B {
    struct A;
  };
};

using B = C::B;
using A = B::A;

Adding a test specifically for this.

This revision is now accepted and ready to land.Jun 21 2017, 3:04 AM
This revision was automatically updated to reflect the committed changes.