summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-21 15:00:29 +0000
committerDaniel Jasper <djasper@google.com>2013-02-21 15:00:29 +0000
commit37905f711cb286baae724f1e438ec572ba26fbf3 (patch)
treecdb7e3977cd661460cd2c60ff8ad03d4de8b6808 /clang/lib/Format/Format.cpp
parente8ba1c851a8f3f3397422dd49e4554e017f0eb8f (diff)
downloadbcm5719-llvm-37905f711cb286baae724f1e438ec572ba26fbf3.tar.gz
bcm5719-llvm-37905f711cb286baae724f1e438ec572ba26fbf3.zip
Allow breaking between type and name in for loops.
This fixes llvm.org/PR15033. Also: Always break before a parameter, if the previous parameter was split over multiple lines. This was necessary to make the right decisions in for-loops, almost always makes the code more readable and also fixes llvm.org/PR14873. Before: for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope() .begin(), E = FD->getDeclsInPrototypeScope().end(); I != E; ++I) { } foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccc), d, bar(e, f)); After: for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope().begin(), E = FD->getDeclsInPrototypeScope().end(); I != E; ++I) { } foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccc), d, bar(e, f)); llvm-svn: 175741
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 44a91a96ecb..2bd53322276 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -258,6 +258,12 @@ private:
tooling::Replacements Replaces;
};
+static bool isVarDeclName(const AnnotatedToken &Tok) {
+ return Tok.Parent != NULL && Tok.is(tok::identifier) &&
+ (Tok.Parent->Type == TT_PointerOrReference ||
+ Tok.Parent->is(tok::identifier));
+}
+
class UnwrappedLineFormatter {
public:
UnwrappedLineFormatter(const FormatStyle &Style, SourceManager &SourceMgr,
@@ -512,7 +518,7 @@ private:
State.Stack.back().ColonPos =
State.Column + Current.FormatTok.TokenLength;
}
- } else if (Previous.Type == TT_ObjCMethodExpr) {
+ } else if (Previous.Type == TT_ObjCMethodExpr || isVarDeclName(Current)) {
State.Column = State.Stack.back().Indent + 4;
} else {
State.Column = State.Stack.back().Indent;
@@ -610,7 +616,9 @@ private:
(!Style.AllowAllParametersOfDeclarationOnNextLine &&
Line.MustBeDeclaration))
State.Stack.back().BreakBeforeParameter = true;
+ }
+ if (Newline) {
// Any break on this level means that the parent level has been broken
// and we need to avoid bin packing there.
for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
@@ -634,13 +642,10 @@ private:
State.Stack.back().FirstLessLess = State.Column;
if (Current.is(tok::question))
State.Stack.back().QuestionColumn = State.Column;
- if (Current.Type == TT_CtorInitializerColon &&
- Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
- State.Stack.back().AvoidBinPacking = true;
- if (Current.is(tok::l_brace) && Current.MatchingParen != NULL &&
- !Current.MatchingParen->MustBreakBefore) {
- if (getLengthToMatchingParen(Current) + State.Column > getColumnLimit())
- State.Stack.back().BreakBeforeParameter = true;
+ if (Current.Type == TT_CtorInitializerColon) {
+ if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
+ State.Stack.back().AvoidBinPacking = true;
+ State.Stack.back().BreakBeforeParameter = false;
}
// Insert scopes created by fake parenthesis.
@@ -908,7 +913,8 @@ private:
if (State.NextToken->Parent->is(tok::comma) &&
State.Stack.back().BreakBeforeParameter &&
!isTrailingComment(*State.NextToken) &&
- State.NextToken->isNot(tok::r_paren))
+ State.NextToken->isNot(tok::r_paren) &&
+ State.NextToken->isNot(tok::r_brace))
return true;
// FIXME: Comparing LongestObjCSelectorName to 0 is a hacky way of finding
// out whether it is the first parameter. Clean this up.
OpenPOWER on IntegriCloud