Normal indent for last element of builder-type call.
In builder type call, we indent to the laster function calls.
However, for the last element of such a call, we don't need to do
so, as that normally just wastes space and does not increase
readability.
Before:
aaaaaa->aaaaaa->aaaaaa( // break
aaaaaa);
aaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaa
->aaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
aaaaaa->aaaaaa->aaaaaa( // break
aaaaaa);
aaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176352 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index b9e3512..125619c 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -464,6 +464,7 @@
public:
LineType parseLine() {
int PeriodsAndArrows = 0;
+ AnnotatedToken *LastPeriodOrArrow = NULL;
bool CanBeBuilderTypeStmt = true;
if (CurrentToken->is(tok::hash)) {
parsePreprocessorDirective();
@@ -472,8 +473,10 @@
while (CurrentToken != NULL) {
if (CurrentToken->is(tok::kw_virtual))
KeywordVirtualFound = true;
- if (CurrentToken->is(tok::period) || CurrentToken->is(tok::arrow))
+ if (CurrentToken->is(tok::period) || CurrentToken->is(tok::arrow)) {
++PeriodsAndArrows;
+ LastPeriodOrArrow = CurrentToken;
+ }
AnnotatedToken *TheToken = CurrentToken;
if (!consumeToken())
return LT_Invalid;
@@ -485,8 +488,10 @@
return LT_VirtualFunctionDecl;
// Assume a builder-type call if there are 2 or more "." and "->".
- if (PeriodsAndArrows >= 2 && CanBeBuilderTypeStmt)
+ if (PeriodsAndArrows >= 2 && CanBeBuilderTypeStmt) {
+ LastPeriodOrArrow->LastInChainOfCalls = true;
return LT_BuilderTypeCall;
+ }
if (Line.First.Type == TT_ObjCMethodSpecifier) {
if (Contexts.back().FirstObjCSelectorName != NULL)
@@ -934,7 +939,7 @@
if (Level != prec::Unknown)
return Level;
-
+
return 3;
}