diff options
author | Daniel Jasper <djasper@google.com> | 2013-11-23 10:22:59 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-11-23 10:22:59 +0000 |
commit | 1a1a2ab77ebb1702b893ffb25ed59791285e57cb (patch) | |
tree | a944ea3908013b3ba2091d819720865ad5e6d5a7 /clang/lib/Format/FormatToken.cpp | |
parent | 556f03ef908f13f4a5c54ba2b1fbdaa276acee36 (diff) | |
download | bcm5719-llvm-1a1a2ab77ebb1702b893ffb25ed59791285e57cb.tar.gz bcm5719-llvm-1a1a2ab77ebb1702b893ffb25ed59791285e57cb.zip |
clang-format: Prefer column layout if possible.
Add a severe penalty for not using column layout for braced lists. If
there are solutions with column layout, these are generally preferable
over bin-packed solutions.
Before:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa,
aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a,
aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a };
After:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
aaaaaaa, aaaaaaaaaa,
aaaaa, aaaaaaaaaaaaaaa,
aaa, aaaaaaaaaa,
a, aaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a
};
llvm-svn: 195546
Diffstat (limited to 'clang/lib/Format/FormatToken.cpp')
-rw-r--r-- | clang/lib/Format/FormatToken.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 8ac704a3bb6..bab2425205c 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -48,8 +48,11 @@ unsigned CommaSeparatedList::format(LineState &State, // Find the best ColumnFormat, i.e. the best number of columns to use. const ColumnFormat *Format = getColumnFormat(RemainingCodePoints); + // If no ColumnFormat can be used, the braced list would generally be + // bin-packed. Add a severe penalty to this so that column layouts are + // prefered if possible. if (!Format) - return 0; + return 10000; // Format the entire list. unsigned Penalty = 0; |