This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Make include sorting's main include detection configurable.
ClosedPublic

Authored by djasper on Mar 21 2016, 6:25 AM.

Details

Reviewers
klimek
Summary

This patch adds a regular expression to configure suffixes of an included file to check whether it is the "main" include of the current file. Previously, clang-format has allowed arbitrary suffixes on the formatted file, which is still the case when no IncludeMainRegex is specified.

Diff Detail

Event Timeline

djasper updated this revision to Diff 51153.Mar 21 2016, 6:25 AM
djasper retitled this revision from to clang-format: Make include sorting's main include detection configurable..
djasper updated this object.
djasper added a reviewer: klimek.
djasper added a subscriber: cfe-commits.
djasper updated this revision to Diff 51154.Mar 21 2016, 6:29 AM
klimek accepted this revision.Mar 21 2016, 6:30 AM
klimek edited edge metadata.

lg

include/clang/Format/Format.h
415

I'd probably call it MainIncludeRegex.

lib/Format/Format.cpp
1967

Try to not set up the Regex in a loop.

1968

Twine() shouldn't be needed.

This revision is now accepted and ready to land.Mar 21 2016, 6:30 AM
djasper added inline comments.Mar 21 2016, 6:44 AM
include/clang/Format/Format.h
415

I chose this name for better alphabetical ordering. I don't strongly lean either way, WDYT?

lib/Format/Format.cpp
1967

I believe this is more efficient. In many cases, no Regex will need to be formed at all and the cases where it is formed more than once are rare (many includes starting with HeaderStem, but not matching the regex).

klimek added inline comments.Mar 21 2016, 6:49 AM
include/clang/Format/Format.h
415

I'd still lean slightly towards MainIncludeRegex... but feel free to keep.

lib/Format/Format.cpp
1967

Ok, makes sense.

djasper closed this revision.Sep 10 2016, 1:26 AM
djasper marked 6 inline comments as done.

Submitted as r263943.

include/clang/Format/Format.h
415

Renamed to IncludeIsMainRegex, which seems to be better than either of the other.