Author: Haojian Wu Date: 2020-04-23T09:25:01+02:00 New Revision: 47ef09e4848a970c530928496b54085cfdba5a76
URL: https://github.com/llvm/llvm-project/commit/47ef09e4848a970c530928496b54085cfdba5a76 DIFF: https://github.com/llvm/llvm-project/commit/47ef09e4848a970c530928496b54085cfdba5a76.diff LOG: Revert "clang-format: support aligned nested conditionals formatting" This reverts 3d61b1120e8267aa39f4c9a33d618dbaec4ec6fa, 5daa25fd7a184524759b6ad065a8bd7e95aa149a The clang-format test (FormatTest.ConfigurableUseOfTab) is failing in the buildbot: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/31811/steps/ninja%20check%201/logs/stdio Added: Modified: clang/docs/ClangFormatStyleOptions.rst clang/include/clang/Format/Format.h clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/ContinuationIndenter.h clang/lib/Format/Format.cpp clang/lib/Format/WhitespaceManager.cpp clang/lib/Format/WhitespaceManager.h clang/unittests/Format/FormatTest.cpp clang/unittests/Format/FormatTestJS.cpp Removed: ################################################################################ diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index e5a69fdb9c5a..6d486224e3c2 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -270,49 +270,17 @@ the configuration (without a prefix: ``Auto``). -**AlignOperands** (``OperandAlignmentStyle``) +**AlignOperands** (``bool``) If ``true``, horizontally align operands of binary and ternary expressions. - Possible values: - - * ``OAS_DontAlign`` (in configuration: ``DontAlign``) - Do not align operands of binary and ternary expressions. - The wrapped lines are indented ``ContinuationIndentWidth`` spaces from - the start of the line. - - * ``OAS_Align`` (in configuration: ``Align``) - Horizontally align operands of binary and ternary expressions. - - Specifically, this aligns operands of a single expression that needs - to be split over multiple lines, e.g.: - - .. code-block:: c++ - - int aaa = bbbbbbbbbbbbbbb + - ccccccccccccccc; - - When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is - aligned with the operand on the first line. - - .. code-block:: c++ - - int aaa = bbbbbbbbbbbbbbb - + ccccccccccccccc; - - * ``OAS_AlignAfterOperator`` (in configuration: ``AlignAfterOperator``) - Horizontally align operands of binary and ternary expressions. - - This is similar to ``AO_Align``, except when - ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so - that the wrapped operand is aligned with the operand on the first line. - - .. code-block:: c++ - - int aaa = bbbbbbbbbbbbbbb - + ccccccccccccccc; + Specifically, this aligns operands of a single expression that needs to be + split over multiple lines, e.g.: + .. code-block:: c++ + int aaa = bbbbbbbbbbbbbbb + + ccccccccccccccc; **AlignTrailingComments** (``bool``) If ``true``, aligns trailing comments. diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index f5fa6b44a127..2b2edc4adc11 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -153,43 +153,16 @@ struct FormatStyle { /// Options for aligning backslashes in escaped newlines. EscapedNewlineAlignmentStyle AlignEscapedNewlines; - /// Different styles for aligning operands. - enum OperandAlignmentStyle { - /// Do not align operands of binary and ternary expressions. - /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from - /// the start of the line. - OAS_DontAlign, - /// Horizontally align operands of binary and ternary expressions. - /// - /// Specifically, this aligns operands of a single expression that needs - /// to be split over multiple lines, e.g.: - /// \code - /// int aaa = bbbbbbbbbbbbbbb + - /// ccccccccccccccc; - /// \endcode - /// - /// When ``BreakBeforeBinaryOperators`` is set, the wrapped operator is - /// aligned with the operand on the first line. - /// \code - /// int aaa = bbbbbbbbbbbbbbb - /// + ccccccccccccccc; - /// \endcode - OAS_Align, - /// Horizontally align operands of binary and ternary expressions. - /// - /// This is similar to ``AO_Align``, except when - /// ``BreakBeforeBinaryOperators`` is set, the operator is un-indented so - /// that the wrapped operand is aligned with the operand on the first line. - /// \code - /// int aaa = bbbbbbbbbbbbbbb - /// + ccccccccccccccc; - /// \endcode - OAS_AlignAfterOperator, - }; - /// If ``true``, horizontally align operands of binary and ternary /// expressions. - OperandAlignmentStyle AlignOperands; + /// + /// Specifically, this aligns operands of a single expression that needs to be + /// split over multiple lines, e.g.: + /// \code + /// int aaa = bbbbbbbbbbbbbbb + + /// ccccccccccccccc; + /// \endcode + bool AlignOperands; /// If ``true``, aligns trailing comments. /// \code diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index dcecb30c22c7..e70ae7efb0c3 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -367,12 +367,6 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() && !Current.isOneOf(tok::r_paren, tok::r_brace)) return true; - if (State.Stack.back().IsChainedConditional && - ((Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) && - Current.is(tok::colon)) || - (!Style.BreakBeforeTernaryOperators && Previous.is(TT_ConditionalExpr) && - Previous.is(tok::colon)))) - return true; if (((Previous.is(TT_DictLiteral) && Previous.is(tok::l_brace)) || (Previous.is(TT_ArrayInitializerLSquare) && Previous.ParameterCount > 1) || @@ -693,9 +687,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, // does not help. bool HasTwoOperands = P->OperatorIndex == 0 && !P->NextOperator && !P->is(TT_ConditionalExpr); - if ((!BreakBeforeOperator && - !(HasTwoOperands && - Style.AlignOperands != FormatStyle::OAS_DontAlign)) || + if ((!BreakBeforeOperator && !(HasTwoOperands && Style.AlignOperands)) || (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator)) State.Stack.back().NoLineBreakInOperand = true; } @@ -1030,23 +1022,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { if (State.Stack.back().QuestionColumn != 0 && ((NextNonComment->is(tok::colon) && NextNonComment->is(TT_ConditionalExpr)) || - Previous.is(TT_ConditionalExpr))) { - if (((NextNonComment->is(tok::colon) && NextNonComment->Next && - !NextNonComment->Next->FakeLParens.empty() && - NextNonComment->Next->FakeLParens.back() == prec::Conditional) || - (Previous.is(tok::colon) && !Current.FakeLParens.empty() && - Current.FakeLParens.back() == prec::Conditional)) && - !State.Stack.back().IsWrappedConditional) { - //NOTE: we may tweak this slightly: - // * not remove the 'lead' ContinuationIndentWidth - // * always un-indent by the operator when BreakBeforeTernaryOperators=true - unsigned Indent = State.Stack.back().Indent - Style.ContinuationIndentWidth; - if (Style.BreakBeforeTernaryOperators && State.Stack.back().UnindentOperator) - Indent -= 2; - return Indent; - } + Previous.is(TT_ConditionalExpr))) return State.Stack.back().QuestionColumn; - } if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0) return State.Stack.back().VariablePos; if ((PreviousNonComment && @@ -1122,13 +1099,6 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { return ContinuationIndent; if (Current.is(TT_ProtoExtensionLSquare)) return State.Stack.back().Indent; - if (Current.isBinaryOperator() && State.Stack.back().UnindentOperator) - return State.Stack.back().Indent - Current.Tok.getLength() - - Current.SpacesRequiredBefore; - if (Current.isOneOf(tok::comment, TT_BlockComment, TT_LineComment) && - NextNonComment->isBinaryOperator() && State.Stack.back().UnindentOperator) - return State.Stack.back().Indent - NextNonComment->Tok.getLength() - - NextNonComment->SpacesRequiredBefore; if (State.Stack.back().Indent == State.FirstIndent && PreviousNonComment && !PreviousNonComment->isOneOf(tok::r_brace, TT_CtorInitializerComma)) // Ensure that we fall back to the continuation indent width instead of @@ -1174,10 +1144,6 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, if (Current.is(TT_ArraySubscriptLSquare) && State.Stack.back().StartOfArraySubscripts == 0) State.Stack.back().StartOfArraySubscripts = State.Column; - if (Current.is(TT_ConditionalExpr) && Current.is(tok::question) && - ((Current.MustBreakBefore) || - (Current.getNextNonComment() && Current.getNextNonComment()->MustBreakBefore))) - State.Stack.back().IsWrappedConditional = true; if (Style.BreakBeforeTernaryOperators && Current.is(tok::question)) State.Stack.back().QuestionColumn = State.Column; if (!Style.BreakBeforeTernaryOperators && Current.isNot(tok::colon)) { @@ -1308,7 +1274,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, (Previous && (Previous->opensScope() || Previous->isOneOf(tok::semi, tok::kw_return) || (Previous->getPrecedence() == prec::Assignment && - Style.AlignOperands != FormatStyle::OAS_DontAlign) || + Style.AlignOperands) || Previous->is(TT_ObjCMethodExpr))); for (SmallVectorImpl<prec::Level>::const_reverse_iterator I = Current.FakeLParens.rbegin(), @@ -1318,9 +1284,6 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, NewParenState.Tok = nullptr; NewParenState.ContainsLineBreak = false; NewParenState.LastOperatorWrapped = true; - NewParenState.IsChainedConditional = false; - NewParenState.IsWrappedConditional = false; - NewParenState.UnindentOperator = false; NewParenState.NoLineBreak = NewParenState.NoLineBreak || State.Stack.back().NoLineBreakInOperand; @@ -1332,26 +1295,14 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, // a builder type call after 'return' or, if the alignment after opening // brackets is disabled. if (!Current.isTrailingComment() && - (Style.AlignOperands != FormatStyle::OAS_DontAlign || - *I < prec::Assignment) && + (Style.AlignOperands || *I < prec::Assignment) && (!Previous || Previous->isNot(tok::kw_return) || (Style.Language != FormatStyle::LK_Java && *I > 0)) && (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign || - *I != prec::Comma || Current.NestingLevel == 0)) { + *I != prec::Comma || Current.NestingLevel == 0)) NewParenState.Indent = std::max(std::max(State.Column, NewParenState.Indent), State.Stack.back().LastSpace); - } - - // If BreakBeforeBinaryOperators is set, un-indent a bit to account for - // the operator and keep the operands aligned - if (Style.AlignOperands == FormatStyle::OAS_AlignAfterOperator && Previous && - (Previous->getPrecedence() == prec::Assignment || - Previous->is(tok::kw_return) || - (*I == prec::Conditional && Previous->is(tok::question) && - Previous->is(TT_ConditionalExpr))) && - !Newline) - NewParenState.UnindentOperator = true; // Do not indent relative to the fake parentheses inserted for "." or "->". // This is a special case to make the following to statements consistent: @@ -1365,21 +1316,14 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) NewParenState.StartOfFunctionCall = State.Column; - // Indent conditional expressions, unless they are chained "else-if" - // conditionals. Never indent expression where the 'operator' is ',', ';' or - // an assignment (i.e. *I <= prec::Assignment) as those have diff erent - // indentation rules. Indent other expression, unless the indentation needs - // to be skipped. - if (*I == prec::Conditional && Previous && Previous->is(tok::colon) && - Previous->is(TT_ConditionalExpr) && I == Current.FakeLParens.rbegin() && - !State.Stack.back().IsWrappedConditional) { - NewParenState.IsChainedConditional = true; - NewParenState.UnindentOperator = State.Stack.back().UnindentOperator; - } else if (*I == prec::Conditional || - (!SkipFirstExtraIndent && *I > prec::Assignment && - !Current.isTrailingComment())) { + // Always indent conditional expressions. Never indent expression where + // the 'operator' is ',', ';' or an assignment (i.e. *I <= + // prec::Assignment) as those have diff erent indentation rules. Indent + // other expression, unless the indentation needs to be skipped. + if (*I == prec::Conditional || + (!SkipFirstExtraIndent && *I > prec::Assignment && + !Current.isTrailingComment())) NewParenState.Indent += Style.ContinuationIndentWidth; - } if ((Previous && !Previous->opensScope()) || *I != prec::Comma) NewParenState.BreakBeforeParameter = false; State.Stack.push_back(NewParenState); diff --git a/clang/lib/Format/ContinuationIndenter.h b/clang/lib/Format/ContinuationIndenter.h index 5caa1b5bad0e..5ad4548529d7 100644 --- a/clang/lib/Format/ContinuationIndenter.h +++ b/clang/lib/Format/ContinuationIndenter.h @@ -202,15 +202,14 @@ struct ParenState { ParenState(const FormatToken *Tok, unsigned Indent, unsigned LastSpace, bool AvoidBinPacking, bool NoLineBreak) : Tok(Tok), Indent(Indent), LastSpace(LastSpace), - NestedBlockIndent(Indent), BreakBeforeClosingBrace(false), - AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false), - NoLineBreak(NoLineBreak), NoLineBreakInOperand(false), - LastOperatorWrapped(true), ContainsLineBreak(false), - ContainsUnwrappedBuilder(false), AlignColons(true), - ObjCSelectorNameFound(false), HasMultipleNestedBlocks(false), - NestedBlockInlined(false), IsInsideObjCArrayLiteral(false), - IsCSharpGenericTypeConstraint(false), IsChainedConditional(false), - IsWrappedConditional(false), UnindentOperator(false) {} + NestedBlockIndent(Indent), IsAligned(false), + BreakBeforeClosingBrace(false), AvoidBinPacking(AvoidBinPacking), + BreakBeforeParameter(false), NoLineBreak(NoLineBreak), + NoLineBreakInOperand(false), LastOperatorWrapped(true), + ContainsLineBreak(false), ContainsUnwrappedBuilder(false), + AlignColons(true), ObjCSelectorNameFound(false), + HasMultipleNestedBlocks(false), NestedBlockInlined(false), + IsInsideObjCArrayLiteral(false), IsCSharpGenericTypeConstraint(false) {} /// \brief The token opening this parenthesis level, or nullptr if this level /// is opened by fake parenthesis. @@ -336,18 +335,6 @@ struct ParenState { bool IsCSharpGenericTypeConstraint : 1; - /// \brief true if the current \c ParenState represents the false branch of - /// a chained conditional expression (e.g. else-if) - bool IsChainedConditional : 1; - - /// \brief true if there conditionnal was wrapped on the first operator (the - /// question mark) - bool IsWrappedConditional : 1; - - /// \brief Indicates the indent should be reduced by the length of the - /// operator. - bool UnindentOperator : 1; - bool operator<(const ParenState &Other) const { if (Indent != Other.Indent) return Indent < Other.Indent; @@ -389,12 +376,6 @@ struct ParenState { return NestedBlockInlined; if (IsCSharpGenericTypeConstraint != Other.IsCSharpGenericTypeConstraint) return IsCSharpGenericTypeConstraint; - if (IsChainedConditional != Other.IsChainedConditional) - return IsChainedConditional; - if (IsWrappedConditional != Other.IsWrappedConditional) - return IsWrappedConditional; - if (UnindentOperator != Other.UnindentOperator) - return UnindentOperator; return false; } }; diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index c8fcb5b81cfe..eead2b4a520a 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -308,18 +308,6 @@ struct ScalarEnumerationTraits<FormatStyle::EscapedNewlineAlignmentStyle> { } }; -template <> struct ScalarEnumerationTraits<FormatStyle::OperandAlignmentStyle> { - static void enumeration(IO &IO, FormatStyle::OperandAlignmentStyle &Value) { - IO.enumCase(Value, "DontAlign", FormatStyle::OAS_DontAlign); - IO.enumCase(Value, "Align", FormatStyle::OAS_Align); - IO.enumCase(Value, "AlignAfterOperator", FormatStyle::OAS_AlignAfterOperator); - - // For backward compatibility. - IO.enumCase(Value, "true", FormatStyle::OAS_Align); - IO.enumCase(Value, "false", FormatStyle::OAS_DontAlign); - } -}; - template <> struct ScalarEnumerationTraits<FormatStyle::PointerAlignmentStyle> { static void enumeration(IO &IO, FormatStyle::PointerAlignmentStyle &Value) { IO.enumCase(Value, "Middle", FormatStyle::PAS_Middle); @@ -756,7 +744,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AccessModifierOffset = -2; LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right; LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align; - LLVMStyle.AlignOperands = FormatStyle::OAS_Align; + LLVMStyle.AlignOperands = true; LLVMStyle.AlignTrailingComments = true; LLVMStyle.AlignConsecutiveAssignments = false; LLVMStyle.AlignConsecutiveDeclarations = false; @@ -955,7 +943,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { if (Language == FormatStyle::LK_Java) { GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; - GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign; + GoogleStyle.AlignOperands = false; GoogleStyle.AlignTrailingComments = false; GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; GoogleStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; @@ -966,7 +954,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.SpacesBeforeTrailingComments = 1; } else if (Language == FormatStyle::LK_JavaScript) { GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; - GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign; + GoogleStyle.AlignOperands = false; GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; // TODO: still under discussion whether to switch to SLS_All. GoogleStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Empty; @@ -1097,7 +1085,7 @@ FormatStyle getWebKitStyle() { FormatStyle Style = getLLVMStyle(); Style.AccessModifierOffset = -4; Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; - Style.AlignOperands = FormatStyle::OAS_DontAlign; + Style.AlignOperands = false; Style.AlignTrailingComments = false; Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Empty; Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All; diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index ac033c023f6e..bc71a89fc92b 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -95,7 +95,6 @@ const tooling::Replacements &WhitespaceManager::generateReplacements() { alignConsecutiveMacros(); alignConsecutiveDeclarations(); alignConsecutiveAssignments(); - alignChainedConditionals(); alignTrailingComments(); alignEscapedNewlines(); generateChanges(); @@ -228,32 +227,6 @@ void WhitespaceManager::calculateLineBreakInformation() { LastBlockComment = nullptr; } } - - // Compute conditional nesting level - // Level is increased for each conditional, unless this conditional continues - // a chain of conditional, i.e. starts immediately after the colon of another - // conditional. - SmallVector<bool, 16> ScopeStack; - int ConditionalsLevel = 0; - for (auto &Change : Changes) { - for (unsigned i = 0, e = Change.Tok->FakeLParens.size(); i != e; ++i) { - bool isNestedConditional = - Change.Tok->FakeLParens[e - 1 - i] == prec::Conditional && - !(i == 0 && Change.Tok->Previous && - Change.Tok->Previous->is(TT_ConditionalExpr) && - Change.Tok->Previous->is(tok::colon)); - if (isNestedConditional) - ++ConditionalsLevel; - ScopeStack.push_back(isNestedConditional); - } - - Change.ConditionalsLevel = ConditionalsLevel; - - for (unsigned i = Change.Tok->FakeRParens; i > 0 && ScopeStack.size(); --i) { - if (ScopeStack.pop_back_val()) - --ConditionalsLevel; - } - } } // Align a single sequence of tokens, see AlignTokens below. @@ -275,7 +248,6 @@ AlignTokenSequence(unsigned Start, unsigned End, unsigned Column, F &&Matches, // double z); // In the above example, we need to take special care to ensure that // 'double z' is indented along with it's owning function 'b'. - // Special handling is required for 'nested' ternary operators. SmallVector<unsigned, 16> ScopeStack; for (unsigned i = Start; i != End; ++i) { @@ -316,10 +288,7 @@ AlignTokenSequence(unsigned Start, unsigned End, unsigned Column, F &&Matches, unsigned ScopeStart = ScopeStack.back(); if (Changes[ScopeStart - 1].Tok->is(TT_FunctionDeclarationName) || (ScopeStart > Start + 1 && - Changes[ScopeStart - 2].Tok->is(TT_FunctionDeclarationName)) || - Changes[i].Tok->is(TT_ConditionalExpr) || - (Changes[i].Tok->Previous && - Changes[i].Tok->Previous->is(TT_ConditionalExpr))) + Changes[ScopeStart - 2].Tok->is(TT_FunctionDeclarationName))) Changes[i].Spaces += Shift; } @@ -372,7 +341,7 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches, // abort when we hit any token in a higher scope than the starting one. auto IndentAndNestingLevel = StartAt < Changes.size() ? Changes[StartAt].indentAndNestingLevel() - : std::tuple<unsigned, unsigned, unsigned>(); + : std::pair<unsigned, unsigned>(0, 0); // Keep track of the number of commas before the matching tokens, we will only // align a sequence of matching tokens if they are preceded by the same number @@ -440,8 +409,8 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches, StartOfSequence = i; unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; - int LineLengthAfter = Changes[i].TokenLength; - for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) + int LineLengthAfter = -Changes[i].Spaces; + for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j) LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength; unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; @@ -639,52 +608,6 @@ void WhitespaceManager::alignConsecutiveDeclarations() { Changes, /*StartAt=*/0); } -void WhitespaceManager::alignChainedConditionals() -{ - if (Style.BreakBeforeTernaryOperators) { - AlignTokens(Style, - [](Change const &C) { - // Align question operators and last colon - return C.Tok->is(TT_ConditionalExpr) && - ((C.Tok->is(tok::question) && !C.NewlinesBefore) || - (C.Tok->is(tok::colon) && C.Tok->Next && - (C.Tok->Next->FakeLParens.size() == 0 || - C.Tok->Next->FakeLParens.back() != - prec::Conditional))); - }, - Changes, /*StartAt=*/0); - } else { - static auto AlignWrappedOperand = [](Change const &C) { - auto Previous = C.Tok->getPreviousNonComment();//Previous; - return C.NewlinesBefore && Previous && Previous->is(TT_ConditionalExpr) && - (Previous->is(tok::question) || - (Previous->is(tok::colon) && - (C.Tok->FakeLParens.size() == 0 || - C.Tok->FakeLParens.back() != prec::Conditional))); - }; - // Ensure we keep alignment of wrapped operands with non-wrapped operands - // Since we actually align the operators, the wrapped operands need the - // extra offset to be properly aligned. - for (Change & C: Changes) { - if (AlignWrappedOperand(C)) - C.StartOfTokenColumn -= 2; - } - AlignTokens(Style, - [this](Change const &C) { - // Align question operators if next operand is not wrapped, as - // well as wrapped operands after question operator or last - // colon in conditional sequence - return (C.Tok->is(TT_ConditionalExpr) && - C.Tok->is(tok::question) && - &C != &Changes.back() && - (&C + 1)->NewlinesBefore == 0 && - !(&C + 1)->IsTrailingComment) || - AlignWrappedOperand(C); - }, - Changes, /*StartAt=*/0); - } -} - void WhitespaceManager::alignTrailingComments() { unsigned MinColumn = 0; unsigned MaxColumn = UINT_MAX; diff --git a/clang/lib/Format/WhitespaceManager.h b/clang/lib/Format/WhitespaceManager.h index 87f24e97f0fb..a9f83920801f 100644 --- a/clang/lib/Format/WhitespaceManager.h +++ b/clang/lib/Format/WhitespaceManager.h @@ -19,7 +19,6 @@ #include "clang/Basic/SourceManager.h" #include "clang/Format/Format.h" #include <string> -#include <tuple> namespace clang { namespace format { @@ -159,16 +158,11 @@ class WhitespaceManager { const Change *StartOfBlockComment; int IndentationOffset; - // Depth of conditionals. Computed from tracking fake parenthesis, except - // it does not increase the indent for "chained" conditionals. - int ConditionalsLevel; - - // A combination of indent, nesting and conditionals levels, which are used - // in tandem to compute lexical scope, for the purposes of deciding + // A combination of indent level and nesting level, which are used in + // tandem to compute lexical scope, for the purposes of deciding // when to stop consecutive alignment runs. - std::tuple<unsigned, unsigned, unsigned> indentAndNestingLevel() const { - return std::make_tuple(Tok->IndentLevel, Tok->NestingLevel, - ConditionalsLevel); + std::pair<unsigned, unsigned> indentAndNestingLevel() const { + return std::make_pair(Tok->IndentLevel, Tok->NestingLevel); } }; @@ -187,9 +181,6 @@ class WhitespaceManager { /// Align consecutive declarations over all \c Changes. void alignConsecutiveDeclarations(); - /// Align consecutive declarations over all \c Changes. - void alignChainedConditionals(); - /// Align trailing comments over all \c Changes. void alignTrailingComments(); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 25555802a568..69a2001cd995 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4240,9 +4240,6 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) { " > ccccc) {\n" "}", Style); - verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " && bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;", - Style); verifyFormat("return (a)\n" " // comment\n" " + b;", @@ -4271,7 +4268,7 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) { Style.ColumnLimit = 60; verifyFormat("zzzzzzzzzz\n" - " = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" + " = bbbbbbbbbbbbbbbbb\n" " >> aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa);", Style); @@ -4280,7 +4277,7 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) { Style.TabWidth = 4; Style.UseTab = FormatStyle::UT_Always; Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; - Style.AlignOperands = FormatStyle::OAS_DontAlign; + Style.AlignOperands = false; EXPECT_EQ("return someVeryVeryLongConditionThatBarelyFitsOnALine\n" "\t&& (someOtherLongishConditionPart1\n" "\t\t|| someOtherEvenLongerNestedConditionPart2);", @@ -4290,107 +4287,6 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) { Style)); } -TEST_F(FormatTest, ExpressionIndentationStrictAlign) { - FormatStyle Style = getLLVMStyle(); - Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All; - Style.AlignOperands = FormatStyle::OAS_AlignAfterOperator; - - verifyFormat("bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" - " + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" - " && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " > ccccccccccccccccccccccccccccccccccccccccc;", - Style); - verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " == bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) {\n}", - Style); - verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " == bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) {\n}", - Style); - verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) {\n}", - Style); - verifyFormat("if () {\n" - "} else if (aaaaa\n" - " && bbbbb // break\n" - " > ccccc) {\n" - "}", - Style); - verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " && bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;", - Style); - verifyFormat("return (a)\n" - " // comment\n" - " + b;", - Style); - verifyFormat( - "int aaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" - " + cc;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : ccccccccccccccc ? dddddddddddddddddd\n" - " : eeeeeeeeeeeeeeeeee)\n" - " : bbbbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" - " = aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaa;", - Style); - - verifyFormat("return boost::fusion::at_c<0>(iiii).second\n" - " == boost::fusion::at_c<1>(iiii).second;", - Style); - - Style.ColumnLimit = 60; - verifyFormat("zzzzzzzzzzzzz\n" - " = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" - " >> aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa);", - Style); - - // Forced by comments. - Style.ColumnLimit = 80; - verifyFormat( - "unsigned ContentSize\n" - " = sizeof(int16_t) // DWARF ARange version number\n" - " + sizeof(int32_t) // Offset of CU in the .debug_info section\n" - " + sizeof(int8_t) // Pointer Size (in bytes)\n" - " + sizeof(int8_t); // Segment Size (in bytes)", - Style); - - Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; - verifyFormat( - "unsigned ContentSize =\n" - " sizeof(int16_t) // DWARF ARange version number\n" - " + sizeof(int32_t) // Offset of CU in the .debug_info section\n" - " + sizeof(int8_t) // Pointer Size (in bytes)\n" - " + sizeof(int8_t); // Segment Size (in bytes)", - Style); - - Style.BreakBeforeBinaryOperators = FormatStyle::BOS_None; - verifyFormat( - "unsigned ContentSize =\n" - " sizeof(int16_t) // DWARF ARange version number\n" - " + sizeof(int32_t) // Offset of CU in the .debug_info section\n" - " + sizeof(int8_t) // Pointer Size (in bytes)\n" - " + sizeof(int8_t); // Segment Size (in bytes)", - Style); -} - TEST_F(FormatTest, EnforcedOperatorWraps) { // Here we'd like to wrap after the || operators, but a comment is forcing an // earlier wrap. @@ -4402,7 +4298,7 @@ TEST_F(FormatTest, EnforcedOperatorWraps) { TEST_F(FormatTest, NoOperandAlignment) { FormatStyle Style = getLLVMStyle(); - Style.AlignOperands = FormatStyle::OAS_DontAlign; + Style.AlignOperands = false; verifyFormat("aaaaaaaaaaaaaa(aaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);", @@ -5902,17 +5798,17 @@ TEST_F(FormatTest, ParenthesesAndOperandAlignment) { " bbbbbbbbbbbbbbbbbbbbbb);", Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_Align; - Style.AlignOperands = FormatStyle::OAS_DontAlign; + Style.AlignOperands = false; verifyFormat("int a = f(aaaaaaaaaaaaaaaaaaaaaa &&\n" " bbbbbbbbbbbbbbbbbbbbbb);", Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; - Style.AlignOperands = FormatStyle::OAS_Align; + Style.AlignOperands = true; verifyFormat("int a = f(aaaaaaaaaaaaaaaaaaaaaa &&\n" " bbbbbbbbbbbbbbbbbbbbbb);", Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; - Style.AlignOperands = FormatStyle::OAS_DontAlign; + Style.AlignOperands = false; verifyFormat("int a = f(aaaaaaaaaaaaaaaaaaaaaa &&\n" " bbbbbbbbbbbbbbbbbbbbbb);", Style); @@ -6054,113 +5950,6 @@ TEST_F(FormatTest, BreaksConditionalExpressions) { " // comment\n" " ? a = b\n" " : a;"); - - // Chained conditionals - FormatStyle Style = getLLVMStyle(); - Style.ColumnLimit = 70; - Style.AlignOperands = FormatStyle::OAS_Align; - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbb ? 222222\n" - " : 333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : cccccccccccccc ? 3333333333333333\n" - " : 4444444444444444;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaa ? bbb : ccc)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : (aaa ? bbb : ccc);", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccccccccc)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccccccccc)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? a = (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : dddddddddddddddddd)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? a + (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : dddddddddddddddddd)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : a + (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : dddddddddddddddddd)\n", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccccccccc);", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : ccccccccccccccc ? dddddddddddddddddd\n" - " : eeeeeeeeeeeeeeeeee)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : ccccccccccccccc ? dddddddddddddddddd\n" - " : eeeeeeeeeeeeeeeeee)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccc ? dddddddddddddddddd\n" - " : eeeeeeeeeeeeeeeeee)\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccccccccc\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccccccc ? dddddddddddddddddd\n" - " : eeeeeeeeeeeeeeeeee\n" - " : bbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaaaaaaa\n" - " ? (aaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccccccccc ? dddddddddddddddddd\n" - " : eeeeeeeeeeeeeeeeee)\n" - " : bbbbbbbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaa\n" - " ? aaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : cccccccccccccccc ? dddddddddddddddddd\n" - " : eeeeeeeeeeeeeeeeee\n" - " : bbbbbbbbbbbbbbbbbbbbbbb ? 2222222222222222\n" - " : 3333333333333333;", - Style); } TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { @@ -6266,110 +6055,6 @@ TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { " aaaaa :\n" " bbbbbbbbbbbbbbb + cccccccccccccccc;", Style); - - // Chained conditionals - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbbbbbbbb ? 222222 :\n" - " 333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " cccccccccccccccc ? 3333333333333333 :\n" - " 4444444444444444;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaa ? bbb : ccc) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " (aaa ? bbb : ccc);", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " cccccccccccccccccc) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " cccccccccccccccccc) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? a = (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " dddddddddddddddddd) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? a + (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " dddddddddddddddddd) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " a + (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " dddddddddddddddddd)\n", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? 1111111111111111 :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " cccccccccccccccccc);", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " ccccccccccccccccc ? dddddddddddddddddd :\n" - " eeeeeeeeeeeeeeeeee) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " ccccccccccccc ? dddddddddddddddddd :\n" - " eeeeeeeeeeeeeeeeee) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " ccccccccccccccccc ? dddddddddddddddddd :\n" - " eeeeeeeeeeeeeeeeee) :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " cccccccccccccccccc :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " cccccccccccccccccc ? dddddddddddddddddd :\n" - " eeeeeeeeeeeeeeeeee :\n" - " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaaaaaaa ?\n" - " (aaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " cccccccccccccccccc ? dddddddddddddddddd :\n" - " eeeeeeeeeeeeeeeeee) :\n" - " bbbbbbbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); - verifyFormat("return aaaaaaaaaaaaaaaaaaaaa ?\n" - " aaaaaaaaaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " cccccccccccccccccccc ? dddddddddddddddddd :\n" - " eeeeeeeeeeeeeeeeee :\n" - " bbbbbbbbbbbbbbbbbbbbb ? 2222222222222222 :\n" - " 3333333333333333;", - Style); } TEST_F(FormatTest, DeclarationsOfMultipleVariables) { @@ -13240,6 +12925,7 @@ TEST_F(FormatTest, GetsCorrectBasedOnStyle) { TEST_F(FormatTest, ParsesConfigurationBools) { FormatStyle Style = {}; Style.Language = FormatStyle::LK_Cpp; + CHECK_PARSE_BOOL(AlignOperands); CHECK_PARSE_BOOL(AlignTrailingComments); CHECK_PARSE_BOOL(AlignConsecutiveAssignments); CHECK_PARSE_BOOL(AlignConsecutiveDeclarations); @@ -13423,17 +13109,6 @@ TEST_F(FormatTest, ParsesConfiguration) { CHECK_PARSE("AlignEscapedNewlinesLeft: false", AlignEscapedNewlines, FormatStyle::ENAS_Right); - Style.AlignOperands = FormatStyle::OAS_Align; - CHECK_PARSE("AlignOperands: DontAlign", AlignOperands, - FormatStyle::OAS_DontAlign); - CHECK_PARSE("AlignOperands: Align", AlignOperands, FormatStyle::OAS_Align); - CHECK_PARSE("AlignOperands: AlignAfterOperator", AlignOperands, - FormatStyle::OAS_AlignAfterOperator); - // For backward compatibility: - CHECK_PARSE("AlignOperands: false", AlignOperands, - FormatStyle::OAS_DontAlign); - CHECK_PARSE("AlignOperands: true", AlignOperands, FormatStyle::OAS_Align); - Style.UseTab = FormatStyle::UT_ForIndentation; CHECK_PARSE("UseTab: Never", UseTab, FormatStyle::UT_Never); CHECK_PARSE("UseTab: ForIndentation", UseTab, FormatStyle::UT_ForIndentation); diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index c1c47065c185..eadea35f051a 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -277,7 +277,7 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) { verifyFormat("var x = aaaaaaaaaaaaaaaaaaaaaaaaa() in\n" " aaaa.aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;"); FormatStyle Style = getGoogleJSStyleWithColumns(80); - Style.AlignOperands = FormatStyle::OAS_Align; + Style.AlignOperands = true; verifyFormat("var x = aaaaaaaaaaaaaaaaaaaaaaaaa() in\n" " aaaa.aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;", Style); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits