aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-13 16:10:20 +0000
committerDaniel Jasper <djasper@google.com>2013-01-13 16:10:20 +0000
commit487f64b2ae3f991216eb1346a62ea18156f0b519 (patch)
treede0cb69a627145f39c9116c8c5c2324a99b96291 /lib/Format/Format.cpp
parenta5bec298d96f7eb5309df5aab9d19eb7f8b75a81 (diff)
Stronger respect the input codes line breaks wrt. comments.
clang-format should not change whether or not there is a line break before a line comment as this strongly influences the percieved binding. User input: void f(int a, // b is awesome int b); void g(int a, // a is awesome int b); Before: void f(int a, // b is awesome int b); void g(int a, // a is awesome int b); After: <unchanged from input> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172361 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 727e85fa4f..67a5b8c4cd 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -901,9 +901,12 @@ public:
if (Current.FormatTok.MustBreakBefore) {
Current.MustBreakBefore = true;
} else {
- if (Current.Type == TT_CtorInitializerColon || Current.Parent->Type ==
- TT_LineComment || (Current.is(tok::string_literal) &&
- Current.Parent->is(tok::string_literal))) {
+ if (Current.Type == TT_LineComment) {
+ Current.MustBreakBefore = Current.FormatTok.NewlinesBefore > 0;
+ } else if (Current.Type == TT_CtorInitializerColon ||
+ Current.Parent->Type == TT_LineComment ||
+ (Current.is(tok::string_literal) &&
+ Current.Parent->is(tok::string_literal))) {
Current.MustBreakBefore = true;
} else {
Current.MustBreakBefore = false;
@@ -1219,7 +1222,10 @@ private:
return false;
if (Right.is(tok::comment))
- return !Right.Children.empty();
+ // We rely on MustBreakBefore being set correctly here as we should not
+ // change the "binding" behavior of a comment.
+ return false;
+
if (Right.is(tok::r_paren) || Right.is(tok::l_brace) ||
Right.is(tok::greater))
return false;