<div dir="ltr">Ah, no problem at all, sorry for causing the trouble in the first place. Will create a version without variadic templates.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 24, 2014 at 4:43 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have reverted this commit, and r222641 (which relied on this change)<br>
in r222656. Hopefully it doesn't cause too many problems for you!<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Mon, Nov 24, 2014 at 7:17 AM, NAKAMURA Takumi <<a href="mailto:geek4civic@gmail.com">geek4civic@gmail.com</a>> wrote:<br>
> 2014-11-24 4:03 GMT+09:00 Daniel Jasper <<a href="mailto:djasper@google.com">djasper@google.com</a>>:<br>
>> Author: djasper<br>
>> Date: Sun Nov 23 13:03:25 2014<br>
>> New Revision: 222638<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=222638&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=222638&view=rev</a><br>
>> Log:<br>
>> clang-format: Refactoring.<br>
>><br>
>> Provide more overloads to simplify testing the type of a token. No<br>
>> functional changes intended.<br>
>><br>
>> Modified:<br>
>> cfe/trunk/lib/Format/ContinuationIndenter.cpp<br>
>> cfe/trunk/lib/Format/Format.cpp<br>
>> cfe/trunk/lib/Format/FormatToken.h<br>
>> cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
>> cfe/trunk/lib/Format/WhitespaceManager.cpp<br>
>><br>
>> Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=222638&r1=222637&r2=222638&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=222638&r1=222637&r2=222638&view=diff</a><br>
>> ==============================================================================<br>
>> --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)<br>
>> +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Nov 23 13:03:25 2014<br>
>> @@ -48,11 +48,11 @@ static bool startsSegmentOfBuilderTypeCa<br>
>> static bool startsNextParameter(const FormatToken &Current,<br>
>> const FormatStyle &Style) {<br>
>> const FormatToken &Previous = *Current.Previous;<br>
>> - if (Current.Type == TT_CtorInitializerComma &&<br>
>> + if (Current.is(TT_CtorInitializerComma) &&<br>
>> Style.BreakConstructorInitializersBeforeComma)<br>
>> return true;<br>
>> return Previous.is(tok::comma) && !Current.isTrailingComment() &&<br>
>> - (Previous.Type != TT_CtorInitializerComma ||<br>
>> + (Previous.isNot(TT_CtorInitializerComma) ||<br>
>> !Style.BreakConstructorInitializersBeforeComma);<br>
>> }<br>
>><br>
>> @@ -99,7 +99,7 @@ bool ContinuationIndenter::canBreak(cons<br>
>> // The opening "{" of a braced list has to be on the same line as the first<br>
>> // element if it is nested in another braced init list or function call.<br>
>> if (!Current.MustBreakBefore && Previous.is(tok::l_brace) &&<br>
>> - Previous.Type != TT_DictLiteral && Previous.BlockKind == BK_BracedInit &&<br>
>> + Previous.isNot(TT_DictLiteral) && Previous.BlockKind == BK_BracedInit &&<br>
>> Previous.Previous &&<br>
>> Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma))<br>
>> return false;<br>
>> @@ -124,7 +124,7 @@ bool ContinuationIndenter::canBreak(cons<br>
>><br>
>> // Don't break after very short return types (e.g. "void") as that is often<br>
>> // unexpected.<br>
>> - if (Current.Type == TT_FunctionDeclarationName &&<br>
>> + if (Current.is(TT_FunctionDeclarationName) &&<br>
>> !Style.AlwaysBreakAfterDefinitionReturnType && State.Column < 6)<br>
>> return false;<br>
>><br>
>> @@ -134,7 +134,7 @@ bool ContinuationIndenter::canBreak(cons<br>
>> bool ContinuationIndenter::mustBreak(const LineState &State) {<br>
>> const FormatToken &Current = *State.NextToken;<br>
>> const FormatToken &Previous = *Current.Previous;<br>
>> - if (Current.MustBreakBefore || Current.Type == TT_InlineASMColon)<br>
>> + if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))<br>
>> return true;<br>
>> if (State.Stack.back().BreakBeforeClosingBrace &&<br>
>> Current.closesBlockTypeList(Style))<br>
>> @@ -143,25 +143,25 @@ bool ContinuationIndenter::mustBreak(con<br>
>> return true;<br>
>> if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||<br>
>> (Style.BreakBeforeTernaryOperators &&<br>
>> - (Current.is(tok::question) || (Current.Type == TT_ConditionalExpr &&<br>
>> - Previous.isNot(tok::question)))) ||<br>
>> + (Current.is(tok::question) ||<br>
>> + (Current.is(TT_ConditionalExpr) && Previous.isNot(tok::question)))) ||<br>
>> (!Style.BreakBeforeTernaryOperators &&<br>
>> - (Previous.is(tok::question) || Previous.Type == TT_ConditionalExpr))) &&<br>
>> + (Previous.is(tok::question) || Previous.is(TT_ConditionalExpr)))) &&<br>
>> State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() &&<br>
>> !Current.isOneOf(tok::r_paren, tok::r_brace))<br>
>> return true;<br>
>> if (Style.AlwaysBreakBeforeMultilineStrings &&<br>
>> State.Column > State.Stack.back().Indent && // Breaking saves columns.<br>
>> !Previous.isOneOf(tok::kw_return, tok::lessless, tok::at) &&<br>
>> - Previous.Type != TT_InlineASMColon &&<br>
>> - Previous.Type != TT_ConditionalExpr && nextIsMultilineString(State))<br>
>> + !Previous.isOneOf(TT_InlineASMColon, TT_ConditionalExpr) &&<br>
>> + nextIsMultilineString(State))<br>
>> return true;<br>
>> - if (((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||<br>
>> - Previous.Type == TT_ArrayInitializerLSquare) &&<br>
>> + if (((Previous.is(TT_DictLiteral) && Previous.is(tok::l_brace)) ||<br>
>> + Previous.is(TT_ArrayInitializerLSquare)) &&<br>
>> Style.ColumnLimit > 0 &&<br>
>> getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State))<br>
>> return true;<br>
>> - if (Current.Type == TT_CtorInitializerColon &&<br>
>> + if (Current.is(TT_CtorInitializerColon) &&<br>
>> ((Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All) ||<br>
>> Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))<br>
>> return true;<br>
>> @@ -184,12 +184,11 @@ bool ContinuationIndenter::mustBreak(con<br>
>> bool IsComparison = (Previous.getPrecedence() == prec::Relational ||<br>
>> Previous.getPrecedence() == prec::Equality) &&<br>
>> Previous.Previous &&<br>
>> - Previous.Previous->Type != TT_BinaryOperator; // For >>.<br>
>> + Previous.Previous->isNot(TT_BinaryOperator); // For >>.<br>
>> bool LHSIsBinaryExpr =<br>
>> Previous.Previous && Previous.Previous->EndsBinaryExpression;<br>
>> - if (Previous.Type == TT_BinaryOperator &&<br>
>> - (!IsComparison || LHSIsBinaryExpr) &&<br>
>> - Current.Type != TT_BinaryOperator && // For >>.<br>
>> + if (Previous.is(TT_BinaryOperator) && (!IsComparison || LHSIsBinaryExpr) &&<br>
>> + Current.isNot(TT_BinaryOperator) && // For >>.<br>
>> !Current.isTrailingComment() && !Previous.is(tok::lessless) &&<br>
>> Previous.getPrecedence() != prec::Assignment &&<br>
>> State.Stack.back().BreakBeforeParameter)<br>
>> @@ -197,13 +196,12 @@ bool ContinuationIndenter::mustBreak(con<br>
>> }<br>
>><br>
>> // Same as above, but for the first "<<" operator.<br>
>> - if (Current.is(tok::lessless) && Current.Type != TT_OverloadedOperator &&<br>
>> + if (Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator) &&<br>
>> State.Stack.back().BreakBeforeParameter &&<br>
>> State.Stack.back().FirstLessLess == 0)<br>
>> return true;<br>
>><br>
>> - if (Current.Type == TT_SelectorName &&<br>
>> - State.Stack.back().ObjCSelectorNameFound &&<br>
>> + if (Current.is(TT_SelectorName) && State.Stack.back().ObjCSelectorNameFound &&<br>
>> State.Stack.back().BreakBeforeParameter)<br>
>> return true;<br>
>> if (Previous.ClosesTemplateDeclaration && Current.NestingLevel == 0 &&<br>
>> @@ -211,8 +209,7 @@ bool ContinuationIndenter::mustBreak(con<br>
>> return true;<br>
>><br>
>> // If the return type spans multiple lines, wrap before the function name.<br>
>> - if ((Current.Type == TT_FunctionDeclarationName ||<br>
>> - Current.is(tok::kw_operator)) &&<br>
>> + if (Current.isOneOf(TT_FunctionDeclarationName ,tok::kw_operator) &&<br>
>> State.Stack.back().BreakBeforeParameter)<br>
>> return true;<br>
>><br>
>> @@ -238,7 +235,7 @@ unsigned ContinuationIndenter::addTokenT<br>
>> const FormatToken &Current = *State.NextToken;<br>
>><br>
>> assert(!State.Stack.empty());<br>
>> - if ((Current.Type == TT_ImplicitStringLiteral &&<br>
>> + if ((Current.is(TT_ImplicitStringLiteral) &&<br>
>> (Current.Previous->Tok.getIdentifierInfo() == nullptr ||<br>
>> Current.Previous->Tok.getIdentifierInfo()->getPPKeywordID() ==<br>
>> tok::pp_not_keyword))) {<br>
>> @@ -287,7 +284,7 @@ void ContinuationIndenter::addTokenOnCur<br>
>> Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, /*IndentLevel=*/0,<br>
>> Spaces, State.Column + Spaces);<br>
>><br>
>> - if (Current.Type == TT_SelectorName &&<br>
>> + if (Current.is(TT_SelectorName) &&<br>
>> !State.Stack.back().ObjCSelectorNameFound) {<br>
>> if (Current.LongestObjCSelectorName == 0)<br>
>> State.Stack.back().AlignColons = false;<br>
>> @@ -299,9 +296,9 @@ void ContinuationIndenter::addTokenOnCur<br>
>> State.Stack.back().ColonPos = State.Column + Spaces + Current.ColumnWidth;<br>
>> }<br>
>><br>
>> - if (Style.AlignAfterOpenBracket &&<br>
>> - Previous.opensScope() && Previous.Type != TT_ObjCMethodExpr &&<br>
>> - (Current.Type != TT_LineComment || Previous.BlockKind == BK_BracedInit))<br>
>> + if (Style.AlignAfterOpenBracket && Previous.opensScope() &&<br>
>> + Previous.isNot(TT_ObjCMethodExpr) &&<br>
>> + (Current.isNot(TT_LineComment) || Previous.BlockKind == BK_BracedInit))<br>
>> State.Stack.back().Indent = State.Column + Spaces;<br>
>> if (State.Stack.back().AvoidBinPacking && startsNextParameter(Current, Style))<br>
>> State.Stack.back().NoLineBreak = true;<br>
>> @@ -328,11 +325,10 @@ void ContinuationIndenter::addTokenOnCur<br>
>> State.Stack.back().LastSpace = State.Column;<br>
>> else if (!Current.isOneOf(tok::comment, tok::caret) &&<br>
>> (Previous.is(tok::comma) ||<br>
>> - (Previous.is(tok::colon) && Previous.Type == TT_ObjCMethodExpr)))<br>
>> + (Previous.is(tok::colon) && Previous.is(TT_ObjCMethodExpr))))<br>
>> State.Stack.back().LastSpace = State.Column;<br>
>> - else if ((Previous.Type == TT_BinaryOperator ||<br>
>> - Previous.Type == TT_ConditionalExpr ||<br>
>> - Previous.Type == TT_CtorInitializerColon) &&<br>
>> + else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr,<br>
>> + TT_CtorInitializerColon)) &&<br>
>> ((Previous.getPrecedence() != prec::Assignment &&<br>
>> (Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 ||<br>
>> !Previous.LastOperator)) ||<br>
>> @@ -341,7 +337,7 @@ void ContinuationIndenter::addTokenOnCur<br>
>> // simple assignment without binary expression on the RHS. Also indent<br>
>> // relative to unary operators and the colons of constructor initializers.<br>
>> State.Stack.back().LastSpace = State.Column;<br>
>> - else if (Previous.Type == TT_InheritanceColon) {<br>
>> + else if (Previous.is(TT_InheritanceColon)) {<br>
>> State.Stack.back().Indent = State.Column;<br>
>> State.Stack.back().LastSpace = State.Column;<br>
>> } else if (Previous.opensScope()) {<br>
>> @@ -395,7 +391,7 @@ unsigned ContinuationIndenter::addTokenO<br>
>> if (NextNonComment->isMemberAccess()) {<br>
>> if (State.Stack.back().CallContinuation == 0)<br>
>> State.Stack.back().CallContinuation = State.Column;<br>
>> - } else if (NextNonComment->Type == TT_SelectorName) {<br>
>> + } else if (NextNonComment->is(TT_SelectorName)) {<br>
>> if (!State.Stack.back().ObjCSelectorNameFound) {<br>
>> if (NextNonComment->LongestObjCSelectorName == 0) {<br>
>> State.Stack.back().AlignColons = false;<br>
>> @@ -408,8 +404,7 @@ unsigned ContinuationIndenter::addTokenO<br>
>> State.Stack.back().ColonPos = State.Column + NextNonComment->ColumnWidth;<br>
>> }<br>
>> } else if (PreviousNonComment && PreviousNonComment->is(tok::colon) &&<br>
>> - (PreviousNonComment->Type == TT_ObjCMethodExpr ||<br>
>> - PreviousNonComment->Type == TT_DictLiteral)) {<br>
>> + PreviousNonComment->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral)) {<br>
>> // FIXME: This is hacky, find a better way. The problem is that in an ObjC<br>
>> // method expression, the block should be aligned to the line starting it,<br>
>> // e.g.:<br>
>> @@ -427,10 +422,9 @@ unsigned ContinuationIndenter::addTokenO<br>
>><br>
>> if ((Previous.isOneOf(tok::comma, tok::semi) &&<br>
>> !State.Stack.back().AvoidBinPacking) ||<br>
>> - Previous.Type == TT_BinaryOperator)<br>
>> + Previous.is(TT_BinaryOperator))<br>
>> State.Stack.back().BreakBeforeParameter = false;<br>
>> - if ((Previous.Type == TT_TemplateCloser ||<br>
>> - Previous.Type == TT_JavaAnnotation) &&<br>
>> + if (Previous.isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&<br>
>> Current.NestingLevel == 0)<br>
>> State.Stack.back().BreakBeforeParameter = false;<br>
>> if (NextNonComment->is(tok::question) ||<br>
>> @@ -463,30 +457,27 @@ unsigned ContinuationIndenter::addTokenO<br>
>><br>
>> if (PreviousNonComment &&<br>
>> !PreviousNonComment->isOneOf(tok::comma, tok::semi) &&<br>
>> - (PreviousNonComment->Type != TT_TemplateCloser ||<br>
>> + (PreviousNonComment->isNot(TT_TemplateCloser) ||<br>
>> Current.NestingLevel != 0) &&<br>
>> - PreviousNonComment->Type != TT_BinaryOperator &&<br>
>> - PreviousNonComment->Type != TT_JavaAnnotation &&<br>
>> - PreviousNonComment->Type != TT_LeadingJavaAnnotation &&<br>
>> - Current.Type != TT_BinaryOperator && !PreviousNonComment->opensScope())<br>
>> + !PreviousNonComment->isOneOf(TT_BinaryOperator, TT_JavaAnnotation,<br>
>> + TT_LeadingJavaAnnotation) &&<br>
>> + Current.isNot(TT_BinaryOperator) && !PreviousNonComment->opensScope())<br>
>> State.Stack.back().BreakBeforeParameter = true;<br>
>><br>
>> // If we break after { or the [ of an array initializer, we should also break<br>
>> // before the corresponding } or ].<br>
>> if (PreviousNonComment &&<br>
>> - (PreviousNonComment->is(tok::l_brace) ||<br>
>> - PreviousNonComment->Type == TT_ArrayInitializerLSquare))<br>
>> + (PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)))<br>
>> State.Stack.back().BreakBeforeClosingBrace = true;<br>
>><br>
>> if (State.Stack.back().AvoidBinPacking) {<br>
>> // If we are breaking after '(', '{', '<', this is not bin packing<br>
>> // unless AllowAllParametersOfDeclarationOnNextLine is false or this is a<br>
>> // dict/object literal.<br>
>> - if (!(Previous.isOneOf(tok::l_paren, tok::l_brace) ||<br>
>> - Previous.Type == TT_BinaryOperator) ||<br>
>> + if (!Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) ||<br>
>> (!Style.AllowAllParametersOfDeclarationOnNextLine &&<br>
>> State.Line->MustBeDeclaration) ||<br>
>> - Previous.Type == TT_DictLiteral)<br>
>> + Previous.is(TT_DictLiteral))<br>
>> State.Stack.back().BreakBeforeParameter = true;<br>
>> }<br>
>><br>
>> @@ -528,7 +519,7 @@ unsigned ContinuationIndenter::getNewLin<br>
>> return State.FirstIndent;<br>
>> }<br>
>> if (Current.is(tok::identifier) && Current.Next &&<br>
>> - Current.Next->Type == TT_DictLiteral)<br>
>> + Current.Next->is(TT_DictLiteral))<br>
>> return State.Stack.back().Indent;<br>
>> if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0)<br>
>> return State.StartOfStringLiteral;<br>
>> @@ -544,21 +535,19 @@ unsigned ContinuationIndenter::getNewLin<br>
>> }<br>
>> if (State.Stack.back().QuestionColumn != 0 &&<br>
>> ((NextNonComment->is(tok::colon) &&<br>
>> - NextNonComment->Type == TT_ConditionalExpr) ||<br>
>> - Previous.Type == TT_ConditionalExpr))<br>
>> + NextNonComment->is(TT_ConditionalExpr)) ||<br>
>> + Previous.is(TT_ConditionalExpr)))<br>
>> return State.Stack.back().QuestionColumn;<br>
>> if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0)<br>
>> return State.Stack.back().VariablePos;<br>
>> if ((PreviousNonComment &&<br>
>> (PreviousNonComment->ClosesTemplateDeclaration ||<br>
>> - PreviousNonComment->Type == TT_AttributeParen ||<br>
>> - PreviousNonComment->Type == TT_JavaAnnotation ||<br>
>> - PreviousNonComment->Type == TT_LeadingJavaAnnotation)) ||<br>
>> + PreviousNonComment->isOneOf(TT_AttributeParen, TT_JavaAnnotation,<br>
>> + TT_LeadingJavaAnnotation))) ||<br>
>> (!Style.IndentWrappedFunctionNames &&<br>
>> - (NextNonComment->is(tok::kw_operator) ||<br>
>> - NextNonComment->Type == TT_FunctionDeclarationName)))<br>
>> + NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName)))<br>
>> return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);<br>
>> - if (NextNonComment->Type == TT_SelectorName) {<br>
>> + if (NextNonComment->is(TT_SelectorName)) {<br>
>> if (!State.Stack.back().ObjCSelectorNameFound) {<br>
>> if (NextNonComment->LongestObjCSelectorName == 0) {<br>
>> return State.Stack.back().Indent;<br>
>> @@ -575,23 +564,22 @@ unsigned ContinuationIndenter::getNewLin<br>
>> return State.Stack.back().Indent;<br>
>> }<br>
>> }<br>
>> - if (NextNonComment->Type == TT_ArraySubscriptLSquare) {<br>
>> + if (NextNonComment->is(TT_ArraySubscriptLSquare)) {<br>
>> if (State.Stack.back().StartOfArraySubscripts != 0)<br>
>> return State.Stack.back().StartOfArraySubscripts;<br>
>> else<br>
>> return ContinuationIndent;<br>
>> }<br>
>> - if (NextNonComment->Type == TT_StartOfName ||<br>
>> + if (NextNonComment->is(TT_StartOfName) ||<br>
>> Previous.isOneOf(tok::coloncolon, tok::equal)) {<br>
>> return ContinuationIndent;<br>
>> }<br>
>> if (PreviousNonComment && PreviousNonComment->is(tok::colon) &&<br>
>> - (PreviousNonComment->Type == TT_ObjCMethodExpr ||<br>
>> - PreviousNonComment->Type == TT_DictLiteral))<br>
>> + PreviousNonComment->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral))<br>
>> return ContinuationIndent;<br>
>> - if (NextNonComment->Type == TT_CtorInitializerColon)<br>
>> + if (NextNonComment->is(TT_CtorInitializerColon))<br>
>> return State.FirstIndent + Style.ConstructorInitializerIndentWidth;<br>
>> - if (NextNonComment->Type == TT_CtorInitializerComma)<br>
>> + if (NextNonComment->is(TT_CtorInitializerComma))<br>
>> return State.Stack.back().Indent;<br>
>> if (Previous.is(tok::r_paren) && !Current.isBinaryOperator() &&<br>
>> !Current.isOneOf(tok::colon, tok::comment))<br>
>> @@ -609,18 +597,18 @@ unsigned ContinuationIndenter::moveState<br>
>> assert(State.Stack.size());<br>
>> const FormatToken &Current = *State.NextToken;<br>
>><br>
>> - if (Current.Type == TT_InheritanceColon)<br>
>> + if (Current.is(TT_InheritanceColon))<br>
>> State.Stack.back().AvoidBinPacking = true;<br>
>> - if (Current.is(tok::lessless) && Current.Type != TT_OverloadedOperator) {<br>
>> + if (Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator)) {<br>
>> if (State.Stack.back().FirstLessLess == 0)<br>
>> State.Stack.back().FirstLessLess = State.Column;<br>
>> else<br>
>> State.Stack.back().LastOperatorWrapped = Newline;<br>
>> }<br>
>> - if ((Current.Type == TT_BinaryOperator && Current.isNot(tok::lessless)) ||<br>
>> - Current.Type == TT_ConditionalExpr)<br>
>> + if ((Current.is(TT_BinaryOperator) && Current.isNot(tok::lessless)) ||<br>
>> + Current.is(TT_ConditionalExpr))<br>
>> State.Stack.back().LastOperatorWrapped = Newline;<br>
>> - if (Current.Type == TT_ArraySubscriptLSquare &&<br>
>> + if (Current.is(TT_ArraySubscriptLSquare) &&<br>
>> State.Stack.back().StartOfArraySubscripts == 0)<br>
>> State.Stack.back().StartOfArraySubscripts = State.Column;<br>
>> if ((Current.is(tok::question) && Style.BreakBeforeTernaryOperators) ||<br>
>> @@ -634,9 +622,9 @@ unsigned ContinuationIndenter::moveState<br>
>> if (Current.isMemberAccess())<br>
>> State.Stack.back().StartOfFunctionCall =<br>
>> Current.LastOperator ? 0 : State.Column + Current.ColumnWidth;<br>
>> - if (Current.Type == TT_SelectorName)<br>
>> + if (Current.is(TT_SelectorName))<br>
>> State.Stack.back().ObjCSelectorNameFound = true;<br>
>> - if (Current.Type == TT_CtorInitializerColon) {<br>
>> + if (Current.is(TT_CtorInitializerColon)) {<br>
>> // Indent 2 from the column, so:<br>
>> // SomeClass::SomeClass()<br>
>> // : First(...), ...<br>
>> @@ -652,7 +640,7 @@ unsigned ContinuationIndenter::moveState<br>
>> // In ObjC method declaration we align on the ":" of parameters, but we need<br>
>> // to ensure that we indent parameters on subsequent lines by at least our<br>
>> // continuation indent width.<br>
>> - if (Current.Type == TT_ObjCMethodSpecifier)<br>
>> + if (Current.is(TT_ObjCMethodSpecifier))<br>
>> State.Stack.back().Indent += Style.ContinuationIndentWidth;<br>
>><br>
>> // Insert scopes created by fake parenthesis.<br>
>> @@ -725,7 +713,7 @@ void ContinuationIndenter::moveStatePast<br>
>> bool SkipFirstExtraIndent =<br>
>> (Previous && (Previous->opensScope() || Previous->is(tok::kw_return) ||<br>
>> Previous->getPrecedence() == prec::Assignment ||<br>
>> - Previous->Type == TT_ObjCMethodExpr));<br>
>> + Previous->is(TT_ObjCMethodExpr)));<br>
>> for (SmallVectorImpl<prec::Level>::const_reverse_iterator<br>
>> I = Current.FakeLParens.rbegin(),<br>
>> E = Current.FakeLParens.rend();<br>
>> @@ -750,13 +738,12 @@ void ContinuationIndenter::moveStatePast<br>
>> // Exclude relational operators, as there, it is always more desirable to<br>
>> // have the LHS 'left' of the RHS.<br>
>> if (Previous && Previous->getPrecedence() > prec::Assignment &&<br>
>> - (Previous->Type == TT_BinaryOperator ||<br>
>> - Previous->Type == TT_ConditionalExpr) &&<br>
>> + Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) &&<br>
>> Previous->getPrecedence() != prec::Relational) {<br>
>> bool BreakBeforeOperator = Previous->is(tok::lessless) ||<br>
>> - (Previous->Type == TT_BinaryOperator &&<br>
>> + (Previous->is(TT_BinaryOperator) &&<br>
>> Style.BreakBeforeBinaryOperators) ||<br>
>> - (Previous->Type == TT_ConditionalExpr &&<br>
>> + (Previous->is(TT_ConditionalExpr) &&<br>
>> Style.BreakBeforeTernaryOperators);<br>
>> if ((!Newline && !BreakBeforeOperator) ||<br>
>> (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))<br>
>> @@ -829,8 +816,7 @@ static bool fakeRParenSpecialCase(const<br>
>> return !State.Stack.back().HasMultipleNestedBlocks &&<br>
>> Left->isOneOf(tok::l_brace, tok::l_square) &&<br>
>> (Left->BlockKind == BK_Block ||<br>
>> - Left->Type == TT_ArrayInitializerLSquare ||<br>
>> - Left->Type == TT_DictLiteral);<br>
>> + Left->isOneOf(TT_ArrayInitializerLSquare, TT_DictLiteral));<br>
>> }<br>
>><br>
>> void ContinuationIndenter::moveStatePastFakeRParens(LineState &State) {<br>
>> @@ -857,7 +843,7 @@ void ContinuationIndenter::moveStatePast<br>
>> unsigned NewIndentLevel = State.Stack.back().IndentLevel;<br>
>> bool AvoidBinPacking;<br>
>> bool BreakBeforeParameter = false;<br>
>> - if (Current.is(tok::l_brace) || Current.Type == TT_ArrayInitializerLSquare) {<br>
>> + if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {<br>
>> if (fakeRParenSpecialCase(State))<br>
>> consumeRParens(State, *Current.MatchingParen);<br>
>><br>
>> @@ -871,12 +857,10 @@ void ContinuationIndenter::moveStatePast<br>
>> NewIndent = std::min(State.Column + 1, NewIndent);<br>
>> }<br>
>> const FormatToken *NextNoComment = Current.getNextNonComment();<br>
>> - AvoidBinPacking = Current.Type == TT_ArrayInitializerLSquare ||<br>
>> - Current.Type == TT_DictLiteral ||<br>
>> - Style.Language == FormatStyle::LK_Proto ||<br>
>> - !Style.BinPackParameters ||<br>
>> - (NextNoComment &&<br>
>> - NextNoComment->Type == TT_DesignatedInitializerPeriod);<br>
>> + AvoidBinPacking =<br>
>> + Current.isOneOf(TT_ArrayInitializerLSquare, TT_DictLiteral) ||<br>
>> + Style.Language == FormatStyle::LK_Proto || !Style.BinPackParameters ||<br>
>> + (NextNoComment && NextNoComment->is(TT_DesignatedInitializerPeriod));<br>
>> } else {<br>
>> NewIndent = Style.ContinuationIndentWidth +<br>
>> std::max(State.Stack.back().LastSpace,<br>
>> @@ -890,13 +874,13 @@ void ContinuationIndenter::moveStatePast<br>
>> Current.PackingKind == PPK_Inconclusive)));<br>
>> // If this '[' opens an ObjC call, determine whether all parameters fit<br>
>> // into one line and put one per line if they don't.<br>
>> - if (Current.Type == TT_ObjCMethodExpr && Style.ColumnLimit != 0 &&<br>
>> + if (Current.is(TT_ObjCMethodExpr) && Style.ColumnLimit != 0 &&<br>
>> getLengthToMatchingParen(Current) + State.Column ><br>
>> getColumnLimit(State))<br>
>> BreakBeforeParameter = true;<br>
>> }<br>
>> bool NoLineBreak = State.Stack.back().NoLineBreak ||<br>
>> - (Current.Type == TT_TemplateOpener &&<br>
>> + (Current.is(TT_TemplateOpener) &&<br>
>> State.Stack.back().ContainsUnwrappedBuilder);<br>
>> State.Stack.push_back(ParenState(NewIndent, NewIndentLevel,<br>
>> State.Stack.back().LastSpace,<br>
>> @@ -915,7 +899,7 @@ void ContinuationIndenter::moveStatePast<br>
>> if (State.Stack.size() > 1 &&<br>
>> (Current.isOneOf(tok::r_paren, tok::r_square) ||<br>
>> (Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||<br>
>> - State.NextToken->Type == TT_TemplateCloser))<br>
>> + State.NextToken->is(TT_TemplateCloser)))<br>
>> State.Stack.pop_back();<br>
>><br>
>> if (Current.is(tok::r_square)) {<br>
>> @@ -933,10 +917,10 @@ void ContinuationIndenter::moveStateToNe<br>
>> consumeRParens(State, *State.NextToken->MatchingParen);<br>
>><br>
>> // ObjC block sometimes follow special indentation rules.<br>
>> - unsigned NewIndent = State.Stack.back().LastSpace +<br>
>> - (State.NextToken->Type == TT_ObjCBlockLBrace<br>
>> - ? Style.ObjCBlockIndentWidth<br>
>> - : Style.IndentWidth);<br>
>> + unsigned NewIndent =<br>
>> + State.Stack.back().LastSpace + (State.NextToken->is(TT_ObjCBlockLBrace)<br>
>> + ? Style.ObjCBlockIndentWidth<br>
>> + : Style.IndentWidth);<br>
>> State.Stack.push_back(ParenState(<br>
>> NewIndent, /*NewIndentLevel=*/State.Stack.back().IndentLevel + 1,<br>
>> State.Stack.back().LastSpace, /*AvoidBinPacking=*/true,<br>
>> @@ -983,11 +967,11 @@ unsigned ContinuationIndenter::breakProt<br>
>> bool DryRun) {<br>
>> // Don't break multi-line tokens other than block comments. Instead, just<br>
>> // update the state.<br>
>> - if (Current.Type != TT_BlockComment && Current.IsMultiline)<br>
>> + if (Current.isNot(TT_BlockComment) && Current.IsMultiline)<br>
>> return addMultilineToken(Current, State);<br>
>><br>
>> // Don't break implicit string literals or import statements.<br>
>> - if (Current.Type == TT_ImplicitStringLiteral ||<br>
>> + if (Current.is(TT_ImplicitStringLiteral) ||<br>
>> State.Line->Type == LT_ImportStatement)<br>
>> return 0;<br>
>><br>
>> @@ -1037,15 +1021,15 @@ unsigned ContinuationIndenter::breakProt<br>
>> } else {<br>
>> return 0;<br>
>> }<br>
>> - } else if (Current.Type == TT_BlockComment && Current.isTrailingComment()) {<br>
>> + } else if (Current.is(TT_BlockComment) && Current.isTrailingComment()) {<br>
>> if (CommentPragmasRegex.match(Current.TokenText.substr(2)))<br>
>> return 0;<br>
>> Token.reset(new BreakableBlockComment(<br>
>> Current, State.Line->Level, StartColumn, Current.OriginalColumn,<br>
>> !Current.Previous, State.Line->InPPDirective, Encoding, Style));<br>
>> - } else if (Current.Type == TT_LineComment &&<br>
>> + } else if (Current.is(TT_LineComment) &&<br>
>> (Current.Previous == nullptr ||<br>
>> - Current.Previous->Type != TT_ImplicitStringLiteral)) {<br>
>> + Current.Previous->isNot(TT_ImplicitStringLiteral))) {<br>
>> if (CommentPragmasRegex.match(Current.TokenText.substr(2)))<br>
>> return 0;<br>
>> Token.reset(new BreakableLineComment(Current, State.Line->Level,<br>
>> @@ -1119,7 +1103,7 @@ unsigned ContinuationIndenter::breakProt<br>
>> // If we break the token inside a parameter list, we need to break before<br>
>> // the next parameter on all levels, so that the next parameter is clearly<br>
>> // visible. Line comments already introduce a break.<br>
>> - if (Current.Type != TT_LineComment) {<br>
>> + if (Current.isNot(TT_LineComment)) {<br>
>> for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)<br>
>> State.Stack[i].BreakBeforeParameter = true;<br>
>> }<br>
>> @@ -1139,7 +1123,7 @@ unsigned ContinuationIndenter::getColumn<br>
>><br>
>> bool ContinuationIndenter::nextIsMultilineString(const LineState &State) {<br>
>> const FormatToken &Current = *State.NextToken;<br>
>> - if (!Current.isStringLiteral() || Current.Type == TT_ImplicitStringLiteral)<br>
>> + if (!Current.isStringLiteral() || Current.is(TT_ImplicitStringLiteral))<br>
>> return false;<br>
>> // We never consider raw string literals "multiline" for the purpose of<br>
>> // AlwaysBreakBeforeMultilineStrings implementation as they are special-cased<br>
>><br>
>> Modified: cfe/trunk/lib/Format/Format.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=222638&r1=222637&r2=222638&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=222638&r1=222637&r2=222638&view=diff</a><br>
>> ==============================================================================<br>
>> --- cfe/trunk/lib/Format/Format.cpp (original)<br>
>> +++ cfe/trunk/lib/Format/Format.cpp Sun Nov 23 13:03:25 2014<br>
>> @@ -618,7 +618,7 @@ public:<br>
>> SmallVectorImpl<AnnotatedLine *>::const_iterator E) {<br>
>> // We can never merge stuff if there are trailing line comments.<br>
>> const AnnotatedLine *TheLine = *I;<br>
>> - if (TheLine->Last->Type == TT_LineComment)<br>
>> + if (TheLine->Last->is(TT_LineComment))<br>
>> return 0;<br>
>><br>
>> if (Style.ColumnLimit > 0 && Indent > Style.ColumnLimit)<br>
>> @@ -642,7 +642,7 @@ public:<br>
>> (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline &&<br>
>> TheLine->Level != 0);<br>
>><br>
>> - if (TheLine->Last->Type == TT_FunctionLBrace &&<br>
>> + if (TheLine->Last->is(TT_FunctionLBrace) &&<br>
>> TheLine->First != TheLine->Last) {<br>
>> return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;<br>
>> }<br>
>> @@ -651,7 +651,7 @@ public:<br>
>> ? tryMergeSimpleBlock(I, E, Limit)<br>
>> : 0;<br>
>> }<br>
>> - if (I[1]->First->Type == TT_FunctionLBrace &&<br>
>> + if (I[1]->First->is(TT_FunctionLBrace) &&<br>
>> Style.BreakBeforeBraces != FormatStyle::BS_Attach) {<br>
>> // Check for Limit <= 2 to account for the " {".<br>
>> if (Limit <= 2 || (Style.ColumnLimit == 0 && containsMustBreak(TheLine)))<br>
>> @@ -725,8 +725,7 @@ private:<br>
>> if (1 + I[1]->Last->TotalLength > Limit)<br>
>> return 0;<br>
>> if (I[1]->First->isOneOf(tok::semi, tok::kw_if, tok::kw_for,<br>
>> - tok::kw_while) ||<br>
>> - I[1]->First->Type == TT_LineComment)<br>
>> + tok::kw_while, TT_LineComment))<br>
>> return 0;<br>
>> // Only inline simple if's (no nested if or else).<br>
>> if (I + 2 != E && Line.First->is(tok::kw_if) &&<br>
>> @@ -813,7 +812,7 @@ private:<br>
>><br>
>> // Second, check that the next line does not contain any braces - if it<br>
>> // does, readability declines when putting it into a single line.<br>
>> - if (I[1]->Last->Type == TT_LineComment)<br>
>> + if (I[1]->Last->is(TT_LineComment))<br>
>> return 0;<br>
>> do {<br>
>> if (Tok->is(tok::l_brace) && Tok->BlockKind != BK_BracedInit)<br>
>> @@ -1655,7 +1654,7 @@ private:<br>
>> }<br>
>> }<br>
>><br>
>> - if (FormatTok->Type == TT_ImplicitStringLiteral)<br>
>> + if (FormatTok->is(TT_ImplicitStringLiteral))<br>
>> break;<br>
>> WhitespaceLength += FormatTok->Tok.getLength();<br>
>><br>
>> @@ -2027,7 +2026,7 @@ private:<br>
>> continue;<br>
>> FormatToken *Tok = AnnotatedLines[i]->First->Next;<br>
>> while (Tok->Next) {<br>
>> - if (Tok->Type == TT_PointerOrReference) {<br>
>> + if (Tok->is(TT_PointerOrReference)) {<br>
>> bool SpacesBefore =<br>
>> Tok->WhitespaceRange.getBegin() != Tok->WhitespaceRange.getEnd();<br>
>> bool SpacesAfter = Tok->Next->WhitespaceRange.getBegin() !=<br>
>> @@ -2039,11 +2038,10 @@ private:<br>
>> }<br>
>><br>
>> if (Tok->WhitespaceRange.getBegin() == Tok->WhitespaceRange.getEnd()) {<br>
>> - if (Tok->is(tok::coloncolon) &&<br>
>> - Tok->Previous->Type == TT_TemplateOpener)<br>
>> + if (Tok->is(tok::coloncolon) && Tok->Previous->is(TT_TemplateOpener))<br>
>> HasCpp03IncompatibleFormat = true;<br>
>> - if (Tok->Type == TT_TemplateCloser &&<br>
>> - Tok->Previous->Type == TT_TemplateCloser)<br>
>> + if (Tok->is(TT_TemplateCloser) &&<br>
>> + Tok->Previous->is(TT_TemplateCloser))<br>
>> HasCpp03IncompatibleFormat = true;<br>
>> }<br>
>><br>
>><br>
>> Modified: cfe/trunk/lib/Format/FormatToken.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=222638&r1=222637&r2=222638&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=222638&r1=222637&r2=222638&view=diff</a><br>
>> ==============================================================================<br>
>> --- cfe/trunk/lib/Format/FormatToken.h (original)<br>
>> +++ cfe/trunk/lib/Format/FormatToken.h Sun Nov 23 13:03:25 2014<br>
>> @@ -271,38 +271,22 @@ struct FormatToken {<br>
>> bool IsForEachMacro;<br>
>><br>
>> bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }<br>
>> -<br>
>> bool is(TokenType TT) const { return Type == TT; }<br>
>> -<br>
>> bool is(const IdentifierInfo *II) const {<br>
>> return II && II == Tok.getIdentifierInfo();<br>
>> }<br>
>><br>
>> - template <typename T><br>
>> - bool isOneOf(T K1, T K2) const {<br>
>> + bool isOneOf() const { return false; }<br>
>> + template <typename T, typename... L> bool isOneOf(T Type, L... args) const {<br>
>> + return is(Type) || isOneOf(args...);<br>
>> + }<br>
><br>
> Variadic templates are unsupported in Visual Studio 2012.<br>
> <a href="http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/11709" target="_blank">http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/11709</a><br>
><br>
>> + // This overload increases performance by ~3%.<br>
>> + // FIXME: Re-evaluate this.<br>
>> + template <typename T> bool isOneOf(T K1, T K2) const {<br>
>> return is(K1) || is(K2);<br>
>> }<br>
>><br>
>> - template <typename T><br>
>> - bool isOneOf(T K1, T K2, T K3) const {<br>
>> - return is(K1) || is(K2) || is(K3);<br>
>> - }<br>
>> -<br>
>> - template <typename T><br>
>> - bool isOneOf(T K1, T K2, T K3, T K4, T K5 = tok::NUM_TOKENS,<br>
>> - T K6 = tok::NUM_TOKENS, T K7 = tok::NUM_TOKENS,<br>
>> - T K8 = tok::NUM_TOKENS, T K9 = tok::NUM_TOKENS,<br>
>> - T K10 = tok::NUM_TOKENS, T K11 = tok::NUM_TOKENS,<br>
>> - T K12 = tok::NUM_TOKENS) const {<br>
>> - return is(K1) || is(K2) || is(K3) || is(K4) || is(K5) || is(K6) || is(K7) ||<br>
>> - is(K8) || is(K9) || is(K10) || is(K11) || is(K12);<br>
>> - }<br>
>> -<br>
>> - template <typename T><br>
>> - bool isNot(T Kind) const {<br>
>> - return Tok.isNot(Kind);<br>
>> - }<br>
>> - bool isNot(IdentifierInfo *II) const { return II != Tok.getIdentifierInfo(); }<br>
>> + template <typename T> bool isNot(T Kind) const { return !is(Kind); }<br>
>><br>
>> bool isStringLiteral() const { return tok::isStringLiteral(Tok.getKind()); }<br>
>><br>
>> @@ -327,20 +311,19 @@ struct FormatToken {<br>
>><br>
>> /// \brief Returns whether \p Tok is ([{ or a template opening <.<br>
>> bool opensScope() const {<br>
>> - return isOneOf(tok::l_paren, tok::l_brace, tok::l_square) ||<br>
>> - Type == TT_TemplateOpener;<br>
>> + return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,<br>
>> + TT_TemplateOpener);<br>
>> }<br>
>> /// \brief Returns whether \p Tok is )]} or a template closing >.<br>
>> bool closesScope() const {<br>
>> - return isOneOf(tok::r_paren, tok::r_brace, tok::r_square) ||<br>
>> - Type == TT_TemplateCloser;<br>
>> + return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,<br>
>> + TT_TemplateCloser);<br>
>> }<br>
>><br>
>> /// \brief Returns \c true if this is a "." or "->" accessing a member.<br>
>> bool isMemberAccess() const {<br>
>> return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&<br>
>> - Type != TT_DesignatedInitializerPeriod &&<br>
>> - Type != TT_TrailingReturnArrow;<br>
>> + !isOneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow);<br>
>> }<br>
>><br>
>> bool isUnaryOperator() const {<br>
>> @@ -366,7 +349,7 @@ struct FormatToken {<br>
>><br>
>> bool isTrailingComment() const {<br>
>> return is(tok::comment) &&<br>
>> - (Type == TT_LineComment || !Next || Next->NewlinesBefore > 0);<br>
>> + (is(TT_LineComment) || !Next || Next->NewlinesBefore > 0);<br>
>> }<br>
>><br>
>> /// \brief Returns \c true if this is a keyword that can be used<br>
>> @@ -412,10 +395,9 @@ struct FormatToken {<br>
>> /// \brief Returns \c true if this tokens starts a block-type list, i.e. a<br>
>> /// list that should be indented with a block indent.<br>
>> bool opensBlockTypeList(const FormatStyle &Style) const {<br>
>> - return Type == TT_ArrayInitializerLSquare ||<br>
>> - (is(tok::l_brace) &&<br>
>> - (BlockKind == BK_Block || Type == TT_DictLiteral ||<br>
>> - !Style.Cpp11BracedListStyle));<br>
>> + return is(TT_ArrayInitializerLSquare) ||<br>
>> + (is(tok::l_brace) && (BlockKind == BK_Block || is(TT_DictLiteral) ||<br>
>> + !Style.Cpp11BracedListStyle));<br>
>> }<br>
>><br>
>> /// \brief Same as opensBlockTypeList, but for the closing token.<br>
>><br>
>> Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222638&r1=222637&r2=222638&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222638&r1=222637&r2=222638&view=diff</a><br>
>> ==============================================================================<br>
>> --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)<br>
>> +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Nov 23 13:03:25 2014<br>
>> @@ -78,7 +78,7 @@ private:<br>
>> // parameters.<br>
>> // FIXME: This is getting out of hand, write a decent parser.<br>
>> if (CurrentToken->Previous->isOneOf(tok::pipepipe, tok::ampamp) &&<br>
>> - CurrentToken->Previous->Type == TT_BinaryOperator &&<br>
>> + CurrentToken->Previous->is(TT_BinaryOperator) &&<br>
>> Contexts[Contexts.size() - 2].IsExpression &&<br>
>> Line.First->isNot(tok::kw_template))<br>
>> return false;<br>
>> @@ -114,17 +114,17 @@ private:<br>
>> if (Left->Previous &&<br>
>> (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_if,<br>
>> tok::kw_while, tok::l_paren, tok::comma) ||<br>
>> - Left->Previous->Type == TT_BinaryOperator)) {<br>
>> + Left->Previous->is(TT_BinaryOperator))) {<br>
>> // static_assert, if and while usually contain expressions.<br>
>> Contexts.back().IsExpression = true;<br>
>> } else if (Line.InPPDirective &&<br>
>> (!Left->Previous ||<br>
>> - (Left->Previous->isNot(tok::identifier) &&<br>
>> - Left->Previous->Type != TT_OverloadedOperator))) {<br>
>> + !Left->Previous->isOneOf(tok::identifier,<br>
>> + TT_OverloadedOperator))) {<br>
>> Contexts.back().IsExpression = true;<br>
>> } else if (Left->Previous && Left->Previous->is(tok::r_square) &&<br>
>> Left->Previous->MatchingParen &&<br>
>> - Left->Previous->MatchingParen->Type == TT_LambdaLSquare) {<br>
>> + Left->Previous->MatchingParen->is(TT_LambdaLSquare)) {<br>
>> // This is a parameter list of a lambda expression.<br>
>> Contexts.back().IsExpression = false;<br>
>> } else if (Contexts[Contexts.size() - 2].CaretFound) {<br>
>> @@ -137,7 +137,7 @@ private:<br>
>> Contexts.back().IsForEachMacro = true;<br>
>> Contexts.back().IsExpression = false;<br>
>> } else if (Left->Previous && Left->Previous->MatchingParen &&<br>
>> - Left->Previous->MatchingParen->Type == TT_ObjCBlockLParen) {<br>
>> + Left->Previous->MatchingParen->is(TT_ObjCBlockLParen)) {<br>
>> Contexts.back().IsExpression = false;<br>
>> }<br>
>><br>
>> @@ -168,11 +168,11 @@ private:<br>
>> }<br>
>> }<br>
>><br>
>> - if (CurrentToken->Previous->Type == TT_PointerOrReference &&<br>
>> + if (CurrentToken->Previous->is(TT_PointerOrReference) &&<br>
>> CurrentToken->Previous->Previous->isOneOf(tok::l_paren,<br>
>> tok::coloncolon))<br>
>> MightBeFunctionType = true;<br>
>> - if (CurrentToken->Previous->Type == TT_BinaryOperator)<br>
>> + if (CurrentToken->Previous->is(TT_BinaryOperator))<br>
>> Contexts.back().IsExpression = true;<br>
>> if (CurrentToken->is(tok::r_paren)) {<br>
>> if (MightBeFunctionType && CurrentToken->Next &&<br>
>> @@ -191,11 +191,11 @@ private:<br>
>> }<br>
>> }<br>
>><br>
>> - if (Left->Type == TT_AttributeParen)<br>
>> + if (Left->is(TT_AttributeParen))<br>
>> CurrentToken->Type = TT_AttributeParen;<br>
>> - if (Left->Previous && Left->Previous->Type == TT_JavaAnnotation)<br>
>> + if (Left->Previous && Left->Previous->is(TT_JavaAnnotation))<br>
>> CurrentToken->Type = TT_JavaAnnotation;<br>
>> - if (Left->Previous && Left->Previous->Type == TT_LeadingJavaAnnotation)<br>
>> + if (Left->Previous && Left->Previous->is(TT_LeadingJavaAnnotation))<br>
>> CurrentToken->Type = TT_LeadingJavaAnnotation;<br>
>><br>
>> if (!HasMultipleLines)<br>
>> @@ -239,12 +239,13 @@ private:<br>
>> FormatToken *Left = CurrentToken->Previous;<br>
>> FormatToken *Parent = Left->getPreviousNonComment();<br>
>> bool StartsObjCMethodExpr =<br>
>> - Contexts.back().CanBeExpression && Left->Type != TT_LambdaLSquare &&<br>
>> + Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&<br>
>> CurrentToken->isNot(tok::l_brace) &&<br>
>> - (!Parent || Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,<br>
>> - tok::kw_return, tok::kw_throw) ||<br>
>> - Parent->isUnaryOperator() || Parent->Type == TT_ObjCForIn ||<br>
>> - Parent->Type == TT_CastRParen ||<br>
>> + (!Parent ||<br>
>> + Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,<br>
>> + tok::kw_return, tok::kw_throw) ||<br>
>> + Parent->isUnaryOperator() ||<br>
>> + Parent->isOneOf(TT_ObjCForIn, TT_CastRParen) ||<br>
>> getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown);<br>
>> ScopedContextCreator ContextCreator(*this, tok::l_square, 10);<br>
>> Contexts.back().IsExpression = true;<br>
>> @@ -255,14 +256,14 @@ private:<br>
>> Left->Type = TT_ObjCMethodExpr;<br>
>> } else if (Parent && Parent->is(tok::at)) {<br>
>> Left->Type = TT_ArrayInitializerLSquare;<br>
>> - } else if (Left->Type == TT_Unknown) {<br>
>> + } else if (Left->is(TT_Unknown)) {<br>
>> Left->Type = TT_ArraySubscriptLSquare;<br>
>> }<br>
>><br>
>> while (CurrentToken) {<br>
>> if (CurrentToken->is(tok::r_square)) {<br>
>> if (CurrentToken->Next && CurrentToken->Next->is(tok::l_paren) &&<br>
>> - Left->Type == TT_ObjCMethodExpr) {<br>
>> + Left->is(TT_ObjCMethodExpr)) {<br>
>> // An ObjC method call is rarely followed by an open parenthesis.<br>
>> // FIXME: Do we incorrectly label ":" with this?<br>
>> StartsObjCMethodExpr = false;<br>
>> @@ -273,7 +274,7 @@ private:<br>
>> // determineStarAmpUsage() thinks that '*' '[' is allocating an<br>
>> // array of pointers, but if '[' starts a selector then '*' is a<br>
>> // binary operator.<br>
>> - if (Parent && Parent->Type == TT_PointerOrReference)<br>
>> + if (Parent && Parent->is(TT_PointerOrReference))<br>
>> Parent->Type = TT_BinaryOperator;<br>
>> }<br>
>> Left->MatchingParen = CurrentToken;<br>
>> @@ -290,7 +291,7 @@ private:<br>
>> if (CurrentToken->isOneOf(tok::r_paren, tok::r_brace))<br>
>> return false;<br>
>> if (CurrentToken->is(tok::colon)) {<br>
>> - if (Left->Type == TT_ArraySubscriptLSquare) {<br>
>> + if (Left->is(TT_ArraySubscriptLSquare)) {<br>
>> Left->Type = TT_ObjCMethodExpr;<br>
>> StartsObjCMethodExpr = true;<br>
>> Contexts.back().ColonIsObjCMethodExpr = true;<br>
>> @@ -301,8 +302,8 @@ private:<br>
>> }<br>
>> if (CurrentToken->is(tok::comma) &&<br>
>> Style.Language != FormatStyle::LK_Proto &&<br>
>> - (Left->Type == TT_ArraySubscriptLSquare ||<br>
>> - (Left->Type == TT_ObjCMethodExpr && !ColonFound)))<br>
>> + (Left->is(TT_ArraySubscriptLSquare) ||<br>
>> + (Left->is(TT_ObjCMethodExpr) && !ColonFound)))<br>
>> Left->Type = TT_ArrayInitializerLSquare;<br>
>> FormatToken* Tok = CurrentToken;<br>
>> if (!consumeToken())<br>
>> @@ -352,8 +353,8 @@ private:<br>
>> }<br>
>><br>
>> void updateParameterCount(FormatToken *Left, FormatToken *Current) {<br>
>> - if (Current->Type == TT_LambdaLSquare ||<br>
>> - (Current->is(tok::caret) && Current->Type == TT_UnaryOperator) ||<br>
>> + if (Current->is(TT_LambdaLSquare) ||<br>
>> + (Current->is(tok::caret) && Current->is(TT_UnaryOperator)) ||<br>
>> (Style.Language == FormatStyle::LK_JavaScript &&<br>
>> Current->is(Keywords.kw_function))) {<br>
>> ++Left->BlockParameterCount;<br>
>> @@ -413,7 +414,7 @@ private:<br>
>> } else if (Contexts.back().ColonIsDictLiteral) {<br>
>> Tok->Type = TT_DictLiteral;<br>
>> } else if (Contexts.back().ColonIsObjCMethodExpr ||<br>
>> - Line.First->Type == TT_ObjCMethodSpecifier) {<br>
>> + Line.First->is(TT_ObjCMethodSpecifier)) {<br>
>> Tok->Type = TT_ObjCMethodExpr;<br>
>> Tok->Previous->Type = TT_SelectorName;<br>
>> if (Tok->Previous->ColumnWidth ><br>
>> @@ -456,8 +457,7 @@ private:<br>
>> if (!parseParens())<br>
>> return false;<br>
>> if (Line.MustBeDeclaration && Contexts.size() == 1 &&<br>
>> - !Contexts.back().IsExpression &&<br>
>> - Line.First->Type != TT_ObjCProperty &&<br>
>> + !Contexts.back().IsExpression && Line.First->isNot(TT_ObjCProperty) &&<br>
>> (!Tok->Previous || Tok->Previous->isNot(tok::kw_decltype)))<br>
>> Line.MightBeFunctionDecl = true;<br>
>> break;<br>
>> @@ -495,12 +495,12 @@ private:<br>
>> if (CurrentToken->isOneOf(tok::star, tok::amp))<br>
>> CurrentToken->Type = TT_PointerOrReference;<br>
>> consumeToken();<br>
>> - if (CurrentToken && CurrentToken->Previous->Type == TT_BinaryOperator)<br>
>> + if (CurrentToken && CurrentToken->Previous->is(TT_BinaryOperator))<br>
>> CurrentToken->Previous->Type = TT_OverloadedOperator;<br>
>> }<br>
>> if (CurrentToken) {<br>
>> CurrentToken->Type = TT_OverloadedOperatorLParen;<br>
>> - if (CurrentToken->Previous->Type == TT_BinaryOperator)<br>
>> + if (CurrentToken->Previous->is(TT_BinaryOperator))<br>
>> CurrentToken->Previous->Type = TT_OverloadedOperator;<br>
>> }<br>
>> break;<br>
>> @@ -641,7 +641,7 @@ public:<br>
>> if (ImportStatement)<br>
>> return LT_ImportStatement;<br>
>><br>
>> - if (Line.First->Type == TT_ObjCMethodSpecifier) {<br>
>> + if (Line.First->is(TT_ObjCMethodSpecifier)) {<br>
>> if (Contexts.back().FirstObjCSelectorName)<br>
>> Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =<br>
>> Contexts.back().LongestObjCSelectorName;<br>
>> @@ -668,11 +668,9 @@ private:<br>
>><br>
>> // Reset token type in case we have already looked at it and then<br>
>> // recovered from an error (e.g. failure to find the matching >).<br>
>> - if (CurrentToken->Type != TT_LambdaLSquare &&<br>
>> - CurrentToken->Type != TT_FunctionLBrace &&<br>
>> - CurrentToken->Type != TT_ImplicitStringLiteral &&<br>
>> - CurrentToken->Type != TT_RegexLiteral &&<br>
>> - CurrentToken->Type != TT_TrailingReturnArrow)<br>
>> + if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_FunctionLBrace,<br>
>> + TT_ImplicitStringLiteral, TT_RegexLiteral,<br>
>> + TT_TrailingReturnArrow))<br>
>> CurrentToken->Type = TT_Unknown;<br>
>> CurrentToken->Role.reset();<br>
>> CurrentToken->FakeLParens.clear();<br>
>> @@ -683,6 +681,7 @@ private:<br>
>> if (CurrentToken) {<br>
>> CurrentToken->NestingLevel = Contexts.size() - 1;<br>
>> CurrentToken->BindingStrength = Contexts.back().BindingStrength;<br>
>> + modifyContext(*CurrentToken);<br>
>> determineTokenType(*CurrentToken);<br>
>> CurrentToken = CurrentToken->Next;<br>
>> }<br>
>> @@ -735,7 +734,7 @@ private:<br>
>> ~ScopedContextCreator() { P.Contexts.pop_back(); }<br>
>> };<br>
>><br>
>> - void determineTokenType(FormatToken &Current) {<br>
>> + void modifyContext(const FormatToken &Current) {<br>
>> if (Current.getPrecedence() == prec::Assignment &&<br>
>> !Line.First->isOneOf(tok::kw_template, tok::kw_using) &&<br>
>> (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {<br>
>> @@ -748,8 +747,7 @@ private:<br>
>> if (!Previous)<br>
>> break;<br>
>> }<br>
>> - if ((Previous->Type == TT_BinaryOperator ||<br>
>> - Previous->Type == TT_UnaryOperator) &&<br>
>> + if ((Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator)) &&<br>
>> Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&<br>
>> Previous->Previous->isNot(tok::equal)) {<br>
>> Previous->Type = TT_PointerOrReference;<br>
>> @@ -766,7 +764,7 @@ private:<br>
>> bool ParametersOfFunctionType =<br>
>> Current.Previous && Current.Previous->is(tok::r_paren) &&<br>
>> Current.Previous->MatchingParen &&<br>
>> - Current.Previous->MatchingParen->Type == TT_FunctionTypeLParen;<br>
>> + Current.Previous->MatchingParen->is(TT_FunctionTypeLParen);<br>
>> bool IsForOrCatch = Current.Previous &&<br>
>> Current.Previous->isOneOf(tok::kw_for, tok::kw_catch);<br>
>> Contexts.back().IsExpression = !ParametersOfFunctionType && !IsForOrCatch;<br>
>> @@ -778,7 +776,7 @@ private:<br>
>> if (Line.MustBeDeclaration)<br>
>> Contexts.back().IsExpression = Contexts.front().InCtorInitializer;<br>
>> } else if (Current.Previous &&<br>
>> - Current.Previous->Type == TT_CtorInitializerColon) {<br>
>> + Current.Previous->is(TT_CtorInitializerColon)) {<br>
>> Contexts.back().IsExpression = true;<br>
>> Contexts.back().InCtorInitializer = true;<br>
>> } else if (Current.is(tok::kw_new)) {<br>
>> @@ -787,85 +785,87 @@ private:<br>
>> // This should be the condition or increment in a for-loop.<br>
>> Contexts.back().IsExpression = true;<br>
>> }<br>
>> + }<br>
>> +<br>
>> + void determineTokenType(FormatToken &Current) {<br>
>> + if (!Current.is(TT_Unknown))<br>
>> + // The token type is already known.<br>
>> + return;<br>
>><br>
>> - if (Current.Type == TT_Unknown) {<br>
>> + // Line.MightBeFunctionDecl can only be true after the parentheses of a<br>
>> + // function declaration have been found. In this case, 'Current' is a<br>
>> + // trailing token of this declaration and thus cannot be a name.<br>
>> + if (isStartOfName(Current) &&<br>
>> + (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {<br>
>> + Contexts.back().FirstStartOfName = &Current;<br>
>> + Current.Type = TT_StartOfName;<br>
>> + } else if (Current.is(tok::kw_auto)) {<br>
>> + AutoFound = true;<br>
>> + } else if (Current.is(tok::arrow) &&<br>
>> + Style.Language == FormatStyle::LK_Java) {<br>
>> + Current.Type = TT_LambdaArrow;<br>
>> + } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration &&<br>
>> + Current.NestingLevel == 0) {<br>
>> + Current.Type = TT_TrailingReturnArrow;<br>
>> + } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {<br>
>> + Current.Type =<br>
>> + determineStarAmpUsage(Current, Contexts.back().CanBeExpression &&<br>
>> + Contexts.back().IsExpression,<br>
>> + Contexts.back().InTemplateArgument);<br>
>> + } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret)) {<br>
>> + Current.Type = determinePlusMinusCaretUsage(Current);<br>
>> + if (Current.is(TT_UnaryOperator) && Current.is(tok::caret))<br>
>> + Contexts.back().CaretFound = true;<br>
>> + } else if (Current.isOneOf(tok::minusminus, tok::plusplus)) {<br>
>> + Current.Type = determineIncrementUsage(Current);<br>
>> + } else if (Current.isOneOf(tok::exclaim, tok::tilde)) {<br>
>> + Current.Type = TT_UnaryOperator;<br>
>> + } else if (Current.is(tok::question)) {<br>
>> + Current.Type = TT_ConditionalExpr;<br>
>> + } else if (Current.isBinaryOperator() &&<br>
>> + (!Current.Previous || Current.Previous->isNot(tok::l_square))) {<br>
>> + Current.Type = TT_BinaryOperator;<br>
>> + } else if (Current.is(tok::comment)) {<br>
>> + if (Current.TokenText.startswith("//"))<br>
>> + Current.Type = TT_LineComment;<br>
>> + else<br>
>> + Current.Type = TT_BlockComment;<br>
>> + } else if (Current.is(tok::r_paren)) {<br>
>> + if (rParenEndsCast(Current))<br>
>> + Current.Type = TT_CastRParen;<br>
>> + } else if (Current.is(tok::at) && Current.Next) {<br>
>> + switch (Current.Next->Tok.getObjCKeywordID()) {<br>
>> + case tok::objc_interface:<br>
>> + case tok::objc_implementation:<br>
>> + case tok::objc_protocol:<br>
>> + Current.Type = TT_ObjCDecl;<br>
>> + break;<br>
>> + case tok::objc_property:<br>
>> + Current.Type = TT_ObjCProperty;<br>
>> + break;<br>
>> + default:<br>
>> + break;<br>
>> + }<br>
>> + } else if (Current.is(tok::period)) {<br>
>> + FormatToken *PreviousNoComment = Current.getPreviousNonComment();<br>
>> + if (PreviousNoComment &&<br>
>> + PreviousNoComment->isOneOf(tok::comma, tok::l_brace))<br>
>> + Current.Type = TT_DesignatedInitializerPeriod;<br>
>> + } else if (Current.isOneOf(tok::identifier, tok::kw_const) &&<br>
>> + Current.Previous &&<br>
>> + !Current.Previous->isOneOf(tok::equal, tok::at) &&<br>
>> + Line.MightBeFunctionDecl && Contexts.size() == 1) {<br>
>> // Line.MightBeFunctionDecl can only be true after the parentheses of a<br>
>> - // function declaration have been found. In this case, 'Current' is a<br>
>> - // trailing token of this declaration and thus cannot be a name.<br>
>> - if (isStartOfName(Current) &&<br>
>> - (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {<br>
>> - Contexts.back().FirstStartOfName = &Current;<br>
>> - Current.Type = TT_StartOfName;<br>
>> - } else if (Current.is(tok::kw_auto)) {<br>
>> - AutoFound = true;<br>
>> - } else if (Current.is(tok::arrow) &&<br>
>> - Style.Language == FormatStyle::LK_Java) {<br>
>> - Current.Type = TT_LambdaArrow;<br>
>> - } else if (Current.is(tok::arrow) && AutoFound &&<br>
>> - Line.MustBeDeclaration && Current.NestingLevel == 0) {<br>
>> - Current.Type = TT_TrailingReturnArrow;<br>
>> - } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {<br>
>> - Current.Type =<br>
>> - determineStarAmpUsage(Current, Contexts.back().CanBeExpression &&<br>
>> - Contexts.back().IsExpression,<br>
>> - Contexts.back().InTemplateArgument);<br>
>> - } else if (Current.isOneOf(tok::minus, tok::plus, tok::caret)) {<br>
>> - Current.Type = determinePlusMinusCaretUsage(Current);<br>
>> - if (Current.Type == TT_UnaryOperator && Current.is(tok::caret))<br>
>> - Contexts.back().CaretFound = true;<br>
>> - } else if (Current.isOneOf(tok::minusminus, tok::plusplus)) {<br>
>> - Current.Type = determineIncrementUsage(Current);<br>
>> - } else if (Current.isOneOf(tok::exclaim, tok::tilde)) {<br>
>> - Current.Type = TT_UnaryOperator;<br>
>> - } else if (Current.is(tok::question)) {<br>
>> - Current.Type = TT_ConditionalExpr;<br>
>> - } else if (Current.isBinaryOperator() &&<br>
>> - (!Current.Previous ||<br>
>> - Current.Previous->isNot(tok::l_square))) {<br>
>> - Current.Type = TT_BinaryOperator;<br>
>> - } else if (Current.is(tok::comment)) {<br>
>> - if (Current.TokenText.startswith("//"))<br>
>> - Current.Type = TT_LineComment;<br>
>> - else<br>
>> - Current.Type = TT_BlockComment;<br>
>> - } else if (Current.is(tok::r_paren)) {<br>
>> - if (rParenEndsCast(Current))<br>
>> - Current.Type = TT_CastRParen;<br>
>> - } else if (Current.is(tok::at) && Current.Next) {<br>
>> - switch (Current.Next->Tok.getObjCKeywordID()) {<br>
>> - case tok::objc_interface:<br>
>> - case tok::objc_implementation:<br>
>> - case tok::objc_protocol:<br>
>> - Current.Type = TT_ObjCDecl;<br>
>> - break;<br>
>> - case tok::objc_property:<br>
>> - Current.Type = TT_ObjCProperty;<br>
>> - break;<br>
>> - default:<br>
>> - break;<br>
>> - }<br>
>> - } else if (Current.is(tok::period)) {<br>
>> - FormatToken *PreviousNoComment = Current.getPreviousNonComment();<br>
>> - if (PreviousNoComment &&<br>
>> - PreviousNoComment->isOneOf(tok::comma, tok::l_brace))<br>
>> - Current.Type = TT_DesignatedInitializerPeriod;<br>
>> - } else if (Current.isOneOf(tok::identifier, tok::kw_const) &&<br>
>> - Current.Previous &&<br>
>> - !Current.Previous->isOneOf(tok::equal, tok::at) &&<br>
>> - Line.MightBeFunctionDecl && Contexts.size() == 1) {<br>
>> - // Line.MightBeFunctionDecl can only be true after the parentheses of a<br>
>> - // function declaration have been found.<br>
>> - Current.Type = TT_TrailingAnnotation;<br>
>> - } else if (Style.Language == FormatStyle::LK_Java && Current.Previous &&<br>
>> - Current.Previous->is(tok::at) &&<br>
>> - Current.isNot(Keywords.kw_interface)) {<br>
>> - const FormatToken& AtToken = *Current.Previous;<br>
>> - if (!AtToken.Previous ||<br>
>> - AtToken.Previous->Type == TT_LeadingJavaAnnotation)<br>
>> - Current.Type = TT_LeadingJavaAnnotation;<br>
>> - else<br>
>> - Current.Type = TT_JavaAnnotation;<br>
>> - }<br>
>> + // function declaration have been found.<br>
>> + Current.Type = TT_TrailingAnnotation;<br>
>> + } else if (Style.Language == FormatStyle::LK_Java && Current.Previous &&<br>
>> + Current.Previous->is(tok::at) &&<br>
>> + Current.isNot(Keywords.kw_interface)) {<br>
>> + const FormatToken &AtToken = *Current.Previous;<br>
>> + if (!AtToken.Previous || AtToken.Previous->is(TT_LeadingJavaAnnotation))<br>
>> + Current.Type = TT_LeadingJavaAnnotation;<br>
>> + else<br>
>> + Current.Type = TT_JavaAnnotation;<br>
>> }<br>
>> }<br>
>><br>
>> @@ -890,7 +890,7 @@ private:<br>
>> PreviousNotConst->Previous &&<br>
>> PreviousNotConst->Previous->is(tok::hash);<br>
>><br>
>> - if (PreviousNotConst->Type == TT_TemplateCloser)<br>
>> + if (PreviousNotConst->is(TT_TemplateCloser))<br>
>> return PreviousNotConst && PreviousNotConst->MatchingParen &&<br>
>> PreviousNotConst->MatchingParen->Previous &&<br>
>> PreviousNotConst->MatchingParen->Previous->isNot(tok::period) &&<br>
>> @@ -902,7 +902,7 @@ private:<br>
>> return true;<br>
>><br>
>> return (!IsPPKeyword && PreviousNotConst->is(tok::identifier)) ||<br>
>> - PreviousNotConst->Type == TT_PointerOrReference ||<br>
>> + PreviousNotConst->is(TT_PointerOrReference) ||<br>
>> PreviousNotConst->isSimpleTypeSpecifier();<br>
>> }<br>
>><br>
>> @@ -916,14 +916,14 @@ private:<br>
>> LeftOfParens = LeftOfParens->MatchingParen->Previous;<br>
>> if (LeftOfParens && LeftOfParens->is(tok::r_square) &&<br>
>> LeftOfParens->MatchingParen &&<br>
>> - LeftOfParens->MatchingParen->Type == TT_LambdaLSquare)<br>
>> + LeftOfParens->MatchingParen->is(TT_LambdaLSquare))<br>
>> return false;<br>
>> bool IsCast = false;<br>
>> bool ParensAreEmpty = Tok.Previous == Tok.MatchingParen;<br>
>> - bool ParensAreType = !Tok.Previous ||<br>
>> - Tok.Previous->Type == TT_PointerOrReference ||<br>
>> - Tok.Previous->Type == TT_TemplateCloser ||<br>
>> - Tok.Previous->isSimpleTypeSpecifier();<br>
>> + bool ParensAreType =<br>
>> + !Tok.Previous ||<br>
>> + Tok.Previous->isOneOf(TT_PointerOrReference, TT_TemplateCloser) ||<br>
>> + Tok.Previous->isSimpleTypeSpecifier();<br>
>> if (Style.Language == FormatStyle::LK_JavaScript && Tok.Next &&<br>
>> Tok.Next->is(Keywords.kw_in))<br>
>> return false;<br>
>> @@ -941,12 +941,11 @@ private:<br>
>> IsCast = true;<br>
>> // If there is an identifier after the (), it is likely a cast, unless<br>
>> // there is also an identifier before the ().<br>
>> - else if (LeftOfParens &&<br>
>> + else if (LeftOfParens && Tok.Next &&<br>
>> (LeftOfParens->Tok.getIdentifierInfo() == nullptr ||<br>
>> LeftOfParens->is(tok::kw_return)) &&<br>
>> - LeftOfParens->Type != TT_OverloadedOperator &&<br>
>> - LeftOfParens->isNot(tok::at) &&<br>
>> - LeftOfParens->Type != TT_TemplateCloser && Tok.Next) {<br>
>> + !LeftOfParens->isOneOf(TT_OverloadedOperator, tok::at,<br>
>> + TT_TemplateCloser)) {<br>
>> if (Tok.Next->isOneOf(tok::identifier, tok::numeric_constant)) {<br>
>> IsCast = true;<br>
>> } else {<br>
>> @@ -994,13 +993,12 @@ private:<br>
>><br>
>> if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,<br>
>> tok::comma, tok::semi, tok::kw_return, tok::colon,<br>
>> - tok::equal, tok::kw_delete, tok::kw_sizeof) ||<br>
>> - PrevToken->Type == TT_BinaryOperator ||<br>
>> - PrevToken->Type == TT_ConditionalExpr ||<br>
>> - PrevToken->Type == TT_UnaryOperator || PrevToken->Type == TT_CastRParen)<br>
>> + tok::equal, tok::kw_delete, tok::kw_sizeof,<br>
>> + TT_BinaryOperator, TT_ConditionalExpr,<br>
>> + TT_UnaryOperator, TT_CastRParen))<br>
>> return TT_UnaryOperator;<br>
>><br>
>> - if (NextToken->is(tok::l_square) && NextToken->Type != TT_LambdaLSquare)<br>
>> + if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))<br>
>> return TT_PointerOrReference;<br>
>> if (NextToken->isOneOf(tok::kw_operator, tok::comma))<br>
>> return TT_PointerOrReference;<br>
>> @@ -1043,7 +1041,7 @@ private:<br>
>><br>
>> TokenType determinePlusMinusCaretUsage(const FormatToken &Tok) {<br>
>> const FormatToken *PrevToken = Tok.getPreviousNonComment();<br>
>> - if (!PrevToken || PrevToken->Type == TT_CastRParen)<br>
>> + if (!PrevToken || PrevToken->is(TT_CastRParen))<br>
>> return TT_UnaryOperator;<br>
>><br>
>> // Use heuristics to recognize unary operators.<br>
>> @@ -1053,7 +1051,7 @@ private:<br>
>> return TT_UnaryOperator;<br>
>><br>
>> // There can't be two consecutive binary operators.<br>
>> - if (PrevToken->Type == TT_BinaryOperator)<br>
>> + if (PrevToken->is(TT_BinaryOperator))<br>
>> return TT_UnaryOperator;<br>
>><br>
>> // Fall back to marking the token as binary operator.<br>
>> @@ -1063,7 +1061,7 @@ private:<br>
>> /// \brief Determine whether ++/-- are pre- or post-increments/-decrements.<br>
>> TokenType determineIncrementUsage(const FormatToken &Tok) {<br>
>> const FormatToken *PrevToken = Tok.getPreviousNonComment();<br>
>> - if (!PrevToken || PrevToken->Type == TT_CastRParen)<br>
>> + if (!PrevToken || PrevToken->is(TT_CastRParen))<br>
>> return TT_UnaryOperator;<br>
>> if (PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::identifier))<br>
>> return TT_TrailingUnaryOperator;<br>
>> @@ -1095,10 +1093,9 @@ public:<br>
>> void parse(int Precedence = 0) {<br>
>> // Skip 'return' and ObjC selector colons as they are not part of a binary<br>
>> // expression.<br>
>> - while (Current &&<br>
>> - (Current->is(tok::kw_return) ||<br>
>> - (Current->is(tok::colon) && (Current->Type == TT_ObjCMethodExpr ||<br>
>> - Current->Type == TT_DictLiteral))))<br>
>> + while (Current && (Current->is(tok::kw_return) ||<br>
>> + (Current->is(tok::colon) &&<br>
>> + Current->isOneOf(TT_ObjCMethodExpr, TT_DictLiteral))))<br>
>> next();<br>
>><br>
>> if (!Current || Precedence > PrecedenceArrowAndPeriod)<br>
>> @@ -1127,7 +1124,7 @@ public:<br>
>><br>
>> int CurrentPrecedence = getCurrentPrecedence();<br>
>><br>
>> - if (Current && Current->Type == TT_SelectorName &&<br>
>> + if (Current && Current->is(TT_SelectorName) &&<br>
>> Precedence == CurrentPrecedence) {<br>
>> if (LatestOperator)<br>
>> addFakeParenthesis(Start, prec::Level(Precedence));<br>
>> @@ -1177,21 +1174,21 @@ private:<br>
>> int getCurrentPrecedence() {<br>
>> if (Current) {<br>
>> const FormatToken *NextNonComment = Current->getNextNonComment();<br>
>> - if (Current->Type == TT_ConditionalExpr)<br>
>> + if (Current->is(TT_ConditionalExpr))<br>
>> return prec::Conditional;<br>
>> else if (NextNonComment && NextNonComment->is(tok::colon) &&<br>
>> - NextNonComment->Type == TT_DictLiteral)<br>
>> + NextNonComment->is(TT_DictLiteral))<br>
>> return prec::Comma;<br>
>> else if (Current->is(TT_LambdaArrow))<br>
>> return prec::Comma;<br>
>> - else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||<br>
>> - Current->Type == TT_SelectorName ||<br>
>> + else if (Current->isOneOf(tok::semi, TT_InlineASMColon,<br>
>> + TT_SelectorName) ||<br>
>> (Current->is(tok::comment) && NextNonComment &&<br>
>> - NextNonComment->Type == TT_SelectorName))<br>
>> + NextNonComment->is(TT_SelectorName)))<br>
>> return 0;<br>
>> - else if (Current->Type == TT_RangeBasedForLoopColon)<br>
>> + else if (Current->is(TT_RangeBasedForLoopColon))<br>
>> return prec::Comma;<br>
>> - else if (Current->Type == TT_BinaryOperator || Current->is(tok::comma))<br>
>> + else if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))<br>
>> return Current->getPrecedence();<br>
>> else if (Current->isOneOf(tok::period, tok::arrow))<br>
>> return PrecedenceArrowAndPeriod;<br>
>> @@ -1219,7 +1216,7 @@ private:<br>
>> /// \brief Parse unary operator expressions and surround them with fake<br>
>> /// parentheses if appropriate.<br>
>> void parseUnaryOperator() {<br>
>> - if (!Current || Current->Type != TT_UnaryOperator) {<br>
>> + if (!Current || Current->isNot(TT_UnaryOperator)) {<br>
>> parse(PrecedenceArrowAndPeriod);<br>
>> return;<br>
>> }<br>
>> @@ -1242,7 +1239,7 @@ private:<br>
>> return;<br>
>> next();<br>
>> parse(prec::Assignment);<br>
>> - if (!Current || Current->Type != TT_ConditionalExpr)<br>
>> + if (!Current || Current->isNot(TT_ConditionalExpr))<br>
>> return;<br>
>> next();<br>
>> parse(prec::Assignment);<br>
>> @@ -1295,11 +1292,11 @@ void TokenAnnotator::annotate(AnnotatedL<br>
>> ExpressionParser ExprParser(Style, Keywords, Line);<br>
>> ExprParser.parse();<br>
>><br>
>> - if (Line.First->Type == TT_ObjCMethodSpecifier)<br>
>> + if (Line.First->is(TT_ObjCMethodSpecifier))<br>
>> Line.Type = LT_ObjCMethodDecl;<br>
>> - else if (Line.First->Type == TT_ObjCDecl)<br>
>> + else if (Line.First->is(TT_ObjCDecl))<br>
>> Line.Type = LT_ObjCDecl;<br>
>> - else if (Line.First->Type == TT_ObjCProperty)<br>
>> + else if (Line.First->is(TT_ObjCProperty))<br>
>> Line.Type = LT_ObjCProperty;<br>
>><br>
>> Line.First->SpacesRequiredBefore = 1;<br>
>> @@ -1309,12 +1306,11 @@ void TokenAnnotator::annotate(AnnotatedL<br>
>> // This function heuristically determines whether 'Current' starts the name of a<br>
>> // function declaration.<br>
>> static bool isFunctionDeclarationName(const FormatToken &Current) {<br>
>> - if (Current.Type != TT_StartOfName ||<br>
>> - Current.NestingLevel != 0)<br>
>> + if (!Current.is(TT_StartOfName) || Current.NestingLevel != 0)<br>
>> return false;<br>
>> const FormatToken *Next = Current.Next;<br>
>> for (; Next; Next = Next->Next) {<br>
>> - if (Next->Type == TT_TemplateOpener) {<br>
>> + if (Next->is(TT_TemplateOpener)) {<br>
>> Next = Next->MatchingParen;<br>
>> } else if (Next->is(tok::coloncolon)) {<br>
>> Next = Next->Next;<br>
>> @@ -1334,7 +1330,7 @@ static bool isFunctionDeclarationName(co<br>
>> for (const FormatToken *Tok = Next->Next; Tok != Next->MatchingParen;<br>
>> Tok = Tok->Next) {<br>
>> if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() ||<br>
>> - Tok->Type == TT_PointerOrReference || Tok->Type == TT_StartOfName)<br>
>> + Tok->isOneOf(TT_PointerOrReference, TT_StartOfName))<br>
>> return true;<br>
>> if (Tok->isOneOf(tok::l_brace, tok::string_literal) || Tok->Tok.isLiteral())<br>
>> return false;<br>
>> @@ -1358,7 +1354,7 @@ void TokenAnnotator::calculateFormatting<br>
>> while (Current) {<br>
>> if (isFunctionDeclarationName(*Current))<br>
>> Current->Type = TT_FunctionDeclarationName;<br>
>> - if (Current->Type == TT_LineComment) {<br>
>> + if (Current->is(TT_LineComment)) {<br>
>> if (Current->Previous->BlockKind == BK_BracedInit &&<br>
>> Current->Previous->opensScope())<br>
>> Current->SpacesRequiredBefore = Style.Cpp11BracedListStyle ? 0 : 1;<br>
>> @@ -1378,7 +1374,7 @@ void TokenAnnotator::calculateFormatting<br>
>> if (Parameter->isOneOf(tok::comment, tok::r_brace))<br>
>> break;<br>
>> if (Parameter->Previous && Parameter->Previous->is(tok::comma)) {<br>
>> - if (Parameter->Previous->Type != TT_CtorInitializerComma &&<br>
>> + if (!Parameter->Previous->is(TT_CtorInitializerComma) &&<br>
>> Parameter->HasUnescapedNewline)<br>
>> Parameter->MustBreakBefore = true;<br>
>> break;<br>
>> @@ -1394,7 +1390,7 @@ void TokenAnnotator::calculateFormatting<br>
>> Current->MustBreakBefore || mustBreakBefore(Line, *Current);<br>
>><br>
>> if (Style.AlwaysBreakAfterDefinitionReturnType &&<br>
>> - InFunctionDecl && Current->Type == TT_FunctionDeclarationName &&<br>
>> + InFunctionDecl && Current->is(TT_FunctionDeclarationName) &&<br>
>> !Line.Last->isOneOf(tok::semi, tok::comment)) // Only for definitions.<br>
>> // FIXME: Line.Last points to other characters than tok::semi<br>
>> // and tok::lbrace.<br>
>> @@ -1418,7 +1414,7 @@ void TokenAnnotator::calculateFormatting<br>
>> Current->TotalLength = Prev->TotalLength + Current->ColumnWidth +<br>
>> ChildSize + Current->SpacesRequiredBefore;<br>
>><br>
>> - if (Current->Type == TT_CtorInitializerColon)<br>
>> + if (Current->is(TT_CtorInitializerColon))<br>
>> InFunctionDecl = false;<br>
>><br>
>> // FIXME: Only calculate this if CanBreakBefore is true once static<br>
>> @@ -1465,7 +1461,7 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>> return 0;<br>
>><br>
>> if (Style.Language == FormatStyle::LK_Java) {<br>
>> - if (Left.Type == TT_LeadingJavaAnnotation)<br>
>> + if (Left.is(TT_LeadingJavaAnnotation))<br>
>> return 1;<br>
>> if (Right.is(Keywords.kw_extends))<br>
>> return 1;<br>
>> @@ -1476,20 +1472,20 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>> }<br>
>><br>
>> if (Left.is(tok::comma) || (Right.is(tok::identifier) && Right.Next &&<br>
>> - Right.Next->Type == TT_DictLiteral))<br>
>> + Right.Next->is(TT_DictLiteral)))<br>
>> return 1;<br>
>> if (Right.is(tok::l_square)) {<br>
>> if (Style.Language == FormatStyle::LK_Proto)<br>
>> return 1;<br>
>> - if (Right.Type != TT_ObjCMethodExpr && Right.Type != TT_LambdaLSquare)<br>
>> + if (!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare))<br>
>> return 500;<br>
>> }<br>
>><br>
>> - if (Right.Type == TT_StartOfName ||<br>
>> - Right.Type == TT_FunctionDeclarationName || Right.is(tok::kw_operator)) {<br>
>> + if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) ||<br>
>> + Right.is(tok::kw_operator)) {<br>
>> if (Line.First->is(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)<br>
>> return 3;<br>
>> - if (Left.Type == TT_StartOfName)<br>
>> + if (Left.is(TT_StartOfName))<br>
>> return 20;<br>
>> if (InFunctionDecl && Right.NestingLevel == 0)<br>
>> return Style.PenaltyReturnTypeOnItsOwnLine;<br>
>> @@ -1497,7 +1493,7 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>> }<br>
>> if (Left.is(tok::equal) && Right.is(tok::l_brace))<br>
>> return 150;<br>
>> - if (Left.Type == TT_CastRParen)<br>
>> + if (Left.is(TT_CastRParen))<br>
>> return 100;<br>
>> if (Left.is(tok::coloncolon) ||<br>
>> (Right.is(tok::period) && Style.Language == FormatStyle::LK_Proto))<br>
>> @@ -1505,8 +1501,7 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>> if (Left.isOneOf(tok::kw_class, tok::kw_struct))<br>
>> return 5000;<br>
>><br>
>> - if (Left.Type == TT_RangeBasedForLoopColon ||<br>
>> - Left.Type == TT_InheritanceColon)<br>
>> + if (Left.isOneOf(TT_RangeBasedForLoopColon, TT_InheritanceColon))<br>
>> return 2;<br>
>><br>
>> if (Right.isMemberAccess()) {<br>
>> @@ -1516,11 +1511,11 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>> return 150;<br>
>> }<br>
>><br>
>> - if (Right.Type == TT_TrailingAnnotation &&<br>
>> + if (Right.is(TT_TrailingAnnotation) &&<br>
>> (!Right.Next || Right.Next->isNot(tok::l_paren))) {<br>
>> // Moving trailing annotations to the next line is fine for ObjC method<br>
>> // declarations.<br>
>> - if (Line.First->Type == TT_ObjCMethodSpecifier)<br>
>> + if (Line.First->is(TT_ObjCMethodSpecifier))<br>
>><br>
>> return 10;<br>
>> // Generally, breaking before a trailing annotation is bad unless it is<br>
>> @@ -1538,9 +1533,9 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>><br>
>> // In Objective-C method expressions, prefer breaking before "param:" over<br>
>> // breaking after it.<br>
>> - if (Right.Type == TT_SelectorName)<br>
>> + if (Right.is(TT_SelectorName))<br>
>> return 0;<br>
>> - if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)<br>
>> + if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr))<br>
>> return Line.MightBeFunctionDecl ? 50 : 500;<br>
>><br>
>> if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket)<br>
>> @@ -1549,7 +1544,7 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>> return 110;<br>
>> if (Right.is(tok::r_brace))<br>
>> return 1;<br>
>> - if (Left.Type == TT_TemplateOpener)<br>
>> + if (Left.is(TT_TemplateOpener))<br>
>> return 100;<br>
>> if (Left.opensScope()) {<br>
>> if (!Style.AlignAfterOpenBracket)<br>
>> @@ -1572,7 +1567,7 @@ unsigned TokenAnnotator::splitPenalty(co<br>
>> }<br>
>> return 1; // Breaking at a << is really cheap.<br>
>> }<br>
>> - if (Left.Type == TT_ConditionalExpr)<br>
>> + if (Left.is(TT_ConditionalExpr))<br>
>> return prec::Conditional;<br>
>> prec::Level Level = Left.getPrecedence();<br>
>><br>
>> @@ -1597,8 +1592,8 @@ bool TokenAnnotator::spaceRequiredBetwee<br>
>> if (Left.is(tok::l_paren) && Right.is(tok::r_paren))<br>
>> return Style.SpaceInEmptyParentheses;<br>
>> if (Left.is(tok::l_paren) || Right.is(tok::r_paren))<br>
>> - return (Right.Type == TT_CastRParen ||<br>
>> - (Left.MatchingParen && Left.MatchingParen->Type == TT_CastRParen))<br>
>> + return (Right.is(TT_CastRParen )||<br>
>> + (Left.MatchingParen && Left.MatchingParen->is(TT_CastRParen)))<br>
>> ? Style.SpacesInCStyleCastParentheses<br>
>> : Style.SpacesInParentheses;<br>
>> if (Right.isOneOf(tok::semi, tok::comma))<br>
>> @@ -1622,49 +1617,48 @@ bool TokenAnnotator::spaceRequiredBetwee<br>
>> return Left.Tok.isLiteral();<br>
>> if (Left.is(tok::l_square) && Right.is(tok::amp))<br>
>> return false;<br>
>> - if (Right.Type == TT_PointerOrReference)<br>
>> + if (Right.is(TT_PointerOrReference))<br>
>> return Left.Tok.isLiteral() ||<br>
>> - ((Left.Type != TT_PointerOrReference) && Left.isNot(tok::l_paren) &&<br>
>> + (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&<br>
>> Style.PointerAlignment != FormatStyle::PAS_Left);<br>
>> - if (Right.Type == TT_FunctionTypeLParen && Left.isNot(tok::l_paren) &&<br>
>> - (Left.Type != TT_PointerOrReference ||<br>
>> + if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&<br>
>> + (!Left.is(TT_PointerOrReference) ||<br>
>> Style.PointerAlignment != FormatStyle::PAS_Right))<br>
>> return true;<br>
>> - if (Left.Type == TT_PointerOrReference)<br>
>> - return Right.Tok.isLiteral() || Right.Type == TT_BlockComment ||<br>
>> - ((Right.Type != TT_PointerOrReference) &&<br>
>> - Right.isNot(tok::l_paren) &&<br>
>> + if (Left.is(TT_PointerOrReference))<br>
>> + return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||<br>
>> + (!Right.isOneOf(TT_PointerOrReference, tok::l_paren) &&<br>
>> Style.PointerAlignment != FormatStyle::PAS_Right && Left.Previous &&<br>
>> !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon));<br>
>> if (Right.is(tok::star) && Left.is(tok::l_paren))<br>
>> return false;<br>
>> if (Left.is(tok::l_square))<br>
>> - return (Left.Type == TT_ArrayInitializerLSquare &&<br>
>> + return (Left.is(TT_ArrayInitializerLSquare) &&<br>
>> Style.SpacesInContainerLiterals && Right.isNot(tok::r_square)) ||<br>
>> - (Left.Type == TT_ArraySubscriptLSquare &&<br>
>> - Style.SpacesInSquareBrackets && Right.isNot(tok::r_square));<br>
>> + (Left.is(TT_ArraySubscriptLSquare) && Style.SpacesInSquareBrackets &&<br>
>> + Right.isNot(tok::r_square));<br>
>> if (Right.is(tok::r_square))<br>
>> return Right.MatchingParen &&<br>
>> ((Style.SpacesInContainerLiterals &&<br>
>> - Right.MatchingParen->Type == TT_ArrayInitializerLSquare) ||<br>
>> + Right.MatchingParen->is(TT_ArrayInitializerLSquare)) ||<br>
>> (Style.SpacesInSquareBrackets &&<br>
>> - Right.MatchingParen->Type == TT_ArraySubscriptLSquare));<br>
>> - if (Right.is(tok::l_square) && Right.Type != TT_ObjCMethodExpr &&<br>
>> - Right.Type != TT_LambdaLSquare && Left.isNot(tok::numeric_constant) &&<br>
>> - Left.Type != TT_DictLiteral)<br>
>> + Right.MatchingParen->is(TT_ArraySubscriptLSquare)));<br>
>> + if (Right.is(tok::l_square) &&<br>
>> + !Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare) &&<br>
>> + !Left.isOneOf(tok::numeric_constant, TT_DictLiteral))<br>
>> return false;<br>
>> if (Left.is(tok::colon))<br>
>> - return Left.Type != TT_ObjCMethodExpr;<br>
>> + return !Left.is(TT_ObjCMethodExpr);<br>
>> if (Left.is(tok::l_brace) && Right.is(tok::r_brace))<br>
>> return !Left.Children.empty(); // No spaces in "{}".<br>
>> if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||<br>
>> (Right.is(tok::r_brace) && Right.MatchingParen &&<br>
>> Right.MatchingParen->BlockKind != BK_Block))<br>
>> return !Style.Cpp11BracedListStyle;<br>
>> - if (Left.Type == TT_BlockComment)<br>
>> + if (Left.is(TT_BlockComment))<br>
>> return !Left.TokenText.endswith("=*/");<br>
>> if (Right.is(tok::l_paren)) {<br>
>> - if (Left.is(tok::r_paren) && Left.Type == TT_AttributeParen)<br>
>> + if (Left.is(tok::r_paren) && Left.is(TT_AttributeParen))<br>
>> return true;<br>
>> return Line.Type == LT_ObjCDecl ||<br>
>> Left.isOneOf(tok::kw_new, tok::kw_delete, tok::semi) ||<br>
>> @@ -1680,9 +1674,9 @@ bool TokenAnnotator::spaceRequiredBetwee<br>
>> }<br>
>> if (Left.is(tok::at) && Right.Tok.getObjCKeywordID() != tok::objc_not_keyword)<br>
>> return false;<br>
>> - if (Right.Type == TT_UnaryOperator)<br>
>> + if (Right.is(TT_UnaryOperator))<br>
>> return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&<br>
>> - (Left.isNot(tok::colon) || Left.Type != TT_ObjCMethodExpr);<br>
>> + (Left.isNot(tok::colon) || Left.isNot(TT_ObjCMethodExpr));<br>
>> if ((Left.isOneOf(tok::identifier, tok::greater, tok::r_square,<br>
>> tok::r_paren) ||<br>
>> Left.isSimpleTypeSpecifier()) &&<br>
>> @@ -1693,12 +1687,12 @@ bool TokenAnnotator::spaceRequiredBetwee<br>
>> return false;<br>
>> if (Right.is(tok::hash) && Left.is(tok::identifier) && Left.TokenText == "L")<br>
>> return false;<br>
>> - if (Left.Type == TT_TemplateCloser && Left.MatchingParen &&<br>
>> + if (Left.is(TT_TemplateCloser) && Left.MatchingParen &&<br>
>> Left.MatchingParen->Previous &&<br>
>> Left.MatchingParen->Previous->is(tok::period))<br>
>> // A.<B>DoSomething();<br>
>> return false;<br>
>> - if (Left.Type == TT_TemplateCloser && Right.is(tok::l_square))<br>
>> + if (Left.is(TT_TemplateCloser) && Right.is(tok::l_square))<br>
>> return false;<br>
>> return true;<br>
>> }<br>
>> @@ -1725,15 +1719,15 @@ bool TokenAnnotator::spaceRequiredBefore<br>
>> if ((Left.isOneOf(tok::kw_static, tok::kw_public, tok::kw_private,<br>
>> tok::kw_protected) ||<br>
>> Left.isOneOf(Keywords.kw_final, Keywords.kw_abstract)) &&<br>
>> - Right.Type == TT_TemplateOpener)<br>
>> + Right.is(TT_TemplateOpener))<br>
>> return true;<br>
>> }<br>
>> if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo())<br>
>> return true; // Never ever merge two identifiers.<br>
>> - if (Left.Type == TT_ImplicitStringLiteral)<br>
>> + if (Left.is(TT_ImplicitStringLiteral))<br>
>> return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();<br>
>> if (Line.Type == LT_ObjCMethodDecl) {<br>
>> - if (Left.Type == TT_ObjCMethodSpecifier)<br>
>> + if (Left.is(TT_ObjCMethodSpecifier))<br>
>> return true;<br>
>> if (Left.is(tok::r_paren) && Right.is(tok::identifier))<br>
>> // Don't space between ')' and <id><br>
>> @@ -1743,31 +1737,30 @@ bool TokenAnnotator::spaceRequiredBefore<br>
>> (Right.is(tok::equal) || Left.is(tok::equal)))<br>
>> return false;<br>
>><br>
>> - if (Right.Type == TT_TrailingReturnArrow ||<br>
>> - Left.Type == TT_TrailingReturnArrow)<br>
>> + if (Right.is(TT_TrailingReturnArrow) || Left.is(TT_TrailingReturnArrow))<br>
>> return true;<br>
>> if (Left.is(tok::comma))<br>
>> return true;<br>
>> if (Right.is(tok::comma))<br>
>> return false;<br>
>> - if (Right.Type == TT_CtorInitializerColon || Right.Type == TT_ObjCBlockLParen)<br>
>> + if (Right.isOneOf(TT_CtorInitializerColon, TT_ObjCBlockLParen))<br>
>> return true;<br>
>> if (Left.is(tok::kw_operator))<br>
>> return Right.is(tok::coloncolon);<br>
>> - if (Right.Type == TT_OverloadedOperatorLParen)<br>
>> + if (Right.is(TT_OverloadedOperatorLParen))<br>
>> return false;<br>
>> if (Right.is(tok::colon))<br>
>> return !Line.First->isOneOf(tok::kw_case, tok::kw_default) &&<br>
>> - Right.getNextNonComment() && Right.Type != TT_ObjCMethodExpr &&<br>
>> + Right.getNextNonComment() && Right.isNot(TT_ObjCMethodExpr) &&<br>
>> !Left.is(tok::question) &&<br>
>> - !(Right.Type == TT_InlineASMColon && Left.is(tok::coloncolon)) &&<br>
>> - (Right.Type != TT_DictLiteral || Style.SpacesInContainerLiterals);<br>
>> - if (Left.Type == TT_UnaryOperator)<br>
>> - return Right.Type == TT_BinaryOperator;<br>
>> - if (Left.Type == TT_CastRParen)<br>
>> - return Style.SpaceAfterCStyleCast || Right.Type == TT_BinaryOperator;<br>
>> + !(Right.is(TT_InlineASMColon) && Left.is(tok::coloncolon)) &&<br>
>> + (Right.isNot(TT_DictLiteral) || Style.SpacesInContainerLiterals);<br>
>> + if (Left.is(TT_UnaryOperator))<br>
>> + return Right.is(TT_BinaryOperator);<br>
>> + if (Left.is(TT_CastRParen))<br>
>> + return Style.SpaceAfterCStyleCast || Right.is(TT_BinaryOperator);<br>
>> if (Left.is(tok::greater) && Right.is(tok::greater)) {<br>
>> - return Right.Type == TT_TemplateCloser && Left.Type == TT_TemplateCloser &&<br>
>> + return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&<br>
>> (Style.Standard != FormatStyle::LS_Cpp11 || Style.SpacesInAngles);<br>
>> }<br>
>> if (Right.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||<br>
>> @@ -1777,27 +1770,26 @@ bool TokenAnnotator::spaceRequiredBefore<br>
>> Right.getPrecedence() == prec::Assignment)<br>
>> return false;<br>
>> if (Right.is(tok::coloncolon) && Left.isNot(tok::l_brace))<br>
>> - return (Left.Type == TT_TemplateOpener &&<br>
>> + return (Left.is(TT_TemplateOpener) &&<br>
>> Style.Standard == FormatStyle::LS_Cpp03) ||<br>
>> !(Left.isOneOf(tok::identifier, tok::l_paren, tok::r_paren) ||<br>
>> - Left.Type == TT_TemplateCloser || Left.Type == TT_TemplateOpener);<br>
>> - if ((Left.Type == TT_TemplateOpener) != (Right.Type == TT_TemplateCloser))<br>
>> + Left.isOneOf(TT_TemplateCloser, TT_TemplateOpener));<br>
>> + if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))<br>
>> return Style.SpacesInAngles;<br>
>> - if ((Right.Type == TT_BinaryOperator && !Left.is(tok::l_paren)) ||<br>
>> - Left.Type == TT_BinaryOperator || Left.Type == TT_ConditionalExpr)<br>
>> + if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) ||<br>
>> + Left.isOneOf(TT_BinaryOperator, TT_ConditionalExpr))<br>
>> return true;<br>
>> - if (Left.Type == TT_TemplateCloser && Right.is(tok::l_paren))<br>
>> + if (Left.is(TT_TemplateCloser) && Right.is(tok::l_paren))<br>
>> return Style.SpaceBeforeParens == FormatStyle::SBPO_Always;<br>
>> - if (Right.Type == TT_TemplateOpener && Left.is(tok::r_paren) &&<br>
>> - Left.MatchingParen &&<br>
>> - Left.MatchingParen->Type == TT_OverloadedOperatorLParen)<br>
>> + if (Right.is(TT_TemplateOpener) && Left.is(tok::r_paren) &&<br>
>> + Left.MatchingParen && Left.MatchingParen->is(TT_OverloadedOperatorLParen))<br>
>> return false;<br>
>> if (Right.is(tok::less) && Left.isNot(tok::l_paren) &&<br>
>> Line.First->is(tok::hash))<br>
>> return true;<br>
>> - if (Right.Type == TT_TrailingUnaryOperator)<br>
>> + if (Right.is(TT_TrailingUnaryOperator))<br>
>> return false;<br>
>> - if (Left.Type == TT_RegexLiteral)<br>
>> + if (Left.is(TT_RegexLiteral))<br>
>> return false;<br>
>> return spaceRequiredBetween(Line, Left, Right);<br>
>> }<br>
>> @@ -1805,7 +1797,7 @@ bool TokenAnnotator::spaceRequiredBefore<br>
>> // Returns 'true' if 'Tok' is a brace we'd want to break before in Allman style.<br>
>> static bool isAllmanBrace(const FormatToken &Tok) {<br>
>> return Tok.is(tok::l_brace) && Tok.BlockKind == BK_Block &&<br>
>> - Tok.Type != TT_ObjCBlockLBrace && Tok.Type != TT_DictLiteral;<br>
>> + !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);<br>
>> }<br>
>><br>
>> bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,<br>
>> @@ -1828,7 +1820,7 @@ bool TokenAnnotator::mustBreakBefore(con<br>
>><br>
>> if (Right.is(tok::comment)) {<br>
>> return Left.BlockKind != BK_BracedInit &&<br>
>> - Left.Type != TT_CtorInitializerColon &&<br>
>> + Left.isNot(TT_CtorInitializerColon) &&<br>
>> (Right.NewlinesBefore > 0 && Right.HasUnescapedNewline);<br>
>> } else if (Right.Previous->isTrailingComment() ||<br>
>> (Right.isStringLiteral() && Right.Previous->isStringLiteral())) {<br>
>> @@ -1844,8 +1836,8 @@ bool TokenAnnotator::mustBreakBefore(con<br>
>> Right.Previous->MatchingParen->NestingLevel == 0 &&<br>
>> Style.AlwaysBreakTemplateDeclarations) {<br>
>> return true;<br>
>> - } else if ((Right.Type == TT_CtorInitializerComma ||<br>
>> - Right.Type == TT_CtorInitializerColon) &&<br>
>> + } else if ((Right.isOneOf(TT_CtorInitializerComma,<br>
>> + TT_CtorInitializerColon)) &&<br>
>> Style.BreakConstructorInitializersBeforeComma &&<br>
>> !Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {<br>
>> return true;<br>
>> @@ -1870,9 +1862,9 @@ bool TokenAnnotator::mustBreakBefore(con<br>
>> return Style.BreakBeforeBraces == FormatStyle::BS_Allman ||<br>
>> Style.BreakBeforeBraces == FormatStyle::BS_GNU;<br>
>> } else if (Style.Language == FormatStyle::LK_Proto &&<br>
>> - Left.isNot(tok::l_brace) && Right.Type == TT_SelectorName) {<br>
>> + Left.isNot(tok::l_brace) && Right.is(TT_SelectorName)) {<br>
>> return true;<br>
>> - } else if (Left.Type == TT_ObjCBlockLBrace &&<br>
>> + } else if (Left.is(TT_ObjCBlockLBrace) &&<br>
>> !Style.AllowShortBlocksOnASingleLine) {<br>
>> return true;<br>
>> }<br>
>> @@ -1883,7 +1875,7 @@ bool TokenAnnotator::mustBreakBefore(con<br>
>> Left.Previous->is(tok::char_constant))<br>
>> return true;<br>
>> } else if (Style.Language == FormatStyle::LK_Java) {<br>
>> - if (Left.Type == TT_LeadingJavaAnnotation && Right.isNot(tok::l_paren) &&<br>
>> + if (Left.is(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) &&<br>
>> Line.Last->is(tok::l_brace))<br>
>> return true;<br>
>> if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next &&<br>
>> @@ -1911,10 +1903,10 @@ bool TokenAnnotator::canBreakBefore(cons<br>
>> return false;<br>
>> if (Left.Tok.getObjCKeywordID() == tok::objc_interface)<br>
>> return false;<br>
>> - if (Left.Type == TT_JavaAnnotation || Left.Type == TT_LeadingJavaAnnotation)<br>
>> + if (Left.isOneOf(TT_JavaAnnotation, TT_LeadingJavaAnnotation))<br>
>> return true;<br>
>> - if (Right.Type == TT_StartOfName ||<br>
>> - Right.Type == TT_FunctionDeclarationName || Right.is(tok::kw_operator))<br>
>> + if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) ||<br>
>> + Right.is(tok::kw_operator))<br>
>> return true;<br>
>> if (Right.isTrailingComment())<br>
>> // We rely on MustBreakBefore being set correctly here as we should not<br>
>> @@ -1925,47 +1917,46 @@ bool TokenAnnotator::canBreakBefore(cons<br>
>> return Left.BlockKind == BK_BracedInit;<br>
>> if (Left.is(tok::question) && Right.is(tok::colon))<br>
>> return false;<br>
>> - if (Right.Type == TT_ConditionalExpr || Right.is(tok::question))<br>
>> + if (Right.is(TT_ConditionalExpr) || Right.is(tok::question))<br>
>> return Style.BreakBeforeTernaryOperators;<br>
>> - if (Left.Type == TT_ConditionalExpr || Left.is(tok::question))<br>
>> + if (Left.is(TT_ConditionalExpr) || Left.is(tok::question))<br>
>> return !Style.BreakBeforeTernaryOperators;<br>
>> - if (Right.Type == TT_InheritanceColon)<br>
>> + if (Right.is(TT_InheritanceColon))<br>
>> return true;<br>
>> - if (Right.is(tok::colon) && (Right.Type != TT_CtorInitializerColon &&<br>
>> - Right.Type != TT_InlineASMColon))<br>
>> + if (Right.is(tok::colon) &&<br>
>> + !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon))<br>
>> return false;<br>
>> - if (Left.is(tok::colon) &&<br>
>> - (Left.Type == TT_DictLiteral || Left.Type == TT_ObjCMethodExpr))<br>
>> + if (Left.is(tok::colon) && (Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)))<br>
>> return true;<br>
>> - if (Right.Type == TT_SelectorName)<br>
>> + if (Right.is(TT_SelectorName))<br>
>> return true;<br>
>> if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty)<br>
>> return true;<br>
>> if (Left.ClosesTemplateDeclaration)<br>
>> return true;<br>
>> - if (Right.Type == TT_RangeBasedForLoopColon ||<br>
>> - Right.Type == TT_OverloadedOperatorLParen ||<br>
>> - Right.Type == TT_OverloadedOperator)<br>
>> + if (Right.isOneOf(TT_RangeBasedForLoopColon, TT_OverloadedOperatorLParen,<br>
>> + TT_OverloadedOperator))<br>
>> return false;<br>
>> - if (Left.Type == TT_RangeBasedForLoopColon)<br>
>> + if (Left.is(TT_RangeBasedForLoopColon))<br>
>> return true;<br>
>> - if (Right.Type == TT_RangeBasedForLoopColon)<br>
>> + if (Right.is(TT_RangeBasedForLoopColon))<br>
>> return false;<br>
>> - if (Left.Type == TT_PointerOrReference || Left.Type == TT_TemplateCloser ||<br>
>> - Left.Type == TT_UnaryOperator || Left.is(tok::kw_operator))<br>
>> + if (Left.isOneOf(TT_PointerOrReference, TT_TemplateCloser,<br>
>> + TT_UnaryOperator) ||<br>
>> + Left.is(tok::kw_operator))<br>
>> return false;<br>
>> if (Left.is(tok::equal) && Line.Type == LT_VirtualFunctionDecl)<br>
>> return false;<br>
>> - if (Left.is(tok::l_paren) && Left.Type == TT_AttributeParen)<br>
>> + if (Left.is(tok::l_paren) && Left.is(TT_AttributeParen))<br>
>> return false;<br>
>> if (Left.is(tok::l_paren) && Left.Previous &&<br>
>> - (Left.Previous->Type == TT_BinaryOperator ||<br>
>> - Left.Previous->Type == TT_CastRParen || Left.Previous->is(tok::kw_if)))<br>
>> + (Left.Previous->isOneOf(TT_BinaryOperator, TT_CastRParen) ||<br>
>> + Left.Previous->is(tok::kw_if)))<br>
>> return false;<br>
>> - if (Right.Type == TT_ImplicitStringLiteral)<br>
>> + if (Right.is(TT_ImplicitStringLiteral))<br>
>> return false;<br>
>><br>
>> - if (Right.is(tok::r_paren) || Right.Type == TT_TemplateCloser)<br>
>> + if (Right.is(tok::r_paren) || Right.is(TT_TemplateCloser))<br>
>> return false;<br>
>><br>
>> // We only break before r_brace if there was a corresponding break before<br>
>> @@ -1975,7 +1966,7 @@ bool TokenAnnotator::canBreakBefore(cons<br>
>><br>
>> // Allow breaking after a trailing annotation, e.g. after a method<br>
>> // declaration.<br>
>> - if (Left.Type == TT_TrailingAnnotation)<br>
>> + if (Left.is(TT_TrailingAnnotation))<br>
>> return !Right.isOneOf(tok::l_brace, tok::semi, tok::equal, tok::l_paren,<br>
>> tok::less, tok::coloncolon);<br>
>><br>
>> @@ -1985,25 +1976,24 @@ bool TokenAnnotator::canBreakBefore(cons<br>
>> if (Left.is(tok::identifier) && Right.is(tok::string_literal))<br>
>> return true;<br>
>><br>
>> - if (Right.is(tok::identifier) && Right.Next &&<br>
>> - Right.Next->Type == TT_DictLiteral)<br>
>> + if (Right.is(tok::identifier) && Right.Next && Right.Next->is(TT_DictLiteral))<br>
>> return true;<br>
>><br>
>> - if (Left.Type == TT_CtorInitializerComma &&<br>
>> + if (Left.is(TT_CtorInitializerComma) &&<br>
>> Style.BreakConstructorInitializersBeforeComma)<br>
>> return false;<br>
>> - if (Right.Type == TT_CtorInitializerComma &&<br>
>> + if (Right.is(TT_CtorInitializerComma) &&<br>
>> Style.BreakConstructorInitializersBeforeComma)<br>
>> return true;<br>
>> if (Left.is(tok::greater) && Right.is(tok::greater) &&<br>
>> - Left.Type != TT_TemplateCloser)<br>
>> + Left.isNot(TT_TemplateCloser))<br>
>> return false;<br>
>> - if (Right.Type == TT_BinaryOperator &&<br>
>> + if (Right.is(TT_BinaryOperator) &&<br>
>> Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None &&<br>
>> (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_All ||<br>
>> Right.getPrecedence() != prec::Assignment))<br>
>> return true;<br>
>> - if (Left.Type == TT_ArrayInitializerLSquare)<br>
>> + if (Left.is(TT_ArrayInitializerLSquare))<br>
>> return true;<br>
>> if (Right.is(tok::kw_typename) && Left.isNot(tok::kw_const))<br>
>> return true;<br>
>> @@ -2014,7 +2004,7 @@ bool TokenAnnotator::canBreakBefore(cons<br>
>> return true;<br>
>> return Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,<br>
>> tok::kw_class, tok::kw_struct) ||<br>
>> - Right.isMemberAccess() || Right.Type == TT_TrailingReturnArrow ||<br>
>> + Right.isMemberAccess() || Right.is(TT_TrailingReturnArrow) ||<br>
>> Right.isOneOf(tok::lessless, tok::colon, tok::l_square, tok::at) ||<br>
>> (Left.is(tok::r_paren) &&<br>
>> Right.isOneOf(tok::identifier, tok::kw_const)) ||<br>
>><br>
>> Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=222638&r1=222637&r2=222638&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=222638&r1=222637&r2=222638&view=diff</a><br>
>> ==============================================================================<br>
>> --- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)<br>
>> +++ cfe/trunk/lib/Format/WhitespaceManager.cpp Sun Nov 23 13:03:25 2014<br>
>> @@ -81,7 +81,7 @@ void WhitespaceManager::replaceWhitespac<br>
>> // FIXME: We still need to take this change in account to properly<br>
>> // calculate the new length of the comment and to calculate the changes<br>
>> // for which to do the alignment when aligning comments.<br>
>> - Tok.Type == TT_LineComment && Newlines > 0 ? tok::comment : tok::unknown,<br>
>> + Tok.is(TT_LineComment) && Newlines > 0 ? tok::comment : tok::unknown,<br>
>> InPPDirective && !Tok.IsFirst));<br>
>> }<br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> cfe-commits mailing list<br>
>> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>