aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-22 14:28:24 +0000
committerDaniel Jasper <djasper@google.com>2013-01-22 14:28:24 +0000
commit3298327e0e6ecb31ca8f3d0996043292e7c860f2 (patch)
treea85818461d3f1ee9cb066a5da0cd3dec19616011 /lib/Format/Format.cpp
parentffee17126e10a0e2febfcfbf61d8e0d6e2fcf4c0 (diff)
Let the formatter be more restrictive for breaking around . and ->
Before: aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaaa(); After: aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173160 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index e9ff3c9b12..08b0d97983 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -60,6 +60,7 @@ enum TokenType {
enum LineType {
LT_Invalid,
LT_Other,
+ LT_BuilderTypeCall,
LT_PreprocessorDirective,
LT_VirtualFunctionDecl,
LT_ObjCDecl, // An @interface, @implementation, or @protocol line.
@@ -707,7 +708,7 @@ private:
return Level;
if (Right.is(tok::arrow) || Right.is(tok::period)) {
- if (Left.is(tok::r_paren))
+ if (Left.is(tok::r_paren) && Line.Type == LT_BuilderTypeCall)
return 15; // Should be smaller than breaking at a nested comma.
return 150;
}
@@ -1162,18 +1163,27 @@ public:
}
LineType parseLine() {
+ int PeriodsAndArrows = 0;
if (CurrentToken->is(tok::hash)) {
parsePreprocessorDirective();
return LT_PreprocessorDirective;
}
while (CurrentToken != NULL) {
+
if (CurrentToken->is(tok::kw_virtual))
KeywordVirtualFound = true;
+ if (CurrentToken->is(tok::period) || CurrentToken->is(tok::arrow))
+ ++PeriodsAndArrows;
if (!consumeToken())
return LT_Invalid;
}
if (KeywordVirtualFound)
return LT_VirtualFunctionDecl;
+
+ // Assume a builder-type call if there are 2 or more "." and "->".
+ if (PeriodsAndArrows >= 2)
+ return LT_BuilderTypeCall;
+
return LT_Other;
}