diff options
author | Birunthan Mohanathas <birunthan@mohanathas.com> | 2015-06-29 15:30:42 +0000 |
---|---|---|
committer | Birunthan Mohanathas <birunthan@mohanathas.com> | 2015-06-29 15:30:42 +0000 |
commit | a0388a8af20e9c2f16b29e5417b125bad1a42e74 (patch) | |
tree | e8a8b075d4e20a1de5f79363626284437fcb304a /clang/lib/Format | |
parent | bcc976a4434787fefdc0a75835f00669c7338db0 (diff) | |
download | bcm5719-llvm-a0388a8af20e9c2f16b29e5417b125bad1a42e74.tar.gz bcm5719-llvm-a0388a8af20e9c2f16b29e5417b125bad1a42e74.zip |
clang-format: Add option to break after definition return type for top-level functions only
Differential Revision: http://reviews.llvm.org/D10774
llvm-svn: 240959
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Format/Format.cpp | 18 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 7 |
3 files changed, 23 insertions, 5 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 2717c2731d2..ed01d689c59 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -126,7 +126,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) { // 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 == FormatStyle::DRTBS_None && + State.Column < 6) return false; return !State.Stack.back().NoLineBreak; diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index edc44d3e3df..0dd7ca0cbc1 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -99,6 +99,18 @@ template <> struct ScalarEnumerationTraits<FormatStyle::BraceBreakingStyle> { } }; +template <> struct ScalarEnumerationTraits<FormatStyle::DefinitionReturnTypeBreakingStyle> { + static void enumeration(IO &IO, FormatStyle::DefinitionReturnTypeBreakingStyle &Value) { + IO.enumCase(Value, "None", FormatStyle::DRTBS_None); + IO.enumCase(Value, "All", FormatStyle::DRTBS_All); + IO.enumCase(Value, "TopLevel", FormatStyle::DRTBS_TopLevel); + + // For backward compatibility. + IO.enumCase(Value, "false", FormatStyle::DRTBS_None); + IO.enumCase(Value, "true", FormatStyle::DRTBS_All); + } +}; + template <> struct ScalarEnumerationTraits<FormatStyle::NamespaceIndentationKind> { static void enumeration(IO &IO, @@ -338,7 +350,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.AllowShortCaseLabelsOnASingleLine = false; LLVMStyle.AllowShortIfStatementsOnASingleLine = false; LLVMStyle.AllowShortLoopsOnASingleLine = false; - LLVMStyle.AlwaysBreakAfterDefinitionReturnType = false; + LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None; LLVMStyle.AlwaysBreakBeforeMultilineStrings = false; LLVMStyle.AlwaysBreakTemplateDeclarations = false; LLVMStyle.BinPackParameters = true; @@ -463,6 +475,8 @@ FormatStyle getMozillaStyle() { FormatStyle MozillaStyle = getLLVMStyle(); MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false; MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; + MozillaStyle.AlwaysBreakAfterDefinitionReturnType = + FormatStyle::DRTBS_TopLevel; MozillaStyle.AlwaysBreakTemplateDeclarations = true; MozillaStyle.BreakConstructorInitializersBeforeComma = true; MozillaStyle.ConstructorInitializerIndentWidth = 2; @@ -498,7 +512,7 @@ FormatStyle getWebKitStyle() { FormatStyle getGNUStyle() { FormatStyle Style = getLLVMStyle(); - Style.AlwaysBreakAfterDefinitionReturnType = true; + Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All; Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All; Style.BreakBeforeBraces = FormatStyle::BS_GNU; Style.BreakBeforeTernaryOperators = true; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 2f1aae39344..0117f222004 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1539,8 +1539,11 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { Current->MustBreakBefore = Current->MustBreakBefore || mustBreakBefore(Line, *Current); - if (Style.AlwaysBreakAfterDefinitionReturnType && InFunctionDecl && - Current->is(TT_FunctionDeclarationName) && + if ((Style.AlwaysBreakAfterDefinitionReturnType == FormatStyle::DRTBS_All || + (Style.AlwaysBreakAfterDefinitionReturnType == + FormatStyle::DRTBS_TopLevel && + Line.Level == 0)) && + InFunctionDecl && Current->is(TT_FunctionDeclarationName) && !Line.Last->isOneOf(tok::semi, tok::comment)) // Only for definitions. // FIXME: Line.Last points to other characters than tok::semi // and tok::lbrace. |