Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -252,8 +252,7 @@ assert(!State.Stack.empty()); if ((Current.is(TT_ImplicitStringLiteral) && (Current.Previous->Tok.getIdentifierInfo() == nullptr || - Current.Previous->Tok.getIdentifierInfo()->getPPKeywordID() == - tok::pp_not_keyword))) { + Current.Previous->is(tok::pp_not_keyword)))) { unsigned EndColumn = SourceMgr.getSpellingColumnNumber(Current.WhitespaceRange.getEnd()); if (Current.LastNewlineOffset != 0) { Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -1122,9 +1122,7 @@ Column = FormatTok->LastLineColumnWidth; } - if (!(Tokens.size() > 0 && Tokens.back()->Tok.getIdentifierInfo() && - Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() == - tok::pp_define) && + if (!(Tokens.size() > 0 && Tokens.back()->is(tok::pp_define)) && std::find(ForEachMacros.begin(), ForEachMacros.end(), FormatTok->Tok.getIdentifierInfo()) != ForEachMacros.end()) FormatTok->Type = TT_ForEachMacro; Index: lib/Format/FormatToken.h =================================================================== --- lib/Format/FormatToken.h +++ lib/Format/FormatToken.h @@ -284,6 +284,13 @@ bool is(const IdentifierInfo *II) const { return II && II == Tok.getIdentifierInfo(); } + bool is(tok::ObjCKeywordKind Kind) const { + return Tok.getObjCKeywordID() == Kind; + } + bool is(tok::PPKeywordKind Kind) const { + IdentifierInfo *II = Tok.getIdentifierInfo(); + return II && II->getPPKeywordID() == Kind; + } template bool isOneOf(A K1, B K2) const { return is(K1) || is(K2); } Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -681,11 +681,9 @@ // Directly allow to 'import ' to support protocol buffer // definitions (code.google.com/p/protobuf) or missing "#" (either way we // should not break the line). - IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo(); if ((Style.Language == FormatStyle::LK_Java && CurrentToken->is(Keywords.kw_package)) || - (Info && Info->getPPKeywordID() == tok::pp_import && - CurrentToken->Next && + (CurrentToken->is(tok::pp_import) && CurrentToken->Next && CurrentToken->Next->isOneOf(tok::string_literal, tok::identifier, tok::kw_static))) { next(); @@ -1749,7 +1747,7 @@ if (Left.is(tok::kw_return) && Right.isNot(tok::semi)) return true; if (Style.ObjCSpaceAfterProperty && Line.Type == LT_ObjCProperty && - Left.Tok.getObjCKeywordID() == tok::objc_property) + Left.is(tok::objc_property)) return true; if (Right.is(tok::hashhash)) return Left.is(tok::hash); @@ -1848,7 +1846,7 @@ (Left.is(tok::identifier) || Left.isFunctionLikeKeyword() || Left.is(tok::r_paren)) && Line.Type != LT_PreprocessorDirective); } - if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() != tok::objc_not_keyword) + if (Left.is(tok::at) && !Right.is(tok::objc_not_keyword)) return false; if (Right.is(TT_UnaryOperator)) return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) && @@ -2126,7 +2124,7 @@ if (Left.is(tok::at)) return false; - if (Left.Tok.getObjCKeywordID() == tok::objc_interface) + if (Left.is(tok::objc_interface)) return false; if (Left.isOneOf(TT_JavaAnnotation, TT_LeadingJavaAnnotation)) return !Right.is(tok::l_paren);