summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-17 09:35:01 +0000
committerDaniel Jasper <djasper@google.com>2013-05-17 09:35:01 +0000
commit473c62c4850ffbf8615e0937c4bd292a12225180 (patch)
tree5f17c6e0f11b792ea9e9b9718adbf3ff047b6f02 /clang/lib/Format/Format.cpp
parentbf2d56890035f2f633469f43fc116e45f26a7f64 (diff)
downloadbcm5719-llvm-473c62c4850ffbf8615e0937c4bd292a12225180.tar.gz
bcm5719-llvm-473c62c4850ffbf8615e0937c4bd292a12225180.zip
Slightly modify the formatting rules for braced lists.
Basically, the new rule is: The opening "{" always has to be on the same line as the first element if the braced list is nested (e.g. in another braced list or in a function). The solution that clang-format produces almost always adheres to this rule anyway and this makes clang-format significantly faster for larger lists. Added a test cases for the only exception I could find (which doesn't seem to be very important at first sight). llvm-svn: 182082
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 6966aabd696..3dd0002abb5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -977,10 +977,18 @@ private:
/// \brief Returns \c true, if a line break after \p State is allowed.
bool canBreak(const LineState &State) {
- if (!State.NextToken->CanBreakBefore &&
- !(State.NextToken->is(tok::r_brace) &&
+ const AnnotatedToken &Current = *State.NextToken;
+ const AnnotatedToken &Previous = *Current.Parent;
+ if (!Current.CanBreakBefore &&
+ !(Current.is(tok::r_brace) &&
State.Stack.back().BreakBeforeClosingBrace))
return false;
+ // The opening "{" of a braced list has to be on the same line as the first
+ // element if it is nested in another braced init list or function call.
+ if (!Current.MustBreakBefore && Previous.is(tok::l_brace) &&
+ Previous.Parent &&
+ Previous.Parent->isOneOf(tok::l_brace, tok::l_paren, tok::comma))
+ return false;
return !State.Stack.back().NoLineBreak;
}
OpenPOWER on IntegriCloud