aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-18 10:56:38 +0000
committerDaniel Jasper <djasper@google.com>2013-01-18 10:56:38 +0000
commitc79afdae8a2e12d1e8f27a2ae0a43dfca3b8283b (patch)
treeb3d43ece766c6a8a23c6b0ffcda669e6dae9c9b7 /lib/Format/Format.cpp
parent7d1185de4405637094d64f960f2b6d01f8bce04e (diff)
Reduce penalty for splitting between ")" and ".".
').' is likely part of a builder pattern statement. This is based upon a patch developed by Nico Weber. Thank you! Before: int foo() { return llvm::StringSwitch<Reference::Kind>(name).StartsWith( ".eh_frame_hdr", ORDER_EH_FRAMEHDR).StartsWith( ".eh_frame", ORDER_EH_FRAME).StartsWith(".init", ORDER_INIT).StartsWith( ".fini", ORDER_FINI).StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT); } After: int foo() { return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT); } Probably not ideal, but makes many cases much more readable. The changes to overriding-ftemplate-comments.cpp don't seem better or worse. We should address those soon. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172804 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 50df593d85..1821937ec3 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -322,7 +322,7 @@ public:
: Style(Style), SourceMgr(SourceMgr), Line(Line),
FirstIndent(FirstIndent), RootToken(RootToken),
Whitespaces(Whitespaces) {
- Parameters.PenaltyIndentLevel = 15;
+ Parameters.PenaltyIndentLevel = 20;
Parameters.PenaltyLevelDecrease = 30;
Parameters.PenaltyExcessCharacter = 1000000;
}
@@ -674,8 +674,7 @@ private:
(Left.isNot(tok::comma) && Left.isNot(tok::semi)))
return 20;
- if (Left.is(tok::semi) || Left.is(tok::comma) ||
- Left.ClosesTemplateDeclaration)
+ if (Left.is(tok::semi) || Left.is(tok::comma))
return 0;
// In Objective-C method expressions, prefer breaking before "param:" over
@@ -700,8 +699,11 @@ private:
if (Level != prec::Unknown)
return Level;
- if (Right.is(tok::arrow) || Right.is(tok::period))
+ if (Right.is(tok::arrow) || Right.is(tok::period)) {
+ if (Left.is(tok::r_paren))
+ return 15; // Should be smaller than breaking at a nested comma.
return 150;
+ }
return 3;
}
@@ -746,7 +748,9 @@ private:
if (NewLine && State.NextToken->Parent->is(tok::comma) &&
State.Stack.back().HasMultiParameterLine && !Style.BinPackParameters)
return UINT_MAX;
- if (!NewLine && State.NextToken->Type == TT_CtorInitializerColon)
+ if (!NewLine && (State.NextToken->Type == TT_CtorInitializerColon ||
+ (State.NextToken->Parent->ClosesTemplateDeclaration &&
+ State.Stack.size() == 1)))
return UINT_MAX;
unsigned CurrentPenalty = 0;