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.
llvm-svn: 172804
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 50df593..1821937 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -322,7 +322,7 @@
: 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 @@
(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 @@
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 @@
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;