diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-16 18:22:10 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-16 18:22:10 +0000 |
commit | 6ab5468637453ffc90fcc8036e40615c1e04b775 (patch) | |
tree | f4b6b7fd02c89c4117b16554bb53bbdef078d6f5 /clang/lib/Format/Format.cpp | |
parent | 3d527d80b86d98ae80b50db0814d2dc075227bd9 (diff) | |
download | bcm5719-llvm-6ab5468637453ffc90fcc8036e40615c1e04b775.tar.gz bcm5719-llvm-6ab5468637453ffc90fcc8036e40615c1e04b775.zip |
Revamp the formatting of C++11 braced init lists.
The fundamental concept is:
Format as if the braced init list was a function call (with parentheses
replaced by braces). If there is no name/type before the opening brace
(e.g. if the braced list is nested), assume a zero-length identifier
just before the opening brace.
This behavior is gated on a new style flag, which for now replaces the
SpacesInBracedLists style flag. Activate this style flag for Google
style to reflect recent style guide changes.
llvm-svn: 186433
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 79048536891..27dd162d660 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -110,7 +110,7 @@ template <> struct MappingTraits<clang::format::FormatStyle> { IO.mapOptional("PointerBindsToType", Style.PointerBindsToType); IO.mapOptional("SpacesBeforeTrailingComments", Style.SpacesBeforeTrailingComments); - IO.mapOptional("SpacesInBracedLists", Style.SpacesInBracedLists); + IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle); IO.mapOptional("Standard", Style.Standard); IO.mapOptional("IndentWidth", Style.IndentWidth); IO.mapOptional("UseTab", Style.UseTab); @@ -151,7 +151,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.ObjCSpaceBeforeProtocolList = true; LLVMStyle.PointerBindsToType = false; LLVMStyle.SpacesBeforeTrailingComments = 1; - LLVMStyle.SpacesInBracedLists = true; + LLVMStyle.Cpp11BracedListStyle = false; LLVMStyle.Standard = FormatStyle::LS_Cpp03; LLVMStyle.IndentWidth = 2; LLVMStyle.UseTab = false; @@ -183,7 +183,7 @@ FormatStyle getGoogleStyle() { GoogleStyle.ObjCSpaceBeforeProtocolList = false; GoogleStyle.PointerBindsToType = true; GoogleStyle.SpacesBeforeTrailingComments = 2; - GoogleStyle.SpacesInBracedLists = false; + GoogleStyle.Cpp11BracedListStyle = true; GoogleStyle.Standard = FormatStyle::LS_Auto; GoogleStyle.IndentWidth = 2; GoogleStyle.UseTab = false; @@ -815,7 +815,8 @@ private: unsigned LastSpace = State.Stack.back().LastSpace; bool AvoidBinPacking; if (Current.is(tok::l_brace)) { - NewIndent = Style.IndentWidth + LastSpace; + NewIndent = + LastSpace + (Style.Cpp11BracedListStyle ? 4 : Style.IndentWidth); const FormatToken *NextNoComment = Current.getNextNonComment(); AvoidBinPacking = NextNoComment && NextNoComment->Type == TT_DesignatedInitializerPeriod; @@ -1139,8 +1140,9 @@ private: const FormatToken &Previous = *Current.Previous; if (Current.MustBreakBefore || Current.Type == TT_InlineASMColon) return true; - if (Current.is(tok::r_brace) && State.Stack.back().BreakBeforeClosingBrace) - return true; + if (!Style.Cpp11BracedListStyle && Current.is(tok::r_brace) && + State.Stack.back().BreakBeforeClosingBrace) + return true; if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection) return true; if ((Previous.isOneOf(tok::comma, tok::semi) || Current.is(tok::question) || |