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/tools/clang-format/ClangFormat.cpp | |
parent | bc09f39476723d319feaac18c948cd3498681136 (diff) | |
download | bcm5719-llvm-da446770823be1b1d1562734e55da7c1a5f2579c.tar.gz bcm5719-llvm-da446770823be1b1d1562734e55da7c1a5f2579c.zip |
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/tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | clang/tools/clang-format/ClangFormat.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 7cdb823f367..43eded20fab 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -98,9 +98,11 @@ static cl::opt<unsigned> "clang-format from an editor integration"), cl::init(0), cl::cat(ClangFormatCategory)); -static cl::opt<bool> SortIncludes("sort-includes", - cl::desc("Sort touched include lines"), - cl::cat(ClangFormatCategory)); +static cl::opt<bool> SortIncludes( + "sort-includes", + cl::desc("If set, overrides the include sorting behavior determined by the " + "SortIncludes style flag"), + cl::cat(ClangFormatCategory)); static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"), cl::cat(ClangFormatCategory)); @@ -252,17 +254,14 @@ static bool format(StringRef FileName) { return true; StringRef AssumedFileName = (FileName == "-") ? AssumeFileName : FileName; FormatStyle FormatStyle = getStyle(Style, AssumedFileName, FallbackStyle); - Replacements Replaces; - std::string ChangedCode; - if (SortIncludes) { - Replaces = - sortIncludes(FormatStyle, Code->getBuffer(), Ranges, AssumedFileName); - ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces); - for (const auto &R : Replaces) - Ranges.push_back({R.getOffset(), R.getLength()}); - } else { - ChangedCode = Code->getBuffer().str(); - } + if (SortIncludes.getNumOccurrences() != 0) + FormatStyle.SortIncludes = SortIncludes; + Replacements Replaces = + sortIncludes(FormatStyle, Code->getBuffer(), Ranges, AssumedFileName); + std::string ChangedCode = + tooling::applyAllReplacements(Code->getBuffer(), Replaces); + for (const auto &R : Replaces) + Ranges.push_back({R.getOffset(), R.getLength()}); bool IncompleteFormat = false; Replaces = tooling::mergeReplacements( |