diff options
author | Daniel Jasper <djasper@google.com> | 2015-11-16 12:38:56 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-11-16 12:38:56 +0000 |
commit | da446770823be1b1d1562734e55da7c1a5f2579c (patch) | |
tree | 2bf41eaac2d5dcd6b8181359a850bbd26e037fe4 /clang/lib/Format/Format.cpp | |
parent | bc09f39476723d319feaac18c948cd3498681136 (diff) | |
download | llvm-da446770823be1b1d1562734e55da7c1a5f2579c.zip llvm-da446770823be1b1d1562734e55da7c1a5f2579c.tar.gz llvm-da446770823be1b1d1562734e55da7c1a5f2579c.tar.bz2 |
clang-format: Enable #include sorting by default.
This has seen quite some usage and I am not aware of any issues. Also
add a style option to enable/disable include sorting. The existing
command line flag can from now on be used to override whatever is set
in the style.
llvm-svn: 253202
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index c1a3019..4bc12f8 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -284,6 +284,7 @@ template <> struct MappingTraits<FormatStyle> { IO.mapOptional("PenaltyExcessCharacter", Style.PenaltyExcessCharacter); IO.mapOptional("PenaltyReturnTypeOnItsOwnLine", Style.PenaltyReturnTypeOnItsOwnLine); + IO.mapOptional("SortIncludes", Style.SortIncludes); IO.mapOptional("PointerAlignment", Style.PointerAlignment); IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast); IO.mapOptional("SpaceBeforeAssignmentOperators", @@ -507,6 +508,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19; LLVMStyle.DisableFormat = false; + LLVMStyle.SortIncludes = true; return LLVMStyle; } @@ -635,6 +637,7 @@ FormatStyle getGNUStyle() { FormatStyle getNoStyle() { FormatStyle NoStyle = getLLVMStyle(); NoStyle.DisableFormat = true; + NoStyle.SortIncludes = false; return NoStyle; } @@ -1743,6 +1746,9 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, ArrayRef<tooling::Range> Ranges, StringRef FileName) { tooling::Replacements Replaces; + if (!Style.SortIncludes) + return Replaces; + unsigned Prev = 0; unsigned SearchFrom = 0; llvm::Regex IncludeRegex( |