18#include "llvm/ADT/SmallPtrSet.h" 
   19#include "llvm/Support/Debug.h" 
   21#define DEBUG_TYPE "format-token-annotator" 
   27                                     const FormatStyle &Style) {
 
   28  switch (Style.BreakAfterAttributes) {
 
   29  case FormatStyle::ABS_Always:
 
   31  case FormatStyle::ABS_Leave:
 
   32    return Tok.NewlinesBefore > 0;
 
 
   42static bool startsWithInitStatement(
const AnnotatedLine &
Line) {
 
   43  return Line.startsWith(tok::kw_for) || 
Line.startsWith(tok::kw_if) ||
 
   44         Line.startsWith(tok::kw_switch);
 
   59  return Tok.Tok.getIdentifierInfo();
 
   65static bool isLambdaParameterList(
const FormatToken *Left) {
 
   67  if (
Left->Previous && 
Left->Previous->is(tok::greater) &&
 
   68      Left->Previous->MatchingParen &&
 
   69      Left->Previous->MatchingParen->is(TT_TemplateOpener)) {
 
   70    Left = 
Left->Previous->MatchingParen;
 
   74  return Left->Previous && 
Left->Previous->is(tok::r_square) &&
 
   75         Left->Previous->MatchingParen &&
 
   76         Left->Previous->MatchingParen->is(TT_LambdaLSquare);
 
   82  return Tok.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, tok::kw_switch,
 
   83                     tok::kw_constexpr, tok::kw_catch);
 
   88  if (!IsCpp || !
Tok.startsSequence(tok::l_square, tok::l_square))
 
   91  if (
Tok.Previous && 
Tok.Previous->is(tok::at))
 
   98  if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
 
  100  if (AttrTok->isNot(tok::identifier))
 
  102  while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
 
  106    if (AttrTok->is(tok::colon) ||
 
  107        AttrTok->startsSequence(tok::identifier, tok::identifier) ||
 
  108        AttrTok->startsSequence(tok::r_paren, tok::identifier)) {
 
  111    if (AttrTok->is(tok::ellipsis))
 
  113    AttrTok = AttrTok->Next;
 
  115  return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
 
  123class AnnotatingParser {
 
  125  AnnotatingParser(
const FormatStyle &Style, AnnotatedLine &Line,
 
  126                   const AdditionalKeywords &Keywords,
 
  127                   SmallVector<ScopeType> &Scopes)
 
  128      : Style(Style), Line(Line), CurrentToken(Line.
First), AutoFound(
false),
 
  130        Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
 
  131    Contexts.push_back(Context(tok::unknown, 1, 
false));
 
  132    resetTokenMetadata();
 
  137    switch (Token.getType()) {
 
  139    case TT_StructLBrace:
 
  142    case TT_CompoundRequirementLBrace:
 
  153    auto *
Left = CurrentToken->Previous; 
 
  157    if (NonTemplateLess.count(Left) > 0)
 
  160    const auto *BeforeLess = 
Left->Previous;
 
  163      if (BeforeLess->Tok.isLiteral())
 
  165      if (BeforeLess->is(tok::r_brace))
 
  167      if (BeforeLess->is(tok::r_paren) && Contexts.size() > 1 &&
 
  168          !(BeforeLess->MatchingParen &&
 
  169            BeforeLess->MatchingParen->is(TT_OverloadedOperatorLParen))) {
 
  172      if (BeforeLess->is(tok::kw_operator) && CurrentToken->is(tok::l_paren))
 
  176    Left->ParentBracket = Contexts.back().ContextKind;
 
  177    ScopedContextCreator ContextCreator(*
this, tok::less, 12);
 
  178    Contexts.back().IsExpression = 
false;
 
  182    if (BeforeLess && BeforeLess->isNot(tok::kw_template))
 
  183      Contexts.back().ContextType = Context::TemplateArgument;
 
  185    if (Style.isJava() && CurrentToken->is(tok::question))
 
  188    for (
bool SeenTernaryOperator = 
false, MaybeAngles = 
true; CurrentToken;) {
 
  189      const bool InExpr = Contexts[Contexts.size() - 2].IsExpression;
 
  190      if (CurrentToken->is(tok::greater)) {
 
  191        const auto *
Next = CurrentToken->Next;
 
  192        if (CurrentToken->isNot(TT_TemplateCloser)) {
 
  199          if (
Next && 
Next->is(tok::greater) &&
 
  200              Left->ParentBracket != tok::less &&
 
  201              CurrentToken->getStartOfNonWhitespace() ==
 
  202                  Next->getStartOfNonWhitespace().getLocWithOffset(-1)) {
 
  205          if (InExpr && SeenTernaryOperator &&
 
  206              (!
Next || 
Next->isNoneOf(tok::l_paren, tok::l_brace))) {
 
  212        Left->MatchingParen = CurrentToken;
 
  213        CurrentToken->MatchingParen = 
Left;
 
  219        if (Style.isTextProto() ||
 
  220            (Style.Language == FormatStyle::LK_Proto && BeforeLess &&
 
  221             BeforeLess->isOneOf(TT_SelectorName, TT_DictLiteral))) {
 
  222          CurrentToken->setType(TT_DictLiteral);
 
  224          CurrentToken->setType(TT_TemplateCloser);
 
  225          CurrentToken->Tok.setLength(1);
 
  232      if (BeforeLess && BeforeLess->is(TT_TemplateName)) {
 
  236      if (CurrentToken->is(tok::question) && Style.isJava()) {
 
  240      if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace))
 
  242      const auto &Prev = *CurrentToken->Previous;
 
  249      if (MaybeAngles && InExpr && !Line.startsWith(tok::kw_template) &&
 
  250          Prev.is(TT_BinaryOperator) &&
 
  251          Prev.isOneOf(tok::pipepipe, tok::ampamp)) {
 
  254      if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
 
  255        SeenTernaryOperator = 
true;
 
  256      updateParameterCount(Left, CurrentToken);
 
  257      if (Style.Language == FormatStyle::LK_Proto) {
 
  259          if (CurrentToken->is(tok::colon) ||
 
  260              (CurrentToken->isOneOf(tok::l_brace, tok::less) &&
 
  265      } 
else if (Style.isTableGen()) {
 
  266        if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
 
  273        if (!parseTableGenValue())
 
  283  bool parseUntouchableParens() {
 
  284    while (CurrentToken) {
 
  285      CurrentToken->Finalized = 
true;
 
  286      switch (CurrentToken->Tok.getKind()) {
 
  289        if (!parseUntouchableParens())
 
  304  bool parseParens(
bool IsIf = 
false) {
 
  307    assert(CurrentToken->Previous && 
"Unknown previous token");
 
  308    FormatToken &OpeningParen = *CurrentToken->Previous;
 
  309    assert(OpeningParen.is(tok::l_paren));
 
  310    FormatToken *PrevNonComment = OpeningParen.getPreviousNonComment();
 
  311    OpeningParen.ParentBracket = Contexts.back().ContextKind;
 
  312    ScopedContextCreator ContextCreator(*
this, tok::l_paren, 1);
 
  315    Contexts.back().ColonIsForRangeExpr =
 
  316        Contexts.size() == 2 && Contexts[0].ColonIsForRangeExpr;
 
  318    if (OpeningParen.Previous &&
 
  319        OpeningParen.Previous->is(TT_UntouchableMacroFunc)) {
 
  320      OpeningParen.Finalized = 
true;
 
  321      return parseUntouchableParens();
 
  324    bool StartsObjCSelector = 
false;
 
  325    if (!Style.isVerilog()) {
 
  326      if (
FormatToken *MaybeSel = OpeningParen.Previous) {
 
  328        if (MaybeSel->is(tok::objc_selector) && MaybeSel->Previous &&
 
  329            MaybeSel->Previous->is(tok::at)) {
 
  330          StartsObjCSelector = 
true;
 
  335    if (OpeningParen.is(TT_OverloadedOperatorLParen)) {
 
  338      while (Prev->isNot(tok::kw_operator)) {
 
  339        Prev = Prev->Previous;
 
  340        assert(Prev && 
"Expect a kw_operator prior to the OperatorLParen!");
 
  346      bool OperatorCalledAsMemberFunction =
 
  347          Prev->Previous && Prev->Previous->isOneOf(tok::period, tok::arrow);
 
  348      Contexts.back().IsExpression = OperatorCalledAsMemberFunction;
 
  349    } 
else if (OpeningParen.is(TT_VerilogInstancePortLParen)) {
 
  350      Contexts.back().IsExpression = 
true;
 
  351      Contexts.back().ContextType = Context::VerilogInstancePortList;
 
  352    } 
else if (Style.isJavaScript() &&
 
  353               (Line.startsWith(Keywords.kw_type, tok::identifier) ||
 
  354                Line.startsWith(tok::kw_export, Keywords.kw_type,
 
  358      Contexts.back().IsExpression = 
false;
 
  359    } 
else if (OpeningParen.Previous &&
 
  360               (OpeningParen.Previous->isOneOf(
 
  361                    tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit,
 
  362                    tok::kw_while, tok::l_paren, tok::comma, TT_CastRParen,
 
  363                    TT_BinaryOperator) ||
 
  364                OpeningParen.Previous->isIf())) {
 
  366      Contexts.back().IsExpression = 
true;
 
  367    } 
else if (Style.isJavaScript() && OpeningParen.Previous &&
 
  368               (OpeningParen.Previous->is(Keywords.kw_function) ||
 
  369                (OpeningParen.Previous->endsSequence(tok::identifier,
 
  370                                                     Keywords.kw_function)))) {
 
  372      Contexts.back().IsExpression = 
false;
 
  373    } 
else if (Style.isJavaScript() && OpeningParen.Previous &&
 
  374               OpeningParen.Previous->is(TT_JsTypeColon)) {
 
  376      Contexts.back().IsExpression = 
false;
 
  377    } 
else if (isLambdaParameterList(&OpeningParen)) {
 
  379      OpeningParen.setType(TT_LambdaDefinitionLParen);
 
  380      Contexts.back().IsExpression = 
false;
 
  381    } 
else if (OpeningParen.is(TT_RequiresExpressionLParen)) {
 
  382      Contexts.back().IsExpression = 
false;
 
  383    } 
else if (OpeningParen.Previous &&
 
  384               OpeningParen.Previous->is(tok::kw__Generic)) {
 
  385      Contexts.back().ContextType = Context::C11GenericSelection;
 
  386      Contexts.back().IsExpression = 
true;
 
  387    } 
else if (OpeningParen.Previous &&
 
  388               OpeningParen.Previous->TokenText == 
"Q_PROPERTY") {
 
  389      Contexts.back().ContextType = Context::QtProperty;
 
  390      Contexts.back().IsExpression = 
false;
 
  391    } 
else if (Line.InPPDirective &&
 
  392               (!OpeningParen.Previous ||
 
  393                OpeningParen.Previous->isNot(tok::identifier))) {
 
  394      Contexts.back().IsExpression = 
true;
 
  395    } 
else if (Contexts[Contexts.size() - 2].CaretFound) {
 
  397      Contexts.back().IsExpression = 
false;
 
  398    } 
else if (OpeningParen.Previous &&
 
  399               OpeningParen.Previous->is(TT_ForEachMacro)) {
 
  401      Contexts.back().ContextType = Context::ForEachMacro;
 
  402      Contexts.back().IsExpression = 
false;
 
  403    } 
else if (OpeningParen.Previous && OpeningParen.Previous->MatchingParen &&
 
  404               OpeningParen.Previous->MatchingParen->isOneOf(
 
  405                   TT_ObjCBlockLParen, TT_FunctionTypeLParen)) {
 
  406      Contexts.back().IsExpression = 
false;
 
  407    } 
else if (!Line.MustBeDeclaration &&
 
  408               (!Line.InPPDirective || (Line.InMacroBody && !Scopes.empty()))) {
 
  410          OpeningParen.Previous &&
 
  411          OpeningParen.Previous->isOneOf(tok::kw_for, tok::kw_catch);
 
  412      Contexts.back().IsExpression = !IsForOrCatch;
 
  415    if (Style.isTableGen()) {
 
  417        if (Prev->is(TT_TableGenCondOperator)) {
 
  418          Contexts.back().IsTableGenCondOpe = 
true;
 
  419          Contexts.back().IsExpression = 
true;
 
  420        } 
else if (Contexts.size() > 1 &&
 
  421                   Contexts[Contexts.size() - 2].IsTableGenBangOpe) {
 
  426          Contexts.back().IsTableGenBangOpe = 
true;
 
  427          Contexts.back().IsExpression = 
true;
 
  430          if (!parseTableGenDAGArg())
 
  432          return parseTableGenDAGArgAndList(&OpeningParen);
 
  439    if (PrevNonComment && OpeningParen.is(TT_Unknown)) {
 
  440      if (PrevNonComment->isAttribute()) {
 
  441        OpeningParen.setType(TT_AttributeLParen);
 
  442      } 
else if (PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
 
  445#include 
"clang/Basic/TransformTypeTraits.def" 
  447        OpeningParen.setType(TT_TypeDeclarationParen);
 
  449        if (PrevNonComment->isOneOf(tok::kw_decltype, tok::kw_typeof))
 
  450          Contexts.back().IsExpression = 
true;
 
  454    if (StartsObjCSelector)
 
  455      OpeningParen.setType(TT_ObjCSelector);
 
  465    bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
 
  466    bool ProbablyFunctionType =
 
  467        CurrentToken->isPointerOrReference() || CurrentToken->is(tok::caret);
 
  468    bool HasMultipleLines = 
false;
 
  469    bool HasMultipleParametersOnALine = 
false;
 
  470    bool MightBeObjCForRangeLoop =
 
  471        OpeningParen.Previous && OpeningParen.Previous->is(tok::kw_for);
 
  473    while (CurrentToken) {
 
  474      const auto &Prev = *CurrentToken->Previous;
 
  475      const auto *PrevPrev = Prev.Previous;
 
  476      if (Prev.is(TT_PointerOrReference) &&
 
  477          PrevPrev->isOneOf(tok::l_paren, tok::coloncolon)) {
 
  478        ProbablyFunctionType = 
true;
 
  480      if (CurrentToken->is(tok::comma))
 
  481        MightBeFunctionType = 
false;
 
  482      if (Prev.is(TT_BinaryOperator))
 
  483        Contexts.back().IsExpression = 
true;
 
  484      if (CurrentToken->is(tok::r_paren)) {
 
  485        if (Prev.is(TT_PointerOrReference) &&
 
  486            (PrevPrev == &OpeningParen || PrevPrev->is(tok::coloncolon))) {
 
  487          MightBeFunctionType = 
true;
 
  489        if (OpeningParen.isNot(TT_CppCastLParen) && MightBeFunctionType &&
 
  490            ProbablyFunctionType && CurrentToken->Next &&
 
  491            (CurrentToken->Next->is(tok::l_paren) ||
 
  492             (CurrentToken->Next->is(tok::l_square) &&
 
  493              (Line.MustBeDeclaration ||
 
  494               (PrevNonComment && PrevNonComment->isTypeName(LangOpts)))))) {
 
  495          OpeningParen.setType(OpeningParen.Next->is(tok::caret)
 
  497                                   : TT_FunctionTypeLParen);
 
  499        OpeningParen.MatchingParen = CurrentToken;
 
  500        CurrentToken->MatchingParen = &OpeningParen;
 
  502        if (CurrentToken->Next && CurrentToken->Next->is(tok::l_brace) &&
 
  503            OpeningParen.Previous && OpeningParen.Previous->is(tok::l_paren)) {
 
  509            if (
Tok->is(TT_BinaryOperator) && 
Tok->isPointerOrReference())
 
  510              Tok->setType(TT_PointerOrReference);
 
  514        if (StartsObjCSelector) {
 
  515          CurrentToken->setType(TT_ObjCSelector);
 
  516          if (Contexts.back().FirstObjCSelectorName) {
 
  517            Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
 
  518                Contexts.back().LongestObjCSelectorName;
 
  522        if (OpeningParen.is(TT_AttributeLParen))
 
  523          CurrentToken->setType(TT_AttributeRParen);
 
  524        if (OpeningParen.is(TT_TypeDeclarationParen))
 
  525          CurrentToken->setType(TT_TypeDeclarationParen);
 
  526        if (OpeningParen.Previous &&
 
  527            OpeningParen.Previous->is(TT_JavaAnnotation)) {
 
  528          CurrentToken->setType(TT_JavaAnnotation);
 
  530        if (OpeningParen.Previous &&
 
  531            OpeningParen.Previous->is(TT_LeadingJavaAnnotation)) {
 
  532          CurrentToken->setType(TT_LeadingJavaAnnotation);
 
  535        if (!HasMultipleLines)
 
  537        else if (HasMultipleParametersOnALine)
 
  545      if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
 
  548      if (CurrentToken->is(tok::l_brace) && OpeningParen.is(TT_ObjCBlockLParen))
 
  549        OpeningParen.setType(TT_Unknown);
 
  550      if (CurrentToken->is(tok::comma) && CurrentToken->Next &&
 
  551          !CurrentToken->Next->HasUnescapedNewline &&
 
  552          !CurrentToken->Next->isTrailingComment()) {
 
  553        HasMultipleParametersOnALine = 
true;
 
  555      bool ProbablyFunctionTypeLParen =
 
  556          (CurrentToken->is(tok::l_paren) && CurrentToken->Next &&
 
  557           CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret));
 
  558      if ((Prev.isOneOf(tok::kw_const, tok::kw_auto) ||
 
  559           Prev.isTypeName(LangOpts)) &&
 
  560          !(CurrentToken->is(tok::l_brace) ||
 
  561            (CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen))) {
 
  562        Contexts.back().IsExpression = 
false;
 
  564      if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
 
  565        MightBeObjCForRangeLoop = 
false;
 
  566        if (PossibleObjCForInToken) {
 
  567          PossibleObjCForInToken->setType(TT_Unknown);
 
  568          PossibleObjCForInToken = 
nullptr;
 
  571      if (IsIf && CurrentToken->is(tok::semi)) {
 
  572        for (
auto *
Tok = OpeningParen.Next;
 
  573             Tok != CurrentToken &&
 
  574             Tok->isNoneOf(tok::equal, tok::l_paren, tok::l_brace);
 
  576          if (
Tok->isPointerOrReference())
 
  577            Tok->setFinalizedType(TT_PointerOrReference);
 
  580      if (MightBeObjCForRangeLoop && CurrentToken->is(Keywords.kw_in)) {
 
  581        PossibleObjCForInToken = CurrentToken;
 
  582        PossibleObjCForInToken->setType(TT_ObjCForIn);
 
  586      if (CurrentToken->is(tok::comma))
 
  587        Contexts.back().CanBeExpression = 
true;
 
  589      if (Style.isTableGen()) {
 
  590        if (CurrentToken->is(tok::comma)) {
 
  591          if (Contexts.back().IsTableGenCondOpe)
 
  592            CurrentToken->setType(TT_TableGenCondOperatorComma);
 
  594        } 
else if (CurrentToken->is(tok::colon)) {
 
  595          if (Contexts.back().IsTableGenCondOpe)
 
  596            CurrentToken->setType(TT_TableGenCondOperatorColon);
 
  600        if (!parseTableGenValue())
 
  608      updateParameterCount(&OpeningParen, 
Tok);
 
  609      if (CurrentToken && CurrentToken->HasUnescapedNewline)
 
  610        HasMultipleLines = 
true;
 
  616    if (!Style.isCSharp())
 
  620    if (
Tok.Previous && 
Tok.Previous->is(tok::identifier))
 
  624    if (
Tok.Previous && 
Tok.Previous->is(tok::r_square)) {
 
  635    if (AttrTok->is(tok::r_square))
 
  639    while (AttrTok && AttrTok->isNot(tok::r_square))
 
  640      AttrTok = AttrTok->Next;
 
  646    AttrTok = AttrTok->Next;
 
  651    if (AttrTok->isAccessSpecifierKeyword() ||
 
  652        AttrTok->isOneOf(tok::comment, tok::kw_class, tok::kw_static,
 
  653                         tok::l_square, Keywords.kw_internal)) {
 
  659        AttrTok->Next->startsSequence(tok::identifier, tok::l_paren)) {
 
  675    Left->ParentBracket = Contexts.back().ContextKind;
 
  681    bool CppArrayTemplates =
 
  682        IsCpp && Parent && Parent->is(TT_TemplateCloser) &&
 
  683        (Contexts.back().CanBeExpression || Contexts.back().IsExpression ||
 
  684         Contexts.back().ContextType == Context::TemplateArgument);
 
  686    const bool IsInnerSquare = Contexts.back().InCpp11AttributeSpecifier;
 
  687    const bool IsCpp11AttributeSpecifier =
 
  688        isCppAttribute(IsCpp, *Left) || IsInnerSquare;
 
  691    bool IsCSharpAttributeSpecifier =
 
  692        isCSharpAttributeSpecifier(*Left) ||
 
  693        Contexts.back().InCSharpAttributeSpecifier;
 
  695    bool InsideInlineASM = Line.startsWith(tok::kw_asm);
 
  696    bool IsCppStructuredBinding = 
Left->isCppStructuredBinding(IsCpp);
 
  697    bool StartsObjCMethodExpr =
 
  698        !IsCppStructuredBinding && !InsideInlineASM && !CppArrayTemplates &&
 
  699        IsCpp && !IsCpp11AttributeSpecifier && !IsCSharpAttributeSpecifier &&
 
  700        Contexts.back().CanBeExpression && 
Left->isNot(TT_LambdaLSquare) &&
 
  701        CurrentToken->isNoneOf(tok::l_brace, tok::r_square) &&
 
  703         Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
 
  704                         tok::kw_return, tok::kw_throw) ||
 
  705         Parent->isUnaryOperator() ||
 
  707         Parent->isOneOf(TT_ObjCForIn, TT_CastRParen) ||
 
  710    bool ColonFound = 
false;
 
  712    unsigned BindingIncrease = 1;
 
  713    if (IsCppStructuredBinding) {
 
  714      Left->setType(TT_StructuredBindingLSquare);
 
  715    } 
else if (
Left->is(TT_Unknown)) {
 
  716      if (StartsObjCMethodExpr) {
 
  717        Left->setType(TT_ObjCMethodExpr);
 
  718      } 
else if (InsideInlineASM) {
 
  719        Left->setType(TT_InlineASMSymbolicNameLSquare);
 
  720      } 
else if (IsCpp11AttributeSpecifier) {
 
  721        if (!IsInnerSquare) {
 
  722          Left->setType(TT_AttributeLSquare);
 
  724            Left->Previous->EndsCppAttributeGroup = 
false;
 
  726      } 
else if (Style.isJavaScript() && Parent &&
 
  727                 Contexts.back().ContextKind == tok::l_brace &&
 
  728                 Parent->isOneOf(tok::l_brace, tok::comma)) {
 
  729        Left->setType(TT_JsComputedPropertyName);
 
  730      } 
else if (IsCpp && Contexts.back().ContextKind == tok::l_brace &&
 
  731                 Parent && Parent->isOneOf(tok::l_brace, tok::comma)) {
 
  732        Left->setType(TT_DesignatedInitializerLSquare);
 
  733      } 
else if (IsCSharpAttributeSpecifier) {
 
  734        Left->setType(TT_AttributeLSquare);
 
  735      } 
else if (CurrentToken->is(tok::r_square) && Parent &&
 
  736                 Parent->is(TT_TemplateCloser)) {
 
  737        Left->setType(TT_ArraySubscriptLSquare);
 
  738      } 
else if (Style.isProto()) {
 
  765        Left->setType(TT_ArrayInitializerLSquare);
 
  766        if (!
Left->endsSequence(tok::l_square, tok::numeric_constant,
 
  768            !
Left->endsSequence(tok::l_square, tok::numeric_constant,
 
  770            !
Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
 
  771          Left->setType(TT_ProtoExtensionLSquare);
 
  772          BindingIncrease = 10;
 
  774      } 
else if (!CppArrayTemplates && Parent &&
 
  775                 Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,
 
  776                                 tok::comma, tok::l_paren, tok::l_square,
 
  777                                 tok::question, tok::colon, tok::kw_return,
 
  780        Left->setType(TT_ArrayInitializerLSquare);
 
  782        BindingIncrease = 10;
 
  783        Left->setType(TT_ArraySubscriptLSquare);
 
  787    ScopedContextCreator ContextCreator(*
this, tok::l_square, BindingIncrease);
 
  788    Contexts.back().IsExpression = 
true;
 
  789    if (Style.isJavaScript() && Parent && Parent->is(TT_JsTypeColon))
 
  790      Contexts.back().IsExpression = 
false;
 
  792    Contexts.back().ColonIsObjCMethodExpr = StartsObjCMethodExpr;
 
  793    Contexts.back().InCpp11AttributeSpecifier = IsCpp11AttributeSpecifier;
 
  794    Contexts.back().InCSharpAttributeSpecifier = IsCSharpAttributeSpecifier;
 
  796    while (CurrentToken) {
 
  797      if (CurrentToken->is(tok::r_square)) {
 
  798        if (IsCpp11AttributeSpecifier && !IsInnerSquare) {
 
  799          CurrentToken->setType(TT_AttributeRSquare);
 
  800          CurrentToken->EndsCppAttributeGroup = 
true;
 
  802        if (IsCSharpAttributeSpecifier) {
 
  803          CurrentToken->setType(TT_AttributeRSquare);
 
  804        } 
else if (((CurrentToken->Next &&
 
  805                     CurrentToken->Next->is(tok::l_paren)) ||
 
  806                    (CurrentToken->Previous &&
 
  807                     CurrentToken->Previous->Previous == Left)) &&
 
  808                   Left->is(TT_ObjCMethodExpr)) {
 
  813          StartsObjCMethodExpr = 
false;
 
  814          Left->setType(TT_Unknown);
 
  816        if (StartsObjCMethodExpr && CurrentToken->Previous != Left) {
 
  817          CurrentToken->setType(TT_ObjCMethodExpr);
 
  820          if (!ColonFound && CurrentToken->Previous &&
 
  821              CurrentToken->Previous->is(TT_Unknown) &&
 
  822              canBeObjCSelectorComponent(*CurrentToken->Previous)) {
 
  823            CurrentToken->Previous->setType(TT_SelectorName);
 
  828          if (Parent && Parent->is(TT_PointerOrReference))
 
  829            Parent->overwriteFixedType(TT_BinaryOperator);
 
  831        Left->MatchingParen = CurrentToken;
 
  832        CurrentToken->MatchingParen = 
Left;
 
  837        if (!Contexts.back().FirstObjCSelectorName) {
 
  840            Previous->ObjCSelectorNameParts = 1;
 
  841            Contexts.back().FirstObjCSelectorName = 
Previous;
 
  844          Left->ParameterCount =
 
  845              Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts;
 
  847        if (Contexts.back().FirstObjCSelectorName) {
 
  848          Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
 
  849              Contexts.back().LongestObjCSelectorName;
 
  850          if (
Left->BlockParameterCount > 1)
 
  851            Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName = 0;
 
  853        if (Style.isTableGen() && 
Left->is(TT_TableGenListOpener))
 
  854          CurrentToken->setType(TT_TableGenListCloser);
 
  858      if (CurrentToken->isOneOf(tok::r_paren, tok::r_brace))
 
  860      if (CurrentToken->is(tok::colon)) {
 
  861        if (IsCpp11AttributeSpecifier &&
 
  862            CurrentToken->endsSequence(tok::colon, tok::identifier,
 
  866          CurrentToken->setType(TT_AttributeColon);
 
  867        } 
else if (!Style.isVerilog() && !Line.InPragmaDirective &&
 
  868                   Left->isOneOf(TT_ArraySubscriptLSquare,
 
  869                                 TT_DesignatedInitializerLSquare)) {
 
  870          Left->setType(TT_ObjCMethodExpr);
 
  871          StartsObjCMethodExpr = 
true;
 
  872          Contexts.back().ColonIsObjCMethodExpr = 
true;
 
  873          if (Parent && Parent->is(tok::r_paren)) {
 
  875            Parent->setType(TT_CastRParen);
 
  880      if (CurrentToken->is(tok::comma) && 
Left->is(TT_ObjCMethodExpr) &&
 
  882        Left->setType(TT_ArrayInitializerLSquare);
 
  885      if (Style.isTableGen()) {
 
  886        if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
 
  892          if (!parseTableGenValue())
 
  895        updateParameterCount(Left, 
Tok);
 
  900      updateParameterCount(Left, 
Tok);
 
  905  void skipToNextNonComment() {
 
  907    while (CurrentToken && CurrentToken->is(tok::comment))
 
  916  bool parseTableGenValue(
bool ParseNameMode = 
false) {
 
  919    while (CurrentToken->is(tok::comment))
 
  921    if (!parseTableGenSimpleValue())
 
  926    if (CurrentToken->is(tok::hash)) {
 
  927      if (CurrentToken->Next &&
 
  928          CurrentToken->Next->isOneOf(tok::colon, tok::semi, tok::l_brace)) {
 
  931        CurrentToken->setType(TT_TableGenTrailingPasteOperator);
 
  936      skipToNextNonComment();
 
  937      HashTok->setType(TT_Unknown);
 
  938      if (!parseTableGenValue(ParseNameMode))
 
  945    if (ParseNameMode && CurrentToken->is(tok::l_brace))
 
  948    if (CurrentToken->isOneOf(tok::l_brace, tok::l_square, tok::period)) {
 
  949      CurrentToken->setType(TT_TableGenValueSuffix);
 
  951      skipToNextNonComment();
 
  952      if (Suffix->is(tok::l_square))
 
  953        return parseSquare();
 
  954      if (Suffix->is(tok::l_brace)) {
 
  955        Scopes.push_back(getScopeType(*Suffix));
 
  965  bool tryToParseTableGenTokVar() {
 
  968    if (CurrentToken->is(tok::identifier) &&
 
  969        CurrentToken->TokenText.front() == 
'$') {
 
  970      skipToNextNonComment();
 
  978  bool parseTableGenDAGArg(
bool AlignColon = 
false) {
 
  979    if (tryToParseTableGenTokVar())
 
  981    if (parseTableGenValue()) {
 
  982      if (CurrentToken && CurrentToken->is(tok::colon)) {
 
  984          CurrentToken->setType(TT_TableGenDAGArgListColonToAlign);
 
  986          CurrentToken->setType(TT_TableGenDAGArgListColon);
 
  987        skipToNextNonComment();
 
  988        return tryToParseTableGenTokVar();
 
  999    auto &Opes = Style.TableGenBreakingDAGArgOperators;
 
 1004    if (
Tok.isNot(tok::identifier) ||
 
 1005        Tok.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
 
 1009    if (!
Tok.Next || 
Tok.Next->is(tok::colon))
 
 1011    return llvm::is_contained(Opes, 
Tok.TokenText.str());
 
 1016  bool parseTableGenDAGArgAndList(
FormatToken *Opener) {
 
 1018    if (!parseTableGenDAGArg())
 
 1020    bool BreakInside = 
false;
 
 1021    if (Style.TableGenBreakInsideDAGArg != FormatStyle::DAS_DontBreak) {
 
 1024      if (isTableGenDAGArgBreakingOperator(*FirstTok)) {
 
 1027        Opener->setType(TT_TableGenDAGArgOpenerToBreak);
 
 1028        if (FirstTok->isOneOf(TT_TableGenBangOperator,
 
 1029                              TT_TableGenCondOperator)) {
 
 1032          CurrentToken->Previous->setType(TT_TableGenDAGArgOperatorToBreak);
 
 1033        } 
else if (FirstTok->is(tok::identifier)) {
 
 1034          if (Style.TableGenBreakInsideDAGArg == FormatStyle::DAS_BreakAll)
 
 1035            FirstTok->setType(TT_TableGenDAGArgOperatorToBreak);
 
 1037            FirstTok->setType(TT_TableGenDAGArgOperatorID);
 
 1042    return parseTableGenDAGArgList(Opener, BreakInside);
 
 1047  bool parseTableGenDAGArgList(
FormatToken *Opener, 
bool BreakInside) {
 
 1048    ScopedContextCreator ContextCreator(*
this, tok::l_paren, 0);
 
 1049    Contexts.back().IsTableGenDAGArgList = 
true;
 
 1050    bool FirstDAGArgListElm = 
true;
 
 1051    while (CurrentToken) {
 
 1052      if (!FirstDAGArgListElm && CurrentToken->is(tok::comma)) {
 
 1053        CurrentToken->setType(BreakInside ? TT_TableGenDAGArgListCommaToBreak
 
 1054                                          : TT_TableGenDAGArgListComma);
 
 1055        skipToNextNonComment();
 
 1057      if (CurrentToken && CurrentToken->is(tok::r_paren)) {
 
 1058        CurrentToken->setType(TT_TableGenDAGArgCloser);
 
 1059        Opener->MatchingParen = CurrentToken;
 
 1060        CurrentToken->MatchingParen = Opener;
 
 1061        skipToNextNonComment();
 
 1064      if (!parseTableGenDAGArg(
 
 1066              Style.AlignConsecutiveTableGenBreakingDAGArgColons.Enabled)) {
 
 1069      FirstDAGArgListElm = 
false;
 
 1074  bool parseTableGenSimpleValue() {
 
 1075    assert(Style.isTableGen());
 
 1079    skipToNextNonComment();
 
 1081    if (
Tok->isOneOf(tok::numeric_constant, tok::string_literal,
 
 1082                     TT_TableGenMultiLineString, tok::kw_true, tok::kw_false,
 
 1083                     tok::question, tok::kw_int)) {
 
 1087    if (
Tok->is(tok::l_brace)) {
 
 1088      Scopes.push_back(getScopeType(*
Tok));
 
 1089      return parseBrace();
 
 1092    if (
Tok->is(tok::l_square)) {
 
 1093      Tok->setType(TT_TableGenListOpener);
 
 1096      if (
Tok->is(tok::less)) {
 
 1097        CurrentToken->setType(TT_TemplateOpener);
 
 1098        return parseAngle();
 
 1104    if (
Tok->is(tok::l_paren)) {
 
 1105      Tok->setType(TT_TableGenDAGArgOpener);
 
 1107      if (Contexts.back().IsTableGenDAGArgList)
 
 1108        Tok->SpacesRequiredBefore = 1;
 
 1109      return parseTableGenDAGArgAndList(
Tok);
 
 1112    if (
Tok->is(TT_TableGenBangOperator)) {
 
 1113      if (CurrentToken && CurrentToken->is(tok::less)) {
 
 1114        CurrentToken->setType(TT_TemplateOpener);
 
 1115        skipToNextNonComment();
 
 1119      if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
 
 1123      Contexts.back().IsTableGenBangOpe = 
true;
 
 1124      bool Result = parseParens();
 
 1125      Contexts.back().IsTableGenBangOpe = 
false;
 
 1129    if (
Tok->is(TT_TableGenCondOperator)) {
 
 1130      if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
 
 1133      return parseParens();
 
 1138    if (
Tok->is(tok::identifier)) {
 
 1140      if (CurrentToken && CurrentToken->is(tok::less)) {
 
 1141        CurrentToken->setType(TT_TemplateOpener);
 
 1142        skipToNextNonComment();
 
 1143        return parseAngle();
 
 1151  bool couldBeInStructArrayInitializer()
 const {
 
 1152    if (Contexts.size() < 2)
 
 1156    const auto End = std::next(Contexts.rbegin(), 2);
 
 1157    auto Last = Contexts.rbegin();
 
 1160      if (
Last->ContextKind == tok::l_brace)
 
 1162    return Depth == 2 && 
Last->ContextKind != tok::l_brace;
 
 1169    assert(CurrentToken->Previous);
 
 1170    FormatToken &OpeningBrace = *CurrentToken->Previous;
 
 1171    assert(OpeningBrace.is(tok::l_brace));
 
 1172    OpeningBrace.ParentBracket = Contexts.back().ContextKind;
 
 1174    if (Contexts.back().CaretFound)
 
 1175      OpeningBrace.overwriteFixedType(TT_ObjCBlockLBrace);
 
 1176    Contexts.back().CaretFound = 
false;
 
 1178    ScopedContextCreator ContextCreator(*
this, tok::l_brace, 1);
 
 1179    Contexts.back().ColonIsDictLiteral = 
true;
 
 1181      Contexts.back().IsExpression = 
true;
 
 1182    if (Style.isJavaScript() && OpeningBrace.Previous &&
 
 1183        OpeningBrace.Previous->is(TT_JsTypeColon)) {
 
 1184      Contexts.back().IsExpression = 
false;
 
 1186    if (Style.isVerilog() &&
 
 1187        (!OpeningBrace.getPreviousNonComment() ||
 
 1188         OpeningBrace.getPreviousNonComment()->isNot(Keywords.kw_apostrophe))) {
 
 1189      Contexts.back().VerilogMayBeConcatenation = 
true;
 
 1191    if (Style.isTableGen())
 
 1192      Contexts.back().ColonIsDictLiteral = 
false;
 
 1194    unsigned CommaCount = 0;
 
 1195    while (CurrentToken) {
 
 1196      if (CurrentToken->is(tok::r_brace)) {
 
 1197        assert(!Scopes.empty());
 
 1198        assert(Scopes.back() == getScopeType(OpeningBrace));
 
 1200        assert(OpeningBrace.Optional == CurrentToken->Optional);
 
 1201        OpeningBrace.MatchingParen = CurrentToken;
 
 1202        CurrentToken->MatchingParen = &OpeningBrace;
 
 1203        if (Style.AlignArrayOfStructures != FormatStyle::AIAS_None) {
 
 1204          if (OpeningBrace.ParentBracket == tok::l_brace &&
 
 1205              couldBeInStructArrayInitializer() && CommaCount > 0) {
 
 1206            Contexts.back().ContextType = Context::StructArrayInitializer;
 
 1212      if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))
 
 1214      updateParameterCount(&OpeningBrace, CurrentToken);
 
 1215      if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
 
 1217        if (
Previous->is(TT_JsTypeOptionalQuestion))
 
 1219        if ((CurrentToken->is(tok::colon) && !Style.isTableGen() &&
 
 1220             (!Contexts.back().ColonIsDictLiteral || !IsCpp)) ||
 
 1222          OpeningBrace.setType(TT_DictLiteral);
 
 1223          if (
Previous->Tok.getIdentifierInfo() ||
 
 1224              Previous->is(tok::string_literal)) {
 
 1225            Previous->setType(TT_SelectorName);
 
 1228        if (CurrentToken->is(tok::colon) && OpeningBrace.is(TT_Unknown) &&
 
 1229            !Style.isTableGen()) {
 
 1230          OpeningBrace.setType(TT_DictLiteral);
 
 1231        } 
else if (Style.isJavaScript()) {
 
 1232          OpeningBrace.overwriteFixedType(TT_DictLiteral);
 
 1235      if (CurrentToken->is(tok::comma)) {
 
 1236        if (Style.isJavaScript())
 
 1237          OpeningBrace.overwriteFixedType(TT_DictLiteral);
 
 1240      if (!consumeToken())
 
 1250    if (Current->is(tok::l_brace) && Current->is(
BK_Block))
 
 1251      ++
Left->BlockParameterCount;
 
 1252    if (Current->is(tok::comma)) {
 
 1253      ++
Left->ParameterCount;
 
 1255        Left->Role.reset(
new CommaSeparatedList(Style));
 
 1256      Left->Role->CommaFound(Current);
 
 1257    } 
else if (
Left->ParameterCount == 0 && Current->isNot(tok::comment)) {
 
 1258      Left->ParameterCount = 1;
 
 1262  bool parseConditional() {
 
 1263    while (CurrentToken) {
 
 1264      if (CurrentToken->is(tok::colon) && CurrentToken->is(TT_Unknown)) {
 
 1265        CurrentToken->setType(TT_ConditionalExpr);
 
 1269      if (!consumeToken())
 
 1275  bool parseTemplateDeclaration() {
 
 1276    if (!CurrentToken || CurrentToken->isNot(tok::less))
 
 1279    CurrentToken->setType(TT_TemplateOpener);
 
 1282    TemplateDeclarationDepth++;
 
 1283    const bool WellFormed = parseAngle();
 
 1284    TemplateDeclarationDepth--;
 
 1288    if (CurrentToken && TemplateDeclarationDepth == 0)
 
 1289      CurrentToken->Previous->ClosesTemplateDeclaration = 
true;
 
 1294  bool consumeToken() {
 
 1296      const auto *Prev = CurrentToken->getPreviousNonComment();
 
 1297      if (Prev && Prev->is(TT_AttributeRSquare) &&
 
 1298          CurrentToken->isOneOf(tok::kw_if, tok::kw_switch, tok::kw_case,
 
 1299                                tok::kw_default, tok::kw_for, tok::kw_while) &&
 
 1301        CurrentToken->MustBreakBefore = 
true;
 
 1308    if (
Tok->is(TT_VerilogTableItem))
 
 1311    if (
Tok->is(TT_TableGenMultiLineString))
 
 1313    auto *Prev = 
Tok->getPreviousNonComment();
 
 1314    auto *
Next = 
Tok->getNextNonComment();
 
 1315    switch (
bool IsIf = 
false; 
Tok->Tok.getKind()) {
 
 1318      if (!Prev && Line.MustBeDeclaration)
 
 1319        Tok->setType(TT_ObjCMethodSpecifier);
 
 1326      if (
Tok->isTypeFinalized())
 
 1329      if (Style.isJavaScript()) {
 
 1330        if (Contexts.back().ColonIsForRangeExpr || 
 
 1331            (Contexts.size() == 1 &&               
 
 1332             Line.First->isNoneOf(tok::kw_enum, tok::kw_case)) ||
 
 1333            Contexts.back().ContextKind == tok::l_paren ||  
 
 1334            Contexts.back().ContextKind == tok::l_square || 
 
 1335            (!Contexts.back().IsExpression &&
 
 1336             Contexts.back().ContextKind == tok::l_brace) || 
 
 1337            (Contexts.size() == 1 &&
 
 1338             Line.MustBeDeclaration)) { 
 
 1339          Contexts.back().IsExpression = 
false;
 
 1340          Tok->setType(TT_JsTypeColon);
 
 1343      } 
else if (Style.isCSharp()) {
 
 1344        if (Contexts.back().InCSharpAttributeSpecifier) {
 
 1345          Tok->setType(TT_AttributeColon);
 
 1348        if (Contexts.back().ContextKind == tok::l_paren) {
 
 1349          Tok->setType(TT_CSharpNamedArgumentColon);
 
 1352      } 
else if (Style.isVerilog() && 
Tok->isNot(TT_BinaryOperator)) {
 
 1355        if (Keywords.isVerilogEnd(*Prev) || Keywords.isVerilogBegin(*Prev)) {
 
 1356          Tok->setType(TT_VerilogBlockLabelColon);
 
 1357        } 
else if (Contexts.back().ContextKind == tok::l_square) {
 
 1358          Tok->setType(TT_BitFieldColon);
 
 1359        } 
else if (Contexts.back().ColonIsDictLiteral) {
 
 1360          Tok->setType(TT_DictLiteral);
 
 1361        } 
else if (Contexts.size() == 1) {
 
 1365          Tok->setType(TT_CaseLabelColon);
 
 1366          if (Line.Level > 1 || (!Line.InPPDirective && Line.Level > 0))
 
 1371      if (Line.First->isOneOf(Keywords.kw_module, Keywords.kw_import) ||
 
 1372          Line.First->startsSequence(tok::kw_export, Keywords.kw_module) ||
 
 1373          Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) {
 
 1374        Tok->setType(TT_ModulePartitionColon);
 
 1375      } 
else if (Line.First->is(tok::kw_asm)) {
 
 1376        Tok->setType(TT_InlineASMColon);
 
 1377      } 
else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) {
 
 1378        Tok->setType(TT_DictLiteral);
 
 1379        if (Style.isTextProto())
 
 1380          Prev->setType(TT_SelectorName);
 
 1381      } 
else if (Contexts.back().ColonIsObjCMethodExpr ||
 
 1382                 Line.startsWith(TT_ObjCMethodSpecifier)) {
 
 1383        Tok->setType(TT_ObjCMethodExpr);
 
 1384        const auto *PrevPrev = Prev->Previous;
 
 1387        bool UnknownIdentifierInMethodDeclaration =
 
 1388            Line.startsWith(TT_ObjCMethodSpecifier) &&
 
 1389            Prev->is(tok::identifier) && Prev->is(TT_Unknown);
 
 1392            !(PrevPrev->is(TT_CastRParen) ||
 
 1393              (PrevPrev->is(TT_ObjCMethodExpr) && PrevPrev->is(tok::colon))) ||
 
 1394            PrevPrev->is(tok::r_square) ||
 
 1395            Contexts.back().LongestObjCSelectorName == 0 ||
 
 1396            UnknownIdentifierInMethodDeclaration) {
 
 1397          Prev->setType(TT_SelectorName);
 
 1398          if (!Contexts.back().FirstObjCSelectorName)
 
 1399            Contexts.back().FirstObjCSelectorName = Prev;
 
 1400          else if (Prev->ColumnWidth > Contexts.back().LongestObjCSelectorName)
 
 1401            Contexts.back().LongestObjCSelectorName = Prev->ColumnWidth;
 
 1402          Prev->ParameterIndex =
 
 1403              Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts;
 
 1404          ++Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts;
 
 1406      } 
else if (Contexts.back().ColonIsForRangeExpr) {
 
 1407        Tok->setType(TT_RangeBasedForLoopColon);
 
 1408        for (
auto *Token = Prev;
 
 1409             Token && Token->isNoneOf(tok::semi, tok::l_paren);
 
 1410             Token = Token->Previous) {
 
 1411          if (Token->isPointerOrReference())
 
 1412            Token->setFinalizedType(TT_PointerOrReference);
 
 1414      } 
else if (Contexts.back().ContextType == Context::C11GenericSelection) {
 
 1415        Tok->setType(TT_GenericSelectionColon);
 
 1416        if (Prev->isPointerOrReference())
 
 1417          Prev->setFinalizedType(TT_PointerOrReference);
 
 1418      } 
else if ((CurrentToken && CurrentToken->is(tok::numeric_constant)) ||
 
 1419                 (Prev->is(TT_StartOfName) && !Scopes.empty() &&
 
 1421        Tok->setType(TT_BitFieldColon);
 
 1422      } 
else if (Contexts.size() == 1 &&
 
 1423                 Line.getFirstNonComment()->isNoneOf(tok::kw_enum, tok::kw_case,
 
 1425                 !Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
 
 1426        if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
 
 1427            Prev->ClosesRequiresClause) {
 
 1428          Tok->setType(TT_CtorInitializerColon);
 
 1429        } 
else if (Prev->is(tok::kw_try)) {
 
 1431          FormatToken *PrevPrev = Prev->getPreviousNonComment();
 
 1434          if (PrevPrev && PrevPrev->isOneOf(tok::r_paren, tok::kw_noexcept))
 
 1435            Tok->setType(TT_CtorInitializerColon);
 
 1437          Tok->setType(TT_InheritanceColon);
 
 1438          if (Prev->isAccessSpecifierKeyword())
 
 1441      } 
else if (canBeObjCSelectorComponent(*Prev) && 
Next &&
 
 1442                 (
Next->isOneOf(tok::r_paren, tok::comma) ||
 
 1443                  (canBeObjCSelectorComponent(*
Next) && 
Next->Next &&
 
 1444                   Next->Next->is(tok::colon)))) {
 
 1447        Tok->setType(TT_ObjCSelector);
 
 1454      if (Style.isJavaScript() && !Contexts.back().IsExpression)
 
 1455        Tok->setType(TT_JsTypeOperator);
 
 1458      if (Style.isTableGen()) {
 
 1460        if (!parseTableGenValue())
 
 1462        if (CurrentToken && CurrentToken->is(Keywords.kw_then))
 
 1467          CurrentToken->isOneOf(tok::kw_constexpr, tok::identifier)) {
 
 1473      if (CurrentToken && CurrentToken->is(tok::l_paren)) {
 
 1475        if (!parseParens(IsIf))
 
 1480      if (Style.isJavaScript()) {
 
 1482        if ((Prev && Prev->is(tok::period)) || (
Next && 
Next->is(tok::colon)))
 
 1485        if (CurrentToken && CurrentToken->is(Keywords.kw_await))
 
 1488      if (IsCpp && CurrentToken && CurrentToken->is(tok::kw_co_await))
 
 1490      Contexts.back().ColonIsForRangeExpr = 
true;
 
 1491      if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
 
 1502      if (Prev && Prev->is(tok::r_paren) && Prev->MatchingParen &&
 
 1503          Prev->MatchingParen->is(TT_OverloadedOperatorLParen)) {
 
 1504        Prev->setType(TT_OverloadedOperator);
 
 1505        Prev->MatchingParen->setType(TT_OverloadedOperator);
 
 1506        Tok->setType(TT_OverloadedOperatorLParen);
 
 1509      if (Style.isVerilog()) {
 
 1515        auto IsInstancePort = [&]() {
 
 1524          if (!Prev || !(PrevPrev = Prev->getPreviousNonComment()))
 
 1527          if (Keywords.isVerilogIdentifier(*Prev) &&
 
 1528              Keywords.isVerilogIdentifier(*PrevPrev)) {
 
 1532          if (Prev->is(Keywords.kw_verilogHash) &&
 
 1533              Keywords.isVerilogIdentifier(*PrevPrev)) {
 
 1537          if (Keywords.isVerilogIdentifier(*Prev) && PrevPrev->is(tok::r_paren))
 
 1540          if (Keywords.isVerilogIdentifier(*Prev) && PrevPrev->is(tok::comma)) {
 
 1541            const FormatToken *PrevParen = PrevPrev->getPreviousNonComment();
 
 1542            if (PrevParen && PrevParen->is(tok::r_paren) &&
 
 1543                PrevParen->MatchingParen &&
 
 1544                PrevParen->MatchingParen->is(TT_VerilogInstancePortLParen)) {
 
 1551        if (IsInstancePort())
 
 1552          Tok->setType(TT_VerilogInstancePortLParen);
 
 1557      if (Line.MustBeDeclaration && Contexts.size() == 1 &&
 
 1558          !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
 
 1559          !Line.startsWith(tok::l_paren) &&
 
 1560          Tok->isNoneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen)) {
 
 1562            (!Prev->isAttribute() &&
 
 1563             Prev->isNoneOf(TT_RequiresClause, TT_LeadingJavaAnnotation,
 
 1564                            TT_BinaryOperator))) {
 
 1565          Line.MightBeFunctionDecl = 
true;
 
 1566          Tok->MightBeFunctionDeclParen = 
true;
 
 1571      if (Style.isTableGen())
 
 1572        Tok->setType(TT_TableGenListOpener);
 
 1578        if (
Tok->is(TT_RequiresExpressionLBrace))
 
 1580      } 
else if (Style.isTextProto()) {
 
 1581        if (Prev && Prev->isNot(TT_DictLiteral))
 
 1582          Prev->setType(TT_SelectorName);
 
 1584      Scopes.push_back(getScopeType(*
Tok));
 
 1590        Tok->setType(TT_TemplateOpener);
 
 1596        if (Style.isTextProto() ||
 
 1597            (Style.Language == FormatStyle::LK_Proto && Prev &&
 
 1598             Prev->isOneOf(TT_SelectorName, TT_DictLiteral))) {
 
 1599          Tok->setType(TT_DictLiteral);
 
 1600          if (Prev && Prev->isNot(TT_DictLiteral))
 
 1601            Prev->setType(TT_SelectorName);
 
 1603        if (Style.isTableGen())
 
 1604          Tok->setType(TT_TemplateOpener);
 
 1606        Tok->setType(TT_BinaryOperator);
 
 1607        NonTemplateLess.insert(
Tok);
 
 1617      if (!Scopes.empty())
 
 1624      if (!Style.isTextProto() && 
Tok->is(TT_Unknown))
 
 1625        Tok->setType(TT_BinaryOperator);
 
 1626      if (Prev && Prev->is(TT_TemplateCloser))
 
 1627        Tok->SpacesRequiredBefore = 1;
 
 1629    case tok::kw_operator:
 
 1630      if (Style.isProto())
 
 1633      if (IsCpp && CurrentToken) {
 
 1634        const auto *Info = CurrentToken->Tok.getIdentifierInfo();
 
 1636        if (Info && !(CurrentToken->isPlacementOperator() ||
 
 1637                      CurrentToken->is(tok::kw_co_await) ||
 
 1638                      Info->isCPlusPlusOperatorKeyword())) {
 
 1640          if (CurrentToken->startsSequence(tok::kw_decltype, tok::l_paren,
 
 1641                                           tok::kw_auto, tok::r_paren)) {
 
 1643            LParen = CurrentToken->Next->Next->Next->Next;
 
 1646            for (LParen = CurrentToken->Next;
 
 1647                 LParen && LParen->isNot(tok::l_paren); LParen = LParen->Next) {
 
 1648              if (LParen->isPointerOrReference())
 
 1649                LParen->setFinalizedType(TT_PointerOrReference);
 
 1652          if (LParen && LParen->is(tok::l_paren)) {
 
 1653            if (!Contexts.back().IsExpression) {
 
 1654              Tok->setFinalizedType(TT_FunctionDeclarationName);
 
 1655              LParen->setFinalizedType(TT_FunctionDeclarationLParen);
 
 1661      while (CurrentToken &&
 
 1662             CurrentToken->isNoneOf(tok::l_paren, tok::semi, tok::r_paren)) {
 
 1663        if (CurrentToken->isOneOf(tok::star, tok::amp))
 
 1664          CurrentToken->setType(TT_PointerOrReference);
 
 1665        auto Next = CurrentToken->getNextNonComment();
 
 1668        if (
Next->is(tok::less))
 
 1674        auto Previous = CurrentToken->getPreviousNonComment();
 
 1676        if (CurrentToken->is(tok::comma) && 
Previous->isNot(tok::kw_operator))
 
 1678        if (
Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator, tok::comma,
 
 1680            Previous->isPointerOrReference() ||
 
 1682            Previous->TokenText.starts_with(
"\"\"")) {
 
 1683          Previous->setType(TT_OverloadedOperator);
 
 1684          if (CurrentToken->isOneOf(tok::less, tok::greater))
 
 1688      if (CurrentToken && CurrentToken->is(tok::l_paren))
 
 1689        CurrentToken->setType(TT_OverloadedOperatorLParen);
 
 1690      if (CurrentToken && CurrentToken->Previous->is(TT_BinaryOperator))
 
 1691        CurrentToken->Previous->setType(TT_OverloadedOperator);
 
 1694      if (Style.isJavaScript() && 
Next &&
 
 1695          Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
 
 1696                        tok::r_brace, tok::r_square)) {
 
 1701        Tok->setType(TT_JsTypeOptionalQuestion);
 
 1706      if (Line.MustBeDeclaration && !Contexts.back().IsExpression &&
 
 1707          Style.isJavaScript()) {
 
 1710      if (Style.isCSharp()) {
 
 1713        if (
Next && (
Next->isOneOf(tok::r_paren, tok::greater) ||
 
 1714                     Next->startsSequence(tok::identifier, tok::semi) ||
 
 1715                     Next->startsSequence(tok::identifier, tok::equal))) {
 
 1716          Tok->setType(TT_CSharpNullable);
 
 1725        if (!Contexts.back().IsExpression && Line.MustBeDeclaration &&
 
 1726            (!
Next || 
Next->isNoneOf(tok::identifier, tok::string_literal) ||
 
 1727             !
Next->Next || 
Next->Next->isNoneOf(tok::colon, tok::question))) {
 
 1728          Tok->setType(TT_CSharpNullable);
 
 1734    case tok::kw_template:
 
 1735      parseTemplateDeclaration();
 
 1738      switch (Contexts.back().ContextType) {
 
 1739      case Context::CtorInitializer:
 
 1740        Tok->setType(TT_CtorInitializerComma);
 
 1742      case Context::InheritanceList:
 
 1743        Tok->setType(TT_InheritanceComma);
 
 1745      case Context::VerilogInstancePortList:
 
 1746        Tok->setType(TT_VerilogInstancePortComma);
 
 1749        if (Style.isVerilog() && Contexts.size() == 1 &&
 
 1750            Line.startsWith(Keywords.kw_assign)) {
 
 1751          Tok->setFinalizedType(TT_VerilogAssignComma);
 
 1752        } 
else if (Contexts.back().FirstStartOfName &&
 
 1753                   (Contexts.size() == 1 || startsWithInitStatement(Line))) {
 
 1754          Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = 
true;
 
 1755          Line.IsMultiVariableDeclStmt = 
true;
 
 1759      if (Contexts.back().ContextType == Context::ForEachMacro)
 
 1760        Contexts.back().IsExpression = 
true;
 
 1762    case tok::kw_default:
 
 1764      if (Style.isVerilog() && Keywords.isVerilogEndOfLabel(*
Tok) &&
 
 1765          (Line.Level > 1 || (!Line.InPPDirective && Line.Level > 0))) {
 
 1769    case tok::identifier:
 
 1770      if (
Tok->isOneOf(Keywords.kw___has_include,
 
 1771                       Keywords.kw___has_include_next)) {
 
 1775        if (
Next && 
Next->is(tok::l_paren) && Prev &&
 
 1776            Prev->isOneOf(tok::kw___cdecl, tok::kw___stdcall,
 
 1777                          tok::kw___fastcall, tok::kw___thiscall,
 
 1778                          tok::kw___regcall, tok::kw___vectorcall)) {
 
 1779          Tok->setFinalizedType(TT_FunctionDeclarationName);
 
 1780          Next->setFinalizedType(TT_FunctionDeclarationLParen);
 
 1782      } 
else if (Style.isCSharp()) {
 
 1783        if (
Tok->is(Keywords.kw_where) && 
Next && 
Next->isNot(tok::l_paren)) {
 
 1784          Tok->setType(TT_CSharpGenericTypeConstraint);
 
 1785          parseCSharpGenericTypeConstraint();
 
 1787            Line.IsContinuation = 
true;
 
 1789      } 
else if (Style.isTableGen()) {
 
 1790        if (
Tok->is(Keywords.kw_assert)) {
 
 1791          if (!parseTableGenValue())
 
 1793        } 
else if (
Tok->isOneOf(Keywords.kw_def, Keywords.kw_defm) &&
 
 1794                   (!
Next || 
Next->isNoneOf(tok::colon, tok::l_brace))) {
 
 1796          if (!parseTableGenValue(
true))
 
 1800      if (Style.AllowBreakBeforeQtProperty &&
 
 1801          Contexts.back().ContextType == Context::QtProperty &&
 
 1802          Tok->isQtProperty()) {
 
 1803        Tok->setFinalizedType(TT_QtProperty);
 
 1807      if (
Tok->isNot(TT_LambdaArrow) && Prev && Prev->is(tok::kw_noexcept))
 
 1808        Tok->setType(TT_TrailingReturnArrow);
 
 1812      if (Style.isTableGen() && !parseTableGenValue())
 
 1821  void parseCSharpGenericTypeConstraint() {
 
 1822    int OpenAngleBracketsCount = 0;
 
 1823    while (CurrentToken) {
 
 1824      if (CurrentToken->is(tok::less)) {
 
 1826        CurrentToken->setType(TT_TemplateOpener);
 
 1827        ++OpenAngleBracketsCount;
 
 1829      } 
else if (CurrentToken->is(tok::greater)) {
 
 1830        CurrentToken->setType(TT_TemplateCloser);
 
 1831        --OpenAngleBracketsCount;
 
 1833      } 
else if (CurrentToken->is(tok::comma) && OpenAngleBracketsCount == 0) {
 
 1836        CurrentToken->setType(TT_CSharpGenericTypeConstraintComma);
 
 1838      } 
else if (CurrentToken->is(Keywords.kw_where)) {
 
 1839        CurrentToken->setType(TT_CSharpGenericTypeConstraint);
 
 1841      } 
else if (CurrentToken->is(tok::colon)) {
 
 1842        CurrentToken->setType(TT_CSharpGenericTypeConstraintColon);
 
 1850  void parseIncludeDirective() {
 
 1851    if (CurrentToken && CurrentToken->is(tok::less)) {
 
 1853      while (CurrentToken) {
 
 1856        if (CurrentToken->isNot(tok::comment) &&
 
 1857            !CurrentToken->TokenText.starts_with(
"//")) {
 
 1858          CurrentToken->setType(TT_ImplicitStringLiteral);
 
 1865  void parseWarningOrError() {
 
 1870    while (CurrentToken) {
 
 1871      CurrentToken->setType(TT_ImplicitStringLiteral);
 
 1876  void parsePragma() {
 
 1879        CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option,
 
 1880                              Keywords.kw_region)) {
 
 1881      bool IsMarkOrRegion =
 
 1882          CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_region);
 
 1885      while (CurrentToken) {
 
 1886        if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator))
 
 1887          CurrentToken->setType(TT_ImplicitStringLiteral);
 
 1893  void parseHasInclude() {
 
 1894    if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
 
 1897    parseIncludeDirective();
 
 1901  LineType parsePreprocessorDirective() {
 
 1902    bool IsFirstToken = CurrentToken->IsFirst;
 
 1908    if (Style.isJavaScript() && IsFirstToken) {
 
 1912      while (CurrentToken) {
 
 1914        CurrentToken->setType(TT_ImplicitStringLiteral);
 
 1920    if (CurrentToken->is(tok::numeric_constant)) {
 
 1921      CurrentToken->SpacesRequiredBefore = 1;
 
 1926    if (!CurrentToken->Tok.getIdentifierInfo())
 
 1930    if (Style.isVerilog() && !Keywords.isVerilogPPDirective(*CurrentToken))
 
 1932    switch (CurrentToken->Tok.getIdentifierInfo()->getPPKeywordID()) {
 
 1933    case tok::pp_include:
 
 1934    case tok::pp_include_next:
 
 1935    case tok::pp_import:
 
 1937      parseIncludeDirective();
 
 1941    case tok::pp_warning:
 
 1942      parseWarningOrError();
 
 1944    case tok::pp_pragma:
 
 1949      Contexts.back().IsExpression = 
true;
 
 1952        CurrentToken->SpacesRequiredBefore = 1;
 
 1958    while (CurrentToken) {
 
 1961      if (
Tok->is(tok::l_paren)) {
 
 1963      } 
else if (
Tok->isOneOf(Keywords.kw___has_include,
 
 1964                              Keywords.kw___has_include_next)) {
 
 1975    NonTemplateLess.clear();
 
 1976    if (!Line.InMacroBody && CurrentToken->is(tok::hash)) {
 
 1980      auto Type = parsePreprocessorDirective();
 
 1988    IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo();
 
 1989    if ((Style.isJava() && CurrentToken->is(Keywords.kw_package)) ||
 
 1990        (!Style.isVerilog() && Info &&
 
 1991         Info->getPPKeywordID() == tok::pp_import && CurrentToken->Next &&
 
 1992         CurrentToken->Next->isOneOf(tok::string_literal, tok::identifier,
 
 1995      parseIncludeDirective();
 
 2001    if (CurrentToken->is(tok::less) && Line.Last->is(tok::greater)) {
 
 2002      parseIncludeDirective();
 
 2008    if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
 
 2009        CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) {
 
 2011      if (CurrentToken && CurrentToken->is(tok::identifier)) {
 
 2012        while (CurrentToken)
 
 2018    bool KeywordVirtualFound = 
false;
 
 2019    bool ImportStatement = 
false;
 
 2022    if (Style.isJavaScript() && CurrentToken->is(Keywords.kw_import))
 
 2023      ImportStatement = 
true;
 
 2025    while (CurrentToken) {
 
 2026      if (CurrentToken->is(tok::kw_virtual))
 
 2027        KeywordVirtualFound = 
true;
 
 2028      if (Style.isJavaScript()) {
 
 2035        if (Line.First->is(tok::kw_export) &&
 
 2036            CurrentToken->is(Keywords.kw_from) && CurrentToken->Next &&
 
 2037            CurrentToken->Next->isStringLiteral()) {
 
 2038          ImportStatement = 
true;
 
 2040        if (isClosureImportStatement(*CurrentToken))
 
 2041          ImportStatement = 
true;
 
 2043      if (!consumeToken())
 
 2051    if (KeywordVirtualFound)
 
 2053    if (ImportStatement)
 
 2056    if (Line.startsWith(TT_ObjCMethodSpecifier)) {
 
 2057      if (Contexts.back().FirstObjCSelectorName) {
 
 2058        Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
 
 2059            Contexts.back().LongestObjCSelectorName;
 
 2064    for (
const auto &ctx : Contexts)
 
 2065      if (ctx.ContextType == Context::StructArrayInitializer)
 
 2075    return Tok.TokenText == 
"goog" && 
Tok.Next && 
Tok.Next->is(tok::period) &&
 
 2077           (
Tok.Next->Next->TokenText == 
"module" ||
 
 2078            Tok.Next->Next->TokenText == 
"provide" ||
 
 2079            Tok.Next->Next->TokenText == 
"require" ||
 
 2080            Tok.Next->Next->TokenText == 
"requireType" ||
 
 2081            Tok.Next->Next->TokenText == 
"forwardDeclare") &&
 
 2082           Tok.Next->Next->Next && 
Tok.Next->Next->Next->is(tok::l_paren);
 
 2085  void resetTokenMetadata() {
 
 2091    if (!CurrentToken->isTypeFinalized() &&
 
 2092        CurrentToken->isNoneOf(
 
 2093            TT_LambdaLSquare, TT_LambdaLBrace, TT_AttributeMacro, TT_IfMacro,
 
 2094            TT_ForEachMacro, TT_TypenameMacro, TT_FunctionLBrace,
 
 2095            TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_FatArrow,
 
 2096            TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
 
 2097            TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral,
 
 2098            TT_UntouchableMacroFunc, TT_StatementAttributeLikeMacro,
 
 2099            TT_FunctionLikeOrFreestandingMacro, TT_ClassLBrace, TT_EnumLBrace,
 
 2100            TT_RecordLBrace, TT_StructLBrace, TT_UnionLBrace, TT_RequiresClause,
 
 2101            TT_RequiresClauseInARequiresExpression, TT_RequiresExpression,
 
 2102            TT_RequiresExpressionLParen, TT_RequiresExpressionLBrace,
 
 2103            TT_CompoundRequirementLBrace, TT_BracedListLBrace,
 
 2104            TT_FunctionLikeMacro)) {
 
 2105      CurrentToken->setType(TT_Unknown);
 
 2107    CurrentToken->Role.reset();
 
 2108    CurrentToken->MatchingParen = 
nullptr;
 
 2109    CurrentToken->FakeLParens.clear();
 
 2110    CurrentToken->FakeRParens = 0;
 
 2117    CurrentToken->NestingLevel = Contexts.size() - 1;
 
 2118    CurrentToken->BindingStrength = Contexts.back().BindingStrength;
 
 2119    modifyContext(*CurrentToken);
 
 2120    determineTokenType(*CurrentToken);
 
 2121    CurrentToken = CurrentToken->Next;
 
 2123    resetTokenMetadata();
 
 2131        : ContextKind(ContextKind), BindingStrength(BindingStrength),
 
 2132          IsExpression(IsExpression) {}
 
 2135    unsigned BindingStrength;
 
 2137    unsigned LongestObjCSelectorName = 0;
 
 2138    bool ColonIsForRangeExpr = 
false;
 
 2139    bool ColonIsDictLiteral = 
false;
 
 2140    bool ColonIsObjCMethodExpr = 
false;
 
 2143    bool CanBeExpression = 
true;
 
 2144    bool CaretFound = 
false;
 
 2145    bool InCpp11AttributeSpecifier = 
false;
 
 2146    bool InCSharpAttributeSpecifier = 
false;
 
 2147    bool VerilogAssignmentFound = 
false;
 
 2150    bool VerilogMayBeConcatenation = 
false;
 
 2151    bool IsTableGenDAGArgList = 
false;
 
 2152    bool IsTableGenBangOpe = 
false;
 
 2153    bool IsTableGenCondOpe = 
false;
 
 2166      StructArrayInitializer,
 
 2170      C11GenericSelection,
 
 2173      VerilogInstancePortList,
 
 2174    } ContextType = Unknown;
 
 2179  struct ScopedContextCreator {
 
 2180    AnnotatingParser &P;
 
 2182    ScopedContextCreator(AnnotatingParser &P, 
tok::TokenKind ContextKind,
 
 2185      P.Contexts.push_back(Context(ContextKind,
 
 2186                                   P.Contexts.back().BindingStrength + Increase,
 
 2187                                   P.Contexts.back().IsExpression));
 
 2190    ~ScopedContextCreator() {
 
 2191      if (P.Style.AlignArrayOfStructures != FormatStyle::AIAS_None) {
 
 2192        if (P.Contexts.back().ContextType == Context::StructArrayInitializer) {
 
 2193          P.Contexts.pop_back();
 
 2194          P.Contexts.back().ContextType = Context::StructArrayInitializer;
 
 2198      P.Contexts.pop_back();
 
 2203    auto AssignmentStartsExpression = [&]() {
 
 2207      if (Line.First->isOneOf(tok::kw_using, tok::kw_return))
 
 2209      if (Line.First->is(tok::kw_template)) {
 
 2210        assert(Current.Previous);
 
 2211        if (Current.Previous->is(tok::kw_operator)) {
 
 2219        if (
Tok->isNot(TT_TemplateOpener)) {
 
 2226        if (Contexts.back().ContextKind == tok::less) {
 
 2227          assert(Current.Previous->Previous);
 
 2228          return Current.Previous->Previous->isNoneOf(tok::kw_typename,
 
 2232        Tok = 
Tok->MatchingParen;
 
 2235        Tok = 
Tok->getNextNonComment();
 
 2239        if (
Tok->isOneOf(tok::kw_class, tok::kw_enum, tok::kw_struct,
 
 2249      if (Style.isJavaScript() &&
 
 2250          (Line.startsWith(Keywords.kw_type, tok::identifier) ||
 
 2251           Line.startsWith(tok::kw_export, Keywords.kw_type,
 
 2252                           tok::identifier))) {
 
 2256      return !Current.Previous || Current.Previous->isNot(tok::kw_operator);
 
 2259    if (AssignmentStartsExpression()) {
 
 2260      Contexts.back().IsExpression = 
true;
 
 2261      if (!Line.startsWith(TT_UnaryOperator)) {
 
 2264             Previous->Previous->isNoneOf(tok::comma, tok::semi);
 
 2266          if (
Previous->isOneOf(tok::r_square, tok::r_paren, tok::greater)) {
 
 2273          if (
Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
 
 2275              Previous->Previous->isNot(tok::equal)) {
 
 2276            Previous->setType(TT_PointerOrReference);
 
 2280    } 
else if (Current.is(tok::lessless) &&
 
 2281               (!Current.Previous ||
 
 2282                Current.Previous->isNot(tok::kw_operator))) {
 
 2283      Contexts.back().IsExpression = 
true;
 
 2284    } 
else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
 
 2285      Contexts.back().IsExpression = 
true;
 
 2286    } 
else if (Current.is(TT_TrailingReturnArrow)) {
 
 2287      Contexts.back().IsExpression = 
false;
 
 2288    } 
else if (Current.isOneOf(TT_LambdaArrow, Keywords.kw_assert)) {
 
 2289      Contexts.back().IsExpression = Style.isJava();
 
 2290    } 
else if (Current.Previous &&
 
 2291               Current.Previous->is(TT_CtorInitializerColon)) {
 
 2292      Contexts.back().IsExpression = 
true;
 
 2293      Contexts.back().ContextType = Context::CtorInitializer;
 
 2294    } 
else if (Current.Previous && Current.Previous->is(TT_InheritanceColon)) {
 
 2295      Contexts.back().ContextType = Context::InheritanceList;
 
 2296    } 
else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) {
 
 2300        Previous->setType(TT_PointerOrReference);
 
 2302      if (Line.MustBeDeclaration &&
 
 2303          Contexts.front().ContextType != Context::CtorInitializer) {
 
 2304        Contexts.back().IsExpression = 
false;
 
 2306    } 
else if (Current.is(tok::kw_new)) {
 
 2307      Contexts.back().CanBeExpression = 
false;
 
 2308    } 
else if (Current.is(tok::semi) ||
 
 2309               (Current.is(tok::exclaim) && Current.Previous &&
 
 2310                Current.Previous->isNot(tok::kw_operator))) {
 
 2314      Contexts.back().IsExpression = 
true;
 
 2322      if (Current->is(tok::l_paren))
 
 2324      if (Current->is(tok::r_paren))
 
 2328      Current = Current->Next;
 
 2333  static bool isDeductionGuide(
FormatToken &Current) {
 
 2335    if (Current.Previous && Current.Previous->is(tok::r_paren) &&
 
 2336        Current.startsSequence(tok::arrow, tok::identifier, tok::less)) {
 
 2340      while (TemplateCloser) {
 
 2342        if (TemplateCloser->is(tok::l_paren)) {
 
 2344          TemplateCloser = untilMatchingParen(TemplateCloser);
 
 2345          if (!TemplateCloser)
 
 2348        if (TemplateCloser->is(tok::less))
 
 2350        if (TemplateCloser->is(tok::greater))
 
 2354        TemplateCloser = TemplateCloser->Next;
 
 2358      if (TemplateCloser && TemplateCloser->Next &&
 
 2359          TemplateCloser->Next->is(tok::semi) &&
 
 2360          Current.Previous->MatchingParen) {
 
 2364            Current.Previous->MatchingParen->Previous;
 
 2366        return LeadingIdentifier &&
 
 2367               LeadingIdentifier->TokenText == Current.Next->TokenText;
 
 2374    if (Current.isNot(TT_Unknown)) {
 
 2379    if ((Style.isJavaScript() || Style.isCSharp()) &&
 
 2380        Current.is(tok::exclaim)) {
 
 2381      if (Current.Previous) {
 
 2383            Style.isJavaScript()
 
 2384                ? Keywords.isJavaScriptIdentifier(
 
 2385                      *Current.Previous,  
true)
 
 2386                : Current.Previous->is(tok::identifier);
 
 2388            Current.Previous->isOneOf(
 
 2389                tok::kw_default, tok::kw_namespace, tok::r_paren, tok::r_square,
 
 2390                tok::r_brace, tok::kw_false, tok::kw_true, Keywords.kw_type,
 
 2391                Keywords.kw_get, Keywords.kw_init, Keywords.kw_set) ||
 
 2392            Current.Previous->Tok.isLiteral()) {
 
 2393          Current.setType(TT_NonNullAssertion);
 
 2398          Current.Next->isOneOf(TT_BinaryOperator, Keywords.kw_as)) {
 
 2399        Current.setType(TT_NonNullAssertion);
 
 2407    if ((Style.isJavaScript() || Style.isJava()) &&
 
 2408        Current.is(Keywords.kw_instanceof)) {
 
 2409      Current.setType(TT_BinaryOperator);
 
 2410    } 
else if (isStartOfName(Current) &&
 
 2411               (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
 
 2412      Contexts.back().FirstStartOfName = &Current;
 
 2413      Current.setType(TT_StartOfName);
 
 2414    } 
else if (Current.is(tok::semi)) {
 
 2418      Contexts.back().FirstStartOfName = 
nullptr;
 
 2419    } 
else if (Current.isOneOf(tok::kw_auto, tok::kw___auto_type)) {
 
 2421    } 
else if (Current.is(tok::arrow) && Style.isJava()) {
 
 2422      Current.setType(TT_LambdaArrow);
 
 2423    } 
else if (Current.is(tok::arrow) && Style.isVerilog()) {
 
 2425      Current.setType(TT_BinaryOperator);
 
 2426    } 
else if (Current.is(tok::arrow) && AutoFound &&
 
 2427               Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
 
 2428               Current.Previous->isNoneOf(tok::kw_operator, tok::identifier)) {
 
 2430      Current.setType(TT_TrailingReturnArrow);
 
 2431    } 
else if (Current.is(tok::arrow) && Current.Previous &&
 
 2432               Current.Previous->is(tok::r_brace) &&
 
 2436      Current.setType(TT_TrailingReturnArrow);
 
 2437    } 
else if (isDeductionGuide(Current)) {
 
 2439      Current.setType(TT_TrailingReturnArrow);
 
 2440    } 
else if (Current.isPointerOrReference()) {
 
 2441      Current.setType(determineStarAmpUsage(
 
 2443          Contexts.back().CanBeExpression && Contexts.back().IsExpression,
 
 2444          Contexts.back().ContextType == Context::TemplateArgument));
 
 2445    } 
else if (Current.isOneOf(tok::minus, tok::plus, tok::caret) ||
 
 2446               (Style.isVerilog() && Current.is(tok::pipe))) {
 
 2447      Current.setType(determinePlusMinusCaretUsage(Current));
 
 2448      if (Current.is(TT_UnaryOperator) && Current.is(tok::caret))
 
 2449        Contexts.back().CaretFound = 
true;
 
 2450    } 
else if (Current.isOneOf(tok::minusminus, tok::plusplus)) {
 
 2451      Current.setType(determineIncrementUsage(Current));
 
 2452    } 
else if (Current.isOneOf(tok::exclaim, tok::tilde)) {
 
 2453      Current.setType(TT_UnaryOperator);
 
 2454    } 
else if (Current.is(tok::question)) {
 
 2455      if (Style.isJavaScript() && Line.MustBeDeclaration &&
 
 2456          !Contexts.back().IsExpression) {
 
 2459        Current.setType(TT_JsTypeOptionalQuestion);
 
 2460      } 
else if (Style.isTableGen()) {
 
 2462        Current.setType(TT_Unknown);
 
 2464        Current.setType(TT_ConditionalExpr);
 
 2466    } 
else if (Current.isBinaryOperator() &&
 
 2467               (!Current.Previous || Current.Previous->isNot(tok::l_square)) &&
 
 2468               (Current.isNot(tok::greater) && !Style.isTextProto())) {
 
 2469      if (Style.isVerilog()) {
 
 2470        if (Current.is(tok::lessequal) && Contexts.size() == 1 &&
 
 2471            !Contexts.back().VerilogAssignmentFound) {
 
 2475          Current.setFinalizedType(TT_BinaryOperator);
 
 2478          Contexts.back().VerilogAssignmentFound = 
true;
 
 2480      Current.setType(TT_BinaryOperator);
 
 2481    } 
else if (Current.is(tok::comment)) {
 
 2482      if (Current.TokenText.starts_with(
"/*")) {
 
 2483        if (Current.TokenText.ends_with(
"*/")) {
 
 2484          Current.setType(TT_BlockComment);
 
 2488          Current.Tok.setKind(tok::unknown);
 
 2491        Current.setType(TT_LineComment);
 
 2493    } 
else if (Current.is(tok::string_literal)) {
 
 2494      if (Style.isVerilog() && Contexts.back().VerilogMayBeConcatenation &&
 
 2495          Current.getPreviousNonComment() &&
 
 2496          Current.getPreviousNonComment()->isOneOf(tok::comma, tok::l_brace) &&
 
 2497          Current.getNextNonComment() &&
 
 2498          Current.getNextNonComment()->isOneOf(tok::comma, tok::r_brace)) {
 
 2499        Current.setType(TT_StringInConcatenation);
 
 2501    } 
else if (Current.is(tok::l_paren)) {
 
 2502      if (lParenStartsCppCast(Current))
 
 2503        Current.setType(TT_CppCastLParen);
 
 2504    } 
else if (Current.is(tok::r_paren)) {
 
 2505      if (rParenEndsCast(Current))
 
 2506        Current.setType(TT_CastRParen);
 
 2507      if (Current.MatchingParen && Current.Next &&
 
 2508          !Current.Next->isBinaryOperator() &&
 
 2509          Current.Next->isNoneOf(
 
 2510              tok::semi, tok::colon, tok::l_brace, tok::l_paren, tok::comma,
 
 2511              tok::period, tok::arrow, tok::coloncolon, tok::kw_noexcept)) {
 
 2512        if (
FormatToken *AfterParen = Current.MatchingParen->Next;
 
 2513            AfterParen && AfterParen->isNot(tok::caret)) {
 
 2515          if (
FormatToken *BeforeParen = Current.MatchingParen->Previous;
 
 2516              BeforeParen && BeforeParen->is(tok::identifier) &&
 
 2517              BeforeParen->isNot(TT_TypenameMacro) &&
 
 2518              BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
 
 2519              (!BeforeParen->Previous ||
 
 2520               BeforeParen->Previous->ClosesTemplateDeclaration ||
 
 2521               BeforeParen->Previous->ClosesRequiresClause)) {
 
 2522            Current.setType(TT_FunctionAnnotationRParen);
 
 2526    } 
else if (Current.is(tok::at) && Current.Next && !Style.isJavaScript() &&
 
 2530      switch (Current.Next->Tok.getObjCKeywordID()) {
 
 2531      case tok::objc_interface:
 
 2532      case tok::objc_implementation:
 
 2533      case tok::objc_protocol:
 
 2534        Current.setType(TT_ObjCDecl);
 
 2536      case tok::objc_property:
 
 2537        Current.setType(TT_ObjCProperty);
 
 2542    } 
else if (Current.is(tok::period)) {
 
 2543      FormatToken *PreviousNoComment = Current.getPreviousNonComment();
 
 2544      if (PreviousNoComment &&
 
 2545          PreviousNoComment->isOneOf(tok::comma, tok::l_brace)) {
 
 2546        Current.setType(TT_DesignatedInitializerPeriod);
 
 2547      } 
else if (Style.isJava() && Current.Previous &&
 
 2548                 Current.Previous->isOneOf(TT_JavaAnnotation,
 
 2549                                           TT_LeadingJavaAnnotation)) {
 
 2550        Current.setType(Current.Previous->getType());
 
 2552    } 
else if (canBeObjCSelectorComponent(Current) &&
 
 2555               Current.Previous && Current.Previous->is(TT_CastRParen) &&
 
 2556               Current.Previous->MatchingParen &&
 
 2557               Current.Previous->MatchingParen->Previous &&
 
 2558               Current.Previous->MatchingParen->Previous->is(
 
 2559                   TT_ObjCMethodSpecifier)) {
 
 2563      Current.setType(TT_SelectorName);
 
 2564    } 
else if (Current.isOneOf(tok::identifier, tok::kw_const, tok::kw_noexcept,
 
 2565                               tok::kw_requires) &&
 
 2567               Current.Previous->isNoneOf(tok::equal, tok::at,
 
 2568                                          TT_CtorInitializerComma,
 
 2569                                          TT_CtorInitializerColon) &&
 
 2570               Line.MightBeFunctionDecl && Contexts.size() == 1) {
 
 2573      Current.setType(TT_TrailingAnnotation);
 
 2574    } 
else if ((Style.isJava() || Style.isJavaScript()) && Current.Previous) {
 
 2575      if (Current.Previous->is(tok::at) &&
 
 2576          Current.isNot(Keywords.kw_interface)) {
 
 2580          Current.setType(TT_LeadingJavaAnnotation);
 
 2582          Current.setType(TT_JavaAnnotation);
 
 2583      } 
else if (Current.Previous->is(tok::period) &&
 
 2584                 Current.Previous->isOneOf(TT_JavaAnnotation,
 
 2585                                           TT_LeadingJavaAnnotation)) {
 
 2586        Current.setType(Current.Previous->getType());
 
 2598    if (Style.isVerilog())
 
 2601    if (!
Tok.Previous || 
Tok.isNot(tok::identifier) || 
Tok.is(TT_ClassHeadName))
 
 2604    if (
Tok.endsSequence(Keywords.kw_final, TT_ClassHeadName))
 
 2607    if ((Style.isJavaScript() || Style.isJava()) && 
Tok.is(Keywords.kw_extends))
 
 2610    if (
const auto *NextNonComment = 
Tok.getNextNonComment();
 
 2611        (!NextNonComment && !Line.InMacroBody) ||
 
 2613         (NextNonComment->isPointerOrReference() ||
 
 2614          NextNonComment->isOneOf(TT_ClassHeadName, tok::string_literal) ||
 
 2615          (Line.InPragmaDirective && NextNonComment->is(tok::identifier))))) {
 
 2619    if (
Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof,
 
 2623    if (Style.isJavaScript() && 
Tok.Previous->is(Keywords.kw_in))
 
 2630    if (!Style.isJavaScript())
 
 2631      while (PreviousNotConst && PreviousNotConst->is(tok::kw_const))
 
 2632        PreviousNotConst = PreviousNotConst->getPreviousNonComment();
 
 2634    if (!PreviousNotConst)
 
 2637    if (PreviousNotConst->ClosesRequiresClause)
 
 2640    if (Style.isTableGen()) {
 
 2642      if (Keywords.isTableGenDefinition(*PreviousNotConst))
 
 2645      if (Contexts.back().ContextKind != tok::l_brace)
 
 2649    bool IsPPKeyword = PreviousNotConst->is(tok::identifier) &&
 
 2650                       PreviousNotConst->Previous &&
 
 2651                       PreviousNotConst->Previous->is(tok::hash);
 
 2653    if (PreviousNotConst->is(TT_TemplateCloser)) {
 
 2654      return PreviousNotConst && PreviousNotConst->MatchingParen &&
 
 2655             PreviousNotConst->MatchingParen->Previous &&
 
 2656             PreviousNotConst->MatchingParen->Previous->isNoneOf(
 
 2657                 tok::period, tok::kw_template);
 
 2660    if ((PreviousNotConst->is(tok::r_paren) &&
 
 2661         PreviousNotConst->is(TT_TypeDeclarationParen)) ||
 
 2662        PreviousNotConst->is(TT_AttributeRParen)) {
 
 2671    if (PreviousNotConst->isOneOf(tok::identifier, tok::kw_auto) &&
 
 2672        PreviousNotConst->isNot(TT_StatementAttributeLikeMacro)) {
 
 2677    if (PreviousNotConst->is(TT_PointerOrReference) ||
 
 2678        PreviousNotConst->endsSequence(tok::coloncolon,
 
 2679                                       TT_PointerOrReference)) {
 
 2684    if (PreviousNotConst->isTypeName(LangOpts))
 
 2688    if (Style.isJava() && PreviousNotConst->is(tok::r_square))
 
 2692    return Style.isJavaScript() && PreviousNotConst->is(tok::kw_const);
 
 2702    if (LeftOfParens && LeftOfParens->is(TT_TemplateCloser) &&
 
 2703        LeftOfParens->MatchingParen) {
 
 2704      auto *Prev = LeftOfParens->MatchingParen->getPreviousNonComment();
 
 2706          Prev->isOneOf(tok::kw_const_cast, tok::kw_dynamic_cast,
 
 2707                        tok::kw_reinterpret_cast, tok::kw_static_cast)) {
 
 2718    assert(
Tok.is(tok::r_paren));
 
 2720    if (!
Tok.MatchingParen || !
Tok.Previous)
 
 2724    if (!IsCpp && !Style.isCSharp() && !Style.isJava())
 
 2727    const auto *LParen = 
Tok.MatchingParen;
 
 2728    const auto *BeforeRParen = 
Tok.Previous;
 
 2729    const auto *AfterRParen = 
Tok.Next;
 
 2732    if (BeforeRParen == LParen || !AfterRParen)
 
 2735    if (LParen->is(TT_OverloadedOperatorLParen))
 
 2738    auto *LeftOfParens = LParen->getPreviousNonComment();
 
 2742      if (LeftOfParens->is(tok::r_paren) &&
 
 2743          LeftOfParens->isNot(TT_CastRParen)) {
 
 2744        if (!LeftOfParens->MatchingParen ||
 
 2745            !LeftOfParens->MatchingParen->Previous) {
 
 2748        LeftOfParens = LeftOfParens->MatchingParen->Previous;
 
 2751      if (LeftOfParens->is(tok::r_square)) {
 
 2754          if (
Tok->isNot(tok::r_square))
 
 2757          Tok = 
Tok->getPreviousNonComment();
 
 2758          if (!
Tok || 
Tok->isNot(tok::l_square))
 
 2761          Tok = 
Tok->getPreviousNonComment();
 
 2762          if (!
Tok || 
Tok->isNot(tok::kw_delete))
 
 2766        if (
FormatToken *MaybeDelete = MayBeArrayDelete(LeftOfParens))
 
 2767          LeftOfParens = MaybeDelete;
 
 2773      if (LeftOfParens->Tok.getIdentifierInfo() && LeftOfParens->Previous &&
 
 2774          LeftOfParens->Previous->is(tok::kw_operator)) {
 
 2780      if (LeftOfParens->Tok.getIdentifierInfo() &&
 
 2781          LeftOfParens->isNoneOf(Keywords.kw_in, tok::kw_return, tok::kw_case,
 
 2782                                 tok::kw_delete, tok::kw_throw)) {
 
 2788      if (LeftOfParens->isOneOf(tok::at, tok::r_square, TT_OverloadedOperator,
 
 2789                                TT_TemplateCloser, tok::ellipsis)) {
 
 2794    if (AfterRParen->is(tok::question) ||
 
 2795        (AfterRParen->is(tok::ampamp) && !BeforeRParen->isTypeName(LangOpts))) {
 
 2800    if (AfterRParen->is(Keywords.kw_in) && Style.isCSharp())
 
 2805    if (AfterRParen->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
 
 2806                             tok::kw_requires, tok::kw_throw, tok::arrow,
 
 2807                             Keywords.kw_override, Keywords.kw_final) ||
 
 2808        isCppAttribute(IsCpp, *AfterRParen)) {
 
 2814    if (Style.isJava() && AfterRParen->is(tok::l_paren))
 
 2818    if (AfterRParen->isOneOf(tok::kw_sizeof, tok::kw_alignof) ||
 
 2819        (AfterRParen->Tok.isLiteral() &&
 
 2820         AfterRParen->isNot(tok::string_literal))) {
 
 2825      if (
Tok.isNot(TT_TemplateCloser))
 
 2827      const auto *
Less = 
Tok.MatchingParen;
 
 2830      const auto *BeforeLess = 
Less->getPreviousNonComment();
 
 2831      return BeforeLess && BeforeLess->isNot(TT_VariableTemplate);
 
 2835    auto IsQualifiedPointerOrReference = [](
const FormatToken *
T,
 
 2836                                            const LangOptions &LangOpts) {
 
 2838      assert(!
T->isTypeName(LangOpts) && 
"Should have already been checked");
 
 2842        if (
T->is(TT_AttributeRParen)) {
 
 2844          assert(
T->is(tok::r_paren));
 
 2845          assert(
T->MatchingParen);
 
 2846          assert(
T->MatchingParen->is(tok::l_paren));
 
 2847          assert(
T->MatchingParen->is(TT_AttributeLParen));
 
 2848          if (
const auto *
Tok = 
T->MatchingParen->Previous;
 
 2849              Tok && 
Tok->isAttribute()) {
 
 2853        } 
else if (
T->is(TT_AttributeRSquare)) {
 
 2855          if (
T->MatchingParen && 
T->MatchingParen->Previous) {
 
 2856            T = 
T->MatchingParen->Previous;
 
 2859        } 
else if (
T->canBePointerOrReferenceQualifier()) {
 
 2865      return T && 
T->is(TT_PointerOrReference);
 
 2868    bool ParensAreType = IsNonVariableTemplate(*BeforeRParen) ||
 
 2869                         BeforeRParen->is(TT_TypeDeclarationParen) ||
 
 2870                         BeforeRParen->isTypeName(LangOpts) ||
 
 2871                         IsQualifiedPointerOrReference(BeforeRParen, LangOpts);
 
 2872    bool ParensCouldEndDecl =
 
 2873        AfterRParen->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater);
 
 2874    if (ParensAreType && !ParensCouldEndDecl)
 
 2885    for (
const auto *Token = LParen->Next; Token != &
Tok; Token = Token->Next)
 
 2886      if (Token->is(TT_BinaryOperator))
 
 2891    if (AfterRParen->isOneOf(tok::identifier, tok::kw_this))
 
 2895    if (AfterRParen->is(tok::l_paren)) {
 
 2896      for (
const auto *Prev = BeforeRParen; Prev->is(tok::identifier);) {
 
 2897        Prev = Prev->Previous;
 
 2898        if (Prev->is(tok::coloncolon))
 
 2899          Prev = Prev->Previous;
 
 2905    if (!AfterRParen->Next)
 
 2908    if (AfterRParen->is(tok::l_brace) &&
 
 2916    const bool NextIsAmpOrStar = AfterRParen->isOneOf(tok::amp, tok::star);
 
 2917    if (!(AfterRParen->isUnaryOperator() || NextIsAmpOrStar) ||
 
 2918        AfterRParen->is(tok::plus) ||
 
 2919        AfterRParen->Next->isNoneOf(tok::identifier, tok::numeric_constant)) {
 
 2923    if (NextIsAmpOrStar &&
 
 2924        (AfterRParen->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
 
 2928    if (Line.InPPDirective && AfterRParen->is(tok::minus))
 
 2931    const auto *Prev = BeforeRParen;
 
 2934    if (Prev->is(tok::r_paren)) {
 
 2935      if (Prev->is(TT_CastRParen))
 
 2937      Prev = Prev->MatchingParen;
 
 2940      Prev = Prev->Previous;
 
 2941      if (!Prev || Prev->isNot(tok::r_paren))
 
 2943      Prev = Prev->MatchingParen;
 
 2944      return Prev && Prev->is(TT_FunctionTypeLParen);
 
 2948    for (Prev = BeforeRParen; Prev != LParen; Prev = Prev->Previous)
 
 2949      if (Prev->isNoneOf(tok::kw_const, tok::identifier, tok::coloncolon))
 
 2967    if (PrevToken->isOneOf(
 
 2968            TT_ConditionalExpr, tok::l_paren, tok::comma, tok::colon, tok::semi,
 
 2969            tok::equal, tok::question, tok::l_square, tok::l_brace,
 
 2970            tok::kw_case, tok::kw_co_await, tok::kw_co_return, tok::kw_co_yield,
 
 2971            tok::kw_delete, tok::kw_return, tok::kw_throw)) {
 
 2978    if (PrevToken->is(tok::kw_sizeof))
 
 2982    if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator))
 
 2986    if (PrevToken->is(TT_BinaryOperator))
 
 2994                                  bool InTemplateArgument) {
 
 2995    if (Style.isJavaScript())
 
 2996      return TT_BinaryOperator;
 
 2999    if (Style.isCSharp() && 
Tok.is(tok::ampamp))
 
 3000      return TT_BinaryOperator;
 
 3002    if (Style.isVerilog()) {
 
 3007      if (
Tok.is(tok::star))
 
 3008        return TT_BinaryOperator;
 
 3009      return determineUnaryOperatorByUsage(
Tok) ? TT_UnaryOperator
 
 3010                                                : TT_BinaryOperator;
 
 3015      return TT_UnaryOperator;
 
 3016    if (PrevToken->isTypeName(LangOpts))
 
 3017      return TT_PointerOrReference;
 
 3018    if (PrevToken->isPlacementOperator() && 
Tok.is(tok::ampamp))
 
 3019      return TT_BinaryOperator;
 
 3021    auto *NextToken = 
Tok.getNextNonComment();
 
 3023      return TT_PointerOrReference;
 
 3024    if (NextToken->is(tok::greater)) {
 
 3025      NextToken->setFinalizedType(TT_TemplateCloser);
 
 3026      return TT_PointerOrReference;
 
 3029    if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
 
 3030      return TT_BinaryOperator;
 
 3032    if (NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
 
 3033                           TT_RequiresClause) ||
 
 3034        (NextToken->is(tok::kw_noexcept) && !IsExpression) ||
 
 3035        NextToken->canBePointerOrReferenceQualifier() ||
 
 3036        (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) {
 
 3037      return TT_PointerOrReference;
 
 3040    if (PrevToken->is(tok::coloncolon))
 
 3041      return TT_PointerOrReference;
 
 3043    if (PrevToken->is(tok::r_paren) && PrevToken->is(TT_TypeDeclarationParen))
 
 3044      return TT_PointerOrReference;
 
 3046    if (determineUnaryOperatorByUsage(
Tok))
 
 3047      return TT_UnaryOperator;
 
 3049    if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))
 
 3050      return TT_PointerOrReference;
 
 3051    if (NextToken->is(tok::kw_operator) && !IsExpression)
 
 3052      return TT_PointerOrReference;
 
 3053    if (NextToken->isOneOf(tok::comma, tok::semi))
 
 3054      return TT_PointerOrReference;
 
 3066    if (PrevToken->is(tok::r_brace) && 
Tok.is(tok::star) &&
 
 3067        !PrevToken->MatchingParen) {
 
 3068      return TT_PointerOrReference;
 
 3071    if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
 
 3072      return TT_UnaryOperator;
 
 3074    if (PrevToken->Tok.isLiteral() ||
 
 3075        PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
 
 3076                           tok::kw_false, tok::r_brace)) {
 
 3077      return TT_BinaryOperator;
 
 3081    while (NextNonParen && NextNonParen->is(tok::l_paren))
 
 3082      NextNonParen = NextNonParen->getNextNonComment();
 
 3083    if (NextNonParen && (NextNonParen->Tok.isLiteral() ||
 
 3084                         NextNonParen->isOneOf(tok::kw_true, tok::kw_false) ||
 
 3085                         NextNonParen->isUnaryOperator())) {
 
 3086      return TT_BinaryOperator;
 
 3092    if (InTemplateArgument && NextToken->Tok.isAnyIdentifier())
 
 3093      return TT_BinaryOperator;
 
 3097    if (
Tok.is(tok::ampamp) &&
 
 3098        NextToken->isOneOf(tok::l_paren, tok::star, tok::amp)) {
 
 3099      return TT_BinaryOperator;
 
 3106    if (NextToken->Tok.isAnyIdentifier()) {
 
 3107      auto *NextNextToken = NextToken->getNextNonComment();
 
 3108      if (NextNextToken) {
 
 3109        if (NextNextToken->is(tok::arrow))
 
 3110          return TT_BinaryOperator;
 
 3111        if (NextNextToken->isPointerOrReference() &&
 
 3112            !NextToken->isObjCLifetimeQualifier(Style)) {
 
 3113          NextNextToken->setFinalizedType(TT_BinaryOperator);
 
 3114          return TT_BinaryOperator;
 
 3121    if (IsExpression && !Contexts.back().CaretFound)
 
 3122      return TT_BinaryOperator;
 
 3125    if (!Scopes.empty() && Scopes.back() == 
ST_Class)
 
 3126      return TT_PointerOrReference;
 
 3129    auto IsChainedOperatorAmpOrMember = [](
const FormatToken *token) {
 
 3130      return !token || token->isOneOf(tok::amp, tok::period, tok::arrow,
 
 3131                                      tok::arrowstar, tok::periodstar);
 
 3136    if (
Tok.is(tok::amp) && PrevToken->Tok.isAnyIdentifier() &&
 
 3137        IsChainedOperatorAmpOrMember(PrevToken->getPreviousNonComment()) &&
 
 3138        NextToken && NextToken->Tok.isAnyIdentifier()) {
 
 3139      if (
auto NextNext = NextToken->getNextNonComment();
 
 3141          (IsChainedOperatorAmpOrMember(NextNext) || NextNext->is(tok::semi))) {
 
 3142        return TT_BinaryOperator;
 
 3148      return TT_BinaryOperator;
 
 3151    return TT_PointerOrReference;
 
 3155    if (determineUnaryOperatorByUsage(
Tok))
 
 3156      return TT_UnaryOperator;
 
 3160      return TT_UnaryOperator;
 
 3162    if (PrevToken->is(tok::at))
 
 3163      return TT_UnaryOperator;
 
 3166    return TT_BinaryOperator;
 
 3172    if (!PrevToken || PrevToken->is(TT_CastRParen))
 
 3173      return TT_UnaryOperator;
 
 3174    if (PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::identifier))
 
 3175      return TT_TrailingUnaryOperator;
 
 3177    return TT_UnaryOperator;
 
 3180  SmallVector<Context, 8> Contexts;
 
 3182  const FormatStyle &Style;
 
 3183  AnnotatedLine &Line;
 
 3187  LangOptions LangOpts;
 
 3188  const AdditionalKeywords &Keywords;
 
 3190  SmallVector<ScopeType> &Scopes;
 
 3196  llvm::SmallPtrSet<FormatToken *, 16> NonTemplateLess;
 
 3198  int TemplateDeclarationDepth;
 
 3206class ExpressionParser {
 
 3208  ExpressionParser(
const FormatStyle &Style, 
const AdditionalKeywords &Keywords,
 
 3209                   AnnotatedLine &Line)
 
 3210      : Style(Style), Keywords(Keywords), Line(Line), Current(Line.
First) {}
 
 3213  void parse(
int Precedence = 0) {
 
 3216    while (Current && (Current->is(tok::kw_return) ||
 
 3217                       (Current->is(tok::colon) &&
 
 3218                        Current->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral)))) {
 
 3222    if (!Current || Precedence > PrecedenceArrowAndPeriod)
 
 3227      parseConditionalExpr();
 
 3233    if (Precedence == PrecedenceUnaryOperator) {
 
 3234      parseUnaryOperator();
 
 3251      if (Style.isVerilog() && Precedence == 
prec::Comma) {
 
 3252        VerilogFirstOfType =
 
 3253            verilogGroupDecl(VerilogFirstOfType, LatestOperator);
 
 3257      parse(Precedence + 1);
 
 3259      int CurrentPrecedence = getCurrentPrecedence();
 
 3260      if (Style.BreakBinaryOperations == FormatStyle::BBO_OnePerLine &&
 
 3270      if (Precedence == CurrentPrecedence && Current &&
 
 3271          Current->is(TT_SelectorName)) {
 
 3273          addFakeParenthesis(Start, 
prec::Level(Precedence));
 
 3277      if ((Style.isCSharp() || Style.isJavaScript() || Style.isJava()) &&
 
 3281        FormatToken *Prev = Current->getPreviousNonComment();
 
 3282        if (Prev && Prev->is(tok::string_literal) &&
 
 3283            (Prev == Start || Prev->endsSequence(tok::string_literal, tok::plus,
 
 3284                                                 TT_StringInConcatenation))) {
 
 3285          Prev->setType(TT_StringInConcatenation);
 
 3292          (Current->closesScope() &&
 
 3293           (Current->MatchingParen || Current->is(TT_TemplateString))) ||
 
 3294          (CurrentPrecedence != -1 && CurrentPrecedence < Precedence) ||
 
 3303      if (Current->opensScope() ||
 
 3304          Current->isOneOf(TT_RequiresClause,
 
 3305                           TT_RequiresClauseInARequiresExpression)) {
 
 3308        while (Current && (!Current->closesScope() || Current->opensScope())) {
 
 3315        if (CurrentPrecedence == Precedence) {
 
 3317            LatestOperator->NextOperator = Current;
 
 3318          LatestOperator = Current;
 
 3322        next(Precedence > 0);
 
 3327    if (Style.isVerilog() && Precedence == 
prec::Comma && VerilogFirstOfType)
 
 3328      addFakeParenthesis(VerilogFirstOfType, 
prec::Comma);
 
 3330    if (LatestOperator && (Current || Precedence > 0)) {
 
 3336           Start->Previous->isOneOf(TT_RequiresClause,
 
 3337                                    TT_RequiresClauseInARequiresExpression))
 
 3339                  auto Ret = Current ? Current : Line.Last;
 
 3340                  while (!
Ret->ClosesRequiresClause && 
Ret->Previous)
 
 3346      if (Precedence == PrecedenceArrowAndPeriod) {
 
 3350        addFakeParenthesis(Start, 
prec::Level(Precedence), End);
 
 3358  int getCurrentPrecedence() {
 
 3360      const FormatToken *NextNonComment = Current->getNextNonComment();
 
 3361      if (Current->is(TT_ConditionalExpr))
 
 3363      if (NextNonComment && Current->is(TT_SelectorName) &&
 
 3364          (NextNonComment->isOneOf(TT_DictLiteral, TT_JsTypeColon) ||
 
 3365           (Style.isProto() && NextNonComment->is(tok::less)))) {
 
 3368      if (Current->is(TT_JsComputedPropertyName))
 
 3370      if (Current->is(TT_LambdaArrow))
 
 3372      if (Current->is(TT_FatArrow))
 
 3374      if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName) ||
 
 3375          (Current->is(tok::comment) && NextNonComment &&
 
 3376           NextNonComment->is(TT_SelectorName))) {
 
 3379      if (Current->is(TT_RangeBasedForLoopColon))
 
 3381      if ((Style.isJava() || Style.isJavaScript()) &&
 
 3382          Current->is(Keywords.kw_instanceof)) {
 
 3385      if (Style.isJavaScript() &&
 
 3386          Current->isOneOf(Keywords.kw_in, Keywords.kw_as)) {
 
 3389      if (Current->isOneOf(TT_BinaryOperator, tok::comma))
 
 3390        return Current->getPrecedence();
 
 3391      if (Current->isOneOf(tok::period, tok::arrow) &&
 
 3392          Current->isNot(TT_TrailingReturnArrow)) {
 
 3393        return PrecedenceArrowAndPeriod;
 
 3395      if ((Style.isJava() || Style.isJavaScript()) &&
 
 3396          Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
 
 3397                           Keywords.kw_throws)) {
 
 3402      if (Style.isVerilog() && Current->is(tok::colon))
 
 3414    if (Start->MacroParent)
 
 3417    Start->FakeLParens.push_back(Precedence);
 
 3419      Start->StartsBinaryExpression = 
true;
 
 3420    if (!End && Current)
 
 3421      End = Current->getPreviousNonComment();
 
 3425        End->EndsBinaryExpression = 
true;
 
 3431  void parseUnaryOperator() {
 
 3432    SmallVector<FormatToken *, 2> Tokens;
 
 3433    while (Current && Current->is(TT_UnaryOperator)) {
 
 3434      Tokens.push_back(Current);
 
 3437    parse(PrecedenceArrowAndPeriod);
 
 3444  void parseConditionalExpr() {
 
 3445    while (Current && Current->isTrailingComment())
 
 3449    if (!Current || Current->isNot(tok::question))
 
 3453    if (!Current || Current->isNot(TT_ConditionalExpr))
 
 3460  void next(
bool SkipPastLeadingComments = 
true) {
 
 3462      Current = Current->Next;
 
 3464           (Current->NewlinesBefore == 0 || SkipPastLeadingComments) &&
 
 3465           Current->isTrailingComment()) {
 
 3466      Current = Current->Next;
 
 3480    while (Start->startsSequence(tok::l_paren, tok::star)) {
 
 3481      if (!(Start = Start->MatchingParen) ||
 
 3482          !(Start = Start->getNextNonComment())) {
 
 3489    if (
Tok->is(Keywords.kw_assign))
 
 3490      Tok = 
Tok->getNextNonComment();
 
 3502      if (
Tok->is(tok::hash)) {
 
 3507          Tok = 
Tok->getNextNonComment();
 
 3508      } 
else if (
Tok->is(tok::hashhash)) {
 
 3512          Tok = 
Tok->getNextNonComment();
 
 3513      } 
else if (Keywords.isVerilogQualifier(*
Tok) ||
 
 3514                 Keywords.isVerilogIdentifier(*
Tok)) {
 
 3518        while (
Tok && 
Tok->isOneOf(tok::period, tok::coloncolon) &&
 
 3519               (
Tok = 
Tok->getNextNonComment())) {
 
 3520          if (Keywords.isVerilogIdentifier(*
Tok))
 
 3521            Tok = 
Tok->getNextNonComment();
 
 3525      } 
else if (
Tok->is(tok::l_paren)) {
 
 3530                Keywords.kw_highz0, Keywords.kw_highz1, Keywords.kw_large,
 
 3531                Keywords.kw_medium, Keywords.kw_pull0, Keywords.kw_pull1,
 
 3532                Keywords.kw_small, Keywords.kw_strong0, Keywords.kw_strong1,
 
 3533                Keywords.kw_supply0, Keywords.kw_supply1, Keywords.kw_weak0,
 
 3534                Keywords.kw_weak1)) {
 
 3535          Tok->setType(TT_VerilogStrength);
 
 3536          Tok = 
Tok->MatchingParen;
 
 3538            Tok->setType(TT_VerilogStrength);
 
 3539            Tok = 
Tok->getNextNonComment();
 
 3544      } 
else if (
Tok->is(Keywords.kw_verilogHash)) {
 
 3546        if (
Next->is(tok::l_paren))
 
 3549          Tok = 
Next->getNextNonComment();
 
 3558    while (
Tok && 
Tok->is(tok::l_square) && (
Tok = 
Tok->MatchingParen))
 
 3559      Tok = 
Tok->getNextNonComment();
 
 3560    if (
Tok && (
Tok->is(tok::hash) || Keywords.isVerilogIdentifier(*
Tok)))
 
 3569        First->setType(TT_VerilogDimensionedTypeName);
 
 3570    } 
else if (
First != Start) {
 
 3578      if (TypedName->is(TT_Unknown))
 
 3579        TypedName->setType(TT_StartOfName);
 
 3581      if (FirstOfType && PreviousComma) {
 
 3582        PreviousComma->setType(TT_VerilogTypeComma);
 
 3583        addFakeParenthesis(FirstOfType, 
prec::Comma, PreviousComma->Previous);
 
 3586      FirstOfType = TypedName;
 
 3593      while (Current && Current != FirstOfType) {
 
 3594        if (Current->opensScope()) {
 
 3605  const FormatStyle &Style;
 
 3606  const AdditionalKeywords &Keywords;
 
 3607  const AnnotatedLine &Line;
 
 3617    assert(
Line->First);
 
 3624            Line->First->OriginalColumn) {
 
 3625      const bool PPDirectiveOrImportStmt =
 
 3628      if (PPDirectiveOrImportStmt)
 
 3633      Line->Level = Style.IndentPPDirectives < FormatStyle::PPDIS_BeforeHash &&
 
 3634                            PPDirectiveOrImportStmt
 
 3636                        : NextNonCommentLine->
Level;
 
 3638      NextNonCommentLine = 
Line->First->isNot(tok::r_brace) ? 
Line : 
nullptr;
 
 
 3657       Tok = 
Tok->getNextNonComment()) {
 
 3659    if (
Tok->is(TT_AttributeLSquare)) {
 
 3660      Tok = 
Tok->MatchingParen;
 
 3668      if (
Tok->is(tok::l_paren) && 
Tok->is(TT_Unknown) && 
Tok->MatchingParen) {
 
 3676    if (
Tok->isOneOf(tok::kw_friend, tok::kw_inline, tok::kw_virtual,
 
 3677                     tok::kw_constexpr, tok::kw_consteval, tok::kw_explicit)) {
 
 3682    if (
Tok->is(tok::coloncolon)) {
 
 3689    while (
Tok->startsSequence(tok::identifier, tok::coloncolon)) {
 
 3697    if (
Tok->is(tok::tilde)) {
 
 3704    if (
Tok->isNot(tok::identifier) || 
Tok->isNot(TT_Unknown))
 
 
 3715  assert(
Tok && 
Tok->is(tok::identifier));
 
 3716  const auto *Prev = 
Tok->Previous;
 
 3718  if (Prev && Prev->is(tok::tilde))
 
 3719    Prev = Prev->Previous;
 
 3721  if (!Prev || !Prev->endsSequence(tok::coloncolon, tok::identifier))
 
 3724  assert(Prev->Previous);
 
 3725  return Prev->Previous->TokenText == 
Tok->TokenText;
 
 
 3729  if (!
Line.InMacroBody)
 
 3730    MacroBodyScopes.clear();
 
 3732  auto &ScopeStack = 
Line.InMacroBody ? MacroBodyScopes : Scopes;
 
 3733  AnnotatingParser 
Parser(Style, 
Line, Keywords, ScopeStack);
 
 3736  if (!
Line.Children.empty()) {
 
 3739    for (
auto &Child : 
Line.Children) {
 
 3740      if (InRequiresExpression &&
 
 3741          Child->First->isNoneOf(tok::kw_typename, tok::kw_requires,
 
 3742                                 TT_CompoundRequirementLBrace)) {
 
 3748    if (!ScopeStack.empty())
 
 3749      ScopeStack.pop_back();
 
 3762  ExpressionParser ExprParser(Style, Keywords, 
Line);
 
 3768    if (
Tok && ((!ScopeStack.empty() && ScopeStack.back() == 
ST_Class) ||
 
 3770      Tok->setFinalizedType(TT_CtorDtorDeclName);
 
 3771      assert(OpeningParen);
 
 3776  if (
Line.startsWith(TT_ObjCMethodSpecifier))
 
 3778  else if (
Line.startsWith(TT_ObjCDecl))
 
 3780  else if (
Line.startsWith(TT_ObjCProperty))
 
 3784  First->SpacesRequiredBefore = 1;
 
 3785  First->CanBreakBefore = 
First->MustBreakBefore;
 
 
 3794  if (Current.
is(TT_FunctionDeclarationName))
 
 3797  if (Current.
isNoneOf(tok::identifier, tok::kw_operator))
 
 3800  const auto *Prev = Current.getPreviousNonComment();
 
 3805  if (
const auto *PrevPrev = 
Previous.getPreviousNonComment();
 
 3806      PrevPrev && PrevPrev->is(TT_ObjCDecl)) {
 
 3810  auto skipOperatorName =
 
 3813      if (
Next->is(TT_OverloadedOperatorLParen))
 
 3815      if (
Next->is(TT_OverloadedOperator))
 
 3817      if (
Next->isPlacementOperator() || 
Next->is(tok::kw_co_await)) {
 
 3820            Next->Next->startsSequence(tok::l_square, tok::r_square)) {
 
 3825      if (
Next->startsSequence(tok::l_square, tok::r_square)) {
 
 3830      if ((
Next->isTypeName(LangOpts) || 
Next->is(tok::identifier)) &&
 
 3831          Next->Next && 
Next->Next->isPointerOrReference()) {
 
 3836      if (
Next->is(TT_TemplateOpener) && 
Next->MatchingParen) {
 
 3847  const bool IsCpp = LangOpts.CXXOperatorNames || LangOpts.C11;
 
 3850  if (Current.
is(tok::kw_operator)) {
 
 3851    if (
Line.startsWith(tok::kw_friend))
 
 3853    if (
Previous.Tok.getIdentifierInfo() &&
 
 3854        Previous.isNoneOf(tok::kw_return, tok::kw_co_return)) {
 
 3859      assert(
Previous.MatchingParen->is(tok::l_paren));
 
 3860      assert(
Previous.MatchingParen->is(TT_TypeDeclarationParen));
 
 3869    while (
Next && 
Next->startsSequence(tok::hashhash, tok::identifier))
 
 3872      if (
Next->is(TT_TemplateOpener) && 
Next->MatchingParen) {
 
 3874      } 
else if (
Next->is(tok::coloncolon)) {
 
 3878        if (
Next->is(tok::kw_operator)) {
 
 3879          Next = skipOperatorName(
Next->Next);
 
 3882        if (
Next->isNot(tok::identifier))
 
 3884      } 
else if (isCppAttribute(IsCpp, *
Next)) {
 
 3888      } 
else if (
Next->is(tok::l_paren)) {
 
 3897  if (!
Next || 
Next->isNot(tok::l_paren) || !
Next->MatchingParen)
 
 3899  ClosingParen = 
Next->MatchingParen;
 
 3900  assert(ClosingParen->
is(tok::r_paren));
 
 3902  if (
Line.Last->is(tok::l_brace))
 
 3904  if (
Next->Next == ClosingParen)
 
 3907  if (ClosingParen->
Next && ClosingParen->
Next->
is(TT_PointerOrReference))
 
 3920  if (IsCpp && 
Next->Next && 
Next->Next->is(tok::identifier) &&
 
 3921      !
Line.endsWith(tok::semi)) {
 
 3927    if (
Tok->is(TT_TypeDeclarationParen))
 
 3929    if (
Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && 
Tok->MatchingParen) {
 
 3930      Tok = 
Tok->MatchingParen;
 
 3933    if (
Tok->is(tok::kw_const) || 
Tok->isTypeName(LangOpts) ||
 
 3934        Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis)) {
 
 3937    if (
Tok->isOneOf(tok::l_brace, TT_ObjCMethodExpr) || 
Tok->Tok.isLiteral())
 
 
 3943bool TokenAnnotator::mustBreakForReturnType(
const AnnotatedLine &
Line)
 const {
 
 3944  assert(
Line.MightBeFunctionDecl);
 
 3946  if ((Style.BreakAfterReturnType == FormatStyle::RTBS_TopLevel ||
 
 3947       Style.BreakAfterReturnType == FormatStyle::RTBS_TopLevelDefinitions) &&
 
 3952  switch (Style.BreakAfterReturnType) {
 
 3953  case FormatStyle::RTBS_None:
 
 3954  case FormatStyle::RTBS_Automatic:
 
 3955  case FormatStyle::RTBS_ExceptShortType:
 
 3957  case FormatStyle::RTBS_All:
 
 3958  case FormatStyle::RTBS_TopLevel:
 
 3960  case FormatStyle::RTBS_AllDefinitions:
 
 3961  case FormatStyle::RTBS_TopLevelDefinitions:
 
 3962    return Line.mightBeFunctionDefinition();
 
 3972  Line.Computed = 
true;
 
 3980                           : 
Line.FirstStartColumn + 
First->ColumnWidth;
 
 3981  bool AlignArrayOfStructures =
 
 3982      (Style.AlignArrayOfStructures != FormatStyle::AIAS_None &&
 
 3984  if (AlignArrayOfStructures)
 
 3985    calculateArrayInitializerColumnList(
Line);
 
 3987  const auto *FirstNonComment = 
Line.getFirstNonComment();
 
 3988  bool SeenName = 
false;
 
 3989  bool LineIsFunctionDeclaration = 
false;
 
 3993  for (
auto *
Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
 
 3994                       ? FirstNonComment->Next
 
 3997    if (
Tok->is(TT_StartOfName))
 
 3999    if (
Tok->Previous->EndsCppAttributeGroup)
 
 4000      AfterLastAttribute = 
Tok;
 
 4001    if (
const bool IsCtorOrDtor = 
Tok->is(TT_CtorDtorDeclName);
 
 4005        Tok->setFinalizedType(TT_FunctionDeclarationName);
 
 4006      LineIsFunctionDeclaration = 
true;
 
 4010        assert(OpeningParen);
 
 4011        if (OpeningParen->is(TT_Unknown))
 
 4012          OpeningParen->setType(TT_FunctionDeclarationLParen);
 
 4019    if ((LineIsFunctionDeclaration ||
 
 4020         (FirstNonComment && FirstNonComment->is(TT_CtorDtorDeclName))) &&
 
 4021        Line.endsWith(tok::semi, tok::r_brace)) {
 
 4022      auto *
Tok = 
Line.Last->Previous;
 
 4023      while (
Tok->isNot(tok::r_brace))
 
 4025      if (
auto *LBrace = 
Tok->MatchingParen; LBrace && LBrace->is(TT_Unknown)) {
 
 4026        assert(LBrace->is(tok::l_brace));
 
 4029        LBrace->setFinalizedType(TT_FunctionLBrace);
 
 4033    if (SeenName && AfterLastAttribute &&
 
 4036      if (LineIsFunctionDeclaration)
 
 4037        Line.ReturnTypeWrapped = 
true;
 
 4040    if (!LineIsFunctionDeclaration) {
 
 4042      for (
const auto *
Tok = FirstNonComment; 
Tok; 
Tok = 
Tok->Next) {
 
 4043        if (
Tok->isNot(tok::kw_operator))
 
 4047        } 
while (
Tok && 
Tok->isNot(TT_OverloadedOperatorLParen));
 
 4048        if (!
Tok || !
Tok->MatchingParen)
 
 4050        const auto *LeftParen = 
Tok;
 
 4051        for (
Tok = 
Tok->Next; 
Tok && 
Tok != LeftParen->MatchingParen;
 
 4053          if (
Tok->isNot(tok::identifier))
 
 4056          const bool NextIsBinaryOperator =
 
 4058              Next->Next->is(tok::identifier);
 
 4059          if (!NextIsBinaryOperator)
 
 4061          Next->setType(TT_BinaryOperator);
 
 4065    } 
else if (ClosingParen) {
 
 4067        if (
Tok->is(TT_CtorInitializerColon))
 
 4069        if (
Tok->is(tok::arrow)) {
 
 4070          Tok->setType(TT_TrailingReturnArrow);
 
 4073        if (
Tok->isNot(TT_TrailingAnnotation))
 
 4076        if (!
Next || 
Next->isNot(tok::l_paren))
 
 4085  if (
First->is(TT_ElseLBrace)) {
 
 4086    First->CanBreakBefore = 
true;
 
 4087    First->MustBreakBefore = 
true;
 
 4090  bool InFunctionDecl = 
Line.MightBeFunctionDecl;
 
 4091  bool InParameterList = 
false;
 
 4092  for (
auto *Current = 
First->Next; Current; Current = Current->Next) {
 
 4094    if (Current->is(TT_LineComment)) {
 
 4096        Current->SpacesRequiredBefore =
 
 4097            (Style.Cpp11BracedListStyle == FormatStyle::BLS_AlignFirstComment &&
 
 4098             !Style.SpacesInParensOptions.Other)
 
 4101      } 
else if (Prev->
is(TT_VerilogMultiLineListLParen)) {
 
 4102        Current->SpacesRequiredBefore = 0;
 
 4104        Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
 
 4114      if (!Current->HasUnescapedNewline) {
 
 4117          if (
Parameter->isOneOf(tok::comment, tok::r_brace))
 
 4120            if (
Parameter->Previous->isNot(TT_CtorInitializerComma) &&
 
 4128    } 
else if (!Current->Finalized && Current->SpacesRequiredBefore == 0 &&
 
 4129               spaceRequiredBefore(
Line, *Current)) {
 
 4130      Current->SpacesRequiredBefore = 1;
 
 4135      Current->MustBreakBefore = 
true;
 
 4137      Current->MustBreakBefore =
 
 4138          Current->MustBreakBefore || mustBreakBefore(
Line, *Current);
 
 4139      if (!Current->MustBreakBefore && InFunctionDecl &&
 
 4140          Current->is(TT_FunctionDeclarationName)) {
 
 4141        Current->MustBreakBefore = mustBreakForReturnType(
Line);
 
 4145    Current->CanBreakBefore =
 
 4146        Current->MustBreakBefore || canBreakBefore(
Line, *Current);
 
 4148    if (Current->is(TT_FunctionDeclarationLParen)) {
 
 4149      InParameterList = 
true;
 
 4150    } 
else if (Current->is(tok::r_paren)) {
 
 4151      const auto *LParen = Current->MatchingParen;
 
 4152      if (LParen && LParen->is(TT_FunctionDeclarationLParen))
 
 4153        InParameterList = 
false;
 
 4154    } 
else if (InParameterList &&
 
 4155               Current->endsSequence(TT_AttributeMacro,
 
 4156                                     TT_PointerOrReference)) {
 
 4157      Current->CanBreakBefore = 
false;
 
 4160    unsigned ChildSize = 0;
 
 4163      ChildSize = LastOfChild.isTrailingComment() ? Style.ColumnLimit
 
 4166    if (Current->MustBreakBefore || Prev->
Children.size() > 1 ||
 
 4168         Prev->
Children[0]->First->MustBreakBefore) ||
 
 4169        Current->IsMultiline) {
 
 4170      Current->TotalLength = Prev->
TotalLength + Style.ColumnLimit;
 
 4172      Current->TotalLength = Prev->
TotalLength + Current->ColumnWidth +
 
 4173                             ChildSize + Current->SpacesRequiredBefore;
 
 4176    if (Current->is(TT_ControlStatementLBrace)) {
 
 4177      if (Style.ColumnLimit > 0 &&
 
 4178          Style.BraceWrapping.AfterControlStatement ==
 
 4179              FormatStyle::BWACS_MultiLine &&
 
 4180          Line.Level * Style.IndentWidth + 
Line.Last->TotalLength >
 
 4181              Style.ColumnLimit) {
 
 4182        Current->CanBreakBefore = 
true;
 
 4183        Current->MustBreakBefore = 
true;
 
 4185    } 
else if (Current->is(TT_CtorInitializerColon)) {
 
 4186      InFunctionDecl = 
false;
 
 4198    Current->SplitPenalty = splitPenalty(
Line, *Current, InFunctionDecl);
 
 4199    if (Style.Language == FormatStyle::LK_ObjC &&
 
 4200        Current->is(TT_SelectorName) && Current->ParameterIndex > 0) {
 
 4201      if (Current->ParameterIndex == 1)
 
 4202        Current->SplitPenalty += 5 * Current->BindingStrength;
 
 4204      Current->SplitPenalty += 20 * Current->BindingStrength;
 
 4208  calculateUnbreakableTailLengths(
Line);
 
 4210  for (
auto *Current = 
First; Current; Current = Current->Next) {
 
 4212      Current->Role->precomputeFormattingInfos(Current);
 
 4213    if (Current->MatchingParen &&
 
 4214        Current->MatchingParen->opensBlockOrBlockTypeList(Style) &&
 
 4219    if (Current->opensBlockOrBlockTypeList(Style))
 
 4223  LLVM_DEBUG({ printDebugInfo(
Line); });
 
 
 4226void TokenAnnotator::calculateUnbreakableTailLengths(
 
 4233        Current->
isOneOf(tok::comment, tok::string_literal)) {
 
 4243void TokenAnnotator::calculateArrayInitializerColumnList(
 
 4247  auto *CurrentToken = 
Line.First;
 
 4248  CurrentToken->ArrayInitializerLineStart = 
true;
 
 4250  while (CurrentToken && CurrentToken != 
Line.Last) {
 
 4251    if (CurrentToken->is(tok::l_brace)) {
 
 4252      CurrentToken->IsArrayInitializer = 
true;
 
 4253      if (CurrentToken->Next)
 
 4254        CurrentToken->Next->MustBreakBefore = 
true;
 
 4256          calculateInitializerColumnList(
Line, CurrentToken->Next, Depth + 1);
 
 4258      CurrentToken = CurrentToken->Next;
 
 4263FormatToken *TokenAnnotator::calculateInitializerColumnList(
 
 4265  while (CurrentToken && CurrentToken != 
Line.Last) {
 
 4266    if (CurrentToken->is(tok::l_brace))
 
 4268    else if (CurrentToken->is(tok::r_brace))
 
 4270    if (Depth == 2 && CurrentToken->isOneOf(tok::l_brace, tok::comma)) {
 
 4271      CurrentToken = CurrentToken->Next;
 
 4274      CurrentToken->StartsColumn = 
true;
 
 4275      CurrentToken = CurrentToken->Previous;
 
 4277    CurrentToken = CurrentToken->Next;
 
 4279  return CurrentToken;
 
 4284                                      bool InFunctionDecl)
 const {
 
 4288  if (
Left.is(tok::semi))
 
 4292  if (Style.isJava()) {
 
 4293    if (
Right.isOneOf(Keywords.kw_extends, Keywords.kw_throws))
 
 4295    if (
Right.is(Keywords.kw_implements))
 
 4297    if (
Left.is(tok::comma) && 
Left.NestingLevel == 0)
 
 4299  } 
else if (Style.isJavaScript()) {
 
 4300    if (
Right.is(Keywords.kw_function) && 
Left.isNot(tok::comma))
 
 4302    if (
Left.is(TT_JsTypeColon))
 
 4304    if ((
Left.is(TT_TemplateString) && 
Left.TokenText.ends_with(
"${")) ||
 
 4305        (
Right.is(TT_TemplateString) && 
Right.TokenText.starts_with(
"}"))) {
 
 4309    if (
Left.opensScope() && 
Right.closesScope())
 
 4311  } 
else if (Style.Language == FormatStyle::LK_Proto) {
 
 4312    if (
Right.is(tok::l_square))
 
 4314    if (
Right.is(tok::period))
 
 4318  if (
Right.is(tok::identifier) && 
Right.Next && 
Right.Next->is(TT_DictLiteral))
 
 4320  if (
Right.is(tok::l_square)) {
 
 4321    if (
Left.is(tok::r_square))
 
 4324    if (
Right.is(TT_LambdaLSquare) && 
Left.is(tok::equal))
 
 4326    if (
Right.isNoneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
 
 4327                       TT_ArrayInitializerLSquare,
 
 4328                       TT_DesignatedInitializerLSquare, TT_AttributeLSquare)) {
 
 4333  if (
Left.is(tok::coloncolon))
 
 4334    return Style.PenaltyBreakScopeResolution;
 
 4335  if (
Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
 
 4336                    tok::kw_operator)) {
 
 4337    if (
Line.startsWith(tok::kw_for) && 
Right.PartOfMultiVariableDeclStmt)
 
 4339    if (
Left.is(TT_StartOfName))
 
 4341    if (InFunctionDecl && 
Right.NestingLevel == 0)
 
 4342      return Style.PenaltyReturnTypeOnItsOwnLine;
 
 4345  if (
Right.is(TT_PointerOrReference))
 
 4347  if (
Right.is(TT_LambdaArrow))
 
 4349  if (
Left.is(tok::equal) && 
Right.is(tok::l_brace))
 
 4351  if (
Left.is(TT_CastRParen))
 
 4353  if (
Left.isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union))
 
 4355  if (
Left.is(tok::comment))
 
 4358  if (
Left.isOneOf(TT_RangeBasedForLoopColon, TT_InheritanceColon,
 
 4359                   TT_CtorInitializerColon)) {
 
 4363  if (
Right.isMemberAccess()) {
 
 4384    const auto Penalty = Style.PenaltyBreakBeforeMemberAccess;
 
 4386               ? std::min(Penalty, 35u)
 
 4390  if (
Right.is(TT_TrailingAnnotation) &&
 
 4391      (!
Right.Next || 
Right.Next->isNot(tok::l_paren))) {
 
 4394    if (
Line.startsWith(TT_ObjCMethodSpecifier))
 
 4401    bool is_short_annotation = 
Right.TokenText.size() < 10;
 
 4402    return (
Left.is(tok::r_paren) ? 100 : 120) + (is_short_annotation ? 50 : 0);
 
 4406  if (
Line.startsWith(tok::kw_for) && 
Left.is(tok::equal))
 
 4411  if (
Right.is(TT_SelectorName))
 
 4413  if (
Left.is(tok::colon)) {
 
 4414    if (
Left.is(TT_ObjCMethodExpr))
 
 4415      return Line.MightBeFunctionDecl ? 50 : 500;
 
 4416    if (
Left.is(TT_ObjCSelector))
 
 4424      Left.Previous->isOneOf(tok::identifier, tok::greater)) {
 
 4428  if (
Left.is(tok::l_paren) && Style.PenaltyBreakOpenParenthesis != 0)
 
 4429    return Style.PenaltyBreakOpenParenthesis;
 
 4430  if (
Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket)
 
 4432  if (
Left.is(tok::l_paren) && 
Left.Previous &&
 
 4433      (
Left.Previous->isOneOf(tok::kw_for, tok::kw__Generic) ||
 
 4434       Left.Previous->isIf())) {
 
 4437  if (
Left.is(tok::equal) && InFunctionDecl)
 
 4439  if (
Right.is(tok::r_brace))
 
 4441  if (
Left.is(TT_TemplateOpener))
 
 4443  if (
Left.opensScope()) {
 
 4447    if (!Style.AlignAfterOpenBracket &&
 
 4448        (
Left.ParameterCount <= 1 || Style.AllowAllArgumentsOnNextLine)) {
 
 4451    if (
Left.is(tok::l_brace) &&
 
 4452        Style.Cpp11BracedListStyle == FormatStyle::BLS_Block) {
 
 4455    return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter
 
 4458  if (
Left.is(TT_JavaAnnotation))
 
 4461  if (
Left.is(TT_UnaryOperator))
 
 4463  if (
Left.isOneOf(tok::plus, tok::comma) && 
Left.Previous &&
 
 4464      Left.Previous->isLabelString() &&
 
 4465      (
Left.NextOperator || 
Left.OperatorIndex != 0)) {
 
 4468  if (
Right.is(tok::plus) && 
Left.isLabelString() &&
 
 4469      (
Right.NextOperator || 
Right.OperatorIndex != 0)) {
 
 4472  if (
Left.is(tok::comma))
 
 4474  if (
Right.is(tok::lessless) && 
Left.isLabelString() &&
 
 4475      (
Right.NextOperator || 
Right.OperatorIndex != 1)) {
 
 4478  if (
Right.is(tok::lessless)) {
 
 4480    if (
Left.isNot(tok::r_paren) || 
Right.OperatorIndex > 0) {
 
 4486  if (
Left.ClosesTemplateDeclaration)
 
 4487    return Style.PenaltyBreakTemplateDeclaration;
 
 4488  if (
Left.ClosesRequiresClause)
 
 4490  if (
Left.is(TT_ConditionalExpr))
 
 4496    return Style.PenaltyBreakAssignment;
 
 4503bool TokenAnnotator::spaceRequiredBeforeParens(
const FormatToken &Right)
 const {
 
 4504  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
 
 4506  if (
Right.is(TT_OverloadedOperatorLParen) &&
 
 4507      Style.SpaceBeforeParensOptions.AfterOverloadedOperator) {
 
 4510  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
 
 4511      Right.ParameterCount > 0) {
 
 4520  if (
Left.is(tok::kw_return) &&
 
 4521      Right.isNoneOf(tok::semi, tok::r_paren, tok::hashhash)) {
 
 4524  if (
Left.is(tok::kw_throw) && 
Right.is(tok::l_paren) && 
Right.MatchingParen &&
 
 4525      Right.MatchingParen->is(TT_CastRParen)) {
 
 4528  if (
Left.is(Keywords.kw_assert) && Style.isJava())
 
 4531      Left.is(tok::objc_property)) {
 
 4534  if (
Right.is(tok::hashhash))
 
 4535    return Left.is(tok::hash);
 
 4536  if (
Left.isOneOf(tok::hashhash, tok::hash))
 
 4537    return Right.is(tok::hash);
 
 4538  if (Style.SpacesInParens == FormatStyle::SIPO_Custom) {
 
 4539    if (
Left.is(tok::l_paren) && 
Right.is(tok::r_paren))
 
 4540      return Style.SpacesInParensOptions.InEmptyParentheses;
 
 4541    if (Style.SpacesInParensOptions.ExceptDoubleParentheses &&
 
 4542        Left.is(tok::r_paren) && 
Right.is(tok::r_paren)) {
 
 4543      auto *InnerLParen = 
Left.MatchingParen;
 
 4544      if (InnerLParen && InnerLParen->Previous == 
Right.MatchingParen) {
 
 4545        InnerLParen->SpacesRequiredBefore = 0;
 
 4550    if (
Left.is(tok::l_paren))
 
 4552    else if (
Right.is(tok::r_paren) && 
Right.MatchingParen)
 
 4553      LeftParen = 
Right.MatchingParen;
 
 4554    if (LeftParen && (LeftParen->is(TT_ConditionLParen) ||
 
 4555                      (LeftParen->Previous &&
 
 4556                       isKeywordWithCondition(*LeftParen->Previous)))) {
 
 4557      return Style.SpacesInParensOptions.InConditionalStatements;
 
 4562  if (
Left.is(tok::kw_auto) && 
Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace,
 
 4564                                             TT_FunctionTypeLParen)) {
 
 4569  if (
Left.is(tok::kw_auto) && 
Right.isOneOf(tok::l_paren, tok::l_brace))
 
 4572  const auto *BeforeLeft = 
Left.Previous;
 
 4575  if (
Right.is(tok::l_paren) && 
Left.is(tok::kw_co_await) && BeforeLeft &&
 
 4576      BeforeLeft->is(tok::kw_operator)) {
 
 4580  if (
Left.isOneOf(tok::kw_co_await, tok::kw_co_yield, tok::kw_co_return) &&
 
 4581      Right.isNoneOf(tok::semi, tok::r_paren)) {
 
 4585  if (
Left.is(tok::l_paren) || 
Right.is(tok::r_paren)) {
 
 4586    return (
Right.is(TT_CastRParen) ||
 
 4587            (
Left.MatchingParen && 
Left.MatchingParen->is(TT_CastRParen)))
 
 4588               ? Style.SpacesInParensOptions.InCStyleCasts
 
 4589               : Style.SpacesInParensOptions.Other;
 
 4591  if (
Right.isOneOf(tok::semi, tok::comma))
 
 4594    bool IsLightweightGeneric = 
Right.MatchingParen &&
 
 4595                                Right.MatchingParen->Next &&
 
 4596                                Right.MatchingParen->Next->is(tok::colon);
 
 4597    return !IsLightweightGeneric && Style.ObjCSpaceBeforeProtocolList;
 
 4599  if (
Right.is(tok::less) && 
Left.is(tok::kw_template))
 
 4600    return Style.SpaceAfterTemplateKeyword;
 
 4601  if (
Left.isOneOf(tok::exclaim, tok::tilde))
 
 4603  if (
Left.is(tok::at) &&
 
 4604      Right.isOneOf(tok::identifier, tok::string_literal, tok::char_constant,
 
 4605                    tok::numeric_constant, tok::l_paren, tok::l_brace,
 
 4606                    tok::kw_true, tok::kw_false)) {
 
 4609  if (
Left.is(tok::colon))
 
 4610    return Left.isNoneOf(TT_ObjCSelector, TT_ObjCMethodExpr);
 
 4611  if (
Left.is(tok::coloncolon))
 
 4613  if (
Left.is(tok::less) || 
Right.isOneOf(tok::greater, tok::less)) {
 
 4614    if (Style.isTextProto() ||
 
 4615        (Style.Language == FormatStyle::LK_Proto &&
 
 4616         (
Left.is(TT_DictLiteral) || 
Right.is(TT_DictLiteral)))) {
 
 4618      if (
Left.is(tok::less) && 
Right.is(tok::greater))
 
 4620      return Style.Cpp11BracedListStyle == FormatStyle::BLS_Block;
 
 4623    if (
Right.isNot(TT_OverloadedOperatorLParen))
 
 4626  if (
Right.is(tok::ellipsis)) {
 
 4627    return Left.Tok.isLiteral() || (
Left.is(tok::identifier) && BeforeLeft &&
 
 4628                                    BeforeLeft->is(tok::kw_case));
 
 4630  if (
Left.is(tok::l_square) && 
Right.is(tok::amp))
 
 4631    return Style.SpacesInSquareBrackets;
 
 4632  if (
Right.is(TT_PointerOrReference)) {
 
 4633    if (
Left.is(tok::r_paren) && 
Line.MightBeFunctionDecl) {
 
 4634      if (!
Left.MatchingParen)
 
 4637          Left.MatchingParen->getPreviousNonComment();
 
 4638      if (!TokenBeforeMatchingParen || 
Left.isNot(TT_TypeDeclarationParen))
 
 4644    if ((Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_After ||
 
 4645         Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&
 
 4646        (
Left.is(TT_AttributeRParen) ||
 
 4647         Left.canBePointerOrReferenceQualifier())) {
 
 4650    if (
Left.Tok.isLiteral())
 
 4653    if (
Left.isTypeOrIdentifier(LangOpts) && 
Right.Next && 
Right.Next->Next &&
 
 4654        Right.Next->Next->is(TT_RangeBasedForLoopColon)) {
 
 4655      return getTokenPointerOrReferenceAlignment(Right) !=
 
 4656             FormatStyle::PAS_Left;
 
 4658    return Left.isNoneOf(TT_PointerOrReference, tok::l_paren) &&
 
 4659           (getTokenPointerOrReferenceAlignment(Right) !=
 
 4660                FormatStyle::PAS_Left ||
 
 4661            (
Line.IsMultiVariableDeclStmt &&
 
 4662             (
Left.NestingLevel == 0 ||
 
 4663              (
Left.NestingLevel == 1 && startsWithInitStatement(
Line)))));
 
 4665  if (
Right.is(TT_FunctionTypeLParen) && 
Left.isNot(tok::l_paren) &&
 
 4666      (
Left.isNot(TT_PointerOrReference) ||
 
 4667       (getTokenPointerOrReferenceAlignment(Left) != FormatStyle::PAS_Right &&
 
 4668        !
Line.IsMultiVariableDeclStmt))) {
 
 4671  if (
Left.is(TT_PointerOrReference)) {
 
 4674    if ((Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Before ||
 
 4675         Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both) &&
 
 4676        Right.canBePointerOrReferenceQualifier()) {
 
 4680    if (
Right.Tok.isLiteral())
 
 4683    if (
Right.is(TT_BlockComment))
 
 4687    if (
Right.isOneOf(Keywords.kw_override, Keywords.kw_final, tok::kw_noexcept,
 
 4688                      TT_RequiresClause) &&
 
 4689        Right.isNot(TT_StartOfName)) {
 
 4696    if (BeforeLeft && BeforeLeft->isTypeOrIdentifier(LangOpts) && 
Right.Next &&
 
 4697        Right.Next->is(TT_RangeBasedForLoopColon)) {
 
 4698      return getTokenPointerOrReferenceAlignment(Left) !=
 
 4699             FormatStyle::PAS_Right;
 
 4701    if (
Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
 
 4705    if (getTokenPointerOrReferenceAlignment(Left) == FormatStyle::PAS_Right)
 
 4713    if (
Line.IsMultiVariableDeclStmt &&
 
 4714        (
Left.NestingLevel == 
Line.First->NestingLevel ||
 
 4715         ((
Left.NestingLevel == 
Line.First->NestingLevel + 1) &&
 
 4716          startsWithInitStatement(
Line)))) {
 
 4721    if (BeforeLeft->is(tok::coloncolon)) {
 
 4722      if (
Left.isNot(tok::star))
 
 4724      assert(Style.PointerAlignment != FormatStyle::PAS_Right);
 
 4725      if (!
Right.startsSequence(tok::identifier, tok::r_paren))
 
 4728      const auto *LParen = 
Right.Next->MatchingParen;
 
 4729      return !LParen || LParen->isNot(TT_FunctionTypeLParen);
 
 4731    return BeforeLeft->isNoneOf(tok::l_paren, tok::l_square);
 
 4734  if (
Left.is(tok::ellipsis) && BeforeLeft &&
 
 4735      BeforeLeft->isPointerOrReference()) {
 
 4736    return Style.PointerAlignment != FormatStyle::PAS_Right;
 
 4739  if (
Right.is(tok::star) && 
Left.is(tok::l_paren))
 
 4741  if (
Left.is(tok::star) && 
Right.isPointerOrReference())
 
 4743  if (
Right.isPointerOrReference()) {
 
 4754      if (
Previous->is(tok::coloncolon)) {
 
 4773      if (
Previous->endsSequence(tok::kw_operator))
 
 4774        return Style.PointerAlignment != FormatStyle::PAS_Left;
 
 4775      if (
Previous->isOneOf(tok::kw_const, tok::kw_volatile)) {
 
 4776        return (Style.PointerAlignment != FormatStyle::PAS_Left) ||
 
 4777               (Style.SpaceAroundPointerQualifiers ==
 
 4778                FormatStyle::SAPQ_After) ||
 
 4779               (Style.SpaceAroundPointerQualifiers == FormatStyle::SAPQ_Both);
 
 4783  if (Style.isCSharp() && 
Left.is(Keywords.kw_is) && 
Right.is(tok::l_square))
 
 4785  const auto SpaceRequiredForArrayInitializerLSquare =
 
 4786      [](
const FormatToken &LSquareTok, 
const FormatStyle &Style) {
 
 4787        return Style.SpacesInContainerLiterals ||
 
 4789                Style.Cpp11BracedListStyle == FormatStyle::BLS_Block &&
 
 4790                LSquareTok.endsSequence(tok::l_square, tok::colon,
 
 4793  if (
Left.is(tok::l_square)) {
 
 4794    return (
Left.is(TT_ArrayInitializerLSquare) && 
Right.isNot(tok::r_square) &&
 
 4795            SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||
 
 4796           (
Left.isOneOf(TT_ArraySubscriptLSquare, TT_StructuredBindingLSquare,
 
 4797                         TT_LambdaLSquare) &&
 
 4798            Style.SpacesInSquareBrackets && 
Right.isNot(tok::r_square));
 
 4800  if (
Right.is(tok::r_square)) {
 
 4801    return Right.MatchingParen &&
 
 4802           ((
Right.MatchingParen->is(TT_ArrayInitializerLSquare) &&
 
 4803             SpaceRequiredForArrayInitializerLSquare(*
Right.MatchingParen,
 
 4805            (Style.SpacesInSquareBrackets &&
 
 4806             Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
 
 4807                                          TT_StructuredBindingLSquare,
 
 4808                                          TT_LambdaLSquare)));
 
 4810  if (
Right.is(tok::l_square) &&
 
 4811      Right.isNoneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
 
 4812                     TT_DesignatedInitializerLSquare,
 
 4813                     TT_StructuredBindingLSquare, TT_AttributeLSquare) &&
 
 4814      Left.isNoneOf(tok::numeric_constant, TT_DictLiteral) &&
 
 4815      !(
Left.isNot(tok::r_square) && Style.SpaceBeforeSquareBrackets &&
 
 4816        Right.is(TT_ArraySubscriptLSquare))) {
 
 4820      (
Right.is(tok::r_brace) && 
Right.MatchingParen &&
 
 4822    return Style.Cpp11BracedListStyle == FormatStyle::BLS_Block ||
 
 4823           Style.SpacesInParensOptions.Other;
 
 4825  if (
Left.is(TT_BlockComment)) {
 
 4827    return Style.isJavaScript() || !
Left.TokenText.ends_with(
"=*/");
 
 4832  if (
Left.is(TT_TemplateCloser) && 
Right.is(TT_AttributeLSquare))
 
 4835  if (
Right.is(tok::l_paren)) {
 
 4836    if (
Left.is(TT_TemplateCloser) && 
Right.isNot(TT_FunctionTypeLParen))
 
 4837      return spaceRequiredBeforeParens(Right);
 
 4838    if (
Left.isOneOf(TT_RequiresClause,
 
 4839                     TT_RequiresClauseInARequiresExpression)) {
 
 4840      return Style.SpaceBeforeParensOptions.AfterRequiresInClause ||
 
 4841             spaceRequiredBeforeParens(Right);
 
 4843    if (
Left.is(TT_RequiresExpression)) {
 
 4844      return Style.SpaceBeforeParensOptions.AfterRequiresInExpression ||
 
 4845             spaceRequiredBeforeParens(Right);
 
 4847    if (
Left.isOneOf(TT_AttributeRParen, TT_AttributeRSquare))
 
 4849    if (
Left.is(TT_ForEachMacro)) {
 
 4850      return Style.SpaceBeforeParensOptions.AfterForeachMacros ||
 
 4851             spaceRequiredBeforeParens(Right);
 
 4853    if (
Left.is(TT_IfMacro)) {
 
 4854      return Style.SpaceBeforeParensOptions.AfterIfMacros ||
 
 4855             spaceRequiredBeforeParens(Right);
 
 4857    if (Style.SpaceBeforeParens == FormatStyle::SBPO_Custom &&
 
 4858        Left.isPlacementOperator() &&
 
 4859        Right.isNot(TT_OverloadedOperatorLParen) &&
 
 4860        !(
Line.MightBeFunctionDecl && 
Left.is(TT_FunctionDeclarationName))) {
 
 4861      const auto *RParen = 
Right.MatchingParen;
 
 4862      return Style.SpaceBeforeParensOptions.AfterPlacementOperator ||
 
 4863             (RParen && RParen->is(TT_CastRParen));
 
 4867    if (
Left.is(tok::semi))
 
 4869    if (
Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while, tok::kw_switch,
 
 4870                     tok::kw_case, TT_ForEachMacro, TT_ObjCForIn) ||
 
 4872        Right.is(TT_ConditionLParen)) {
 
 4873      return Style.SpaceBeforeParensOptions.AfterControlStatements ||
 
 4874             spaceRequiredBeforeParens(Right);
 
 4879    if (
Right.is(TT_OverloadedOperatorLParen))
 
 4880      return spaceRequiredBeforeParens(Right);
 
 4882    if (
Line.MightBeFunctionDecl && 
Right.is(TT_FunctionDeclarationLParen)) {
 
 4883      if (spaceRequiredBeforeParens(Right))
 
 4885      const auto &Options = Style.SpaceBeforeParensOptions;
 
 4886      return Line.mightBeFunctionDefinition()
 
 4887                 ? Options.AfterFunctionDefinitionName
 
 4888                 : Options.AfterFunctionDeclarationName;
 
 4892        Left.MatchingParen && 
Left.MatchingParen->is(TT_LambdaLSquare)) {
 
 4893      return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
 
 4894             spaceRequiredBeforeParens(Right);
 
 4896    if (!BeforeLeft || BeforeLeft->isNoneOf(tok::period, tok::arrow)) {
 
 4897      if (
Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch)) {
 
 4898        return Style.SpaceBeforeParensOptions.AfterControlStatements ||
 
 4899               spaceRequiredBeforeParens(Right);
 
 4901      if (
Left.isPlacementOperator() ||
 
 4902          (
Left.is(tok::r_square) && 
Left.MatchingParen &&
 
 4903           Left.MatchingParen->Previous &&
 
 4904           Left.MatchingParen->Previous->is(tok::kw_delete))) {
 
 4905        return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
 
 4906               spaceRequiredBeforeParens(Right);
 
 4911        (
Left.Tok.getIdentifierInfo() || 
Left.is(tok::r_paren))) {
 
 4912      return spaceRequiredBeforeParens(Right);
 
 4916  if (
Left.is(tok::at) && 
Right.isNot(tok::objc_not_keyword))
 
 4918  if (
Right.is(TT_UnaryOperator)) {
 
 4919    return Left.isNoneOf(tok::l_paren, tok::l_square, tok::at) &&
 
 4920           (
Left.isNot(tok::colon) || 
Left.isNot(TT_ObjCMethodExpr));
 
 4926  if (!Style.isVerilog() &&
 
 4927      (
Left.isOneOf(tok::identifier, tok::greater, tok::r_square,
 
 4929       Left.isTypeName(LangOpts)) &&
 
 4930      Right.is(tok::l_brace) && 
Right.getNextNonComment() &&
 
 4934  if (
Left.is(tok::period) || 
Right.is(tok::period))
 
 4938  if (
Right.is(tok::hash) && 
Left.is(tok::identifier) &&
 
 4939      (
Left.TokenText == 
"L" || 
Left.TokenText == 
"u" ||
 
 4940       Left.TokenText == 
"U" || 
Left.TokenText == 
"u8" ||
 
 4941       Left.TokenText == 
"LR" || 
Left.TokenText == 
"uR" ||
 
 4942       Left.TokenText == 
"UR" || 
Left.TokenText == 
"u8R")) {
 
 4945  if (
Left.is(TT_TemplateCloser) && 
Left.MatchingParen &&
 
 4946      Left.MatchingParen->Previous &&
 
 4947      Left.MatchingParen->Previous->isOneOf(tok::period, tok::coloncolon)) {
 
 4953  if (
Left.is(TT_TemplateCloser) && 
Right.is(tok::l_square))
 
 4955  if (
Left.is(tok::l_brace) && 
Left.endsSequence(TT_DictLiteral, tok::at)) {
 
 4959  if (
Right.is(tok::r_brace) && 
Right.MatchingParen &&
 
 4960      Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at)) {
 
 4964  if (
Right.is(TT_TrailingAnnotation) && 
Right.isOneOf(tok::amp, tok::ampamp) &&
 
 4965      Left.isOneOf(tok::kw_const, tok::kw_volatile) &&
 
 4966      (!
Right.Next || 
Right.Next->is(tok::semi))) {
 
 4970    return getTokenReferenceAlignment(Right) != FormatStyle::PAS_Left;
 
 4983    return Right.hasWhitespaceBefore();
 
 4985  const bool IsVerilog = Style.isVerilog();
 
 4986  assert(!IsVerilog || !IsCpp);
 
 4989  if (Keywords.isWordLike(Right, IsVerilog) &&
 
 4990      Keywords.isWordLike(Left, IsVerilog)) {
 
 4996  if (
Left.is(tok::star) && 
Right.is(tok::comment))
 
 4999  if (
Left.is(tok::l_brace) && 
Right.is(tok::r_brace) &&
 
 5000      Left.Children.empty()) {
 
 5002      return Style.SpaceInEmptyBraces != FormatStyle::SIEB_Never;
 
 5003    if (Style.Cpp11BracedListStyle != FormatStyle::BLS_Block) {
 
 5004      return Style.SpacesInParens == FormatStyle::SIPO_Custom &&
 
 5005             Style.SpacesInParensOptions.InEmptyParentheses;
 
 5007    return Style.SpaceInEmptyBraces == FormatStyle::SIEB_Always;
 
 5010  const auto *BeforeLeft = 
Left.Previous;
 
 5013    if (
Left.is(TT_OverloadedOperator) &&
 
 5014        Right.isOneOf(TT_TemplateOpener, TT_TemplateCloser)) {
 
 5018    if (
Right.is(tok::period) && 
Left.is(tok::numeric_constant))
 
 5022    if (
Left.is(Keywords.kw_import) && 
Right.isOneOf(tok::less, tok::ellipsis))
 
 5025    if (
Left.isOneOf(Keywords.kw_module, Keywords.kw_import) &&
 
 5026        Right.is(TT_ModulePartitionColon)) {
 
 5030    if (
Right.is(TT_AfterPPDirective))
 
 5034    if (
Left.is(tok::identifier) && 
Right.is(TT_ModulePartitionColon))
 
 5037    if (
Left.is(TT_ModulePartitionColon) &&
 
 5038        Right.isOneOf(tok::identifier, tok::kw_private)) {
 
 5041    if (
Left.is(tok::ellipsis) && 
Right.is(tok::identifier) &&
 
 5042        Line.First->is(Keywords.kw_import)) {
 
 5046    if (
Left.isOneOf(TT_AttributeRParen, TT_AttributeMacro) &&
 
 5047        Right.is(tok::coloncolon)) {
 
 5051    if (
Left.is(tok::kw_operator))
 
 5052      return Right.is(tok::coloncolon) || Style.SpaceAfterOperatorKeyword;
 
 5054        !
Left.opensScope() && Style.SpaceBeforeCpp11BracedList) {
 
 5057    if (
Left.is(tok::less) && 
Left.is(TT_OverloadedOperator) &&
 
 5058        Right.is(TT_TemplateOpener)) {
 
 5062    if (
Left.is(tok::identifier) && 
Right.is(tok::numeric_constant))
 
 5063      return Right.TokenText[0] != 
'.';
 
 5065    if (
Left.Tok.getIdentifierInfo() && 
Right.Tok.isLiteral())
 
 5067  } 
else if (Style.isProto()) {
 
 5068    if (
Right.is(tok::period) && !(BeforeLeft && BeforeLeft->is(tok::period)) &&
 
 5069        Left.isOneOf(Keywords.kw_optional, Keywords.kw_required,
 
 5070                     Keywords.kw_repeated, Keywords.kw_extend)) {
 
 5073    if (
Right.is(tok::l_paren) &&
 
 5074        Left.isOneOf(Keywords.kw_returns, Keywords.kw_option)) {
 
 5077    if (
Right.isOneOf(tok::l_brace, tok::less) && 
Left.is(TT_SelectorName))
 
 5080    if (
Left.is(tok::slash) || 
Right.is(tok::slash))
 
 5082    if (
Left.MatchingParen &&
 
 5083        Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
 
 5084        Right.isOneOf(tok::l_brace, tok::less)) {
 
 5085      return Style.Cpp11BracedListStyle == FormatStyle::BLS_Block;
 
 5088    if (
Left.is(tok::percent))
 
 5092    if (
Left.is(tok::numeric_constant) && 
Right.is(tok::percent))
 
 5093      return Right.hasWhitespaceBefore();
 
 5094  } 
else if (Style.isJson()) {
 
 5095    if (
Right.is(tok::colon) && 
Left.is(tok::string_literal))
 
 5096      return Style.SpaceBeforeJsonColon;
 
 5097  } 
else if (Style.isCSharp()) {
 
 5103    if (
Left.is(tok::kw_this) && 
Right.is(tok::l_square))
 
 5107    if (
Left.is(tok::kw_new) && 
Right.is(tok::l_paren))
 
 5111    if (
Right.is(tok::l_brace))
 
 5115    if (
Left.is(tok::l_brace) && 
Right.isNot(tok::r_brace))
 
 5118    if (
Left.isNot(tok::l_brace) && 
Right.is(tok::r_brace))
 
 5122    if (
Left.is(TT_FatArrow) || 
Right.is(TT_FatArrow))
 
 5126    if (
Left.is(TT_AttributeColon) || 
Right.is(TT_AttributeColon))
 
 5130    if (
Left.is(TT_TemplateCloser) && 
Right.is(TT_StartOfName))
 
 5134    if (
Left.is(tok::l_square) || 
Right.is(tok::r_square))
 
 5135      return Style.SpacesInSquareBrackets;
 
 5138    if (
Right.is(TT_CSharpNullable))
 
 5142    if (
Right.is(TT_NonNullAssertion))
 
 5146    if (
Left.is(tok::comma) && 
Right.is(tok::comma))
 
 5150    if (
Left.is(Keywords.kw_var) && 
Right.is(tok::l_paren))
 
 5154    if (
Right.is(tok::l_paren)) {
 
 5155      if (
Left.isOneOf(tok::kw_using, Keywords.kw_async, Keywords.kw_when,
 
 5156                       Keywords.kw_lock)) {
 
 5157        return Style.SpaceBeforeParensOptions.AfterControlStatements ||
 
 5158               spaceRequiredBeforeParens(Right);
 
 5164    if ((
Left.isAccessSpecifierKeyword() ||
 
 5165         Left.isOneOf(tok::kw_virtual, tok::kw_extern, tok::kw_static,
 
 5166                      Keywords.kw_internal, Keywords.kw_abstract,
 
 5167                      Keywords.kw_sealed, Keywords.kw_override,
 
 5168                      Keywords.kw_async, Keywords.kw_unsafe)) &&
 
 5169        Right.is(tok::l_paren)) {
 
 5172  } 
else if (Style.isJavaScript()) {
 
 5173    if (
Left.is(TT_FatArrow))
 
 5176    if (
Right.is(tok::l_paren) && 
Left.is(Keywords.kw_await) && BeforeLeft &&
 
 5177        BeforeLeft->is(tok::kw_for)) {
 
 5180    if (
Left.is(Keywords.kw_async) && 
Right.is(tok::l_paren) &&
 
 5181        Right.MatchingParen) {
 
 5188    if ((
Left.is(TT_TemplateString) && 
Left.TokenText.ends_with(
"${")) ||
 
 5189        (
Right.is(TT_TemplateString) && 
Right.TokenText.starts_with(
"}"))) {
 
 5194    if (Keywords.isJavaScriptIdentifier(Left,
 
 5196        Right.is(TT_TemplateString)) {
 
 5199    if (
Right.is(tok::star) &&
 
 5200        Left.isOneOf(Keywords.kw_function, Keywords.kw_yield)) {
 
 5203    if (
Right.isOneOf(tok::l_brace, tok::l_square) &&
 
 5204        Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
 
 5205                     Keywords.kw_extends, Keywords.kw_implements)) {
 
 5208    if (
Right.is(tok::l_paren)) {
 
 5210      if (
Line.MustBeDeclaration && 
Left.Tok.getIdentifierInfo())
 
 5214      if (BeforeLeft && BeforeLeft->is(tok::period) &&
 
 5215          Left.Tok.getIdentifierInfo()) {
 
 5219      if (
Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof,
 
 5225    if (
Left.endsSequence(tok::kw_const, Keywords.kw_as))
 
 5227    if ((
Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
 
 5232         (
Left.is(Keywords.kw_of) && BeforeLeft &&
 
 5233          BeforeLeft->isOneOf(tok::identifier, tok::r_square, tok::r_brace))) &&
 
 5234        (!BeforeLeft || BeforeLeft->isNot(tok::period))) {
 
 5237    if (
Left.isOneOf(tok::kw_for, Keywords.kw_as) && BeforeLeft &&
 
 5238        BeforeLeft->is(tok::period) && 
Right.is(tok::l_paren)) {
 
 5241    if (
Left.is(Keywords.kw_as) &&
 
 5242        Right.isOneOf(tok::l_square, tok::l_brace, tok::l_paren)) {
 
 5245    if (
Left.is(tok::kw_default) && BeforeLeft &&
 
 5246        BeforeLeft->is(tok::kw_export)) {
 
 5249    if (
Left.is(Keywords.kw_is) && 
Right.is(tok::l_brace))
 
 5251    if (
Right.isOneOf(TT_JsTypeColon, TT_JsTypeOptionalQuestion))
 
 5253    if (
Left.is(TT_JsTypeOperator) || 
Right.is(TT_JsTypeOperator))
 
 5255    if ((
Left.is(tok::l_brace) || 
Right.is(tok::r_brace)) &&
 
 5256        Line.First->isOneOf(Keywords.kw_import, tok::kw_export)) {
 
 5259    if (
Left.is(tok::ellipsis))
 
 5261    if (
Left.is(TT_TemplateCloser) &&
 
 5262        Right.isNoneOf(tok::equal, tok::l_brace, tok::comma, tok::l_square,
 
 5263                       Keywords.kw_implements, Keywords.kw_extends)) {
 
 5269    if (
Right.is(TT_NonNullAssertion))
 
 5271    if (
Left.is(TT_NonNullAssertion) &&
 
 5272        Right.isOneOf(Keywords.kw_as, Keywords.kw_in)) {
 
 5275  } 
else if (Style.isJava()) {
 
 5276    if (
Left.is(TT_CaseLabelArrow) || 
Right.is(TT_CaseLabelArrow))
 
 5278    if (
Left.is(tok::r_square) && 
Right.is(tok::l_brace))
 
 5281    if (
Left.is(tok::l_square) || 
Right.is(tok::r_square))
 
 5282      return Style.SpacesInSquareBrackets;
 
 5284    if (
Left.is(Keywords.kw_synchronized) && 
Right.is(tok::l_paren)) {
 
 5285      return Style.SpaceBeforeParensOptions.AfterControlStatements ||
 
 5286             spaceRequiredBeforeParens(Right);
 
 5288    if ((
Left.isAccessSpecifierKeyword() ||
 
 5289         Left.isOneOf(tok::kw_static, Keywords.kw_final, Keywords.kw_abstract,
 
 5290                      Keywords.kw_native)) &&
 
 5291        Right.is(TT_TemplateOpener)) {
 
 5294  } 
else if (IsVerilog) {
 
 5296    if (
Left.is(tok::identifier) && 
Left.TokenText[0] == 
'\\')
 
 5300    if ((
Left.is(TT_VerilogTableItem) &&
 
 5301         Right.isNoneOf(tok::r_paren, tok::semi)) ||
 
 5302        (
Right.is(TT_VerilogTableItem) && 
Left.isNot(tok::l_paren))) {
 
 5304      return !(
Next && 
Next->is(tok::r_paren));
 
 5307    if (
Left.isNot(TT_BinaryOperator) &&
 
 5308        Left.isOneOf(Keywords.kw_verilogHash, Keywords.kw_verilogHashHash)) {
 
 5312    if (
Right.isNot(tok::semi) &&
 
 5313        (
Left.endsSequence(tok::numeric_constant, Keywords.kw_verilogHash) ||
 
 5314         Left.endsSequence(tok::numeric_constant,
 
 5315                           Keywords.kw_verilogHashHash) ||
 
 5316         (
Left.is(tok::r_paren) && 
Left.MatchingParen &&
 
 5317          Left.MatchingParen->endsSequence(tok::l_paren, tok::at)))) {
 
 5322    if (
Left.is(Keywords.kw_apostrophe) ||
 
 5323        (
Left.is(TT_VerilogNumberBase) && 
Right.is(tok::numeric_constant))) {
 
 5327    if (
Left.is(tok::arrow) || 
Right.is(tok::arrow))
 
 5332    if (
Left.is(tok::at) && 
Right.isOneOf(tok::l_paren, tok::star, tok::at))
 
 5335    if (
Right.is(tok::l_square) &&
 
 5336        Left.isOneOf(TT_VerilogDimensionedTypeName, Keywords.kw_function)) {
 
 5340    if (
Right.isOneOf(tok::period, Keywords.kw_apostrophe) &&
 
 5341        Keywords.isVerilogIdentifier(Left) && 
Left.getPreviousNonComment() &&
 
 5342        Left.getPreviousNonComment()->is(Keywords.kw_tagged)) {
 
 5348    if ((
Right.is(Keywords.kw_apostrophe) ||
 
 5350        Left.isNoneOf(Keywords.kw_assign, Keywords.kw_unique) &&
 
 5351        !Keywords.isVerilogWordOperator(Left) &&
 
 5352        (
Left.isOneOf(tok::r_square, tok::r_paren, tok::r_brace,
 
 5353                      tok::numeric_constant) ||
 
 5354         Keywords.isWordLike(Left))) {
 
 5358    if ((
Right.is(tok::star) && 
Left.is(tok::coloncolon)) ||
 
 5359        (
Left.is(tok::star) && 
Right.is(tok::semi))) {
 
 5363    if (
Left.endsSequence(tok::star, tok::l_paren) && 
Right.is(tok::identifier))
 
 5366    if (
Right.is(tok::l_paren) && 
Right.is(TT_VerilogStrength))
 
 5369    if ((
Left.is(tok::l_brace) &&
 
 5370         Right.isOneOf(tok::lessless, tok::greatergreater)) ||
 
 5371        (
Left.endsSequence(tok::lessless, tok::l_brace) ||
 
 5372         Left.endsSequence(tok::greatergreater, tok::l_brace))) {
 
 5375  } 
else if (Style.isTableGen()) {
 
 5377    if (
Left.is(tok::l_square) && 
Right.is(tok::l_brace))
 
 5379    if (
Left.is(tok::r_brace) && 
Right.is(tok::r_square))
 
 5382    if (
Right.isOneOf(TT_TableGenDAGArgListColon,
 
 5383                      TT_TableGenDAGArgListColonToAlign) ||
 
 5384        Left.isOneOf(TT_TableGenDAGArgListColon,
 
 5385                     TT_TableGenDAGArgListColonToAlign)) {
 
 5388    if (
Right.is(TT_TableGenCondOperatorColon))
 
 5390    if (
Left.isOneOf(TT_TableGenDAGArgOperatorID,
 
 5391                     TT_TableGenDAGArgOperatorToBreak) &&
 
 5392        Right.isNot(TT_TableGenDAGArgCloser)) {
 
 5396    if (
Right.isOneOf(tok::l_paren, tok::less) &&
 
 5397        Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator)) {
 
 5402    if (
Left.is(TT_TableGenTrailingPasteOperator) &&
 
 5403        Right.isOneOf(tok::l_brace, tok::colon)) {
 
 5407    if (
Left.is(tok::hash) || 
Right.is(tok::hash))
 
 5410    if (Keywords.isTableGenDefinition(Left))
 
 5414  if (
Left.is(TT_ImplicitStringLiteral))
 
 5415    return Right.hasWhitespaceBefore();
 
 5417    if (
Left.is(TT_ObjCMethodSpecifier))
 
 5419    if (
Left.is(tok::r_paren) && 
Left.isNot(TT_AttributeRParen) &&
 
 5420        canBeObjCSelectorComponent(Right)) {
 
 5428      (
Right.is(tok::equal) || 
Left.is(tok::equal))) {
 
 5432  if (
Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow) ||
 
 5433      Left.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow)) {
 
 5436  if (
Left.is(tok::comma) && 
Right.isNot(TT_OverloadedOperatorLParen) &&
 
 5439      (
Left.Children.empty() || !
Left.MacroParent)) {
 
 5442  if (
Right.is(tok::comma))
 
 5444  if (
Right.is(TT_ObjCBlockLParen))
 
 5446  if (
Right.is(TT_CtorInitializerColon))
 
 5447    return Style.SpaceBeforeCtorInitializerColon;
 
 5448  if (
Right.is(TT_InheritanceColon) && !Style.SpaceBeforeInheritanceColon)
 
 5450  if (
Right.is(TT_RangeBasedForLoopColon) &&
 
 5451      !Style.SpaceBeforeRangeBasedForLoopColon) {
 
 5454  if (
Left.is(TT_BitFieldColon)) {
 
 5455    return Style.BitFieldColonSpacing == FormatStyle::BFCS_Both ||
 
 5456           Style.BitFieldColonSpacing == FormatStyle::BFCS_After;
 
 5458  if (
Right.is(tok::colon)) {
 
 5459    if (
Right.is(TT_CaseLabelColon))
 
 5460      return Style.SpaceBeforeCaseColon;
 
 5461    if (
Right.is(TT_GotoLabelColon))
 
 5464    if (!
Right.getNextNonComment())
 
 5466    if (
Right.isOneOf(TT_ObjCSelector, TT_ObjCMethodExpr))
 
 5468    if (
Left.is(tok::question))
 
 5470    if (
Right.is(TT_InlineASMColon) && 
Left.is(tok::coloncolon))
 
 5472    if (
Right.is(TT_DictLiteral))
 
 5473      return Style.SpacesInContainerLiterals;
 
 5474    if (
Right.is(TT_AttributeColon))
 
 5476    if (
Right.is(TT_CSharpNamedArgumentColon))
 
 5478    if (
Right.is(TT_GenericSelectionColon))
 
 5480    if (
Right.is(TT_BitFieldColon)) {
 
 5481      return Style.BitFieldColonSpacing == FormatStyle::BFCS_Both ||
 
 5482             Style.BitFieldColonSpacing == FormatStyle::BFCS_Before;
 
 5487  if ((
Left.isOneOf(tok::minus, tok::minusminus) &&
 
 5488       Right.isOneOf(tok::minus, tok::minusminus)) ||
 
 5489      (
Left.isOneOf(tok::plus, tok::plusplus) &&
 
 5490       Right.isOneOf(tok::plus, tok::plusplus))) {
 
 5493  if (
Left.is(TT_UnaryOperator)) {
 
 5496    if (
Left.is(tok::amp) && 
Right.is(tok::r_square))
 
 5497      return Style.SpacesInSquareBrackets;
 
 5498    if (
Left.isNot(tok::exclaim))
 
 5500    if (
Left.TokenText == 
"!")
 
 5501      return Style.SpaceAfterLogicalNot;
 
 5502    assert(
Left.TokenText == 
"not");
 
 5503    return Right.isOneOf(tok::coloncolon, TT_UnaryOperator) ||
 
 5504           (
Right.is(tok::l_paren) && Style.SpaceBeforeParensOptions.AfterNot);
 
 5509  if (
Left.is(TT_CastRParen)) {
 
 5510    return Style.SpaceAfterCStyleCast ||
 
 5511           Right.isOneOf(TT_BinaryOperator, TT_SelectorName);
 
 5514  auto ShouldAddSpacesInAngles = [
this, &
Right]() {
 
 5515    if (this->Style.SpacesInAngles == FormatStyle::SIAS_Always)
 
 5517    if (this->Style.SpacesInAngles == FormatStyle::SIAS_Leave)
 
 5518      return Right.hasWhitespaceBefore();
 
 5522  if (
Left.is(tok::greater) && 
Right.is(tok::greater)) {
 
 5523    if (Style.isTextProto() ||
 
 5524        (Style.Language == FormatStyle::LK_Proto && 
Left.is(TT_DictLiteral))) {
 
 5525      return Style.Cpp11BracedListStyle == FormatStyle::BLS_Block;
 
 5527    return Right.is(TT_TemplateCloser) && 
Left.is(TT_TemplateCloser) &&
 
 5528           ((Style.Standard < FormatStyle::LS_Cpp11) ||
 
 5529            ShouldAddSpacesInAngles());
 
 5531  if (
Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
 
 5532      Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
 
 5533      (
Right.is(tok::period) && 
Right.isNot(TT_DesignatedInitializerPeriod))) {
 
 5536  if (!Style.SpaceBeforeAssignmentOperators && 
Left.isNot(TT_TemplateCloser) &&
 
 5540  if (Style.isJava() && 
Right.is(tok::coloncolon) &&
 
 5541      Left.isOneOf(tok::identifier, tok::kw_this)) {
 
 5544  if (
Right.is(tok::coloncolon) && 
Left.is(tok::identifier)) {
 
 5548    return Right.hasWhitespaceBefore();
 
 5550  if (
Right.is(tok::coloncolon) &&
 
 5551      Left.isNoneOf(tok::l_brace, tok::comment, tok::l_paren)) {
 
 5553    return (
Left.is(TT_TemplateOpener) &&
 
 5554            ((Style.Standard < FormatStyle::LS_Cpp11) ||
 
 5555             ShouldAddSpacesInAngles())) ||
 
 5556           Left.isNoneOf(tok::l_paren, tok::r_paren, tok::l_square,
 
 5557                         tok::kw___super, TT_TemplateOpener,
 
 5558                         TT_TemplateCloser) ||
 
 5559           (
Left.is(tok::l_paren) && Style.SpacesInParensOptions.Other);
 
 5561  if ((
Left.is(TT_TemplateOpener)) != (
Right.is(TT_TemplateCloser)))
 
 5562    return ShouldAddSpacesInAngles();
 
 5563  if (
Left.is(tok::r_paren) && 
Left.isNot(TT_TypeDeclarationParen) &&
 
 5564      Right.is(TT_PointerOrReference) && 
Right.isOneOf(tok::amp, tok::ampamp)) {
 
 5568  if (
Right.is(TT_StructuredBindingLSquare)) {
 
 5569    return Left.isNoneOf(tok::amp, tok::ampamp) ||
 
 5570           getTokenReferenceAlignment(Left) != FormatStyle::PAS_Right;
 
 5573  if (
Right.Next && 
Right.Next->is(TT_StructuredBindingLSquare) &&
 
 5574      Right.isOneOf(tok::amp, tok::ampamp)) {
 
 5575    return getTokenReferenceAlignment(Right) != FormatStyle::PAS_Left;
 
 5577  if ((
Right.is(TT_BinaryOperator) && 
Left.isNot(tok::l_paren)) ||
 
 5578      (
Left.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) &&
 
 5579       Right.isNot(tok::r_paren))) {
 
 5582  if (
Right.is(TT_TemplateOpener) && 
Left.is(tok::r_paren) &&
 
 5583      Left.MatchingParen &&
 
 5584      Left.MatchingParen->is(TT_OverloadedOperatorLParen)) {
 
 5587  if (
Right.is(tok::less) && 
Left.isNot(tok::l_paren) &&
 
 5591  if (
Right.is(TT_TrailingUnaryOperator))
 
 5593  if (
Left.is(TT_RegexLiteral))
 
 5595  return spaceRequiredBetween(
Line, Left, Right);
 
 5601         Tok.isNoneOf(TT_ObjCBlockLBrace, TT_LambdaLBrace, TT_DictLiteral);
 
 
 5606  return Tok.MatchingParen && 
Tok.MatchingParen->Next &&
 
 5607         Tok.MatchingParen->Next->isOneOf(tok::comma, tok::r_paren,
 
 
 5613                     FormatStyle::ShortLambdaStyle ShortLambdaOption) {
 
 5614  return Tok.Children.empty() && ShortLambdaOption != FormatStyle::SLS_None;
 
 
 5619         Tok.isNoneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
 
 
 5622bool TokenAnnotator::mustBreakBefore(
const AnnotatedLine &
Line,
 
 5624  if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0 &&
 
 5625      (!Style.RemoveEmptyLinesInUnwrappedLines || &Right == 
Line.First)) {
 
 5631  if (Style.BreakFunctionDefinitionParameters && 
Line.MightBeFunctionDecl &&
 
 5632      Line.mightBeFunctionDefinition() && Left.MightBeFunctionDeclParen &&
 
 5633      Left.ParameterCount > 0) {
 
 5639  if (Style.BinPackParameters == FormatStyle::BPPS_AlwaysOnePerLine &&
 
 5640      Line.MightBeFunctionDecl && !
Left.opensScope() &&
 
 5645  const auto *BeforeLeft = 
Left.Previous;
 
 5646  const auto *AfterRight = 
Right.Next;
 
 5648  if (Style.isCSharp()) {
 
 5649    if (
Left.is(TT_FatArrow) && 
Right.is(tok::l_brace) &&
 
 5650        Style.BraceWrapping.AfterFunction) {
 
 5653    if (
Right.is(TT_CSharpNamedArgumentColon) ||
 
 5654        Left.is(TT_CSharpNamedArgumentColon)) {
 
 5657    if (
Right.is(TT_CSharpGenericTypeConstraint))
 
 5659    if (AfterRight && AfterRight->is(TT_FatArrow) &&
 
 5660        (
Right.is(tok::numeric_constant) ||
 
 5661         (
Right.is(tok::identifier) && 
Right.TokenText == 
"_"))) {
 
 5666    if (
Left.is(TT_AttributeRSquare) &&
 
 5667        (
Right.isAccessSpecifier(
false) ||
 
 5668         Right.is(Keywords.kw_internal))) {
 
 5672    if (
Left.is(TT_AttributeRSquare) && 
Right.is(TT_AttributeLSquare))
 
 5674  } 
else if (Style.isJavaScript()) {
 
 5676    if (
Right.is(tok::string_literal) && 
Left.is(tok::plus) && BeforeLeft &&
 
 5677        BeforeLeft->is(tok::string_literal)) {
 
 5680    if (
Left.is(TT_DictLiteral) && 
Left.is(tok::l_brace) && 
Line.Level == 0 &&
 
 5681        BeforeLeft && BeforeLeft->is(tok::equal) &&
 
 5682        Line.First->isOneOf(tok::identifier, Keywords.kw_import, tok::kw_export,
 
 5686        Line.First->isNoneOf(Keywords.kw_var, Keywords.kw_let)) {
 
 5691    if (
Left.is(tok::l_brace) && 
Line.Level == 0 &&
 
 5692        (
Line.startsWith(tok::kw_enum) ||
 
 5693         Line.startsWith(tok::kw_const, tok::kw_enum) ||
 
 5694         Line.startsWith(tok::kw_export, tok::kw_enum) ||
 
 5695         Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum))) {
 
 5700    if (
Right.is(tok::r_brace) && 
Left.is(tok::l_brace) && BeforeLeft &&
 
 5701        BeforeLeft->is(TT_FatArrow)) {
 
 5703      switch (Style.AllowShortLambdasOnASingleLine) {
 
 5704      case FormatStyle::SLS_All:
 
 5706      case FormatStyle::SLS_None:
 
 5708      case FormatStyle::SLS_Empty:
 
 5709        return !
Left.Children.empty();
 
 5710      case FormatStyle::SLS_Inline:
 
 5713        return (
Left.NestingLevel == 0 && 
Line.Level == 0) &&
 
 5714               !
Left.Children.empty();
 
 5716      llvm_unreachable(
"Unknown FormatStyle::ShortLambdaStyle enum");
 
 5719    if (
Right.is(tok::r_brace) && 
Left.is(tok::l_brace) &&
 
 5720        !
Left.Children.empty()) {
 
 5722      return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
 
 5723             Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty ||
 
 5724             (
Left.NestingLevel == 0 && 
Line.Level == 0 &&
 
 5725              Style.AllowShortFunctionsOnASingleLine &
 
 5726                  FormatStyle::SFS_InlineOnly);
 
 5728  } 
else if (Style.isJava()) {
 
 5729    if (
Right.is(tok::plus) && 
Left.is(tok::string_literal) && AfterRight &&
 
 5730        AfterRight->is(tok::string_literal)) {
 
 5733  } 
else if (Style.isVerilog()) {
 
 5735    if (
Left.is(TT_VerilogAssignComma))
 
 5738    if (
Left.is(TT_VerilogTypeComma))
 
 5742    if (Style.VerilogBreakBetweenInstancePorts &&
 
 5743        (
Left.is(TT_VerilogInstancePortComma) ||
 
 5744         (
Left.is(tok::r_paren) && Keywords.isVerilogIdentifier(Right) &&
 
 5745          Left.MatchingParen &&
 
 5746          Left.MatchingParen->is(TT_VerilogInstancePortLParen)))) {
 
 5751    if (!Keywords.isVerilogBegin(Right) && Keywords.isVerilogEndOfLabel(Left))
 
 5753  } 
else if (Style.BreakAdjacentStringLiterals &&
 
 5754             (IsCpp || Style.isProto() || Style.isTableGen())) {
 
 5755    if (
Left.isStringLiteral() && 
Right.isStringLiteral())
 
 5760  if (Style.isJson()) {
 
 5764    if (
Left.is(TT_DictLiteral) && 
Left.is(tok::l_brace))
 
 5767    if ((
Left.is(TT_ArrayInitializerLSquare) && 
Left.is(tok::l_square) &&
 
 5768         Right.isNot(tok::r_square)) ||
 
 5769        Left.is(tok::comma)) {
 
 5770      if (
Right.is(tok::l_brace))
 
 5775        if (
Tok->isOneOf(tok::l_brace, tok::l_square))
 
 5777        if (
Tok->isOneOf(tok::r_brace, tok::r_square))
 
 5780      return Style.BreakArrays;
 
 5782  } 
else if (Style.isTableGen()) {
 
 5786    if (
Left.is(TT_TableGenCondOperatorComma))
 
 5788    if (
Left.is(TT_TableGenDAGArgOperatorToBreak) &&
 
 5789        Right.isNot(TT_TableGenDAGArgCloser)) {
 
 5792    if (
Left.is(TT_TableGenDAGArgListCommaToBreak))
 
 5794    if (
Right.is(TT_TableGenDAGArgCloser) && 
Right.MatchingParen &&
 
 5795        Right.MatchingParen->is(TT_TableGenDAGArgOpenerToBreak) &&
 
 5796        &Left != 
Right.MatchingParen->Next) {
 
 5798      return Style.TableGenBreakInsideDAGArg == FormatStyle::DAS_BreakAll;
 
 5802  if (
Line.startsWith(tok::kw_asm) && 
Right.is(TT_InlineASMColon) &&
 
 5803      Style.BreakBeforeInlineASMColon == FormatStyle::BBIAS_Always) {
 
 5813    if ((
Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
 
 5814         (Style.isJavaScript() && 
Left.is(tok::l_paren))) &&
 
 5816      BeforeClosingBrace = 
Left.MatchingParen->Previous;
 
 5817    } 
else if (
Right.MatchingParen &&
 
 5818               (
Right.MatchingParen->isOneOf(tok::l_brace,
 
 5819                                             TT_ArrayInitializerLSquare) ||
 
 5820                (Style.isJavaScript() &&
 
 5821                 Right.MatchingParen->is(tok::l_paren)))) {
 
 5822      BeforeClosingBrace = &
Left;
 
 5824    if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
 
 5825                               BeforeClosingBrace->isTrailingComment())) {
 
 5830  if (
Right.is(tok::comment)) {
 
 5832           Right.NewlinesBefore > 0 && 
Right.HasUnescapedNewline;
 
 5834  if (
Left.isTrailingComment())
 
 5836  if (
Left.IsUnterminatedLiteral)
 
 5839  if (BeforeLeft && BeforeLeft->is(tok::lessless) &&
 
 5840      Left.is(tok::string_literal) && 
Right.is(tok::lessless) && AfterRight &&
 
 5841      AfterRight->is(tok::string_literal)) {
 
 5842    return Right.NewlinesBefore > 0;
 
 5845  if (
Right.is(TT_RequiresClause)) {
 
 5846    switch (Style.RequiresClausePosition) {
 
 5847    case FormatStyle::RCPS_OwnLine:
 
 5848    case FormatStyle::RCPS_OwnLineWithBrace:
 
 5849    case FormatStyle::RCPS_WithFollowing:
 
 5856  if (
Left.ClosesTemplateDeclaration && 
Left.MatchingParen &&
 
 5857      Left.MatchingParen->NestingLevel == 0) {
 
 5861    if (
Right.is(tok::kw_concept))
 
 5862      return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
 
 5863    return Style.BreakTemplateDeclarations == FormatStyle::BTDS_Yes ||
 
 5864           (Style.BreakTemplateDeclarations == FormatStyle::BTDS_Leave &&
 
 5865            Right.NewlinesBefore > 0);
 
 5867  if (
Left.ClosesRequiresClause) {
 
 5868    switch (Style.RequiresClausePosition) {
 
 5869    case FormatStyle::RCPS_OwnLine:
 
 5870    case FormatStyle::RCPS_WithPreceding:
 
 5871      return Right.isNot(tok::semi);
 
 5872    case FormatStyle::RCPS_OwnLineWithBrace:
 
 5873      return Right.isNoneOf(tok::semi, tok::l_brace);
 
 5878  if (Style.PackConstructorInitializers == FormatStyle::PCIS_Never) {
 
 5879    if (Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeColon &&
 
 5880        (
Left.is(TT_CtorInitializerComma) ||
 
 5881         Right.is(TT_CtorInitializerColon))) {
 
 5885    if (Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon &&
 
 5886        Left.isOneOf(TT_CtorInitializerColon, TT_CtorInitializerComma)) {
 
 5890  if (Style.PackConstructorInitializers < FormatStyle::PCIS_CurrentLine &&
 
 5891      Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma &&
 
 5892      Right.isOneOf(TT_CtorInitializerComma, TT_CtorInitializerColon)) {
 
 5895  if (Style.PackConstructorInitializers == FormatStyle::PCIS_NextLineOnly) {
 
 5896    if ((Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeColon ||
 
 5897         Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) &&
 
 5898        Right.is(TT_CtorInitializerColon)) {
 
 5902    if (Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon &&
 
 5903        Left.is(TT_CtorInitializerColon)) {
 
 5908  if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
 
 5909      Right.is(TT_InheritanceComma)) {
 
 5912  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
 
 5913      Left.is(TT_InheritanceComma)) {
 
 5916  if (
Right.is(tok::string_literal) && 
Right.TokenText.starts_with(
"R\"")) {
 
 5920    return Right.IsMultiline && 
Right.NewlinesBefore > 0;
 
 5922  if ((
Left.is(tok::l_brace) ||
 
 5923       (
Left.is(tok::less) && BeforeLeft && BeforeLeft->is(tok::equal))) &&
 
 5924      Right.NestingLevel == 1 && Style.Language == FormatStyle::LK_Proto) {
 
 5929  if (
Right.is(TT_InlineASMBrace))
 
 5930    return Right.HasUnescapedNewline;
 
 5933    auto *FirstNonComment = 
Line.getFirstNonComment();
 
 5935        FirstNonComment && (FirstNonComment->is(Keywords.kw_internal) ||
 
 5936                            FirstNonComment->isAccessSpecifierKeyword());
 
 5938    if (Style.BraceWrapping.AfterEnum) {
 
 5939      if (
Line.startsWith(tok::kw_enum) ||
 
 5940          Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
 
 5945          FirstNonComment->Next->is(tok::kw_enum)) {
 
 5951    if (Style.BraceWrapping.AfterClass &&
 
 5953          FirstNonComment->Next->is(Keywords.kw_interface)) ||
 
 5954         Line.startsWith(Keywords.kw_interface))) {
 
 5959    if (
Right.isNot(TT_FunctionLBrace)) {
 
 5960      return (
Line.startsWith(tok::kw_class) &&
 
 5961              Style.BraceWrapping.AfterClass) ||
 
 5962             (
Line.startsWith(tok::kw_struct) &&
 
 5963              Style.BraceWrapping.AfterStruct);
 
 5967  if (
Left.is(TT_ObjCBlockLBrace) &&
 
 5968      Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never) {
 
 5973  if (
Left.isOneOf(TT_AttributeRParen, TT_AttributeMacro) &&
 
 5974      Right.is(TT_ObjCDecl)) {
 
 5978  if (
Left.is(TT_LambdaLBrace)) {
 
 5980        Style.AllowShortLambdasOnASingleLine == FormatStyle::SLS_Inline) {
 
 5984    if (Style.AllowShortLambdasOnASingleLine == FormatStyle::SLS_None ||
 
 5985        Style.AllowShortLambdasOnASingleLine == FormatStyle::SLS_Inline ||
 
 5986        (!
Left.Children.empty() &&
 
 5987         Style.AllowShortLambdasOnASingleLine == FormatStyle::SLS_Empty)) {
 
 5992  if (Style.BraceWrapping.BeforeLambdaBody && 
Right.is(TT_LambdaLBrace) &&
 
 5993      (
Left.isPointerOrReference() || 
Left.is(TT_TemplateCloser))) {
 
 5998  if ((Style.isJava() || Style.isJavaScript()) &&
 
 5999      Left.is(TT_LeadingJavaAnnotation) &&
 
 6000      Right.isNoneOf(TT_LeadingJavaAnnotation, tok::l_paren) &&
 
 6001      (
Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations)) {
 
 6005  if (
Right.is(TT_ProtoExtensionLSquare))
 
 6035  if (Style.isProto() && 
Right.is(TT_SelectorName) &&
 
 6036      Right.isNot(tok::r_square) && AfterRight) {
 
 6039    if (
Left.is(tok::at))
 
 6045    const auto *LBrace = AfterRight;
 
 6046    if (LBrace && LBrace->is(tok::colon)) {
 
 6047      LBrace = LBrace->Next;
 
 6048      if (LBrace && LBrace->is(tok::at)) {
 
 6049        LBrace = LBrace->Next;
 
 6051          LBrace = LBrace->Next;
 
 6063        ((LBrace->is(tok::l_brace) &&
 
 6064          (LBrace->is(TT_DictLiteral) ||
 
 6065           (LBrace->Next && LBrace->Next->is(tok::r_brace)))) ||
 
 6066         LBrace->isOneOf(TT_ArrayInitializerLSquare, tok::less))) {
 
 6073      if (
Left.ParameterCount == 0)
 
 6088    if (
Left.isOneOf(tok::r_brace, tok::greater, tok::r_square))
 
 6099  if (Style.isCSharp()) {
 
 6100    if (
Left.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon) ||
 
 6101        Right.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon)) {
 
 6105    if (
Line.First->is(TT_CSharpGenericTypeConstraint))
 
 6106      return Left.is(TT_CSharpGenericTypeConstraintComma);
 
 6108    if (
Right.is(TT_CSharpNullable))
 
 6110  } 
else if (Style.isJava()) {
 
 6111    if (
Left.isOneOf(Keywords.kw_throws, Keywords.kw_extends,
 
 6112                     Keywords.kw_implements)) {
 
 6115    if (
Right.isOneOf(Keywords.kw_throws, Keywords.kw_extends,
 
 6116                      Keywords.kw_implements)) {
 
 6119  } 
else if (Style.isJavaScript()) {
 
 6122        (NonComment->isAccessSpecifierKeyword() ||
 
 6123         NonComment->isOneOf(
 
 6124             tok::kw_return, Keywords.kw_yield, tok::kw_continue, tok::kw_break,
 
 6125             tok::kw_throw, Keywords.kw_interface, Keywords.kw_type,
 
 6126             tok::kw_static, Keywords.kw_readonly, Keywords.kw_override,
 
 6127             Keywords.kw_abstract, Keywords.kw_get, Keywords.kw_set,
 
 6128             Keywords.kw_async, Keywords.kw_await))) {
 
 6131    if (
Right.NestingLevel == 0 &&
 
 6132        (
Left.Tok.getIdentifierInfo() ||
 
 6133         Left.isOneOf(tok::r_square, tok::r_paren)) &&
 
 6134        Right.isOneOf(tok::l_square, tok::l_paren)) {
 
 6137    if (NonComment && NonComment->is(tok::identifier) &&
 
 6138        NonComment->TokenText == 
"asserts") {
 
 6141    if (
Left.is(TT_FatArrow) && 
Right.is(tok::l_brace))
 
 6143    if (
Left.is(TT_JsTypeColon))
 
 6146    if (
Left.is(tok::exclaim) && 
Right.is(tok::colon))
 
 6151    if (
Right.is(Keywords.kw_is)) {
 
 6160      if (!
Next || 
Next->isNot(tok::colon))
 
 6163    if (
Left.is(Keywords.kw_in))
 
 6164      return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
 
 6165    if (
Right.is(Keywords.kw_in))
 
 6166      return Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None;
 
 6167    if (
Right.is(Keywords.kw_as))
 
 6169    if (
Right.isOneOf(Keywords.kw_extends, Keywords.kw_infer)) {
 
 6175    if (
Left.is(Keywords.kw_as))
 
 6177    if (
Left.is(TT_NonNullAssertion))
 
 6179    if (
Left.is(Keywords.kw_declare) &&
 
 6180        Right.isOneOf(Keywords.kw_module, tok::kw_namespace,
 
 6181                      Keywords.kw_function, tok::kw_class, tok::kw_enum,
 
 6182                      Keywords.kw_interface, Keywords.kw_type, Keywords.kw_var,
 
 6183                      Keywords.kw_let, tok::kw_const)) {
 
 6188    if (
Left.isOneOf(Keywords.kw_module, tok::kw_namespace) &&
 
 6189        Right.isOneOf(tok::identifier, tok::string_literal)) {
 
 6192    if (
Right.is(TT_TemplateString) && 
Right.closesScope())
 
 6196    if (
Left.is(tok::identifier) && 
Right.is(TT_TemplateString))
 
 6198    if (
Left.is(TT_TemplateString) && 
Left.opensScope())
 
 6200  } 
else if (Style.isTableGen()) {
 
 6202    if (Keywords.isTableGenDefinition(Left))
 
 6205    if (
Right.is(tok::l_paren)) {
 
 6206      return Left.isNoneOf(TT_TableGenBangOperator, TT_TableGenCondOperator,
 
 6210    if (
Left.is(TT_TableGenValueSuffix))
 
 6213    if (
Left.is(tok::hash) || 
Right.is(tok::hash))
 
 6215    if (
Left.isOneOf(TT_TableGenBangOperator, TT_TableGenCondOperator))
 
 6222  if (
Right.is(tok::r_brace)) {
 
 6224                                   (
Right.isBlockIndentedInitRBrace(Style)));
 
 6229  if (
Right.is(tok::r_paren)) {
 
 6230    if (!
Right.MatchingParen)
 
 6233    if (
Next && 
Next->is(tok::r_paren))
 
 6235    if (
Next && 
Next->is(tok::l_paren))
 
 6241      return Style.BreakBeforeCloseBracketIf;
 
 6243      return Style.BreakBeforeCloseBracketLoop;
 
 6245      return Style.BreakBeforeCloseBracketSwitch;
 
 6246    return Style.BreakBeforeCloseBracketFunction;
 
 6249  if (
Left.isOneOf(tok::r_paren, TT_TrailingAnnotation) &&
 
 6250      Right.is(TT_TrailingAnnotation) &&
 
 6251      Style.BreakBeforeCloseBracketFunction) {
 
 6255  if (
Right.is(TT_TemplateCloser))
 
 6256    return Style.BreakBeforeTemplateCloser;
 
 6258  if (
Left.isOneOf(tok::at, tok::objc_interface))
 
 6260  if (
Left.isOneOf(TT_JavaAnnotation, TT_LeadingJavaAnnotation))
 
 6261    return Right.isNot(tok::l_paren);
 
 6262  if (
Right.is(TT_PointerOrReference)) {
 
 6263    return Line.IsMultiVariableDeclStmt ||
 
 6264           (getTokenPointerOrReferenceAlignment(Right) ==
 
 6265                FormatStyle::PAS_Right &&
 
 6267              Right.Next->isOneOf(TT_FunctionDeclarationName, tok::kw_const)));
 
 6269  if (
Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
 
 6270                    TT_ClassHeadName, TT_QtProperty, tok::kw_operator)) {
 
 6273  if (
Left.is(TT_PointerOrReference))
 
 6275  if (
Right.isTrailingComment()) {
 
 6282           (
Left.is(TT_CtorInitializerColon) && 
Right.NewlinesBefore > 0 &&
 
 6283            Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon);
 
 6285  if (
Left.is(tok::question) && 
Right.is(tok::colon))
 
 6287  if (
Right.isOneOf(TT_ConditionalExpr, tok::question))
 
 6288    return Style.BreakBeforeTernaryOperators;
 
 6289  if (
Left.isOneOf(TT_ConditionalExpr, tok::question))
 
 6290    return !Style.BreakBeforeTernaryOperators;
 
 6291  if (
Left.is(TT_InheritanceColon))
 
 6292    return Style.BreakInheritanceList == FormatStyle::BILS_AfterColon;
 
 6293  if (
Right.is(TT_InheritanceColon))
 
 6294    return Style.BreakInheritanceList != FormatStyle::BILS_AfterColon;
 
 6296  if (
Right.is(TT_ObjCMethodExpr) && 
Right.isNot(tok::r_square) &&
 
 6297      Left.isNot(TT_SelectorName)) {
 
 6301  if (
Right.is(tok::colon) &&
 
 6302      Right.isNoneOf(TT_CtorInitializerColon, TT_InlineASMColon,
 
 6303                     TT_BitFieldColon)) {
 
 6306  if (
Left.is(tok::colon) && 
Left.isOneOf(TT_ObjCSelector, TT_ObjCMethodExpr))
 
 6308  if (
Left.is(tok::colon) && 
Left.is(TT_DictLiteral)) {
 
 6309    if (Style.isProto()) {
 
 6310      if (!Style.AlwaysBreakBeforeMultilineStrings && 
Right.isStringLiteral())
 
 6336      if ((
Right.isOneOf(tok::l_brace, tok::less) &&
 
 6337           Right.is(TT_DictLiteral)) ||
 
 6338          Right.is(TT_ArrayInitializerLSquare)) {
 
 6344  if (
Right.is(tok::r_square) && 
Right.MatchingParen &&
 
 6345      Right.MatchingParen->is(TT_ProtoExtensionLSquare)) {
 
 6348  if (
Right.is(TT_SelectorName) || (
Right.is(tok::identifier) && 
Right.Next &&
 
 6349                                    Right.Next->is(TT_ObjCMethodExpr))) {
 
 6350    return Left.isNot(tok::period); 
 
 6354  if (
Right.is(tok::kw_concept))
 
 6355    return Style.BreakBeforeConceptDeclarations != FormatStyle::BBCDS_Never;
 
 6356  if (
Right.is(TT_RequiresClause))
 
 6358  if (
Left.ClosesTemplateDeclaration) {
 
 6359    return Style.BreakTemplateDeclarations != FormatStyle::BTDS_Leave ||
 
 6360           Right.NewlinesBefore > 0;
 
 6362  if (
Left.is(TT_FunctionAnnotationRParen))
 
 6364  if (
Left.ClosesRequiresClause)
 
 6366  if (
Right.isOneOf(TT_RangeBasedForLoopColon, TT_OverloadedOperatorLParen,
 
 6367                    TT_OverloadedOperator)) {
 
 6370  if (
Left.is(TT_RangeBasedForLoopColon))
 
 6372  if (
Right.is(TT_RangeBasedForLoopColon))
 
 6374  if (
Left.is(TT_TemplateCloser) && 
Right.is(TT_TemplateOpener))
 
 6376  if ((
Left.is(tok::greater) && 
Right.is(tok::greater)) ||
 
 6377      (
Left.is(tok::less) && 
Right.is(tok::less))) {
 
 6380  if (
Right.is(TT_BinaryOperator) &&
 
 6381      Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None &&
 
 6382      (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_All ||
 
 6386  if (
Left.isOneOf(TT_TemplateCloser, TT_UnaryOperator, tok::kw_operator))
 
 6388  if (
Left.is(tok::equal) && 
Right.isNoneOf(tok::kw_default, tok::kw_delete) &&
 
 6392  if (
Left.is(tok::equal) && 
Right.is(tok::l_brace) &&
 
 6393      Style.Cpp11BracedListStyle == FormatStyle::BLS_Block) {
 
 6396  if (
Left.is(TT_AttributeLParen) ||
 
 6397      (
Left.is(tok::l_paren) && 
Left.is(TT_TypeDeclarationParen))) {
 
 6400  if (
Left.is(tok::l_paren) && 
Left.Previous &&
 
 6401      (
Left.Previous->isOneOf(TT_BinaryOperator, TT_CastRParen))) {
 
 6404  if (
Right.is(TT_ImplicitStringLiteral))
 
 6407  if (
Right.is(tok::r_square) && 
Right.MatchingParen &&
 
 6408      Right.MatchingParen->is(TT_LambdaLSquare)) {
 
 6414  if (
Left.is(TT_TrailingAnnotation)) {
 
 6415    return Right.isNoneOf(tok::l_brace, tok::semi, tok::equal, tok::l_paren,
 
 6416                          tok::less, tok::coloncolon);
 
 6419  if (
Right.isAttribute())
 
 6422  if (
Right.is(TT_AttributeLSquare)) {
 
 6423    assert(
Left.isNot(tok::l_square));
 
 6427  if (
Left.is(tok::identifier) && 
Right.is(tok::string_literal))
 
 6430  if (
Right.is(tok::identifier) && 
Right.Next && 
Right.Next->is(TT_DictLiteral))
 
 6433  if (
Left.is(TT_CtorInitializerColon)) {
 
 6434    return Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon &&
 
 6435           (!
Right.isTrailingComment() || 
Right.NewlinesBefore > 0);
 
 6437  if (
Right.is(TT_CtorInitializerColon))
 
 6438    return Style.BreakConstructorInitializers != FormatStyle::BCIS_AfterColon;
 
 6439  if (
Left.is(TT_CtorInitializerComma) &&
 
 6440      Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) {
 
 6443  if (
Right.is(TT_CtorInitializerComma) &&
 
 6444      Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma) {
 
 6447  if (
Left.is(TT_InheritanceComma) &&
 
 6448      Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma) {
 
 6451  if (
Right.is(TT_InheritanceComma) &&
 
 6452      Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma) {
 
 6455  if (
Left.is(TT_ArrayInitializerLSquare))
 
 6457  if (
Right.is(tok::kw_typename) && 
Left.isNot(tok::kw_const))
 
 6459  if ((
Left.isBinaryOperator() || 
Left.is(TT_BinaryOperator)) &&
 
 6460      Left.isNoneOf(tok::arrowstar, tok::lessless) &&
 
 6461      Style.BreakBeforeBinaryOperators != FormatStyle::BOS_All &&
 
 6462      (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None ||
 
 6466  if (
Left.is(TT_AttributeLSquare) && 
Right.is(tok::l_square)) {
 
 6467    assert(
Right.isNot(TT_AttributeLSquare));
 
 6470  if (
Left.is(tok::r_square) && 
Right.is(TT_AttributeRSquare)) {
 
 6471    assert(
Left.isNot(TT_AttributeRSquare));
 
 6475  auto ShortLambdaOption = Style.AllowShortLambdasOnASingleLine;
 
 6476  if (Style.BraceWrapping.BeforeLambdaBody && 
Right.is(TT_LambdaLBrace)) {
 
 6483  if (
Right.is(tok::kw_noexcept) && 
Right.is(TT_TrailingAnnotation)) {
 
 6484    switch (Style.AllowBreakBeforeNoexceptSpecifier) {
 
 6485    case FormatStyle::BBNSS_Never:
 
 6487    case FormatStyle::BBNSS_Always:
 
 6489    case FormatStyle::BBNSS_OnlyWithParen:
 
 6490      return Right.Next && 
Right.Next->is(tok::l_paren);
 
 6494  return Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,
 
 6495                      tok::kw_class, tok::kw_struct, tok::comment) ||
 
 6496         Right.isMemberAccess() ||
 
 6497         Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow, tok::lessless,
 
 6498                       tok::colon, tok::l_square, tok::at) ||
 
 6499         (
Left.is(tok::r_paren) &&
 
 6500          Right.isOneOf(tok::identifier, tok::kw_const)) ||
 
 6501         (
Left.is(tok::l_paren) && 
Right.isNot(tok::r_paren)) ||
 
 6502         (
Left.is(TT_TemplateOpener) && 
Right.isNot(TT_TemplateCloser));
 
 6506  llvm::errs() << 
"AnnotatedTokens(L=" << 
Line.Level << 
", P=" << 
Line.PPLevel
 
 6507               << 
", T=" << 
Line.Type << 
", C=" << 
Line.IsContinuation
 
 6511    llvm::errs() << 
" I=" << 
Tok->IndentLevel << 
" M=" << 
Tok->MustBreakBefore
 
 6512                 << 
" C=" << 
Tok->CanBreakBefore
 
 6514                 << 
" S=" << 
Tok->SpacesRequiredBefore
 
 6515                 << 
" F=" << 
Tok->Finalized << 
" B=" << 
Tok->BlockParameterCount
 
 6516                 << 
" BK=" << 
Tok->getBlockKind() << 
" P=" << 
Tok->SplitPenalty
 
 6517                 << 
" Name=" << 
Tok->Tok.getName() << 
" N=" << 
Tok->NestingLevel
 
 6518                 << 
" L=" << 
Tok->TotalLength
 
 6519                 << 
" PPK=" << 
Tok->getPackingKind() << 
" FakeLParens=";
 
 6521      llvm::errs() << LParen << 
"/";
 
 6522    llvm::errs() << 
" FakeRParens=" << 
Tok->FakeRParens;
 
 6523    llvm::errs() << 
" II=" << 
Tok->Tok.getIdentifierInfo();
 
 6524    llvm::errs() << 
" Text='" << 
Tok->TokenText << 
"'\n";
 
 6529  llvm::errs() << 
"----\n";
 
 6532FormatStyle::PointerAlignmentStyle
 
 6534  assert(
Reference.isOneOf(tok::amp, tok::ampamp));
 
 6535  switch (Style.ReferenceAlignment) {
 
 6536  case FormatStyle::RAS_Pointer:
 
 6537    return Style.PointerAlignment;
 
 6538  case FormatStyle::RAS_Left:
 
 6539    return FormatStyle::PAS_Left;
 
 6540  case FormatStyle::RAS_Right:
 
 6541    return FormatStyle::PAS_Right;
 
 6542  case FormatStyle::RAS_Middle:
 
 6543    return FormatStyle::PAS_Middle;
 
 6546  return Style.PointerAlignment;
 
 6549FormatStyle::PointerAlignmentStyle
 
 6550TokenAnnotator::getTokenPointerOrReferenceAlignment(
 
 6552  if (PointerOrReference.isOneOf(tok::amp, tok::ampamp))
 
 6553    return getTokenReferenceAlignment(PointerOrReference);
 
 6554  assert(PointerOrReference.is(tok::star));
 
 6555  return Style.PointerAlignment;
 
This file implements a token annotator, i.e.
 
Defines the clang::TokenKind enum and support functions.
 
#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _)
 
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
 
Parser - This implements a parser for the C family of languages.
 
bool Ret(InterpState &S, CodePtr &PC)
 
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
 
The JSON file list parser is used to communicate input to InstallAPI.
 
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
 
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
 
@ Parameter
The parameter type of a method or function.
 
@ Result
The result type of a method or function.
 
const FunctionProtoType * T
 
@ Type
The name was classified as a type.
 
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator, bool CPlusPlus11)
Return the precedence of the specified binary operator token.