Lines Matching refs:tok
23 static bool isUnaryOperator(const AnnotatedToken &Tok) {
24 switch (Tok.FormatTok.Tok.getKind()) {
25 case tok::plus:
26 case tok::plusplus:
27 case tok::minus:
28 case tok::minusminus:
29 case tok::exclaim:
30 case tok::tilde:
31 case tok::kw_sizeof:
32 case tok::kw_alignof:
39 static bool isBinaryOperator(const AnnotatedToken &Tok) {
41 return getPrecedence(Tok) > prec::Comma;
45 static AnnotatedToken *getPreviousToken(AnnotatedToken &Tok) {
46 AnnotatedToken *PrevToken = Tok.Parent;
47 while (PrevToken != NULL && PrevToken->is(tok::comment))
51 static const AnnotatedToken *getPreviousToken(const AnnotatedToken &Tok) {
52 return getPreviousToken(const_cast<AnnotatedToken &>(Tok));
55 static bool isTrailingComment(AnnotatedToken *Tok) {
56 return Tok != NULL && Tok->is(tok::comment) &&
57 (Tok->Children.empty() ||
58 Tok->Children[0].FormatTok.NewlinesBefore > 0);
62 static const AnnotatedToken *getNextToken(const AnnotatedToken &Tok) {
63 if (Tok.Children.empty())
65 const AnnotatedToken *NextToken = &Tok.Children[0];
66 while (NextToken->is(tok::comment)) {
74 static bool closesScope(const AnnotatedToken &Tok) {
75 return Tok.isOneOf(tok::r_paren, tok::r_brace, tok::r_square) ||
76 Tok.Type == TT_TemplateCloser;
79 static bool opensScope(const AnnotatedToken &Tok) {
80 return Tok.isOneOf(tok::l_paren, tok::l_brace, tok::l_square) ||
81 Tok.Type == TT_TemplateOpener;
95 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/ false));
102 ScopedContextCreator ContextCreator(*this, tok::less, 10);
106 if (CurrentToken->is(tok::greater)) {
113 if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace,
114 tok::pipepipe, tok::ampamp, tok::question,
115 tok::colon))
127 ScopedContextCreator ContextCreator(*this, tok::l_paren, 1);
135 if (CurrentToken->is(tok::caret)) {
140 if (MaybeSel->isObjCAtKeyword(tok::objc_selector) && MaybeSel->Parent &&
141 MaybeSel->Parent->is(tok::at)) {
159 if (Prev.Parent->is(tok::identifier) &&
160 Prev.isOneOf(tok::star, tok::amp, tok::ampamp) &&
161 CurrentToken->is(tok::identifier) && Next.isNot(tok::equal)) {
167 if (CurrentToken->is(tok::r_paren)) {
182 if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
202 (!Parent || Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
203 tok::kw_return, tok::kw_throw) ||
206 getBinOpPrecedence(Parent->FormatTok.Tok.getKind(), true, true) >
208 ScopedContextCreator ContextCreator(*this, tok::l_square, 10);
210 bool StartsObjCArrayLiteral = Parent && Parent->is(tok::at);
220 if (CurrentToken->is(tok::r_square)) {
222 CurrentToken->Children[0].is(tok::l_paren)) {
246 if (CurrentToken->isOneOf(tok::r_paren, tok::r_brace))
259 ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);
262 if (CurrentToken->is(tok::r_brace)) {
268 if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))
278 if (Current->is(tok::comma))
280 else if (Left->ParameterCount == 0 && Current->isNot(tok::comment))
286 if (CurrentToken->is(tok::colon)) {
298 if (CurrentToken != NULL && CurrentToken->is(tok::less)) {
311 AnnotatedToken *Tok = CurrentToken;
313 switch (Tok->FormatTok.Tok.getKind()) {
314 case tok::plus:
315 case tok::minus:
318 if (Tok->Parent == NULL)
319 Tok->Type = TT_ObjCMethodSpecifier;
321 case tok::colon:
322 if (Tok->Parent == NULL)
325 if (Tok->Parent->is(tok::r_paren) && Contexts.size() == 1) {
326 Tok->Type = TT_CtorInitializerColon;
329 Tok->Type = TT_ObjCMethodExpr;
330 Tok->Parent->Type = TT_ObjCSelectorName;
331 if (Tok->Parent->FormatTok.TokenLength >
334 Tok->Parent->FormatTok.TokenLength;
336 Contexts.back().FirstObjCSelectorName = Tok->Parent;
338 Tok->Type = TT_RangeBasedForLoopColon;
340 Tok->Type = TT_InheritanceColon;
341 } else if (Contexts.back().ContextKind == tok::l_paren) {
342 Tok->Type = TT_InlineASMColon;
345 case tok::kw_if:
346 case tok::kw_while:
347 if (CurrentToken != NULL && CurrentToken->is(tok::l_paren)) {
353 case tok::kw_for:
359 case tok::l_paren:
365 case tok::l_square:
369 case tok::l_brace:
373 case tok::less:
375 Tok->Type = TT_TemplateOpener;
377 Tok->Type = TT_BinaryOperator;
378 CurrentToken = Tok;
382 case tok::r_paren:
383 case tok::r_square:
385 case tok::r_brace:
387 if (Tok->Parent != NULL)
390 case tok::greater:
391 Tok->Type = TT_BinaryOperator;
393 case tok::kw_operator:
394 while (CurrentToken && CurrentToken->isNot(tok::l_paren)) {
395 if (CurrentToken->isOneOf(tok::star, tok::amp))
402 case tok::question:
405 case tok::kw_template:
408 case tok::identifier:
409 if (Line.First.is(tok::kw_for) &&
410 Tok->FormatTok.Tok.getIdentifierInfo() == &Ident_in)
411 Tok->Type = TT_ObjCForIn;
421 if (CurrentToken != NULL && CurrentToken->is(tok::less)) {
424 if (CurrentToken->isNot(tok::comment) ||
431 if (CurrentToken->is(tok::string_literal))
457 if (CurrentToken->FormatTok.Tok.getIdentifierInfo() == NULL)
459 switch (CurrentToken->FormatTok.Tok.getIdentifierInfo()->getPPKeywordID()) {
460 case tok::pp_include:
461 case tok::pp_import:
464 case tok::pp_error:
465 case tok::pp_warning:
480 if (CurrentToken->is(tok::hash)) {
485 if (CurrentToken->is(tok::kw_virtual))
487 if (CurrentToken->isOneOf(tok::period, tok::arrow)) {
538 Context(tok::TokenKind ContextKind, unsigned BindingStrength,
545 tok::TokenKind ContextKind;
560 ScopedContextCreator(AnnotatingParser &P, tok::TokenKind ContextKind,
575 Previous && Previous->isNot(tok::comma);
577 if (Previous->is(tok::r_square))
580 Previous->isOneOf(tok::star, tok::amp)) {
584 } else if (Current.isOneOf(tok::kw_return, tok::kw_throw) ||
585 (Current.is(tok::l_paren) && !Line.MustBeDeclaration &&
586 (!Current.Parent || Current.Parent->isNot(tok::kw_for)))) {
588 } else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) {
590 Previous && Previous->isOneOf(tok::star, tok::amp);
596 } else if (Current.is(tok::kw_new)) {
601 if (Current.Parent && Current.is(tok::identifier) &&
602 ((Current.Parent->is(tok::identifier) &&
603 Current.Parent->FormatTok.Tok.getIdentifierInfo()
604 ->getPPKeywordID() == tok::pp_not_keyword) ||
608 } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {
611 } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret)) {
613 } else if (Current.isOneOf(tok::minusminus, tok::plusplus)) {
615 } else if (Current.is(tok::exclaim)) {
619 } else if (Current.is(tok::comment)) {
620 std::string Data(Lexer::getSpelling(Current.FormatTok.Tok, SourceMgr,
626 } else if (Current.is(tok::r_paren)) {
632 Current.Children[0].isOneOf(tok::equal, tok::semi, tok::l_brace);
635 Current.MatchingParen->Parent->isOneOf(tok::kw_sizeof,
636 tok::kw_alignof);
641 } else if (Current.is(tok::at) && Current.Children.size()) {
642 switch (Current.Children[0].FormatTok.Tok.getObjCKeywordID()) {
643 case tok::objc_interface:
644 case tok::objc_implementation:
645 case tok::objc_protocol:
648 case tok::objc_property:
660 determineStarAmpUsage(const AnnotatedToken &Tok, bool IsExpression) {
661 const AnnotatedToken *PrevToken = getPreviousToken(Tok);
665 const AnnotatedToken *NextToken = getNextToken(Tok);
669 if (PrevToken->is(tok::l_paren) && !IsExpression)
672 if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
673 tok::comma, tok::semi, tok::kw_return, tok::colon,
674 tok::equal) ||
679 if (NextToken->is(tok::l_square))
682 if (PrevToken->FormatTok.Tok.isLiteral() ||
683 PrevToken->isOneOf(tok::r_paren, tok::r_square) ||
684 NextToken->FormatTok.Tok.isLiteral() || isUnaryOperator(*NextToken) ||
685 NextToken->isOneOf(tok::l_paren, tok::l_square))
696 TokenType determinePlusMinusCaretUsage(const AnnotatedToken &Tok) {
697 const AnnotatedToken *PrevToken = getPreviousToken(Tok);
702 if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square,
703 tok::question, tok::colon, tok::kw_return,
704 tok::kw_case, tok::at, tok::l_brace))
716 TokenType determineIncrementUsage(const AnnotatedToken &Tok) {
717 const AnnotatedToken *PrevToken = getPreviousToken(Tok);
720 if (PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::identifier))
748 if (Current->is(tok::kw_return))
767 else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||
770 else if (Current->Type == TT_BinaryOperator || Current->is(tok::comma))
858 (Current->is(tok::string_literal) &&
859 Current->Parent->is(tok::string_literal))) {
861 } else if (Current->is(tok::lessless) && !Current->Children.empty() &&
862 Current->Parent->is(tok::string_literal) &&
863 Current->Children[0].is(tok::string_literal)) {
887 const AnnotatedToken &Tok) {
888 const AnnotatedToken &Left = *Tok.Parent;
889 const AnnotatedToken &Right = Tok;
892 if (Line.First.is(tok::kw_for))
900 if (Left.is(tok::equal) && Right.is(tok::l_brace))
902 if (Left.is(tok::coloncolon))
909 if (Right.isOneOf(tok::arrow, tok::period)) {
912 if (Left.isOneOf(tok::r_paren, tok::r_square) && Left.MatchingParen &&
919 if (Line.First.is(tok::kw_for) && Left.is(tok::equal))
922 if (Left.is(tok::semi))
924 if (Left.is(tok::comma))
931 if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
937 if (Right.is(tok::lessless)) {
938 if (Left.is(tok::string_literal)) {
939 StringRef Content = StringRef(Left.FormatTok.Tok.getLiteralData(),
961 if (Right.is(tok::hashhash))
962 return Left.is(tok::hash);
963 tok::hashhash, tok::hash))
964 return Right.is(tok::hash);
965 if (Right.isOneOf(tok::r_paren, tok::semi, tok::comma))
967 if (Right.is(tok::less) &&
968 (Left.is(tok::kw_template) ||
971 if (Left.is(tok::arrow) || Right.is(tok::arrow))
973 if (Left.isOneOf(tok::exclaim, tok::tilde))
975 if (Left.is(tok::at) &&
976 Right.isOneOf(tok::identifier, tok::string_literal, tok::char_constant,
977 tok::numeric_constant, tok::l_paren, tok::l_brace,
978 tok::kw_true, tok::kw_false))
980 if (Left.is(tok::coloncolon))
982 if (Right.is(tok::coloncolon))
983 return !Left.isOneOf(tok::identifier, tok::greater, tok::l_paren);
984 if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less))
987 return Left.FormatTok.Tok.isLiteral() ||
988 ((Left.Type != TT_PointerOrReference) && Left.isNot(tok::l_paren) &&
991 return Right.FormatTok.Tok.isLiteral() ||
993 if (Right.is(tok::star) && Left.is(tok::l_paren))
995 if (Left.is(tok::l_square))
996 return Left.Type == TT_ObjCArrayLiteral && Right.isNot(tok::r_square);
997 if (Right.is(tok::r_square))
999 if (Right.is(tok::l_square) && Right.Type != TT_ObjCMethodExpr)
1001 if (Left.is(tok::period) || Right.is(tok::period))
1003 if (Left.is(tok::colon))
1005 if (Right.is(tok::colon))
1007 if (Left.is(tok::l_paren))
1009 if (Right.is(tok::l_paren)) {
1011 Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, tok::kw_switch,
1012 tok::kw_return, tok::kw_catch, tok::kw_new,
1013 tok::kw_delete);
1015 if (Left.is(tok::at) &&
1016 Right.FormatTok.Tok.getObjCKeywordID() != tok::objc_not_keyword)
1018 if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
1024 const AnnotatedToken &Tok) {
1025 if (Tok.FormatTok.Tok.getIdentifierInfo() &&
1026 Tok.Parent->FormatTok.Tok.getIdentifierInfo())
1029 if (Tok.Parent->Type == TT_ObjCMethodSpecifier)
1031 if (Tok.Parent->is(tok::r_paren) && Tok.is(tok::identifier))
1036 (Tok.is(tok::equal) || Tok.Parent->is(tok::equal)))
1039 if (Tok.Parent->is(tok::comma))
1041 if (Tok.is(tok::comma))
1043 if (Tok.Type == TT_CtorInitializerColon || Tok.Type == TT_ObjCBlockLParen)
1045 if (Tok.Parent->FormatTok.Tok.is(tok::kw_operator))
1047 if (Tok.Type == TT_OverloadedOperatorLParen)
1049 if (Tok.is(tok::colon))
1050 return !Line.First.isOneOf(tok::kw_case, tok::kw_default) &&
1051 !Tok.Children.empty() && Tok.Type != TT_ObjCMethodExpr;
1052 if (Tok.is(tok::l_paren) && !Tok.Children.empty() &&
1053 Tok.Children[0].Type == TT_PointerOrReference &&
1054 !Tok.Children[0].Children.empty() &&
1055 Tok.Children[0].Children[0].isNot(tok::r_paren))
1057 if (Tok.Parent->Type == TT_UnaryOperator || Tok.Parent->Type == TT_CastRParen)
1059 if (Tok.Type == TT_UnaryOperator)
1060 return !Tok.Parent->isOneOf(tok::l_paren, tok::l_square, tok::at) &&
1061 (Tok.Parent->isNot(tok::colon) ||
1062 Tok.Parent->Type != TT_ObjCMethodExpr);
1063 if (Tok.Parent->is(tok::greater) && Tok.is(tok::greater)) {
1064 return Tok.Type == TT_TemplateCloser &&
1065 Tok.Parent->Type == TT_TemplateCloser &&
1068 if (Tok.is(tok::arrowstar) || Tok.Parent->is(tok::arrowstar))
1070 if (Tok.Type == TT_BinaryOperator || Tok.Parent->Type == TT_BinaryOperator)
1072 if (Tok.Parent->Type == TT_TemplateCloser && Tok.is(tok::l_paren))
1074 if (Tok.is(tok::less) && Line.First.is(tok::hash))
1076 if (Tok.Type == TT_TrailingUnaryOperator)
1078 return spaceRequiredBetween(Line, *Tok.Parent, Tok);
1086 if (Right.is(tok::colon) && Right.Type == TT_ObjCMethodExpr)
1088 if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
1094 if (Right.Type == TT_ConditionalExpr || Right.is(tok::question))
1106 Left.isOneOf(tok::question, tok::kw_operator))
1108 if (Left.is(tok::equal) && Line.Type == LT_VirtualFunctionDecl)
1110 if (Left.is(tok::l_paren) && Right.is(tok::l_paren) && Left.Parent &&
1111 Left.Parent->is(tok::kw___attribute))
1121 if (Left.is(tok::kw_const) && Left.Parent != NULL &&
1122 Left.Parent->is(tok::r_paren))
1123 return !Right.isOneOf(tok::l_brace, tok::semi, tok::equal);
1125 if (Right.is(tok::kw___attribute))
1130 if (Right.isOneOf(tok::r_brace, tok::r_paren, tok::greater))
1132 if (Left.is(tok::identifier) && Right.is(tok::string_literal))
1134 return (isBinaryOperator(Left) && Left.isNot(tok::lessless)) ||
1135 Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace) ||
1136 Right.isOneOf(tok::lessless, tok::arrow, tok::period, tok::colon) ||
1137 (Left.is(tok::r_paren) && Left.Type != TT_CastRParen &&
1138 Right.isOneOf(tok::identifier, tok::kw___attribute)) ||
1139 (Left.is(tok::l_paren) && !Right.is(tok::r_paren)) ||
1140 (Left.is(tok::l_square) && !Right.is(tok::r_square));