Lines Matching +full:asi +full:- +full:format

1 //===--- TokenAnnotator.cpp - Format C++ code -----------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
22 #define DEBUG_TYPE "format-token-annotator"
25 namespace format {
49 /// an Objective-C \c \@selector, \c false otherwise.
52 /// Objective-C++, C++ keywords like \c new and \c delete are
53 /// lexed as tok::kw_*, not tok::identifier, even for Objective-C.
55 /// For Objective-C and Objective-C++, both identifiers and keywords
58 /// keyword as a potential Objective-C selector component.
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);
91 if (Tok.Previous && Tok.Previous->is(tok::at))
93 const FormatToken *AttrTok = Tok.Next->Next;
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);
152 if (!CurrentToken || !CurrentToken->Previous)
154 if (NonTemplateLess.count(CurrentToken->Previous) > 0)
157 if (const auto &Previous = *CurrentToken->Previous; // The '<'.
159 if (Previous.Previous->Tok.isLiteral())
161 if (Previous.Previous->is(tok::r_brace))
163 if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 &&
164 (!Previous.Previous->MatchingParen ||
165 Previous.Previous->MatchingParen->isNot(
169 if (Previous.Previous->is(tok::kw_operator) &&
170 CurrentToken->is(tok::l_paren)) {
175 FormatToken *Left = CurrentToken->Previous;
176 Left->ParentBracket = Contexts.back().ContextKind;
180 const auto *BeforeLess = Left->Previous;
184 if (BeforeLess && BeforeLess->isNot(tok::kw_template))
188 CurrentToken->is(tok::question)) {
193 const bool InExpr = Contexts[Contexts.size() - 2].IsExpression;
194 if (CurrentToken->is(tok::greater)) {
195 const auto *Next = CurrentToken->Next;
196 if (CurrentToken->isNot(TT_TemplateCloser)) {
203 if (Next && Next->is(tok::greater) &&
204 Left->ParentBracket != tok::less &&
205 CurrentToken->getStartOfNonWhitespace() ==
206 Next->getStartOfNonWhitespace().getLocWithOffset(-1)) {
210 (!Next || !Next->isOneOf(tok::l_paren, tok::l_brace))) {
216 Left->MatchingParen = CurrentToken;
217 CurrentToken->MatchingParen = Left;
225 BeforeLess->isOneOf(TT_SelectorName, TT_DictLiteral))) {
226 CurrentToken->setType(TT_DictLiteral);
228 CurrentToken->setType(TT_TemplateCloser);
229 CurrentToken->Tok.setLength(1);
231 if (Next && Next->Tok.isLiteral())
236 if (CurrentToken->is(tok::question) &&
241 if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace))
243 const auto &Prev = *CurrentToken->Previous;
260 if (FormatToken *Previous = CurrentToken->getPreviousNonComment()) {
261 if (CurrentToken->is(tok::colon) ||
262 (CurrentToken->isOneOf(tok::l_brace, tok::less) &&
263 Previous->isNot(tok::colon))) {
264 Previous->setType(TT_SelectorName);
269 if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
288 CurrentToken->Finalized = true;
289 switch (CurrentToken->Tok.getKind()) {
299 // no-op
310 assert(CurrentToken->Previous && "Unknown previous token");
311 FormatToken &OpeningParen = *CurrentToken->Previous;
322 OpeningParen.Previous->is(TT_UntouchableMacroFunc)) {
331 if (MaybeSel->isObjCAtKeyword(tok::objc_selector) &&
332 MaybeSel->Previous && MaybeSel->Previous->is(tok::at)) {
341 while (Prev->isNot(tok::kw_operator)) {
342 Prev = Prev->Previous;
346 // If faced with "a.operator*(argument)" or "a->operator*(argument)",
350 Prev->Previous && Prev->Previous->isOneOf(tok::period, tok::arrow);
363 (OpeningParen.Previous->isOneOf(
367 OpeningParen.Previous->isIf())) {
371 (OpeningParen.Previous->is(Keywords.kw_function) ||
372 (OpeningParen.Previous->endsSequence(tok::identifier,
377 OpeningParen.Previous->is(TT_JsTypeColon)) {
386 OpeningParen.Previous->is(tok::kw__Generic)) {
391 OpeningParen.Previous->isNot(tok::identifier))) {
393 } else if (Contexts[Contexts.size() - 2].CaretFound) {
397 OpeningParen.Previous->is(TT_ForEachMacro)) {
401 } else if (OpeningParen.Previous && OpeningParen.Previous->MatchingParen &&
402 OpeningParen.Previous->MatchingParen->isOneOf(
408 OpeningParen.Previous->isOneOf(tok::kw_for, tok::kw_catch);
414 if (Prev->is(TT_TableGenCondOperator)) {
418 Contexts[Contexts.size() - 2].IsTableGenBangOpe) {
437 if (PrevNonComment->isAttribute()) {
439 } else if (PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype,
446 if (PrevNonComment->isOneOf(tok::kw_decltype, tok::kw_typeof))
457 // function pointer and reference types as well as Objective-C
464 bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
466 CurrentToken->isPointerOrReference() || CurrentToken->is(tok::caret);
470 OpeningParen.Previous && OpeningParen.Previous->is(tok::kw_for);
474 // 'identifier' '*' 'identifier' followed by not '=' -- this
477 if (LookForDecls && CurrentToken->Next) {
478 FormatToken *Prev = CurrentToken->getPreviousNonComment();
480 FormatToken *PrevPrev = Prev->getPreviousNonComment();
481 FormatToken *Next = CurrentToken->Next;
482 if (PrevPrev && PrevPrev->is(tok::identifier) &&
483 PrevPrev->isNot(TT_TypeName) && Prev->isPointerOrReference() &&
484 CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
485 Prev->setType(TT_BinaryOperator);
491 if (CurrentToken->Previous->is(TT_PointerOrReference) &&
492 CurrentToken->Previous->Previous->isOneOf(tok::l_paren,
496 if (CurrentToken->is(tok::comma))
498 if (CurrentToken->Previous->is(TT_BinaryOperator))
500 if (CurrentToken->is(tok::r_paren)) {
502 ProbablyFunctionType && CurrentToken->Next &&
503 (CurrentToken->Next->is(tok::l_paren) ||
504 (CurrentToken->Next->is(tok::l_square) &&
506 OpeningParen.setType(OpeningParen.Next->is(tok::caret)
511 CurrentToken->MatchingParen = &OpeningParen;
513 if (CurrentToken->Next && CurrentToken->Next->is(tok::l_brace) &&
514 OpeningParen.Previous && OpeningParen.Previous->is(tok::l_paren)) {
519 Tok = Tok->Next) {
520 if (Tok->is(TT_BinaryOperator) && Tok->isPointerOrReference())
521 Tok->setType(TT_PointerOrReference);
526 CurrentToken->setType(TT_ObjCMethodExpr);
528 Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
534 CurrentToken->setType(TT_AttributeRParen);
536 CurrentToken->setType(TT_TypeDeclarationParen);
538 OpeningParen.Previous->is(TT_JavaAnnotation)) {
539 CurrentToken->setType(TT_JavaAnnotation);
542 OpeningParen.Previous->is(TT_LeadingJavaAnnotation)) {
543 CurrentToken->setType(TT_LeadingJavaAnnotation);
546 OpeningParen.Previous->is(TT_AttributeSquare)) {
547 CurrentToken->setType(TT_AttributeSquare);
560 if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
563 if (CurrentToken->is(tok::l_brace) && OpeningParen.is(TT_ObjCBlockLParen))
565 if (CurrentToken->is(tok::comma) && CurrentToken->Next &&
566 !CurrentToken->Next->HasUnescapedNewline &&
567 !CurrentToken->Next->isTrailingComment()) {
571 (CurrentToken->is(tok::l_paren) && CurrentToken->Next &&
572 CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret));
573 if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) ||
574 CurrentToken->Previous->isTypeName(LangOpts)) &&
575 !(CurrentToken->is(tok::l_brace) ||
576 (CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen))) {
579 if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
582 PossibleObjCForInToken->setType(TT_Unknown);
586 if (MightBeObjCForRangeLoop && CurrentToken->is(Keywords.kw_in)) {
588 PossibleObjCForInToken->setType(TT_ObjCForIn);
592 if (CurrentToken->is(tok::comma))
596 if (CurrentToken->is(tok::comma)) {
598 CurrentToken->setType(TT_TableGenCondOperatorComma);
600 } else if (CurrentToken->is(tok::colon)) {
602 CurrentToken->setType(TT_TableGenCondOperatorColon);
615 if (CurrentToken && CurrentToken->HasUnescapedNewline)
626 if (Tok.Previous && Tok.Previous->is(tok::identifier))
630 if (Tok.Previous && Tok.Previous->is(tok::r_square)) {
631 auto *MatchingParen = Tok.Previous->MatchingParen;
632 if (!MatchingParen || MatchingParen->is(TT_ArraySubscriptLSquare))
641 if (AttrTok->is(tok::r_square))
645 while (AttrTok && AttrTok->isNot(tok::r_square))
646 AttrTok = AttrTok->Next;
652 AttrTok = AttrTok->Next;
657 if (AttrTok->isAccessSpecifierKeyword() ||
658 AttrTok->isOneOf(tok::comment, tok::kw_class, tok::kw_static,
664 if (AttrTok->Next &&
665 AttrTok->Next->startsSequence(tok::identifier, tok::l_paren)) {
677 // ')' or ']'), it could be the start of an Objective-C method
678 // expression, it could the start of an Objective-C array literal,
680 FormatToken *Left = CurrentToken->Previous;
681 Left->ParentBracket = Contexts.back().ContextKind;
682 FormatToken *Parent = Left->getPreviousNonComment();
688 IsCpp && Parent && Parent->is(TT_TemplateCloser) &&
702 bool IsCppStructuredBinding = Left->isCppStructuredBinding(IsCpp);
706 Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
707 !CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
709 Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
711 Parent->isUnaryOperator() ||
713 Parent->isOneOf(TT_ObjCForIn, TT_CastRParen) ||
714 (getBinOpPrecedence(Parent->Tok.getKind(), true, true) >
720 Left->setType(TT_StructuredBindingLSquare);
721 } else if (Left->is(TT_Unknown)) {
723 Left->setType(TT_ObjCMethodExpr);
725 Left->setType(TT_InlineASMSymbolicNameLSquare);
727 Left->setType(TT_AttributeSquare);
728 if (!IsInnerSquare && Left->Previous)
729 Left->Previous->EndsCppAttributeGroup = false;
732 Parent->isOneOf(tok::l_brace, tok::comma)) {
733 Left->setType(TT_JsComputedPropertyName);
735 Parent && Parent->isOneOf(tok::l_brace, tok::comma)) {
736 Left->setType(TT_DesignatedInitializerLSquare);
738 Left->setType(TT_AttributeSquare);
739 } else if (CurrentToken->is(tok::r_square) && Parent &&
740 Parent->is(TT_TemplateCloser)) {
741 Left->setType(TT_ArraySubscriptLSquare);
769 Left->setType(TT_ArrayInitializerLSquare);
770 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
772 !Left->endsSequence(tok::l_square, tok::numeric_constant,
774 !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
775 Left->setType(TT_ProtoExtensionLSquare);
779 Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,
784 Left->setType(TT_ArrayInitializerLSquare);
787 Left->setType(TT_ArraySubscriptLSquare);
793 if (Style.isJavaScript() && Parent && Parent->is(TT_JsTypeColon))
801 if (CurrentToken->is(tok::r_square)) {
803 CurrentToken->setType(TT_AttributeSquare);
805 CurrentToken->EndsCppAttributeGroup = true;
808 CurrentToken->setType(TT_AttributeSquare);
809 } else if (((CurrentToken->Next &&
810 CurrentToken->Next->is(tok::l_paren)) ||
811 (CurrentToken->Previous &&
812 CurrentToken->Previous->Previous == Left)) &&
813 Left->is(TT_ObjCMethodExpr)) {
819 Left->setType(TT_Unknown);
821 if (StartsObjCMethodExpr && CurrentToken->Previous != Left) {
822 CurrentToken->setType(TT_ObjCMethodExpr);
825 if (!ColonFound && CurrentToken->Previous &&
826 CurrentToken->Previous->is(TT_Unknown) &&
827 canBeObjCSelectorComponent(*CurrentToken->Previous)) {
828 CurrentToken->Previous->setType(TT_SelectorName);
833 if (Parent && Parent->is(TT_PointerOrReference))
834 Parent->overwriteFixedType(TT_BinaryOperator);
837 if (CurrentToken->is(TT_ObjCMethodExpr) && CurrentToken->Next &&
838 CurrentToken->Next->is(TT_LambdaArrow)) {
839 CurrentToken->Next->overwriteFixedType(TT_Unknown);
841 Left->MatchingParen = CurrentToken;
842 CurrentToken->MatchingParen = Left;
848 FormatToken *Previous = CurrentToken->getPreviousNonComment();
849 if (Previous && Previous->is(TT_SelectorName)) {
850 Previous->ObjCSelectorNameParts = 1;
854 Left->ParameterCount =
855 Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts;
858 Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
860 if (Left->BlockParameterCount > 1)
861 Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName = 0;
863 if (Style.isTableGen() && Left->is(TT_TableGenListOpener))
864 CurrentToken->setType(TT_TableGenListCloser);
868 if (CurrentToken->isOneOf(tok::r_paren, tok::r_brace))
870 if (CurrentToken->is(tok::colon)) {
872 CurrentToken->endsSequence(tok::colon, tok::identifier,
876 CurrentToken->setType(TT_AttributeColon);
878 Left->isOneOf(TT_ArraySubscriptLSquare,
880 Left->setType(TT_ObjCMethodExpr);
883 if (Parent && Parent->is(tok::r_paren)) {
885 Parent->setType(TT_CastRParen);
890 if (CurrentToken->is(tok::comma) && Left->is(TT_ObjCMethodExpr) &&
892 Left->setType(TT_ArrayInitializerLSquare);
896 if (CurrentToken->isOneOf(tok::comma, tok::minus, tok::ellipsis)) {
897 // '-' and '...' appears as a separator in slice.
917 while (CurrentToken && CurrentToken->is(tok::comment))
929 while (CurrentToken->is(tok::comment))
936 if (CurrentToken->is(tok::hash)) {
937 if (CurrentToken->Next &&
938 CurrentToken->Next->isOneOf(tok::colon, tok::semi, tok::l_brace)) {
941 CurrentToken->setType(TT_TableGenTrailingPasteOperator);
947 HashTok->setType(TT_Unknown);
953 if (ParseNameMode && CurrentToken->is(tok::l_brace))
956 if (CurrentToken->isOneOf(tok::l_brace, tok::l_square, tok::period)) {
957 CurrentToken->setType(TT_TableGenValueSuffix);
960 if (Suffix->is(tok::l_square))
962 if (Suffix->is(tok::l_brace)) {
976 if (CurrentToken->is(tok::identifier) &&
977 CurrentToken->TokenText.front() == '$') {
990 if (CurrentToken && CurrentToken->is(tok::colon)) {
992 CurrentToken->setType(TT_TableGenDAGArgListColonToAlign);
994 CurrentToken->setType(TT_TableGenDAGArgListColon);
1017 if (!Tok.Next || Tok.Next->is(tok::colon))
1036 Opener->setType(TT_TableGenDAGArgOpenerToBreak);
1037 if (FirstTok->isOneOf(TT_TableGenBangOperator,
1041 CurrentToken->Previous->setType(TT_TableGenDAGArgOperatorToBreak);
1042 } else if (FirstTok->is(tok::identifier)) {
1044 FirstTok->setType(TT_TableGenDAGArgOperatorToBreak);
1046 FirstTok->setType(TT_TableGenDAGArgOperatorID);
1053 if (!FirstDAGArgListElm && CurrentToken->is(tok::comma)) {
1054 CurrentToken->setType(BreakInside ? TT_TableGenDAGArgListCommaToBreak
1058 if (CurrentToken && CurrentToken->is(tok::r_paren)) {
1059 CurrentToken->setType(TT_TableGenDAGArgCloser);
1060 Opener->MatchingParen = CurrentToken;
1061 CurrentToken->MatchingParen = Opener;
1082 if (Tok->isOneOf(tok::numeric_constant, tok::string_literal,
1088 if (Tok->is(tok::l_brace)) {
1093 if (Tok->is(tok::l_square)) {
1094 Tok->setType(TT_TableGenListOpener);
1097 if (Tok->is(tok::less)) {
1098 CurrentToken->setType(TT_TemplateOpener);
1105 if (Tok->is(tok::l_paren)) {
1106 Tok->setType(TT_TableGenDAGArgOpener);
1110 if (Tok->is(TT_TableGenBangOperator)) {
1111 if (CurrentToken && CurrentToken->is(tok::less)) {
1112 CurrentToken->setType(TT_TemplateOpener);
1117 if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
1127 if (Tok->is(TT_TableGenCondOperator)) {
1130 if (!Tok || Tok->isNot(tok::l_paren))
1138 if (Tok->is(tok::identifier)) {
1140 if (CurrentToken && CurrentToken->is(tok::less)) {
1141 CurrentToken->setType(TT_TemplateOpener);
1155 // . { { <-
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;
1183 OpeningBrace.Previous->is(TT_JsTypeColon)) {
1188 OpeningBrace.getPreviousNonComment()->isNot(Keywords.kw_apostrophe))) {
1196 if (CurrentToken->is(tok::r_brace)) {
1200 assert(OpeningBrace.Optional == CurrentToken->Optional);
1202 CurrentToken->MatchingParen = &OpeningBrace;
1212 if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))
1215 if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
1216 FormatToken *Previous = CurrentToken->getPreviousNonComment();
1217 if (Previous->is(TT_JsTypeOptionalQuestion))
1218 Previous = Previous->getPreviousNonComment();
1219 if ((CurrentToken->is(tok::colon) && !Style.isTableGen() &&
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) &&
1235 if (CurrentToken->is(tok::comma)) {
1250 if (Current->is(tok::l_brace) && Current->is(BK_Block))
1251 ++Left->BlockParameterCount;
1252 if (Current->is(tok::comma)) {
1253 ++Left->ParameterCount;
1254 if (!Left->Role)
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;
1264 if (CurrentToken->is(tok::colon)) {
1265 CurrentToken->setType(TT_ConditionalExpr);
1276 if (!CurrentToken || CurrentToken->isNot(tok::less))
1279 CurrentToken->setType(TT_TemplateOpener);
1284 TemplateDeclarationDepth--;
1289 CurrentToken->Previous->ClosesTemplateDeclaration = true;
1296 const auto *Prev = CurrentToken->getPreviousNonComment();
1297 if (Prev && Prev->is(tok::r_square) && Prev->is(TT_AttributeSquare) &&
1298 CurrentToken->isOneOf(tok::kw_if, tok::kw_switch, tok::kw_case,
1301 CurrentToken->MustBreakBefore = true;
1306 // In Verilog primitives' state tables, `:`, `?`, and `-` aren't normal
1308 if (Tok->is(TT_VerilogTableItem))
1310 // Multi-line string itself is a single annotated token.
1311 if (Tok->is(TT_TableGenMultiLineString))
1313 switch (Tok->Tok.getKind()) {
1316 if (!Tok->Previous && Line.MustBeDeclaration)
1317 Tok->setType(TT_ObjCMethodSpecifier);
1320 if (!Tok->Previous)
1324 if (Tok->isTypeFinalized())
1330 !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) ||
1338 Tok->setType(TT_JsTypeColon);
1343 Tok->setType(TT_AttributeColon);
1347 Tok->setType(TT_CSharpNamedArgumentColon);
1350 } else if (Style.isVerilog() && Tok->isNot(TT_BinaryOperator)) {
1353 if (Keywords.isVerilogEnd(*Tok->Previous) ||
1354 Keywords.isVerilogBegin(*Tok->Previous)) {
1355 Tok->setType(TT_VerilogBlockLabelColon);
1357 Tok->setType(TT_BitFieldColon);
1359 Tok->setType(TT_DictLiteral);
1364 Tok->setType(TT_CaseLabelColon);
1366 --Line.Level;
1370 if (Line.First->isOneOf(Keywords.kw_module, Keywords.kw_import) ||
1371 Line.First->startsSequence(tok::kw_export, Keywords.kw_module) ||
1372 Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) {
1373 Tok->setType(TT_ModulePartitionColon);
1374 } else if (Line.First->is(tok::kw_asm)) {
1375 Tok->setType(TT_InlineASMColon);
1377 Tok->setType(TT_DictLiteral);
1379 if (FormatToken *Previous = Tok->getPreviousNonComment())
1380 Previous->setType(TT_SelectorName);
1384 Tok->setType(TT_ObjCMethodExpr);
1385 const FormatToken *BeforePrevious = Tok->Previous->Previous;
1390 Tok->Previous->is(tok::identifier) && Tok->Previous->is(TT_Unknown);
1393 !(BeforePrevious->is(TT_CastRParen) ||
1394 (BeforePrevious->is(TT_ObjCMethodExpr) &&
1395 BeforePrevious->is(tok::colon))) ||
1396 BeforePrevious->is(tok::r_square) ||
1399 Tok->Previous->setType(TT_SelectorName);
1401 Contexts.back().FirstObjCSelectorName = Tok->Previous;
1402 } else if (Tok->Previous->ColumnWidth >
1405 Tok->Previous->ColumnWidth;
1407 Tok->Previous->ParameterIndex =
1408 Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts;
1409 ++Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts;
1412 Tok->setType(TT_RangeBasedForLoopColon);
1414 Tok->setType(TT_GenericSelectionColon);
1415 } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
1416 Tok->setType(TT_BitFieldColon);
1418 !Line.First->isOneOf(tok::kw_enum, tok::kw_case,
1420 FormatToken *Prev = Tok->getPreviousNonComment();
1423 if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
1424 Prev->ClosesRequiresClause) {
1425 Tok->setType(TT_CtorInitializerColon);
1426 } else if (Prev->is(tok::kw_try)) {
1428 FormatToken *PrevPrev = Prev->getPreviousNonComment();
1431 if (PrevPrev && PrevPrev->isOneOf(tok::r_paren, tok::kw_noexcept))
1432 Tok->setType(TT_CtorInitializerColon);
1434 Tok->setType(TT_InheritanceColon);
1435 if (Prev->isAccessSpecifierKeyword())
1438 } else if (canBeObjCSelectorComponent(*Tok->Previous) && Tok->Next &&
1439 (Tok->Next->isOneOf(tok::r_paren, tok::comma) ||
1440 (canBeObjCSelectorComponent(*Tok->Next) && Tok->Next->Next &&
1441 Tok->Next->Next->is(tok::colon)))) {
1444 Tok->setType(TT_ObjCMethodExpr);
1452 Tok->setType(TT_JsTypeOperator);
1459 if (CurrentToken && CurrentToken->is(Keywords.kw_then))
1464 CurrentToken->isOneOf(tok::kw_constexpr, tok::identifier)) {
1469 if (CurrentToken && CurrentToken->is(tok::l_paren)) {
1478 if ((Tok->Previous && Tok->Previous->is(tok::period)) ||
1479 (Tok->Next && Tok->Next->is(tok::colon))) {
1483 if (CurrentToken && CurrentToken->is(Keywords.kw_await))
1486 if (IsCpp && CurrentToken && CurrentToken->is(tok::kw_co_await))
1489 if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
1500 if (Tok->Previous && Tok->Previous->is(tok::r_paren) &&
1501 Tok->Previous->MatchingParen &&
1502 Tok->Previous->MatchingParen->is(TT_OverloadedOperatorLParen)) {
1503 Tok->Previous->setType(TT_OverloadedOperator);
1504 Tok->Previous->MatchingParen->setType(TT_OverloadedOperator);
1505 Tok->setType(TT_OverloadedOperatorLParen);
1515 const FormatToken *Prev = Tok->getPreviousNonComment();
1524 if (!Prev || !(PrevPrev = Prev->getPreviousNonComment()))
1532 if (Prev->is(Keywords.kw_verilogHash) &&
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->is(tok::r_paren) && PrevParen->MatchingParen &&
1543 PrevParen->MatchingParen->is(TT_VerilogInstancePortLParen)) {
1551 Tok->setFinalizedType(TT_VerilogInstancePortLParen);
1559 !Tok->isOneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen)) {
1560 if (const auto *Previous = Tok->Previous;
1562 (!Previous->isAttribute() &&
1563 !Previous->isOneOf(TT_RequiresClause, TT_LeadingJavaAnnotation))) {
1565 Tok->MightBeFunctionDeclParen = true;
1571 Tok->setType(TT_TableGenListOpener);
1577 FormatToken *Previous = Tok->getPreviousNonComment();
1578 if (Previous && Previous->isNot(TT_DictLiteral))
1579 Previous->setType(TT_SelectorName);
1587 Tok->setType(TT_TemplateOpener);
1594 (Style.Language == FormatStyle::LK_Proto && Tok->Previous &&
1595 Tok->Previous->isOneOf(TT_SelectorName, TT_DictLiteral))) {
1596 Tok->setType(TT_DictLiteral);
1597 FormatToken *Previous = Tok->getPreviousNonComment();
1598 if (Previous && Previous->isNot(TT_DictLiteral))
1599 Previous->setType(TT_SelectorName);
1602 Tok->setType(TT_TemplateOpener);
1604 Tok->setType(TT_BinaryOperator);
1618 if (Tok->Previous)
1622 if (Style.Language != FormatStyle::LK_TextProto && Tok->is(TT_Unknown))
1623 Tok->setType(TT_BinaryOperator);
1624 if (Tok->Previous && Tok->Previous->is(TT_TemplateCloser))
1625 Tok->SpacesRequiredBefore = 1;
1631 !CurrentToken->isOneOf(tok::l_paren, tok::semi, tok::r_paren)) {
1632 if (CurrentToken->isOneOf(tok::star, tok::amp))
1633 CurrentToken->setType(TT_PointerOrReference);
1634 auto Next = CurrentToken->getNextNonComment();
1637 if (Next->is(tok::less))
1643 auto Previous = CurrentToken->getPreviousNonComment();
1645 if (CurrentToken->is(tok::comma) && Previous->isNot(tok::kw_operator))
1647 if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator, tok::comma,
1650 Previous->TokenText.starts_with("\"\"")) {
1651 Previous->setType(TT_OverloadedOperator);
1652 if (CurrentToken->isOneOf(tok::less, tok::greater))
1656 if (CurrentToken && CurrentToken->is(tok::l_paren))
1657 CurrentToken->setType(TT_OverloadedOperatorLParen);
1658 if (CurrentToken && CurrentToken->Previous->is(TT_BinaryOperator))
1659 CurrentToken->Previous->setType(TT_OverloadedOperator);
1662 if (Style.isJavaScript() && Tok->Next &&
1663 Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
1669 Tok->setType(TT_JsTypeOptionalQuestion);
1683 if (Tok->Next &&
1684 (Tok->Next->startsSequence(tok::question, tok::r_paren) ||
1685 Tok->Next->startsSequence(tok::question, tok::greater) ||
1686 Tok->Next->startsSequence(tok::question, tok::identifier,
1688 Tok->setType(TT_CSharpNullable);
1693 if (Tok->Next && Tok->Next->is(tok::identifier) && Tok->Next->Next &&
1694 Tok->Next->Next->is(tok::equal)) {
1695 Tok->setType(TT_CSharpNullable);
1705 (!Tok->Next ||
1706 !Tok->Next->isOneOf(tok::identifier, tok::string_literal) ||
1707 !Tok->Next->Next ||
1708 !Tok->Next->Next->isOneOf(tok::colon, tok::question))) {
1709 Tok->setType(TT_CSharpNullable);
1721 Tok->setType(TT_CtorInitializerComma);
1724 Tok->setType(TT_InheritanceComma);
1727 Tok->setFinalizedType(TT_VerilogInstancePortComma);
1732 Tok->setFinalizedType(TT_VerilogAssignComma);
1735 Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
1747 --Line.Level;
1751 if (Tok->isOneOf(Keywords.kw___has_include,
1755 if (Style.isCSharp() && Tok->is(Keywords.kw_where) && Tok->Next &&
1756 Tok->Next->isNot(tok::l_paren)) {
1757 Tok->setType(TT_CSharpGenericTypeConstraint);
1759 if (!Tok->getPreviousNonComment())
1763 if (Tok->is(Keywords.kw_assert)) {
1766 } else if (Tok->isOneOf(Keywords.kw_def, Keywords.kw_defm) &&
1767 (!Tok->Next ||
1768 !Tok->Next->isOneOf(tok::colon, tok::l_brace))) {
1776 if (Tok->isNot(TT_LambdaArrow) && Tok->Previous &&
1777 Tok->Previous->is(tok::kw_noexcept)) {
1778 Tok->setType(TT_TrailingReturnArrow);
1795 if (CurrentToken->is(tok::less)) {
1797 CurrentToken->setType(TT_TemplateOpener);
1800 } else if (CurrentToken->is(tok::greater)) {
1801 CurrentToken->setType(TT_TemplateCloser);
1802 --OpenAngleBracketsCount;
1804 } else if (CurrentToken->is(tok::comma) && OpenAngleBracketsCount == 0) {
1807 CurrentToken->setType(TT_CSharpGenericTypeConstraintComma);
1809 } else if (CurrentToken->is(Keywords.kw_where)) {
1810 CurrentToken->setType(TT_CSharpGenericTypeConstraint);
1812 } else if (CurrentToken->is(tok::colon)) {
1813 CurrentToken->setType(TT_CSharpGenericTypeConstraintColon);
1822 if (CurrentToken && CurrentToken->is(tok::less)) {
1827 if (CurrentToken->isNot(tok::comment) &&
1828 !CurrentToken->TokenText.starts_with("//")) {
1829 CurrentToken->setType(TT_ImplicitStringLiteral);
1838 // We still want to format the whitespace left of the first token of the
1842 CurrentToken->setType(TT_ImplicitStringLiteral);
1850 CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option,
1853 CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_region);
1857 if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator))
1858 CurrentToken->setType(TT_ImplicitStringLiteral);
1865 if (!CurrentToken || CurrentToken->isNot(tok::l_paren))
1873 bool IsFirstToken = CurrentToken->IsFirst;
1885 CurrentToken->setType(TT_ImplicitStringLiteral);
1891 if (CurrentToken->is(tok::numeric_constant)) {
1892 CurrentToken->SpacesRequiredBefore = 1;
1897 if (!CurrentToken->Tok.getIdentifierInfo())
1903 switch (CurrentToken->Tok.getIdentifierInfo()->getPPKeywordID()) {
1923 CurrentToken->SpacesRequiredBefore = true;
1932 if (Tok->is(tok::l_paren)) {
1934 } else if (Tok->isOneOf(Keywords.kw___has_include,
1947 if (!Line.InMacroBody && CurrentToken->is(tok::hash)) {
1956 // Directly allow to 'import <string-literal>' to support protocol buffer
1959 IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo();
1961 CurrentToken->is(Keywords.kw_package)) ||
1963 Info->getPPKeywordID() == tok::pp_import && CurrentToken->Next &&
1964 CurrentToken->Next->isOneOf(tok::string_literal, tok::identifier,
1973 if (CurrentToken->is(tok::less) && Line.Last->is(tok::greater)) {
1978 // In .proto files, top-level options and package statements are very
1979 // similar to import statements and should not be line-wrapped.
1981 CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) {
1983 if (CurrentToken && CurrentToken->is(tok::identifier)) {
1994 if (Style.isJavaScript() && CurrentToken->is(Keywords.kw_import))
1998 if (CurrentToken->is(tok::kw_virtual))
2002 // An export followed by "from 'some string';" is a re-export from
2007 if (Line.First->is(tok::kw_export) &&
2008 CurrentToken->is(Keywords.kw_from) && CurrentToken->Next &&
2009 CurrentToken->Next->isStringLiteral()) {
2027 Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
2042 // FIXME: Closure-library specific stuff should not be hard-coded but be
2044 return Tok.TokenText == "goog" && Tok.Next && Tok.Next->is(tok::period) &&
2045 Tok.Next->Next &&
2046 (Tok.Next->Next->TokenText == "module" ||
2047 Tok.Next->Next->TokenText == "provide" ||
2048 Tok.Next->Next->TokenText == "require" ||
2049 Tok.Next->Next->TokenText == "requireType" ||
2050 Tok.Next->Next->TokenText == "forwardDeclare") &&
2051 Tok.Next->Next->Next && Tok.Next->Next->Next->is(tok::l_paren);
2060 if (!CurrentToken->isTypeFinalized() &&
2061 !CurrentToken->isOneOf(
2073 CurrentToken->setType(TT_Unknown);
2075 CurrentToken->Role.reset();
2076 CurrentToken->MatchingParen = nullptr;
2077 CurrentToken->FakeLParens.clear();
2078 CurrentToken->FakeRParens = 0;
2085 CurrentToken->NestingLevel = Contexts.size() - 1;
2086 CurrentToken->BindingStrength = Contexts.back().BindingStrength;
2089 CurrentToken = CurrentToken->Next;
2174 if (Line.First->isOneOf(tok::kw_using, tok::kw_return))
2176 if (Line.First->is(tok::kw_template)) {
2178 if (Current.Previous->is(tok::kw_operator)) {
2184 const FormatToken *Tok = Line.First->getNextNonComment();
2186 if (Tok->isNot(TT_TemplateOpener)) {
2192 // type or non-type.
2194 assert(Current.Previous->Previous);
2195 return !Current.Previous->Previous->isOneOf(tok::kw_typename,
2199 Tok = Tok->MatchingParen;
2202 Tok = Tok->getNextNonComment();
2206 if (Tok->isOneOf(tok::kw_class, tok::kw_enum, tok::kw_struct,
2223 return !Current.Previous || Current.Previous->isNot(tok::kw_operator);
2230 Previous && Previous->Previous &&
2231 !Previous->Previous->isOneOf(tok::comma, tok::semi);
2232 Previous = Previous->Previous) {
2233 if (Previous->isOneOf(tok::r_square, tok::r_paren, tok::greater)) {
2234 Previous = Previous->MatchingParen;
2238 if (Previous->opensScope())
2240 if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
2241 Previous->isPointerOrReference() && Previous->Previous &&
2242 Previous->Previous->isNot(tok::equal)) {
2243 Previous->setType(TT_PointerOrReference);
2249 Current.Previous->isNot(tok::kw_operator))) {
2258 Current.Previous->is(TT_CtorInitializerColon)) {
2261 } else if (Current.Previous && Current.Previous->is(TT_InheritanceColon)) {
2265 Previous && Previous->isOneOf(tok::star, tok::amp);
2266 Previous = Previous->Previous) {
2267 Previous->setType(TT_PointerOrReference);
2277 Current.Previous->isNot(tok::kw_operator))) {
2278 // This should be the condition or increment in a for-loop.
2289 if (Current->is(tok::l_paren))
2291 if (Current->is(tok::r_paren))
2292 --ParenLevel;
2295 Current = Current->Next;
2301 // Look for a deduction guide template<T> A(...) -> A<...>;
2302 if (Current.Previous && Current.Previous->is(tok::r_paren) &&
2305 FormatToken *TemplateCloser = Current.Next->Next;
2309 if (TemplateCloser->is(tok::l_paren)) {
2315 if (TemplateCloser->is(tok::less))
2317 if (TemplateCloser->is(tok::greater))
2318 --NestingLevel;
2321 TemplateCloser = TemplateCloser->Next;
2324 // with a semi-colon.
2325 if (TemplateCloser && TemplateCloser->Next &&
2326 TemplateCloser->Next->is(tok::semi) &&
2327 Current.Previous->MatchingParen) {
2331 Current.Previous->MatchingParen->Previous;
2334 LeadingIdentifier->TokenText == Current.Next->TokenText;
2353 : Current.Previous->is(tok::identifier);
2355 Current.Previous->isOneOf(
2359 Current.Previous->Tok.isLiteral()) {
2365 Current.Next->isOneOf(TT_BinaryOperator, Keywords.kw_as)) {
2396 !Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) {
2397 // not auto operator->() -> xxx;
2400 Current.Previous->is(tok::r_brace)) {
2402 // a trailing return type ... } -> <type>.
2405 // Deduction guides trailing arrow " A(...) -> A<T>;".
2434 (!Current.Previous || Current.Previous->isNot(tok::l_square)) &&
2464 Current.getPreviousNonComment()->isOneOf(tok::comma, tok::l_brace) &&
2466 Current.getNextNonComment()->isOneOf(tok::comma, tok::r_brace)) {
2476 !Current.Next->isBinaryOperator() &&
2477 !Current.Next->isOneOf(
2480 if (FormatToken *AfterParen = Current.MatchingParen->Next;
2481 AfterParen && AfterParen->isNot(tok::caret)) {
2482 // Make sure this isn't the return type of an Obj-C block declaration.
2483 if (FormatToken *BeforeParen = Current.MatchingParen->Previous;
2484 BeforeParen && BeforeParen->is(tok::identifier) &&
2485 BeforeParen->isNot(TT_TypenameMacro) &&
2486 BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
2487 (!BeforeParen->Previous ||
2488 BeforeParen->Previous->ClosesTemplateDeclaration ||
2489 BeforeParen->Previous->ClosesRequiresClause)) {
2498 switch (Current.Next->Tok.getObjCKeywordID()) {
2513 PreviousNoComment->isOneOf(tok::comma, tok::l_brace)) {
2516 Current.Previous->isOneOf(TT_JavaAnnotation,
2518 Current.setType(Current.Previous->getType());
2523 Current.Previous && Current.Previous->is(TT_CastRParen) &&
2524 Current.Previous->MatchingParen &&
2525 Current.Previous->MatchingParen->Previous &&
2526 Current.Previous->MatchingParen->Previous->is(
2528 // This is the first part of an Objective-C selector name. (If there's no
2535 !Current.Previous->isOneOf(tok::equal, tok::at,
2545 if (Current.Previous->is(tok::at) &&
2549 if (!Previous || Previous->is(TT_LeadingJavaAnnotation))
2553 } else if (Current.Previous->is(tok::period) &&
2554 Current.Previous->isOneOf(TT_JavaAnnotation,
2556 Current.setType(Current.Previous->getType());
2577 (NextNonComment->isPointerOrReference() ||
2578 NextNonComment->is(tok::string_literal) ||
2579 (Line.InPragmaDirective && NextNonComment->is(tok::identifier))))) {
2583 if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof,
2587 if (Style.isJavaScript() && Tok.Previous->is(Keywords.kw_in))
2595 while (PreviousNotConst && PreviousNotConst->is(tok::kw_const))
2596 PreviousNotConst = PreviousNotConst->getPreviousNonComment();
2601 if (PreviousNotConst->ClosesRequiresClause)
2613 bool IsPPKeyword = PreviousNotConst->is(tok::identifier) &&
2614 PreviousNotConst->Previous &&
2615 PreviousNotConst->Previous->is(tok::hash);
2617 if (PreviousNotConst->is(TT_TemplateCloser)) {
2618 return PreviousNotConst && PreviousNotConst->MatchingParen &&
2619 PreviousNotConst->MatchingParen->Previous &&
2620 PreviousNotConst->MatchingParen->Previous->isNot(tok::period) &&
2621 PreviousNotConst->MatchingParen->Previous->isNot(tok::kw_template);
2624 if ((PreviousNotConst->is(tok::r_paren) &&
2625 PreviousNotConst->is(TT_TypeDeclarationParen)) ||
2626 PreviousNotConst->is(TT_AttributeRParen)) {
2635 if (PreviousNotConst->isOneOf(tok::identifier, tok::kw_auto) &&
2636 PreviousNotConst->isNot(TT_StatementAttributeLikeMacro)) {
2641 if (PreviousNotConst->is(TT_PointerOrReference))
2645 if (PreviousNotConst->isTypeName(LangOpts))
2650 PreviousNotConst->is(tok::r_square)) {
2655 return Style.isJavaScript() && PreviousNotConst->is(tok::kw_const);
2660 // C-style casts are only used in C++.
2665 if (LeftOfParens && LeftOfParens->is(TT_TemplateCloser) &&
2666 LeftOfParens->MatchingParen) {
2667 auto *Prev = LeftOfParens->MatchingParen->getPreviousNonComment();
2669 Prev->isOneOf(tok::kw_const_cast, tok::kw_dynamic_cast,
2686 // C-style casts are only used in C++, C# and Java.
2698 if (LParen->is(TT_OverloadedOperatorLParen))
2701 auto *LeftOfParens = LParen->getPreviousNonComment();
2705 if (LeftOfParens->is(tok::r_paren) &&
2706 LeftOfParens->isNot(TT_CastRParen)) {
2707 if (!LeftOfParens->MatchingParen ||
2708 !LeftOfParens->MatchingParen->Previous) {
2711 LeftOfParens = LeftOfParens->MatchingParen->Previous;
2714 if (LeftOfParens->is(tok::r_square)) {
2716 auto MayBeArrayDelete = [](FormatToken *Tok) -> FormatToken * {
2717 if (Tok->isNot(tok::r_square))
2720 Tok = Tok->getPreviousNonComment();
2721 if (!Tok || Tok->isNot(tok::l_square))
2724 Tok = Tok->getPreviousNonComment();
2725 if (!Tok || Tok->isNot(tok::kw_delete))
2736 if (LeftOfParens->Tok.getIdentifierInfo() && LeftOfParens->Previous &&
2737 LeftOfParens->Previous->is(tok::kw_operator)) {
2743 if (LeftOfParens->Tok.getIdentifierInfo() &&
2744 !LeftOfParens->isOneOf(Keywords.kw_in, tok::kw_return, tok::kw_case,
2751 if (LeftOfParens->isOneOf(tok::at, tok::r_square, TT_OverloadedOperator,
2757 if (AfterRParen->is(tok::question) ||
2758 (AfterRParen->is(tok::ampamp) && !BeforeRParen->isTypeName(LangOpts))) {
2763 if (AfterRParen->is(Keywords.kw_in) && Style.isCSharp())
2768 if (AfterRParen->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
2777 if (Style.Language == FormatStyle::LK_Java && AfterRParen->is(tok::l_paren))
2780 // If a (non-string) literal follows, this is likely a cast.
2781 if (AfterRParen->isOneOf(tok::kw_sizeof, tok::kw_alignof) ||
2782 (AfterRParen->Tok.isLiteral() &&
2783 AfterRParen->isNot(tok::string_literal))) {
2791 assert(!T->isTypeName(LangOpts) && "Should have already been checked");
2795 if (T->is(TT_AttributeRParen)) {
2797 assert(T->is(tok::r_paren));
2798 assert(T->MatchingParen);
2799 assert(T->MatchingParen->is(tok::l_paren));
2800 assert(T->MatchingParen->is(TT_AttributeLParen));
2801 if (const auto *Tok = T->MatchingParen->Previous;
2802 Tok && Tok->isAttribute()) {
2803 T = Tok->Previous;
2806 } else if (T->is(TT_AttributeSquare)) {
2808 if (T->MatchingParen && T->MatchingParen->Previous) {
2809 T = T->MatchingParen->Previous;
2812 } else if (T->canBePointerOrReferenceQualifier()) {
2813 T = T->Previous;
2818 return T && T->is(TT_PointerOrReference);
2821 BeforeRParen->isOneOf(TT_TemplateCloser, TT_TypeDeclarationParen) ||
2822 BeforeRParen->isTypeName(LangOpts) ||
2825 AfterRParen->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater);
2837 for (const auto *Token = LParen->Next; Token != &Tok; Token = Token->Next)
2838 if (Token->is(TT_BinaryOperator))
2843 if (AfterRParen->isOneOf(tok::identifier, tok::kw_this))
2847 if (AfterRParen->is(tok::l_paren) && BeforeRParen->Previous) {
2848 if (BeforeRParen->is(tok::identifier) &&
2849 BeforeRParen->Previous->is(tok::l_paren)) {
2854 if (!AfterRParen->Next)
2857 if (AfterRParen->is(tok::l_brace) &&
2858 AfterRParen->getBlockKind() == BK_BracedInit) {
2865 const bool NextIsAmpOrStar = AfterRParen->isOneOf(tok::amp, tok::star);
2866 if (!(AfterRParen->isUnaryOperator() || NextIsAmpOrStar) ||
2867 AfterRParen->is(tok::plus) ||
2868 !AfterRParen->Next->isOneOf(tok::identifier, tok::numeric_constant)) {
2873 (AfterRParen->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
2877 if (Line.InPPDirective && AfterRParen->is(tok::minus))
2881 for (auto *Prev = BeforeRParen; Prev != LParen; Prev = Prev->Previous) {
2882 if (Prev->is(tok::r_paren)) {
2883 if (Prev->is(TT_CastRParen))
2885 Prev = Prev->MatchingParen;
2888 if (Prev->is(TT_FunctionTypeLParen))
2892 if (!Prev->isOneOf(tok::kw_const, tok::identifier, tok::coloncolon))
2909 // @ - It may be followed by a unary `-` in Objective-C literals. We don't
2911 if (PrevToken->isOneOf(
2922 if (PrevToken->is(tok::kw_sizeof))
2926 if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator))
2930 if (PrevToken->is(TT_BinaryOperator))
2960 if (PrevToken->is(TT_TypeName))
2962 if (PrevToken->isOneOf(tok::kw_new, tok::kw_delete) && Tok.is(tok::ampamp))
2967 if (InTemplateArgument && NextToken && NextToken->is(tok::kw_noexcept))
2971 NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
2973 (NextToken->is(tok::kw_noexcept) && !IsExpression) ||
2974 NextToken->canBePointerOrReferenceQualifier() ||
2975 (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) {
2979 if (PrevToken->is(tok::coloncolon))
2982 if (PrevToken->is(tok::r_paren) && PrevToken->is(TT_TypeDeclarationParen))
2988 if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))
2990 if (NextToken->is(tok::kw_operator) && !IsExpression)
2992 if (NextToken->isOneOf(tok::comma, tok::semi))
2999 // following a brace-initialized expression, as in:
3002 // the `}` are put on separate unwrapped lines; in the brace-initialized
3005 if (PrevToken->is(tok::r_brace) && Tok.is(tok::star) &&
3006 !PrevToken->MatchingParen) {
3010 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
3013 if (PrevToken->Tok.isLiteral() ||
3014 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
3020 while (NextNonParen && NextNonParen->is(tok::l_paren))
3021 NextNonParen = NextNonParen->getNextNonComment();
3022 if (NextNonParen && (NextNonParen->Tok.isLiteral() ||
3023 NextNonParen->isOneOf(tok::kw_true, tok::kw_false) ||
3024 NextNonParen->isUnaryOperator())) {
3029 // Thus, having an identifier on the right-hand side indicates a binary
3031 if (InTemplateArgument && NextToken->Tok.isAnyIdentifier())
3037 NextToken->isOneOf(tok::l_paren, tok::star, tok::amp)) {
3042 // aaa && aaa->f();
3043 if (NextToken->Tok.isAnyIdentifier()) {
3044 const FormatToken *NextNextToken = NextToken->getNextNonComment();
3045 if (NextNextToken && NextNextToken->is(tok::arrow))
3060 return !token || token->isOneOf(tok::amp, tok::period, tok::arrow,
3066 if (Tok.is(tok::amp) && PrevToken && PrevToken->Tok.isAnyIdentifier() &&
3067 IsChainedOperatorAmpOrMember(PrevToken->getPreviousNonComment()) &&
3068 NextToken && NextToken->Tok.isAnyIdentifier()) {
3069 if (auto NextNext = NextToken->getNextNonComment();
3071 (IsChainedOperatorAmpOrMember(NextNext) || NextNext->is(tok::semi))) {
3087 if (PrevToken->is(tok::at))
3094 /// Determine whether ++/-- are pre- or post-increments/-decrements.
3097 if (!PrevToken || PrevToken->is(TT_CastRParen))
3099 if (PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::identifier))
3141 while (Current && (Current->is(tok::kw_return) ||
3142 (Current->is(tok::colon) &&
3143 Current->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral)))) {
3187 Current->is(TT_SelectorName)) {
3198 FormatToken *Prev = Current->getPreviousNonComment();
3199 if (Prev && Prev->is(tok::string_literal) &&
3200 (Prev == Start || Prev->endsSequence(tok::string_literal, tok::plus,
3202 Prev->setType(TT_StringInConcatenation);
3209 (Current->closesScope() &&
3210 (Current->MatchingParen || Current->is(TT_TemplateString))) ||
3211 (CurrentPrecedence != -1 && CurrentPrecedence < Precedence) ||
3213 Precedence == prec::Assignment && Current->is(tok::colon))) {
3220 if (Current->opensScope() ||
3221 Current->isOneOf(TT_RequiresClause,
3225 while (Current && (!Current->closesScope() || Current->opensScope())) {
3234 LatestOperator->NextOperator = Current;
3236 Current->OperatorIndex = OperatorIndex;
3252 (Start->Previous &&
3253 Start->Previous->isOneOf(TT_RequiresClause,
3257 while (!Ret->ClosesRequiresClause && Ret->Previous)
3258 Ret = Ret->Previous;
3277 const FormatToken *NextNonComment = Current->getNextNonComment();
3278 if (Current->is(TT_ConditionalExpr))
3280 if (NextNonComment && Current->is(TT_SelectorName) &&
3281 (NextNonComment->isOneOf(TT_DictLiteral, TT_JsTypeColon) ||
3282 (Style.isProto() && NextNonComment->is(tok::less)))) {
3285 if (Current->is(TT_JsComputedPropertyName))
3287 if (Current->is(TT_LambdaArrow))
3289 if (Current->is(TT_FatArrow))
3291 if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName) ||
3292 (Current->is(tok::comment) && NextNonComment &&
3293 NextNonComment->is(TT_SelectorName))) {
3296 if (Current->is(TT_RangeBasedForLoopColon))
3299 Current->is(Keywords.kw_instanceof)) {
3303 Current->isOneOf(Keywords.kw_in, Keywords.kw_as)) {
3306 if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
3307 return Current->getPrecedence();
3308 if (Current->isOneOf(tok::period, tok::arrow) &&
3309 Current->isNot(TT_TrailingReturnArrow)) {
3313 Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
3319 if (Style.isVerilog() && Current->is(tok::colon))
3322 return -1;
3331 if (Start->MacroParent)
3334 Start->FakeLParens.push_back(Precedence);
3336 Start->StartsBinaryExpression = true;
3338 End = Current->getPreviousNonComment();
3340 ++End->FakeRParens;
3342 End->EndsBinaryExpression = true;
3350 while (Current && Current->is(TT_UnaryOperator)) {
3362 while (Current && Current->isTrailingComment())
3366 if (!Current || Current->isNot(tok::question))
3370 if (!Current || Current->isNot(TT_ConditionalExpr))
3379 Current = Current->Next;
3381 (Current->NewlinesBefore == 0 || SkipPastLeadingComments) &&
3382 Current->isTrailingComment()) {
3383 Current = Current->Next;
3397 while (Start->startsSequence(tok::l_paren, tok::star)) {
3398 if (!(Start = Start->MatchingParen) ||
3399 !(Start = Start->getNextNonComment())) {
3406 if (Tok->is(Keywords.kw_assign))
3407 Tok = Tok->getNextNonComment();
3417 FormatToken *Next = Tok->getNextNonComment();
3419 if (Tok->is(tok::hash)) {
3424 Tok = Tok->getNextNonComment();
3425 } else if (Tok->is(tok::hashhash)) {
3429 Tok = Tok->getNextNonComment();
3435 while (Tok && Tok->isOneOf(tok::period, tok::coloncolon) &&
3436 (Tok = Tok->getNextNonComment())) {
3438 Tok = Tok->getNextNonComment();
3442 } else if (Tok->is(tok::l_paren)) {
3446 if (Next->isOneOf(
3452 Tok->setType(TT_VerilogStrength);
3453 Tok = Tok->MatchingParen;
3455 Tok->setType(TT_VerilogStrength);
3456 Tok = Tok->getNextNonComment();
3461 } else if (Tok->is(Keywords.kw_verilogHash)) {
3463 if (Next->is(tok::l_paren))
3464 Next = Next->MatchingParen;
3466 Tok = Next->getNextNonComment();
3475 while (Tok && Tok->is(tok::l_square) && (Tok = Tok->MatchingParen))
3476 Tok = Tok->getNextNonComment();
3477 if (Tok && (Tok->is(tok::hash) || Keywords.isVerilogIdentifier(*Tok)))
3485 if (First && First->is(TT_Unknown))
3486 First->setType(TT_VerilogDimensionedTypeName);
3495 if (TypedName->is(TT_Unknown))
3496 TypedName->setType(TT_StartOfName);
3499 PreviousComma->setType(TT_VerilogTypeComma);
3500 addFakeParenthesis(FirstOfType, prec::Comma, PreviousComma->Previous);
3511 if (Current->opensScope()) {
3534 assert(Line->First);
3538 if (NextNonCommentLine && NextNonCommentLine->First->NewlinesBefore < 2 &&
3539 Line->isComment() && !isClangFormatOff(Line->First->TokenText) &&
3540 NextNonCommentLine->First->OriginalColumn ==
3541 Line->First->OriginalColumn) {
3543 NextNonCommentLine->Type == LT_PreprocessorDirective ||
3544 NextNonCommentLine->Type == LT_ImportStatement;
3546 Line->Type = LT_CommentAbovePPDirective;
3550 Line->Level = Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
3553 : NextNonCommentLine->Level;
3555 NextNonCommentLine = Line->First->isNot(tok::r_brace) ? Line : nullptr;
3558 setCommentLineLevels(Line->Children);
3564 for (const auto *Tok = Line.First; Tok; Tok = Tok->Next)
3565 Result = std::max(Result, Tok->NestingLevel);
3574 Tok = Tok->getNextNonComment()) {
3576 if (Tok->is(tok::l_square) && Tok->is(TT_AttributeSquare)) {
3577 Tok = Tok->MatchingParen;
3585 if (Tok->is(tok::l_paren) && Tok->isNot(TT_FunctionTypeLParen) &&
3586 Tok->MatchingParen) {
3594 if (Tok->isOneOf(tok::kw_friend, tok::kw_inline, tok::kw_virtual,
3600 if (Tok->is(tok::coloncolon)) {
3601 Tok = Tok->Next;
3607 while (Tok->startsSequence(tok::identifier, tok::coloncolon)) {
3608 assert(Tok->Next);
3609 Tok = Tok->Next->Next;
3615 if (Tok->is(tok::tilde)) {
3616 Tok = Tok->Next;
3622 if (Tok->isNot(tok::identifier) || Tok->isNot(TT_Unknown))
3633 assert(Tok && Tok->is(tok::identifier));
3634 const auto *Prev = Tok->Previous;
3636 if (Prev && Prev->is(tok::tilde))
3637 Prev = Prev->Previous;
3639 if (!Prev || !Prev->endsSequence(tok::coloncolon, tok::identifier))
3642 assert(Prev->Previous);
3643 return Prev->Previous->TokenText == Tok->TokenText;
3655 // anyway - it's probably generated code being formatted by mistake.
3671 Tok->setFinalizedType(TT_CtorDtorDeclName);
3673 OpeningParen->setFinalizedType(TT_FunctionDeclarationLParen);
3685 First->SpacesRequiredBefore = 1;
3686 First->CanBreakBefore = First->MustBreakBefore;
3706 PrevPrev && PrevPrev->is(TT_ObjCDecl)) {
3711 [&LangOpts](const FormatToken *Next) -> const FormatToken * {
3712 for (; Next; Next = Next->Next) {
3713 if (Next->is(TT_OverloadedOperatorLParen))
3715 if (Next->is(TT_OverloadedOperator))
3717 if (Next->isOneOf(tok::kw_new, tok::kw_delete)) {
3719 if (Next->Next &&
3720 Next->Next->startsSequence(tok::l_square, tok::r_square)) {
3721 Next = Next->Next->Next;
3725 if (Next->startsSequence(tok::l_square, tok::r_square)) {
3727 Next = Next->Next;
3730 if ((Next->isTypeName(LangOpts) || Next->is(tok::identifier)) &&
3731 Next->Next && Next->Next->isPointerOrReference()) {
3733 Next = Next->Next;
3736 if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
3737 Next = Next->MatchingParen;
3757 assert(Previous.MatchingParen->is(tok::l_paren));
3758 assert(Previous.MatchingParen->is(TT_TypeDeclarationParen));
3767 for (; Next; Next = Next->Next) {
3768 if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
3769 Next = Next->MatchingParen;
3770 } else if (Next->is(tok::coloncolon)) {
3771 Next = Next->Next;
3774 if (Next->is(tok::kw_operator)) {
3775 Next = skipOperatorName(Next->Next);
3778 if (Next->isNot(tok::identifier))
3781 Next = Next->MatchingParen;
3784 } else if (Next->is(tok::l_paren)) {
3793 if (!Next || Next->isNot(tok::l_paren) || !Next->MatchingParen)
3795 ClosingParen = Next->MatchingParen;
3796 assert(ClosingParen->is(tok::r_paren));
3798 if (Line.Last->is(tok::l_brace))
3800 if (Next->Next == ClosingParen)
3803 if (ClosingParen->Next && ClosingParen->Next->is(TT_PointerOrReference))
3816 if (IsCpp && Next->Next && Next->Next->is(tok::identifier) &&
3821 for (const FormatToken *Tok = Next->Next; Tok && Tok != ClosingParen;
3822 Tok = Tok->Next) {
3823 if (Tok->is(TT_TypeDeclarationParen))
3825 if (Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && Tok->MatchingParen) {
3826 Tok = Tok->MatchingParen;
3829 if (Tok->is(tok::kw_const) || Tok->isTypeName(LangOpts) ||
3830 Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis)) {
3833 if (Tok->isOneOf(tok::l_brace, TT_ObjCMethodExpr) || Tok->Tok.isLiteral())
3869 First->TotalLength = First->IsMultiline
3871 : Line.FirstStartColumn + First->ColumnWidth;
3872 FormatToken *Current = First->Next;
3885 for (auto *Tok = Current; Tok; Tok = Tok->Next) {
3886 if (Tok->is(TT_StartOfName))
3888 if (Tok->Previous->EndsCppAttributeGroup)
3890 if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
3894 Tok->setFinalizedType(TT_FunctionDeclarationName);
3898 auto *OpeningParen = ClosingParen->MatchingParen;
3900 if (OpeningParen->is(TT_Unknown))
3901 OpeningParen->setType(TT_FunctionDeclarationLParen);
3907 if (IsCpp && (LineIsFunctionDeclaration || First->is(TT_CtorDtorDeclName)) &&
3909 auto *Tok = Line.Last->Previous;
3910 while (Tok->isNot(tok::r_brace))
3911 Tok = Tok->Previous;
3912 if (auto *LBrace = Tok->MatchingParen; LBrace) {
3913 assert(LBrace->is(tok::l_brace));
3914 Tok->setBlockKind(BK_Block);
3915 LBrace->setBlockKind(BK_Block);
3916 LBrace->setFinalizedType(TT_FunctionLBrace);
3922 AfterLastAttribute->MustBreakBefore = true;
3930 for (const auto *Tok = First; Tok; Tok = Tok->Next) {
3931 if (Tok->isNot(tok::kw_operator))
3934 Tok = Tok->Next;
3935 } while (Tok && Tok->isNot(TT_OverloadedOperatorLParen));
3936 if (!Tok || !Tok->MatchingParen)
3939 for (Tok = Tok->Next; Tok && Tok != LeftParen->MatchingParen;
3940 Tok = Tok->Next) {
3941 if (Tok->isNot(tok::identifier))
3943 auto *Next = Tok->Next;
3945 Next && Next->isPointerOrReference() && Next->Next &&
3946 Next->Next->is(tok::identifier);
3949 Next->setType(TT_BinaryOperator);
3954 for (auto *Tok = ClosingParen->Next; Tok; Tok = Tok->Next) {
3955 if (Tok->is(TT_CtorInitializerColon))
3957 if (Tok->is(tok::arrow)) {
3958 Tok->setType(TT_TrailingReturnArrow);
3961 if (Tok->isNot(TT_TrailingAnnotation))
3963 const auto *Next = Tok->Next;
3964 if (!Next || Next->isNot(tok::l_paren))
3966 Tok = Next->MatchingParen;
3974 const FormatToken *Prev = Current->Previous;
3975 if (Current->is(TT_LineComment)) {
3976 if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
3977 Current->SpacesRequiredBefore =
3981 } else if (Prev->is(TT_VerilogMultiLineListLParen)) {
3982 Current->SpacesRequiredBefore = 0;
3984 Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
3994 if (!Current->HasUnescapedNewline) {
3995 for (FormatToken *Parameter = Current->Previous; Parameter;
3996 Parameter = Parameter->Previous) {
3997 if (Parameter->isOneOf(tok::comment, tok::r_brace))
3999 if (Parameter->Previous && Parameter->Previous->is(tok::comma)) {
4000 if (Parameter->Previous->isNot(TT_CtorInitializerComma) &&
4001 Parameter->HasUnescapedNewline) {
4002 Parameter->MustBreakBefore = true;
4008 } else if (!Current->Finalized && Current->SpacesRequiredBefore == 0 &&
4010 Current->SpacesRequiredBefore = 1;
4013 const auto &Children = Prev->Children;
4014 if (!Children.empty() && Children.back()->Last->is(TT_LineComment)) {
4015 Current->MustBreakBefore = true;
4017 Current->MustBreakBefore =
4018 Current->MustBreakBefore || mustBreakBefore(Line, *Current);
4019 if (!Current->MustBreakBefore && InFunctionDecl &&
4020 Current->is(TT_FunctionDeclarationName)) {
4021 Current->MustBreakBefore = mustBreakForReturnType(Line);
4025 Current->CanBreakBefore =
4026 Current->MustBreakBefore || canBreakBefore(Line, *Current);
4028 if (Prev->Children.size() == 1) {
4029 FormatToken &LastOfChild = *Prev->Children[0]->Last;
4033 if (Current->MustBreakBefore || Prev->Children.size() > 1 ||
4034 (Prev->Children.size() == 1 &&
4035 Prev->Children[0]->First->MustBreakBefore) ||
4036 Current->IsMultiline) {
4037 Current->TotalLength = Prev->TotalLength + Style.ColumnLimit;
4039 Current->TotalLength = Prev->TotalLength + Current->ColumnWidth +
4040 ChildSize + Current->SpacesRequiredBefore;
4043 if (Current->is(TT_CtorInitializerColon))
4055 Current->SplitPenalty = splitPenalty(Line, *Current, InFunctionDecl);
4057 Current->is(TT_SelectorName) && Current->ParameterIndex > 0) {
4058 if (Current->ParameterIndex == 1)
4059 Current->SplitPenalty += 5 * Current->BindingStrength;
4061 Current->SplitPenalty += 20 * Current->BindingStrength;
4064 Current = Current->Next;
4069 for (Current = First; Current; Current = Current->Next) {
4070 if (Current->Role)
4071 Current->Role->precomputeFormattingInfos(Current);
4072 if (Current->MatchingParen &&
4073 Current->MatchingParen->opensBlockOrBlockTypeList(Style) &&
4075 --IndentLevel;
4077 Current->IndentLevel = IndentLevel;
4078 if (Current->opensBlockOrBlockTypeList(Style))
4090 Current->UnbreakableTailLength = UnbreakableTailLength;
4091 if (Current->CanBreakBefore ||
4092 Current->isOneOf(tok::comment, tok::string_literal)) {
4096 Current->ColumnWidth + Current->SpacesRequiredBefore;
4098 Current = Current->Previous;
4107 CurrentToken->ArrayInitializerLineStart = true;
4110 if (CurrentToken->is(tok::l_brace)) {
4111 CurrentToken->IsArrayInitializer = true;
4112 if (CurrentToken->Next)
4113 CurrentToken->Next->MustBreakBefore = true;
4115 calculateInitializerColumnList(Line, CurrentToken->Next, Depth + 1);
4117 CurrentToken = CurrentToken->Next;
4125 if (CurrentToken->is(tok::l_brace))
4127 else if (CurrentToken->is(tok::r_brace))
4128 --Depth;
4129 if (Depth == 2 && CurrentToken->isOneOf(tok::l_brace, tok::comma)) {
4130 CurrentToken = CurrentToken->Next;
4133 CurrentToken->StartsColumn = true;
4134 CurrentToken = CurrentToken->Previous;
4136 CurrentToken = CurrentToken->Next;
4177 if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral))
4223 // Breaking before the "./->" of a chained call/member access is reasonably
4227 // "hanging" indents. The exception is the very last "./->" to support this
4233 // which might otherwise be blown up onto many lines. Here, clang-format
4242 return !Right.NextOperator || !Right.NextOperator->Previous->closesScope()
4248 (!Right.Next || Right.Next->isNot(tok::l_paren))) {
4254 // function-like. It seems to be especially preferable to keep standard
4262 // In for-loops, prefer breaking at ',' and ';'.
4266 // In Objective-C method expressions, prefer breaking before "param:" over
4273 // In Objective-C type declarations, avoid breaking after the category's
4277 Left.Previous->isOneOf(tok::identifier, tok::greater)) {
4288 (Left.Previous->isOneOf(tok::kw_for, tok::kw__Generic) ||
4289 Left.Previous->isIf())) {
4317 Left.Previous->isLabelString() &&
4334 // Slightly prefer to break before the first one in log-like statements.
4378 Right.MatchingParen->is(TT_CastRParen)) {
4404 if (InnerLParen && InnerLParen->Previous == Right.MatchingParen) {
4405 InnerLParen->SpacesRequiredBefore = 0;
4416 if (LeftParen->is(TT_ConditionLParen))
4418 if (LeftParen->Previous && isKeywordWithCondition(*LeftParen->Previous))
4423 // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
4438 BeforeLeft->is(tok::kw_operator)) {
4449 (Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen)))
4457 Right.MatchingParen->Next &&
4458 Right.MatchingParen->Next->is(tok::colon);
4479 // Format empty list as `<>`.
4484 // Don't attempt to format operator<(), as it is handled later.
4490 BeforeLeft->is(tok::kw_case));
4499 Left.MatchingParen->getPreviousNonComment();
4515 if (Left.isTypeOrIdentifier(LangOpts) && Right.Next && Right.Next->Next &&
4516 Right.Next->Next->is(TT_RangeBasedForLoopColon)) {
4547 // foo() -> const Bar * override/final
4558 if (BeforeLeft && BeforeLeft->isTypeOrIdentifier(LangOpts) && Right.Next &&
4559 Right.Next->is(TT_RangeBasedForLoopColon)) {
4569 // FIXME: Setting IsMultiVariableDeclStmt for the whole line is error-prone,
4571 // In multi-variable declaration statements, attach */& to the variable
4573 // scope, e.g. lambda. We still need to special-case statements with
4576 (Left.NestingLevel == Line.First->NestingLevel ||
4577 ((Left.NestingLevel == Line.First->NestingLevel + 1) &&
4583 if (BeforeLeft->is(tok::coloncolon)) {
4590 const auto *LParen = Right.Next->MatchingParen;
4591 return !LParen || LParen->isNot(TT_FunctionTypeLParen);
4593 return !BeforeLeft->isOneOf(tok::l_paren, tok::l_square);
4597 BeforeLeft->isPointerOrReference()) {
4607 while (Previous && Previous->isNot(tok::kw_operator)) {
4608 if (Previous->is(tok::identifier) || Previous->isTypeName(LangOpts)) {
4609 Previous = Previous->getPreviousNonComment();
4612 if (Previous->is(TT_TemplateCloser) && Previous->MatchingParen) {
4613 Previous = Previous->MatchingParen->getPreviousNonComment();
4616 if (Previous->is(tok::coloncolon)) {
4617 Previous = Previous->getPreviousNonComment();
4635 if (Previous->endsSequence(tok::kw_operator))
4637 if (Previous->is(tok::kw_const) || Previous->is(tok::kw_volatile)) {
4663 ((Right.MatchingParen->is(TT_ArrayInitializerLSquare) &&
4667 Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
4684 Right.MatchingParen->isNot(BK_Block))) {
4754 Left.MatchingParen && Left.MatchingParen->is(TT_LambdaLSquare)) {
4758 if (!BeforeLeft || !BeforeLeft->isOneOf(tok::period, tok::arrow)) {
4770 Left.MatchingParen->Previous &&
4771 Left.MatchingParen->Previous->is(tok::kw_delete)) {
4813 Left.MatchingParen->Previous &&
4814 (Left.MatchingParen->Previous->is(tok::period) ||
4815 Left.MatchingParen->Previous->is(tok::coloncolon))) {
4824 // Objective-C dictionary literal -> no space after opening brace.
4828 Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at)) {
4829 // Objective-C dictionary literal -> no space before closing brace.
4834 (!Right.Next || Right.Next->is(tok::semi))) {
4835 // Match const and volatile ref-qualifiers without any additional
4849 // clang-format-off section).
4893 Line.First->is(Keywords.kw_import)) {
4934 Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
5028 Left.Previous->is(tok::kw_for)) {
5033 const FormatToken *Next = Right.MatchingParen->getNextNonComment();
5036 if (Next && Next->is(TT_FatArrow))
5065 if (Left.Previous && Left.Previous->is(tok::period) &&
5084 (Left.Previous->is(tok::identifier) ||
5085 Left.Previous->isOneOf(tok::r_square, tok::r_brace)))) &&
5086 (!Left.Previous || Left.Previous->isNot(tok::period))) {
5090 Left.Previous->is(tok::period) && Right.is(tok::l_paren)) {
5098 Left.Previous->is(tok::kw_export)) {
5108 Line.First->isOneOf(Keywords.kw_import, tok::kw_export)) {
5156 return !(Next && Next->is(tok::r_paren));
5169 Left.MatchingParen->endsSequence(tok::l_paren, tok::at)))) {
5178 // Add spaces around the implication operator `->`.
5194 Left.getPreviousNonComment()->is(Keywords.kw_tagged)) {
5274 // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
5338 // Do not merge "- -" into "--".
5361 if (this->Style.SpacesInAngles == FormatStyle::SIAS_Always)
5363 if (this->Style.SpacesInAngles == FormatStyle::SIAS_Leave)
5415 if (Right.Next && Right.Next->is(TT_StructuredBindingLSquare) &&
5426 Left.MatchingParen->is(TT_OverloadedOperatorLParen)) {
5448 return Tok.MatchingParen && Tok.MatchingParen->Next &&
5449 Tok.MatchingParen->Next->isOneOf(tok::comma, tok::r_paren);
5489 if (AfterRight && AfterRight->is(TT_FatArrow) &&
5509 BeforeLeft->is(tok::string_literal)) {
5513 BeforeLeft && BeforeLeft->is(tok::equal) &&
5514 Line.First->isOneOf(tok::identifier, Keywords.kw_import, tok::kw_export,
5516 // kw_var/kw_let are pseudo-tokens that are tok::identifier, so match
5518 !Line.First->isOneOf(Keywords.kw_var, Keywords.kw_let)) {
5519 // Object literals on the top level of a file are treated as "enum-style".
5520 // Each key/value pair is put on a separate line, instead of bin-packing.
5528 // JavaScript top-level enum key/value pairs are put on separate lines
5529 // instead of bin-packing.
5533 BeforeLeft->is(TT_FatArrow)) {
5543 // allow one-lining inline (e.g. in function call args) and empty arrow
5562 AfterRight->is(tok::string_literal)) {
5578 Left.MatchingParen->is(TT_VerilogInstancePortLParen)))) {
5607 for (const auto *Tok = &Right; Tok; Tok = Tok->Next) {
5608 if (Tok->isOneOf(tok::l_brace, tok::l_square))
5610 if (Tok->isOneOf(tok::r_brace, tok::r_square))
5628 Right.MatchingParen->is(TT_TableGenDAGArgOpenerToBreak) &&
5629 &Left != Right.MatchingParen->Next) {
5649 BeforeClosingBrace = Left.MatchingParen->Previous;
5651 (Right.MatchingParen->isOneOf(tok::l_brace,
5654 Right.MatchingParen->is(tok::l_paren)))) {
5657 if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
5658 BeforeClosingBrace->isTrailingComment())) {
5672 if (BeforeLeft && BeforeLeft->is(tok::lessless) &&
5674 AfterRight->is(tok::string_literal)) {
5689 Left.MatchingParen->NestingLevel == 0) {
5753 (Left.is(tok::less) && BeforeLeft && BeforeLeft->is(tok::equal))) &&
5765 FirstNonComment && (FirstNonComment->is(Keywords.kw_internal) ||
5766 FirstNonComment->isAccessSpecifierKeyword());
5774 if (AccessSpecifier && FirstNonComment->Next &&
5775 FirstNonComment->Next->is(tok::kw_enum)) {
5782 ((AccessSpecifier && FirstNonComment->Next &&
5783 FirstNonComment->Next->is(Keywords.kw_interface)) ||
5831 (Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations)) {
5876 if (LBrace && LBrace->is(tok::colon)) {
5877 LBrace = LBrace->Next;
5878 if (LBrace && LBrace->is(tok::at)) {
5879 LBrace = LBrace->Next;
5881 LBrace = LBrace->Next;
5893 ((LBrace->is(tok::l_brace) &&
5894 (LBrace->is(TT_DictLiteral) ||
5895 (LBrace->Next && LBrace->Next->is(tok::r_brace)))) ||
5896 LBrace->is(TT_ArrayInitializerLSquare) || LBrace->is(tok::less))) {
5913 // left---. .---right
5928 // Language-specific stuff.
5935 if (Line.First->is(TT_CSharpGenericTypeConstraint))
5952 (NonComment->isAccessSpecifierKeyword() ||
5953 NonComment->isOneOf(
5967 if (NonComment && NonComment->is(tok::identifier) &&
5968 NonComment->TokenText == "asserts") {
5990 if (!Next || Next->isNot(tok::colon))
6001 // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#conditional-types
6002 // do not break before them, as the expressions are subject to ASI.
6015 // https://github.com/Microsoft/TypeScript/blob/main/doc/spec-ARCHIVED.md#A.10
6059 (!Right.Next || Right.Next->isNot(TT_FunctionDeclarationName)));
6133 Right.MatchingParen->is(TT_ProtoExtensionLSquare)) {
6137 Right.Next->is(TT_ObjCMethodExpr))) {
6191 (Left.Previous->isOneOf(TT_BinaryOperator, TT_CastRParen))) {
6200 Right.MatchingParen->is(TT_LambdaLSquare)) {
6207 return Right.MatchingParen && (Right.MatchingParen->is(BK_Block) ||
6218 if (Next && Next->is(tok::r_paren))
6219 Next = Next->Next;
6220 if (Next && Next->is(tok::l_paren))
6222 const FormatToken *Previous = Right.MatchingParen->Previous;
6223 return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
6242 if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral))
6298 return Right.Next && Right.Next->is(tok::l_paren);
6319 llvm::errs() << " M=" << Tok->MustBreakBefore
6320 << " C=" << Tok->CanBreakBefore
6321 << " T=" << getTokenTypeName(Tok->getType())
6322 << " S=" << Tok->SpacesRequiredBefore
6323 << " F=" << Tok->Finalized << " B=" << Tok->BlockParameterCount
6324 << " BK=" << Tok->getBlockKind() << " P=" << Tok->SplitPenalty
6325 << " Name=" << Tok->Tok.getName() << " L=" << Tok->TotalLength
6326 << " PPK=" << Tok->getPackingKind() << " FakeLParens=";
6327 for (prec::Level LParen : Tok->FakeLParens)
6329 llvm::errs() << " FakeRParens=" << Tok->FakeRParens;
6330 llvm::errs() << " II=" << Tok->Tok.getIdentifierInfo();
6331 llvm::errs() << " Text='" << Tok->TokenText << "'\n";
6332 if (!Tok->Next)
6334 Tok = Tok->Next;
6336 llvm::errs() << "----\n";
6375 } // namespace format