diff options
-rw-r--r-- | lib/Format/Format.cpp | 12 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 5 |
2 files changed, 14 insertions, 3 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; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 0c6385b7a1..201a08bb5f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -964,8 +964,9 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { " aaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)));"); verifyGoogleFormat( - "aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa)\n" - " .aaaaaaaaaaaaaaaaaa();"); + "aaaaaaaaaaaaaaa(aaaaaaaaa,\n" + " aaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa();"); verifyGoogleFormat( "somefunction(someotherFunction(ddddddddddddddddddddddddddddddddddd,\n" " ddddddddddddddddddddddddddddd),\n" |