diff options
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 48 | 
1 files changed, 32 insertions, 16 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 021d8c6..cb41756c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -358,11 +358,11 @@ private:        Contexts.back().IsExpression = false;      } else if (OpeningParen.Previous &&                 (OpeningParen.Previous->isOneOf( -                    tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit, -                    tok::kw_while, tok::l_paren, tok::comma, TT_CastRParen, +                    tok::kw_noexcept, tok::kw_explicit, tok::kw_while, +                    tok::l_paren, tok::comma, TT_CastRParen,                      TT_BinaryOperator) ||                  OpeningParen.Previous->isIf())) { -      // static_assert, if and while usually contain expressions. +      // if and while usually contain expressions.        Contexts.back().IsExpression = true;      } else if (Style.isJavaScript() && OpeningParen.Previous &&                 (OpeningParen.Previous->is(Keywords.kw_function) || @@ -454,6 +454,11 @@ private:      if (StartsObjCSelector)        OpeningParen.setType(TT_ObjCSelector); +    const bool IsStaticAssert = +        PrevNonComment && PrevNonComment->is(tok::kw_static_assert); +    if (IsStaticAssert) +      Contexts.back().InStaticAssertFirstArgument = true; +      // MightBeFunctionType and ProbablyFunctionType are used for      // function pointer and reference types as well as Objective-C      // block types: @@ -583,8 +588,12 @@ private:        }        // When we discover a 'new', we set CanBeExpression to 'false' in order to        // parse the type correctly. Reset that after a comma. -      if (CurrentToken->is(tok::comma)) -        Contexts.back().CanBeExpression = true; +      if (CurrentToken->is(tok::comma)) { +        if (IsStaticAssert) +          Contexts.back().InStaticAssertFirstArgument = false; +        else +          Contexts.back().CanBeExpression = true; +      }        if (Style.isTableGen()) {          if (CurrentToken->is(tok::comma)) { @@ -2144,6 +2153,7 @@ private:      bool CaretFound = false;      bool InCpp11AttributeSpecifier = false;      bool InCSharpAttributeSpecifier = false; +    bool InStaticAssertFirstArgument = false;      bool VerilogAssignmentFound = false;      // Whether the braces may mean concatenation instead of structure or array      // literal. @@ -2440,7 +2450,8 @@ private:      } else if (Current.isPointerOrReference()) {        Current.setType(determineStarAmpUsage(            Current, -          Contexts.back().CanBeExpression && Contexts.back().IsExpression, +          (Contexts.back().CanBeExpression && Contexts.back().IsExpression) || +              Contexts.back().InStaticAssertFirstArgument,            Contexts.back().ContextType == Context::TemplateArgument));      } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret) ||                 (Style.isVerilog() && Current.is(tok::pipe))) { @@ -4427,10 +4438,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,    if (Left.is(tok::l_paren) && Style.PenaltyBreakOpenParenthesis != 0)      return Style.PenaltyBreakOpenParenthesis; -  if (Left.is(tok::l_paren) && InFunctionDecl && -      Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) { +  if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket)      return 100; -  }    if (Left.is(tok::l_paren) && Left.Previous &&        (Left.Previous->isOneOf(tok::kw_for, tok::kw__Generic) ||         Left.Previous->isIf())) { @@ -4446,7 +4455,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,      // If we aren't aligning after opening parens/braces we can always break      // here unless the style does not want us to place all arguments on the      // next line. -    if (Style.AlignAfterOpenBracket == FormatStyle::BAS_DontAlign && +    if (!Style.AlignAfterOpenBracket &&          (Left.ParameterCount <= 1 || Style.AllowAllArgumentsOnNextLine)) {        return 0;      } @@ -6226,24 +6235,31 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,                                     (Right.isBlockIndentedInitRBrace(Style)));    } -  // We only break before r_paren if we're in a block indented context. +  // We can break before r_paren if we're in a block indented context or +  // a control statement with an explicit style option.    if (Right.is(tok::r_paren)) { -    if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent || -        !Right.MatchingParen) { +    if (!Right.MatchingParen)        return false; -    }      auto Next = Right.Next;      if (Next && Next->is(tok::r_paren))        Next = Next->Next;      if (Next && Next->is(tok::l_paren))        return false;      const FormatToken *Previous = Right.MatchingParen->Previous; -    return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf())); +    if (!Previous) +      return false; +    if (Previous->isIf()) +      return Style.BreakBeforeCloseBracketIf; +    if (Previous->isLoop(Style)) +      return Style.BreakBeforeCloseBracketLoop; +    if (Previous->is(tok::kw_switch)) +      return Style.BreakBeforeCloseBracketSwitch; +    return Style.BreakBeforeCloseBracketFunction;    }    if (Left.isOneOf(tok::r_paren, TT_TrailingAnnotation) &&        Right.is(TT_TrailingAnnotation) && -      Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) { +      Style.BreakBeforeCloseBracketFunction) {      return false;    }  | 
