Hi djasper,
AlwaysBreakAfterDeclarationReturnType is like
AlwaysBreakAfterDefinitionReturnType, but inserts breaks
before declaration identifiers, not definition identifiers.
AlwaysBreakAfterDeclarationReturnType defaults to false
(old behaviour) for all styles.
http://reviews.llvm.org/D10370
Files:
docs/ClangFormatStyleOptions.rst
include/clang/Format/Format.h
lib/Format/ContinuationIndenter.cpp
lib/Format/Format.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: docs/ClangFormatStyleOptions.rst
===================================================================
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -220,12 +220,23 @@
If ``true``, ``while (true) continue;`` can be put on a
single line.
+**AlwaysBreakAfterDeclarationReturnType** (``bool``)
+ If ``true``, always break after function declaration (prototype) return types.
+
+ More truthfully called 'break before the identifier following the type
+ in a function declarations'. PenaltyReturnTypeOnItsOwnLine becomes
+ irrelevant for function declarations.
+
+ See also AlwaysBreakAfterDefinitionReturnType.
+
**AlwaysBreakAfterDefinitionReturnType** (``bool``)
If ``true``, always break after function definition return types.
More truthfully called 'break before the identifier following the type
in a function definition'. PenaltyReturnTypeOnItsOwnLine becomes
- irrelevant.
+ irrelevant for function definitions.
+
+ See also AlwaysBreakAfterDeclarationReturnType.
**AlwaysBreakBeforeMultilineStrings** (``bool``)
If ``true``, always break before multiline string literals.
Index: include/clang/Format/Format.h
===================================================================
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -275,11 +275,18 @@
/// \brief The number of characters to use for indentation of ObjC blocks.
unsigned ObjCBlockIndentWidth;
+ /// \brief If \c true, always break after function declaration return types.
+ ///
+ /// \see AlwaysBreakAfterDeclarationReturnType
+ bool AlwaysBreakAfterDeclarationReturnType;
+
/// \brief If \c true, always break after function definition return types.
///
/// More truthfully called 'break before the identifier following the type
/// in a function definition'. PenaltyReturnTypeOnItsOwnLine becomes
/// irrelevant.
+ ///
+ /// \see AlwaysBreakAfterDeclarationReturnType
bool AlwaysBreakAfterDefinitionReturnType;
/// \brief If \c true, always break after the <tt>template<...></tt> of a
@@ -433,6 +440,8 @@
AllowShortIfStatementsOnASingleLine ==
R.AllowShortIfStatementsOnASingleLine &&
AllowShortLoopsOnASingleLine == R.AllowShortLoopsOnASingleLine &&
+ AlwaysBreakAfterDeclarationReturnType ==
+ R.AlwaysBreakAfterDeclarationReturnType &&
AlwaysBreakAfterDefinitionReturnType ==
R.AlwaysBreakAfterDefinitionReturnType &&
AlwaysBreakTemplateDeclarations ==
Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -126,7 +126,9 @@
// Don't break after very short return types (e.g. "void") as that is often
// unexpected.
if (Current.is(TT_FunctionDeclarationName) &&
- !Style.AlwaysBreakAfterDefinitionReturnType && State.Column < 6)
+ !(Style.AlwaysBreakAfterDefinitionReturnType ||
+ Style.AlwaysBreakAfterDeclarationReturnType) &&
+ State.Column < 6)
return false;
return !State.Stack.back().NoLineBreak;
Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -187,6 +187,8 @@
Style.AllowShortLoopsOnASingleLine);
IO.mapOptional("AllowShortFunctionsOnASingleLine",
Style.AllowShortFunctionsOnASingleLine);
+ IO.mapOptional("AlwaysBreakAfterDeclarationReturnType",
+ Style.AlwaysBreakAfterDeclarationReturnType);
IO.mapOptional("AlwaysBreakAfterDefinitionReturnType",
Style.AlwaysBreakAfterDefinitionReturnType);
IO.mapOptional("AlwaysBreakTemplateDeclarations",
@@ -337,6 +339,7 @@
LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.AllowShortLoopsOnASingleLine = false;
+ LLVMStyle.AlwaysBreakAfterDeclarationReturnType = false;
LLVMStyle.AlwaysBreakAfterDefinitionReturnType = false;
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AlwaysBreakTemplateDeclarations = false;
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1539,12 +1539,15 @@
Current->MustBreakBefore =
Current->MustBreakBefore || mustBreakBefore(Line, *Current);
- if (Style.AlwaysBreakAfterDefinitionReturnType && InFunctionDecl &&
- Current->is(TT_FunctionDeclarationName) &&
- !Line.Last->isOneOf(tok::semi, tok::comment)) // Only for definitions.
+ if (!Current->MustBreakBefore && InFunctionDecl &&
+ Current->is(TT_FunctionDeclarationName)) {
// FIXME: Line.Last points to other characters than tok::semi
// and tok::lbrace.
- Current->MustBreakBefore = true;
+ bool Definition = !Line.Last->isOneOf(tok::semi, tok::comment);
+ if ((Definition && Style.AlwaysBreakAfterDefinitionReturnType) ||
+ (!Definition && Style.AlwaysBreakAfterDeclarationReturnType))
+ Current->MustBreakBefore = true;
+ }
Current->CanBreakBefore =
Current->MustBreakBefore || canBreakBefore(Line, *Current);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits