Lines Matching refs:Tok
39 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
49 ScopedContextCreator ContextCreator(*this, tok::less, 10);
59 Left->Previous && Left->Previous->Tok.isNot(tok::kw_template);
62 CurrentToken->is(tok::question))
66 if (CurrentToken->is(tok::greater)) {
73 if (CurrentToken->is(tok::question) &&
78 if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace) ||
79 (CurrentToken->isOneOf(tok::colon, tok::question) && InExprContext))
87 if (CurrentToken->Previous->isOneOf(tok::pipepipe, tok::ampamp) &&
90 !Line.startsWith(tok::kw_template))
104 ScopedContextCreator ContextCreator(*this, tok::l_paren, 1);
111 if (CurrentToken->is(tok::caret)) {
116 if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Previous &&
117 MaybeSel->Previous->is(tok::at)) {
123 (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_decltype,
124 tok::kw_if, tok::kw_while, tok::l_paren,
125 tok::comma) ||
129 } else if (Left->Previous && Left->Previous->is(tok::r_square) &&
136 !Left->Previous->isOneOf(tok::identifier,
142 } else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
158 bool MightBeFunctionType = CurrentToken->isOneOf(tok::star, tok::amp);
162 Left->Previous && Left->Previous->is(tok::kw_for);
173 if (PrevPrev && PrevPrev->is(tok::identifier) &&
174 Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
175 CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
183 CurrentToken->Previous->Previous->isOneOf(tok::l_paren,
184 tok::coloncolon))
188 if (CurrentToken->is(tok::r_paren)) {
190 (CurrentToken->Next->is(tok::l_paren) ||
191 (CurrentToken->Next->is(tok::l_square) &&
222 if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
225 if (CurrentToken->is(tok::l_brace))
227 if (CurrentToken->is(tok::comma) && CurrentToken->Next &&
231 if (CurrentToken->isOneOf(tok::kw_const, tok::kw_auto) ||
234 if (CurrentToken->isOneOf(tok::semi, tok::colon))
240 if (CurrentToken->is(tok::comma))
243 FormatToken *Tok = CurrentToken;
246 updateParameterCount(Left, Tok);
266 CurrentToken->isNot(tok::l_brace) &&
268 Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
269 tok::kw_return, tok::kw_throw) ||
272 getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown);
280 Contexts.back().ContextKind == tok::l_brace &&
281 Parent->isOneOf(tok::l_brace, tok::comma)) {
284 Parent->isOneOf(tok::at, tok::equal, tok::comma, tok::l_paren,
285 tok::l_square, tok::question, tok::colon,
286 tok::kw_return)) {
294 ScopedContextCreator ContextCreator(*this, tok::l_square, BindingIncrease);
299 if (CurrentToken->is(tok::r_square)) {
300 if (CurrentToken->Next && CurrentToken->Next->is(tok::l_paren) &&
326 if (CurrentToken->isOneOf(tok::r_paren, tok::r_brace))
328 if (CurrentToken->is(tok::colon)) {
333 if (Parent && Parent->is(tok::r_paren))
338 if (CurrentToken->is(tok::comma) && Left->is(TT_ObjCMethodExpr) &&
341 FormatToken *Tok = CurrentToken;
344 updateParameterCount(Left, Tok);
358 ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);
364 if (CurrentToken->is(tok::r_brace)) {
370 if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))
373 if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
375 if (((CurrentToken->is(tok::colon) &&
379 Previous->Tok.getIdentifierInfo())
381 if (CurrentToken->is(tok::colon) ||
393 if (Current->is(tok::l_brace) && !Current->is(TT_DictLiteral))
395 if (Current->is(tok::comma)) {
400 } else if (Left->ParameterCount == 0 && Current->isNot(tok::comment)) {
407 if (CurrentToken->is(tok::colon)) {
419 if (CurrentToken && CurrentToken->is(tok::less)) {
432 FormatToken *Tok = CurrentToken;
434 switch (Tok->Tok.getKind()) {
435 case tok::plus:
436 case tok::minus:
437 if (!Tok->Previous && Line.MustBeDeclaration)
438 Tok->Type = TT_ObjCMethodSpecifier;
440 case tok::colon:
441 if (!Tok->Previous)
447 !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) ||
448 Contexts.back().ContextKind == tok::l_paren || // function params
449 Contexts.back().ContextKind == tok::l_square || // array type
452 Tok->Type = TT_JsTypeColon;
457 Tok->Type = TT_DictLiteral;
460 Tok->Type = TT_ObjCMethodExpr;
461 Tok->Previous->Type = TT_SelectorName;
462 if (Tok->Previous->ColumnWidth >
464 Contexts.back().LongestObjCSelectorName = Tok->Previous->ColumnWidth;
467 Contexts.back().FirstObjCSelectorName = Tok->Previous;
469 Tok->Type = TT_RangeBasedForLoopColon;
470 } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
471 Tok->Type = TT_BitFieldColon;
473 !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) {
474 if (Tok->Previous->is(tok::r_paren))
475 Tok->Type = TT_CtorInitializerColon;
477 Tok->Type = TT_InheritanceColon;
478 } else if (Tok->Previous->is(tok::identifier) && Tok->Next &&
479 Tok->Next->isOneOf(tok::r_paren, tok::comma)) {
482 Tok->Type = TT_ObjCMethodExpr;
483 } else if (Contexts.back().ContextKind == tok::l_paren) {
484 Tok->Type = TT_InlineASMColon;
487 case tok::kw_if:
488 case tok::kw_while:
489 if (CurrentToken && CurrentToken->is(tok::l_paren)) {
495 case tok::kw_for:
501 case tok::l_paren:
506 if (Tok->Previous &&
507 Tok->Previous->is(tok::r_paren) &&
508 Tok->Previous->MatchingParen &&
509 Tok->Previous->MatchingParen->is(TT_OverloadedOperatorLParen)) {
510 Tok->Previous->Type = TT_OverloadedOperator;
511 Tok->Previous->MatchingParen->Type = TT_OverloadedOperator;
512 Tok->Type = TT_OverloadedOperatorLParen;
519 (!Tok->Previous ||
520 !Tok->Previous->isOneOf(tok::kw_decltype, tok::kw___attribute,
524 case tok::l_square:
528 case tok::l_brace:
532 case tok::less:
533 if (!NonTemplateLess.count(Tok) &&
534 (!Tok->Previous ||
535 (!Tok->Previous->Tok.isLiteral() &&
536 !(Tok->Previous->is(tok::r_paren) && Contexts.size() > 1))) &&
538 Tok->Type = TT_TemplateOpener;
540 Tok->Type = TT_BinaryOperator;
541 NonTemplateLess.insert(Tok);
542 CurrentToken = Tok;
546 case tok::r_paren:
547 case tok::r_square:
549 case tok::r_brace:
551 if (Tok->Previous)
554 case tok::greater:
555 Tok->Type = TT_BinaryOperator;
557 case tok::kw_operator:
559 !CurrentToken->isOneOf(tok::l_paren, tok::semi, tok::r_paren)) {
560 if (CurrentToken->isOneOf(tok::star, tok::amp))
572 case tok::question:
573 if (Style.Language == FormatStyle::LK_JavaScript && Tok->Next &&
574 Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
575 tok::r_brace)) {
580 Tok->Type = TT_JsTypeOptionalQuestion;
590 case tok::kw_template:
593 case tok::comma:
595 Tok->Type = TT_CtorInitializerComma;
597 (Contexts.size() == 1 || Line.startsWith(tok::kw_for))) {
611 if (CurrentToken && CurrentToken->is(tok::less)) {
614 if (CurrentToken->isNot(tok::comment) || CurrentToken->Next)
652 if (CurrentToken->Tok.is(tok::numeric_constant)) {
658 if (!CurrentToken->Tok.getIdentifierInfo())
660 switch (CurrentToken->Tok.getIdentifierInfo()->getPPKeywordID()) {
661 case tok::pp_include:
662 case tok::pp_include_next:
663 case tok::pp_import:
668 case tok::pp_error:
669 case tok::pp_warning:
672 case tok::pp_pragma:
675 case tok::pp_if:
676 case tok::pp_elif:
691 if (CurrentToken->is(tok::hash))
697 IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo();
700 (Info && Info->getPPKeywordID() == tok::pp_import &&
702 CurrentToken->Next->isOneOf(tok::string_literal, tok::identifier,
703 tok::kw_static))) {
711 if (CurrentToken->is(tok::less) && Line.Last->is(tok::greater)) {
721 if (CurrentToken && CurrentToken->is(tok::identifier))
728 if (CurrentToken->is(tok::kw_virtual))
751 bool isImportStatement(const FormatToken &Tok) {
755 Tok.TokenText == "goog" && Tok.Next && Tok.Next->is(tok::period) &&
756 Tok.Next->Next && (Tok.Next->Next->TokenText == "module" ||
757 Tok.Next->Next->TokenText == "provide" ||
758 Tok.Next->Next->TokenText == "require" ||
759 Tok.Next->Next->TokenText == "setTestOnly") &&
760 Tok.Next->Next->Next && Tok.Next->Next->Next->is(tok::l_paren);
795 Context(tok::TokenKind ContextKind, unsigned BindingStrength,
800 tok::TokenKind ContextKind;
821 ScopedContextCreator(AnnotatingParser &P, tok::TokenKind ContextKind,
834 !Line.First->isOneOf(tok::kw_template, tok::kw_using) &&
835 (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
840 !Previous->Previous->isOneOf(tok::comma, tok::semi);
842 if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
850 Previous->isOneOf(tok::star, tok::amp, tok::ampamp) &&
851 Previous->Previous && Previous->Previous->isNot(tok::equal))
855 } else if (Current.is(tok::lessless) &&
856 (!Current.Previous || !Current.Previous->is(tok::kw_operator))) {
858 } else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
864 } else if (Current.is(tok::l_paren) && !Line.MustBeDeclaration &&
867 Current.Previous->isNot(tok::kw_decltype))) {
869 tok::r_paren) &&
873 Current.Previous->isOneOf(tok::kw_for, tok::kw_catch);
875 } else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) {
877 Previous && Previous->isOneOf(tok::star, tok::amp);
886 } else if (Current.is(tok::kw_new)) {
888 } else if (Current.isOneOf(tok::semi, tok::exclaim)) {
908 } else if (Current.isOneOf(tok::kw_auto, tok::kw___auto_type)) {
910 } else if (Current.is(tok::arrow) &&
913 } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration &&
916 } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {
921 } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret)) {
923 if (Current.is(TT_UnaryOperator) && Current.is(tok::caret))
925 } else if (Current.isOneOf(tok::minusminus, tok::plusplus)) {
927 } else if (Current.isOneOf(tok::exclaim, tok::tilde)) {
929 } else if (Current.is(tok::question)) {
939 (!Current.Previous || Current.Previous->isNot(tok::l_square))) {
941 } else if (Current.is(tok::comment)) {
948 Current.Tok.setKind(tok::unknown);
952 } else if (Current.is(tok::r_paren)) {
957 !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace))
959 if (BeforeParen->is(tok::identifier) &&
964 } else if (Current.is(tok::at) && Current.Next) {
968 switch (Current.Next->Tok.getObjCKeywordID()) {
969 case tok::objc_interface:
970 case tok::objc_implementation:
971 case tok::objc_protocol:
974 case tok::objc_property:
981 } else if (Current.is(tok::period)) {
984 PreviousNoComment->isOneOf(tok::comma, tok::l_brace))
991 } else if (Current.isOneOf(tok::identifier, tok::kw_const) &&
993 !Current.Previous->isOneOf(tok::equal, tok::at) &&
1001 if (Current.Previous->is(tok::at) &&
1009 } else if (Current.Previous->is(tok::period) &&
1017 /// \brief Take a guess at whether \p Tok starts a name of a function or
1020 /// This is a heuristic based on whether \p Tok is an identifier following
1022 bool isStartOfName(const FormatToken &Tok) {
1023 if (Tok.isNot(tok::identifier) || !Tok.Previous)
1026 if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof))
1030 FormatToken *PreviousNotConst = Tok.Previous;
1031 while (PreviousNotConst && PreviousNotConst->is(tok::kw_const))
1037 bool IsPPKeyword = PreviousNotConst->is(tok::identifier) &&
1039 PreviousNotConst->Previous->is(tok::hash);
1044 PreviousNotConst->MatchingParen->Previous->isNot(tok::period) &&
1045 PreviousNotConst->MatchingParen->Previous->isNot(tok::kw_template);
1047 if (PreviousNotConst->is(tok::r_paren) && PreviousNotConst->MatchingParen &&
1049 PreviousNotConst->MatchingParen->Previous->is(tok::kw_decltype))
1053 PreviousNotConst->isOneOf(tok::identifier, tok::kw_auto)) ||
1059 bool rParenEndsCast(const FormatToken &Tok) {
1066 if (Tok.Previous == Tok.MatchingParen || !Tok.Next || !Tok.MatchingParen)
1069 FormatToken *LeftOfParens = Tok.MatchingParen->getPreviousNonComment();
1073 if (LeftOfParens->is(tok::r_paren)) {
1082 if (LeftOfParens->Tok.getIdentifierInfo() &&
1083 !LeftOfParens->isOneOf(Keywords.kw_in, tok::kw_return, tok::kw_case,
1084 tok::kw_delete))
1089 if (LeftOfParens->isOneOf(tok::at, tok::r_square, TT_OverloadedOperator,
1094 if (Tok.Next->is(tok::question))
1099 if (Style.Language == FormatStyle::LK_Java && Tok.Next->is(tok::l_paren))
1103 if (Tok.Next->isNot(tok::string_literal) &&
1104 (Tok.Next->Tok.isLiteral() ||
1105 Tok.Next->isOneOf(tok::kw_sizeof, tok::kw_alignof)))
1110 !Tok.Previous ||
1111 Tok.Previous->isOneOf(TT_PointerOrReference, TT_TemplateCloser) ||
1112 Tok.Previous->isSimpleTypeSpecifier();
1114 Tok.Next->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater);
1127 if (Tok.Next->is(tok::identifier))
1130 if (!Tok.Next->Next)
1137 Tok.Next->isUnaryOperator() || Tok.Next->isOneOf(tok::amp, tok::star);
1138 if (!NextIsUnary || Tok.Next->is(tok::plus) ||
1139 !Tok.Next->Next->isOneOf(tok::identifier, tok::numeric_constant))
1142 for (FormatToken *Prev = Tok.Previous; Prev != Tok.MatchingParen;
1144 if (!Prev->isOneOf(tok::kw_const, tok::identifier, tok::coloncolon))
1151 TokenType determineStarAmpUsage(const FormatToken &Tok, bool IsExpression,
1156 const FormatToken *PrevToken = Tok.getPreviousNonComment();
1160 const FormatToken *NextToken = Tok.getNextNonComment();
1162 NextToken->isOneOf(tok::arrow, Keywords.kw_final,
1164 (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
1167 if (PrevToken->is(tok::coloncolon))
1170 if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
1171 tok::comma, tok::semi, tok::kw_return, tok::colon,
1172 tok::equal, tok::kw_delete, tok::kw_sizeof) ||
1177 if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))
1179 if (NextToken->is(tok::kw_operator) && !IsExpression)
1181 if (NextToken->isOneOf(tok::comma, tok::semi))
1184 if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
1186 PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
1187 tok::kw_decltype))
1190 if (PrevToken->Tok.isLiteral() ||
1191 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
1192 tok::kw_false, tok::r_brace) ||
1193 NextToken->Tok.isLiteral() ||
1194 NextToken->isOneOf(tok::kw_true, tok::kw_false) ||
1199 (InTemplateArgument && NextToken->Tok.isAnyIdentifier()))
1203 if (Tok.is(tok::ampamp) && NextToken && NextToken->is(tok::l_paren))
1209 if (NextNextToken && NextNextToken->is(tok::arrow))
1220 TokenType determinePlusMinusCaretUsage(const FormatToken &Tok) {
1221 const FormatToken *PrevToken = Tok.getPreviousNonComment();
1226 if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square,
1227 tok::question, tok::colon, tok::kw_return,
1228 tok::kw_case, tok::at, tok::l_brace))
1240 TokenType determineIncrementUsage(const FormatToken &Tok) {
1241 const FormatToken *PrevToken = Tok.getPreviousNonComment();
1244 tok::r_paren, tok::r_square, tok::identifier))
1280 while (Current && (Current->is(tok::kw_return) ||
1281 (Current->is(tok::colon) &&
1323 Precedence == prec::Assignment && Current->is(tok::colon))) {
1364 if (NextNonComment && NextNonComment->is(tok::colon) &&
1371 if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName,
1373 (Current->is(tok::comment) && NextNonComment &&
1382 if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
1384 if (Current->isOneOf(tok::period, tok::arrow))
1400 while (Previous->is(tok::comment) && Previous->Previous)
1430 if (!Current || !Current->is(tok::question))
1463 if (NextNonCommentLine && (*I)->First->is(tok::comment) &&
1467 NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
1507 if (Next->isOneOf(tok::kw_new, tok::kw_delete)) {
1509 if (Next->Next && Next->Next->is(tok::l_square) &&
1510 Next->Next->Next && Next->Next->Next->is(tok::r_square))
1521 if (Current.is(tok::kw_operator)) {
1522 if (Current.Previous && Current.Previous->is(tok::coloncolon))
1531 } else if (Next->is(tok::coloncolon)) {
1535 if (Next->is(tok::kw_operator)) {
1539 if (!Next->is(tok::identifier))
1541 } else if (Next->is(tok::l_paren)) {
1549 if (!Next || !Next->is(tok::l_paren))
1553 for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
1554 Tok = Tok->Next) {
1555 if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() ||
1556 Tok->isOneOf(TT_PointerOrReference, TT_StartOfName))
1558 if (Tok->isOneOf(tok::l_brace, tok::string_literal, TT_ObjCMethodExpr) ||
1559 Tok->Tok.isLiteral())
1621 if (Parameter->isOneOf(tok::comment, tok::r_brace))
1623 if (Parameter->Previous && Parameter->Previous->is(tok::comma)) {
1688 Current->isOneOf(tok::comment, tok::string_literal)) {
1699 const FormatToken &Tok,
1701 const FormatToken &Left = *Tok.Previous;
1702 const FormatToken &Right = Tok;
1704 if (Left.is(tok::semi))
1712 if (Left.is(tok::comma) && Left.NestingLevel == 0)
1715 if (Right.is(Keywords.kw_function) && Left.isNot(tok::comma))
1721 if (Left.is(tok::comma) || (Right.is(tok::identifier) && Right.Next &&
1724 if (Right.is(tok::l_square)) {
1728 if (Right.is(TT_LambdaLSquare) && Left.is(tok::equal))
1736 Right.is(tok::kw_operator)) {
1737 if (Line.startsWith(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)
1749 if (Left.is(tok::equal) && Right.is(tok::l_brace))
1753 if (Left.is(tok::coloncolon) ||
1754 (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto))
1756 if (Left.isOneOf(tok::kw_class, tok::kw_struct))
1780 (!Right.Next || Right.Next->isNot(tok::l_paren))) {
1791 return (Left.is(tok::r_paren) ? 100 : 120) + (is_short_annotation ? 50 : 0);
1795 if (Line.startsWith(tok::kw_for) && Left.is(tok::equal))
1802 if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr))
1805 if (Left.is(tok::l_paren) && InFunctionDecl &&
1808 if (Left.is(tok::l_paren) && Left.Previous &&
1809 Left.Previous->isOneOf(tok::kw_if, tok::kw_for))
1811 if (Left.is(tok::equal) && InFunctionDecl)
1813 if (Right.is(tok::r_brace))
1826 if (Right.is(tok::lessless)) {
1827 if (Left.is(tok::string_literal) &&
1856 if (Left.is(tok::kw_return) && Right.isNot(tok::semi))
1859 Left.Tok.getObjCKeywordID() == tok::objc_property)
1861 if (Right.is(tok::hashhash))
1862 return Left.is(tok::hash);
1863 if (Left.isOneOf(tok::hashhash, tok::hash))
1864 return Right.is(tok::hash);
1865 if (Left.is(tok::l_paren) && Right.is(tok::r_paren))
1867 if (Left.is(tok::l_paren) || Right.is(tok::r_paren))
1872 if (Right.isOneOf(tok::semi, tok::comma))
1874 if (Right.is(tok::less) &&
1875 (Left.is(tok::kw_template) ||
1878 if (Left.isOneOf(tok::exclaim, tok::tilde))
1880 if (Left.is(tok::at) &&
1881 Right.isOneOf(tok::identifier, tok::string_literal, tok::char_constant,
1882 tok::numeric_constant, tok::l_paren, tok::l_brace,
1883 tok::kw_true, tok::kw_false))
1885 if (Left.is(tok::coloncolon))
1887 if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less))
1889 if (Right.is(tok::ellipsis))
1890 return Left.Tok.isLiteral();
1891 if (Left.is(tok::l_square) && Right.is(tok::amp))
1894 return (Left.is(tok::r_paren) && Left.MatchingParen &&
1898 (Left.Tok.isLiteral() ||
1899 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
1902 if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
1908 return Right.Tok.isLiteral() ||
1911 (Right.is(tok::l_brace) && Right.BlockKind == BK_Block) ||
1913 tok::l_paren) &&
1917 !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon));
1918 if (Right.is(tok::star) && Left.is(tok::l_paren))
1920 if (Left.is(tok::l_square))
1922 Style.SpacesInContainerLiterals && Right.isNot(tok::r_square)) ||
1924 Right.isNot(tok::r_square));
1925 if (Right.is(tok::r_square))
1931 if (Right.is(tok::l_square) &&
1933 !Left.isOneOf(tok::numeric_constant, TT_DictLiteral))
1935 if (Left.is(tok::colon))
1937 if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
1939 if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||
1940 (Right.is(tok::r_brace) && Right.MatchingParen &&
1945 if (Right.is(tok::l_paren)) {
1946 if (Left.is(tok::r_paren) && Left.is(TT_AttributeParen))
1948 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
1950 (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
1951 tok::kw_switch, tok::kw_case, TT_ForEachMacro,
1953 (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
1954 tok::kw_new, tok::kw_delete) &&
1955 (!Left.Previous || Left.Previous->isNot(tok::period))))) ||
1957 (Left.is(tok::identifier) || Left.isFunctionLikeKeyword() ||
1958 Left.is(tok::r_paren)) &&
1961 if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() != tok::objc_not_keyword)
1964 return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
1965 (Left.isNot(tok::colon) || Left.isNot(TT_ObjCMethodExpr));
1966 if ((Left.isOneOf(tok::identifier, tok::greater, tok::r_square,
1967 tok::r_paren) ||
1969 Right.is(tok::l_brace) && Right.getNextNonComment() &&
1972 if (Left.is(tok::period) || Right.is(tok::period))
1974 if (Right.is(tok::hash) && Left.is(tok::identifier) && Left.TokenText == "L")
1978 Left.MatchingParen->Previous->is(tok::period))
1981 if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))
1989 if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo())
1992 if (Left.is(tok::kw_operator))
1993 return Right.is(tok::coloncolon);
1995 if (Right.is(tok::period) &&
1999 if (Right.is(tok::l_paren) &&
2008 if ((Left.is(tok::l_brace) || Right.is(tok::r_brace)) &&
2009 Line.First->isOneOf(Keywords.kw_import, tok::kw_export))
2011 if (Left.is(tok::ellipsis))
2014 !Right.isOneOf(tok::equal, tok::l_brace, tok::comma, tok::l_square,
2021 if (Left.is(tok::r_square) && Right.is(tok::l_brace))
2023 if (Left.is(Keywords.kw_synchronized) && Right.is(tok::l_paren))
2025 if ((Left.isOneOf(tok::kw_static, tok::kw_public, tok::kw_private,
2026 tok::kw_protected) ||
2037 if (Left.is(tok::r_paren) && Right.is(tok::identifier))
2042 (Right.is(tok::equal) || Left.is(tok::equal)))
2048 if (Left.is(tok::comma))
2050 if (Right.is(tok::comma))
2056 if (Right.is(tok::colon)) {
2057 if (Line.First->isOneOf(tok::kw_case, tok::kw_default) ||
2058 !Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi))
2062 if (Left.is(tok::question))
2064 if (Right.is(TT_InlineASMColon) && Left.is(tok::coloncolon))
2079 if (Left.is(tok::greater) && Right.is(tok::greater))
2082 if (Right.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
2083 Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar))
2088 if (Right.is(tok::coloncolon) && Left.isNot(tok::l_brace))
2091 !(Left.isOneOf(tok::identifier, tok::l_paren, tok::r_paren) ||
2095 if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) ||
2097 !Right.is(tok::r_paren)))
2099 if (Left.is(TT_TemplateCloser) && Right.is(tok::l_paren) &&
2102 if (Right.is(TT_TemplateOpener) && Left.is(tok::r_paren) &&
2105 if (Right.is(tok::less) && Left.isNot(tok::l_paren) &&
2106 Line.startsWith(tok::hash))
2115 // Returns 'true' if 'Tok' is a brace we'd want to break before in Allman style.
2116 static bool isAllmanBrace(const FormatToken &Tok) {
2117 return Tok.is(tok::l_brace) && Tok.BlockKind == BK_Block &&
2118 !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
2129 if (Right.is(tok::char_constant) && Left.is(tok::plus) && Left.Previous &&
2130 Left.Previous->is(tok::char_constant))
2132 if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace) && Line.Level == 0 &&
2133 Left.Previous && Left.Previous->is(tok::equal) &&
2134 Line.First->isOneOf(tok::identifier, Keywords.kw_import, tok::kw_export,
2135 tok::kw_const) &&
2136 // kw_var/kw_let are pseudo-tokens that are tok::identifier, so match
2142 if (Left.is(tok::l_brace) && Line.Level == 0 &&
2143 (Line.startsWith(tok::kw_enum) ||
2144 Line.startsWith(tok::kw_export, tok::kw_enum)))
2148 if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
2157 if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next &&
2158 Right.Next->is(tok::string_literal))
2166 if (Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
2170 Right.MatchingParen->isOneOf(tok::l_brace,
2173 if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
2177 if (Right.is(tok::comment))
2188 if (Right.is(tok::lessless) && Right.Next &&
2189 Right.Previous->is(tok::string_literal) &&
2190 Right.Next->is(tok::string_literal))
2201 if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
2206 if (Right.Previous->is(tok::l_brace) && Right.NestingLevel == 1 &&
2213 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
2214 (Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
2215 (Line.startsWith(tok::kw_struct) && Style.BraceWrapping.AfterStruct);
2216 if (Style.Language == FormatStyle::LK_Proto && Left.isNot(tok::l_brace) &&
2225 Right.isNot(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) &&
2226 (Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations))
2245 if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
2251 if (Left.is(tok::at))
2253 if (Left.Tok.getObjCKeywordID() == tok::objc_interface)
2256 return !Right.is(tok::l_paren);
2262 Right.is(tok::kw_operator))
2273 if (Left.is(tok::question) && Right.is(tok::colon))
2275 if (Right.is(TT_ConditionalExpr) || Right.is(tok::question))
2277 if (Left.is(TT_ConditionalExpr) || Left.is(tok::question))
2281 if (Right.is(tok::colon) &&
2284 if (Left.is(tok::colon) && (Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)))
2286 if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next &&
2288 return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.
2289 if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty)
2301 Left.is(tok::kw_operator))
2303 if (Left.is(tok::equal) && !Right.isOneOf(tok::kw_default, tok::kw_delete) &&
2306 if (Left.is(tok::l_paren) && Left.is(TT_AttributeParen))
2308 if (Left.is(tok::l_paren) && Left.Previous &&
2314 if (Right.is(tok::r_paren) || Right.is(TT_TemplateCloser))
2316 if (Right.is(tok::r_square) && Right.MatchingParen &&
2322 if (Right.is(tok::r_brace))
2328 return !Right.isOneOf(tok::l_brace, tok::semi, tok::equal, tok::l_paren,
2329 tok::less, tok::coloncolon);
2331 if (Right.is(tok::kw___attribute))
2334 if (Left.is(tok::identifier) && Right.is(tok::string_literal))
2337 if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral))
2346 if ((Left.is(tok::greater) && Right.is(tok::greater)) ||
2347 (Left.is(tok::less) && Right.is(tok::less)))
2356 if (Right.is(tok::kw_typename) && Left.isNot(tok::kw_const))
2359 !Left.isOneOf(tok::arrowstar, tok::lessless) &&
2364 return Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,
2365 tok::kw_class, tok::kw_struct) ||
2367 Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow, tok::lessless,
2368 tok::colon, tok::l_square, tok::at) ||
2369 (Left.is(tok::r_paren) &&
2370 Right.isOneOf(tok::identifier, tok::kw_const)) ||
2371 (Left.is(tok::l_paren) && !Right.is(tok::r_paren));
2376 const FormatToken *Tok = Line.First;
2377 while (Tok) {
2378 llvm::errs() << " M=" << Tok->MustBreakBefore
2379 << " C=" << Tok->CanBreakBefore
2380 << " T=" << getTokenTypeName(Tok->Type)
2381 << " S=" << Tok->SpacesRequiredBefore
2382 << " B=" << Tok->BlockParameterCount
2383 << " P=" << Tok->SplitPenalty << " Name=" << Tok->Tok.getName()
2384 << " L=" << Tok->TotalLength << " PPK=" << Tok->PackingKind
2386 for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
2387 llvm::errs() << Tok->FakeLParens[i] << "/";
2388 llvm::errs() << " FakeRParens=" << Tok->FakeRParens << "\n";
2389 if (!Tok->Next)
2390 assert(Tok == Line.Last);
2391 Tok = Tok->Next;