diff options
| author | Daniel Jasper <djasper@google.com> | 2014-04-15 09:54:30 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-04-15 09:54:30 +0000 |
| commit | 783bac6bba557f4ccd82780c68b7b3dd7d1134ca (patch) | |
| tree | f84270e3d6e39d803e8cb554f96bbe5e21156373 /clang/lib/Format | |
| parent | 9d3adc06c656842713160eb6e654be979b65b613 (diff) | |
| download | bcm5719-llvm-783bac6bba557f4ccd82780c68b7b3dd7d1134ca.tar.gz bcm5719-llvm-783bac6bba557f4ccd82780c68b7b3dd7d1134ca.zip | |
clang-format: Understand proto text format without commas.
Also removed spaces before colons as they don't seem to be used
frequently.
Before:
optional int32 b = 2
[(foo_options) = {aaaaaaaaaaaaaaaaaaa : 123 bbbbbbbbbbbbbbbbbbbbbbbb :
"baz"}];
After:
optional int32 b = 2 [(foo_options) = {aaaaaaaaaaaaaaaaaaa: 123,
bbbbbbbbbbbbbbbbbbbbbbbb:"baz"}];
llvm-svn: 206269
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Format/Format.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 7 |
3 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 0ad8c1eb419..35dc182a2d1 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -472,6 +472,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { else return State.FirstIndent; } + if (Current.is(tok::identifier) && Current.Next && + Current.Next->Type == TT_DictLiteral) + return State.Stack.back().Indent; if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0) return State.StartOfStringLiteral; if (NextNonComment->is(tok::lessless) && diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4a9c37e0841..00e012138b1 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -343,6 +343,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.SpacesInContainerLiterals = false; } else if (Language == FormatStyle::LK_Proto) { GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; + GoogleStyle.SpacesInContainerLiterals = false; } return GoogleStyle; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c4fa784f2a9..98323fcc57c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1243,7 +1243,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Left.is(tok::semi)) return 0; - if (Left.is(tok::comma)) + if (Left.is(tok::comma) || (Right.is(tok::identifier) && Right.Next && + Right.Next->Type == TT_DictLiteral)) return 1; if (Right.is(tok::l_square)) { if (Style.Language == FormatStyle::LK_Proto) @@ -1647,6 +1648,10 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, if (Left.is(tok::identifier) && Right.is(tok::string_literal)) return true; + if (Right.is(tok::identifier) && Right.Next && + Right.Next->Type == TT_DictLiteral) + return true; + if (Left.Type == TT_CtorInitializerComma && Style.BreakConstructorInitializersBeforeComma) return false; |

