diff options
author | Daniel Jasper <djasper@google.com> | 2013-02-11 12:36:37 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-02-11 12:36:37 +0000 |
commit | eef30490fd13fe4f460df5a18695215ddef2ace1 (patch) | |
tree | e593d1a058faa118d9f0b37fa80243aea6e12b25 /clang/lib/Format/TokenAnnotator.cpp | |
parent | 0c13795f68a3d2fe0bc31650260809ad8f160a3b (diff) | |
download | bcm5719-llvm-eef30490fd13fe4f460df5a18695215ddef2ace1.tar.gz bcm5719-llvm-eef30490fd13fe4f460df5a18695215ddef2ace1.zip |
Fix invalid formatting with spaces before trailing comments.
In google style, trailing comments are separated by two spaces. This
patch fixes the counting of these spaces and prevents clang-format from
creating a line with 81 columns.
llvm-svn: 174879
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index aecc24ca9c3..8f2e00ebfd1 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -778,7 +778,7 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) { else if (Line.First.Type == TT_ObjCProperty) Line.Type = LT_ObjCProperty; - Line.First.SpaceRequiredBefore = true; + Line.First.SpacesRequiredBefore = 1; Line.First.MustBreakBefore = Line.First.FormatTok.MustBreakBefore; Line.First.CanBreakBefore = Line.First.MustBreakBefore; @@ -790,7 +790,11 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { return; AnnotatedToken *Current = &Line.First.Children[0]; while (Current != NULL) { - Current->SpaceRequiredBefore = spaceRequiredBefore(Line, *Current); + if (Current->Type == TT_LineComment) + Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments; + else + Current->SpacesRequiredBefore = + spaceRequiredBefore(Line, *Current) ? 1 : 0; if (Current->FormatTok.MustBreakBefore) { Current->MustBreakBefore = true; @@ -814,7 +818,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { else Current->TotalLength = Current->Parent->TotalLength + Current->FormatTok.TokenLength + - (Current->SpaceRequiredBefore ? 1 : 0); + Current->SpacesRequiredBefore; // FIXME: Only calculate this if CanBreakBefore is true once static // initializers etc. are sorted out. // FIXME: Move magic numbers to a better place. |