diff options
author | Paul Hoad <mydeveloperday@gmail.com> | 2019-03-13 08:15:03 +0000 |
---|---|---|
committer | Paul Hoad <mydeveloperday@gmail.com> | 2019-03-13 08:15:03 +0000 |
commit | c7f101d7ac7ea1cedaf1915cff124c5bd2f8f9dc (patch) | |
tree | a44da25ad4a277573066d3d1d90c51dcc60db44c /lib/Format | |
parent | 0ba0294ffd68b08a82fbcf6e132974363331e777 (diff) |
Revert "[clang-format] [PR25010] AllowShortIfStatementsOnASingleLine not working if an "else" statement is present"
This reverts commit b358cbb9b78389e20f7be36e1a98e26515c3ecce.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356030 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/Format.cpp | 26 | ||||
-rw-r--r-- | lib/Format/UnwrappedLineFormatter.cpp | 10 |
2 files changed, 10 insertions, 26 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index ce67b82e10..a56fed9dee 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -106,18 +106,6 @@ template <> struct ScalarEnumerationTraits<FormatStyle::ShortFunctionStyle> { } }; -template <> struct ScalarEnumerationTraits<FormatStyle::ShortIfStyle> { - static void enumeration(IO &IO, FormatStyle::ShortIfStyle &Value) { - IO.enumCase(Value, "Never", FormatStyle::SIS_Never); - IO.enumCase(Value, "Always", FormatStyle::SIS_Always); - IO.enumCase(Value, "WithoutElse", FormatStyle::SIS_WithoutElse); - - // For backward compatibility. - IO.enumCase(Value, "false", FormatStyle::SIS_Never); - IO.enumCase(Value, "true", FormatStyle::SIS_WithoutElse); - } -}; - template <> struct ScalarEnumerationTraits<FormatStyle::BinPackStyle> { static void enumeration(IO &IO, FormatStyle::BinPackStyle &Value) { IO.enumCase(Value, "Auto", FormatStyle::BPS_Auto); @@ -643,7 +631,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; LLVMStyle.AllowShortBlocksOnASingleLine = false; LLVMStyle.AllowShortCaseLabelsOnASingleLine = false; - LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; + LLVMStyle.AllowShortIfStatementsOnASingleLine = false; LLVMStyle.AllowShortLoopsOnASingleLine = false; LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None; LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None; @@ -749,8 +737,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.AccessModifierOffset = -1; GoogleStyle.AlignEscapedNewlines = FormatStyle::ENAS_Left; - GoogleStyle.AllowShortIfStatementsOnASingleLine = - FormatStyle::SIS_WithoutElse; + GoogleStyle.AllowShortIfStatementsOnASingleLine = true; GoogleStyle.AllowShortLoopsOnASingleLine = true; GoogleStyle.AlwaysBreakBeforeMultilineStrings = true; GoogleStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes; @@ -817,7 +804,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.AlignOperands = false; GoogleStyle.AlignTrailingComments = false; GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; - GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; + GoogleStyle.AllowShortIfStatementsOnASingleLine = false; GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; GoogleStyle.ColumnLimit = 100; @@ -859,8 +846,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) { FormatStyle ChromiumStyle = getGoogleStyle(Language); if (Language == FormatStyle::LK_Java) { - ChromiumStyle.AllowShortIfStatementsOnASingleLine = - FormatStyle::SIS_WithoutElse; + ChromiumStyle.AllowShortIfStatementsOnASingleLine = true; ChromiumStyle.BreakAfterJavaFieldAnnotations = true; ChromiumStyle.ContinuationIndentWidth = 8; ChromiumStyle.IndentWidth = 4; @@ -873,12 +859,12 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) { }; ChromiumStyle.SortIncludes = true; } else if (Language == FormatStyle::LK_JavaScript) { - ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; + ChromiumStyle.AllowShortIfStatementsOnASingleLine = false; ChromiumStyle.AllowShortLoopsOnASingleLine = false; } else { ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false; ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; - ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; + ChromiumStyle.AllowShortIfStatementsOnASingleLine = false; ChromiumStyle.AllowShortLoopsOnASingleLine = false; ChromiumStyle.BinPackParameters = false; ChromiumStyle.DerivePointerAlignment = false; diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index f14e3851c8..a62755840d 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -413,12 +413,10 @@ private: if (I[1]->First->isOneOf(tok::semi, tok::kw_if, tok::kw_for, tok::kw_while, TT_LineComment)) return 0; - // Only inline simple if's (no nested if or else), unless specified - if (Style.AllowShortIfStatementsOnASingleLine != FormatStyle::SIS_Always) { - if (I + 2 != E && Line.startsWith(tok::kw_if) && - I[2]->First->is(tok::kw_else)) - return 0; - } + // Only inline simple if's (no nested if or else). + if (I + 2 != E && Line.startsWith(tok::kw_if) && + I[2]->First->is(tok::kw_else)) + return 0; return 1; } |