diff options
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 0d54208bbe9..be42d5046de 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -383,11 +383,18 @@ private: // } // } // - // In the first case we want to spread the contents inside the square - // braces; in the second we want to keep them inline. + // or repeated fields (in options): + // + // option (Aaa.options) = { + // keys: [ 1, 2, 3 ] + // } + // + // In the first and the third case we want to spread the contents inside + // the square braces; in the second we want to keep them inline. Left->Type = TT_ArrayInitializerLSquare; if (!Left->endsSequence(tok::l_square, tok::numeric_constant, - tok::equal)) { + tok::equal) && + !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) { Left->Type = TT_ProtoExtensionLSquare; BindingIncrease = 10; } @@ -2331,16 +2338,26 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon)); if (Right.is(tok::star) && Left.is(tok::l_paren)) return false; + const auto SpaceRequiredForArrayInitializerLSquare = + [](const FormatToken &LSquareTok, const FormatStyle &Style) { + return Style.SpacesInContainerLiterals || + ((Style.Language == FormatStyle::LK_Proto || + Style.Language == FormatStyle::LK_TextProto) && + !Style.Cpp11BracedListStyle && + LSquareTok.endsSequence(tok::l_square, tok::colon, + TT_SelectorName)); + }; if (Left.is(tok::l_square)) - return (Left.is(TT_ArrayInitializerLSquare) && - Style.SpacesInContainerLiterals && Right.isNot(tok::r_square)) || + return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) && + SpaceRequiredForArrayInitializerLSquare(Left, Style)) || (Left.isOneOf(TT_ArraySubscriptLSquare, TT_StructuredBindingLSquare) && Style.SpacesInSquareBrackets && Right.isNot(tok::r_square)); if (Right.is(tok::r_square)) return Right.MatchingParen && - ((Style.SpacesInContainerLiterals && - Right.MatchingParen->is(TT_ArrayInitializerLSquare)) || + ((Right.MatchingParen->is(TT_ArrayInitializerLSquare) && + SpaceRequiredForArrayInitializerLSquare(*Right.MatchingParen, + Style)) || (Style.SpacesInSquareBrackets && Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare, TT_StructuredBindingLSquare))); |

