summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-13 20:33:44 +0000
committerDaniel Jasper <djasper@google.com>2013-02-13 20:33:44 +0000
commitb9caeacd0213ebbde79d096534b46603106e94b4 (patch)
treeb65d5e98957ebba8c71a7b1342d757a2bbe51122 /clang/lib
parentf662cff68902ce072e4442810dffe9769ba2dfe7 (diff)
downloadbcm5719-llvm-b9caeacd0213ebbde79d096534b46603106e94b4.tar.gz
bcm5719-llvm-b9caeacd0213ebbde79d096534b46603106e94b4.zip
Allow breaking after the return type in function declarations.
This has so far been disabled for Google style, but should be done before breaking at nested name specifiers or in template parameters. Before (in Google style): template <typename T> aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaaaaaaaa< T>::aaaaaaa() {} After: template <typename T> aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaa() {} llvm-svn: 175074
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/Format.cpp11
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
2 files changed, 9 insertions, 6 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d8c02e2e18b..8c2128eb018 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -43,11 +43,11 @@ FormatStyle getLLVMStyle() {
LLVMStyle.SpacesBeforeTrailingComments = 1;
LLVMStyle.BinPackParameters = true;
LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
- LLVMStyle.AllowReturnTypeOnItsOwnLine = true;
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
LLVMStyle.PenaltyExcessCharacter = 1000000;
+ LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 5;
return LLVMStyle;
}
@@ -63,11 +63,11 @@ FormatStyle getGoogleStyle() {
GoogleStyle.SpacesBeforeTrailingComments = 2;
GoogleStyle.BinPackParameters = false;
GoogleStyle.AllowAllParametersOfDeclarationOnNextLine = true;
- GoogleStyle.AllowReturnTypeOnItsOwnLine = false;
GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = false;
GoogleStyle.ObjCSpaceBeforeProtocolList = false;
GoogleStyle.PenaltyExcessCharacter = 1000000;
+ GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 100;
return GoogleStyle;
}
@@ -717,9 +717,10 @@ private:
reconstructPath(State, Current->Previous);
DEBUG({
if (Current->NewLine) {
- llvm::errs() << "Penalty for splitting before "
- << Current->State.NextToken->FormatTok.Tok.getName()
- << ": " << Current->State.NextToken->SplitPenalty << "\n";
+ llvm::errs()
+ << "Penalty for splitting before "
+ << Current->Previous->State.NextToken->FormatTok.Tok.getName()
+ << ": " << Current->Previous->State.NextToken->SplitPenalty << "\n";
}
});
addTokenToState(Current->NewLine, false, State);
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index d2e19af56f1..4c365361040 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -847,6 +847,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
const AnnotatedToken &Left = *Tok.Parent;
const AnnotatedToken &Right = Tok;
+ if (Right.Type == TT_StartOfName)
+ return Style.PenaltyReturnTypeOnItsOwnLine;
if (Left.is(tok::l_brace) && Right.isNot(tok::l_brace))
return 50;
if (Left.is(tok::equal) && Right.is(tok::l_brace))
@@ -1026,7 +1028,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
const AnnotatedToken &Right) {
const AnnotatedToken &Left = *Right.Parent;
- if (Right.Type == TT_StartOfName && Style.AllowReturnTypeOnItsOwnLine)
+ if (Right.Type == TT_StartOfName)
return true;
if (Right.is(tok::colon) && Right.Type == TT_ObjCMethodExpr)
return false;
OpenPOWER on IntegriCloud