Column = FormatTok->LastLineColumnWidth;
}
- FormatTok->IsForEachMacro =
- std::binary_search(ForEachMacros.begin(), ForEachMacros.end(),
- FormatTok->Tok.getIdentifierInfo());
+ if (std::find(ForEachMacros.begin(), ForEachMacros.end(),
+ FormatTok->Tok.getIdentifierInfo()) != ForEachMacros.end())
+ FormatTok->Type = TT_ForEachMacro;
return FormatTok;
}
TT_CtorInitializerComma,
TT_DesignatedInitializerPeriod,
TT_DictLiteral,
+ TT_ForEachMacro,
TT_FunctionDeclarationName,
TT_FunctionLBrace,
TT_FunctionTypeLParen,
/// Only set if \c Type == \c TT_StartOfName.
bool PartOfMultiVariableDeclStmt = false;
- /// \brief Is this a foreach macro?
- bool IsForEachMacro = false;
-
-
/// \brief If this is a bracket, this points to the matching one.
FormatToken *MatchingParen = nullptr;
Contexts.back().IsExpression = false;
} else if (Left->Previous && Left->Previous->is(tok::kw___attribute)) {
Left->Type = TT_AttributeParen;
- } else if (Left->Previous && Left->Previous->IsForEachMacro) {
+ } else if (Left->Previous && Left->Previous->is(TT_ForEachMacro)) {
// The first argument to a foreach macro is a declaration.
Contexts.back().IsForEachMacro = true;
Contexts.back().IsExpression = false;
// Reset token type in case we have already looked at it and then
// recovered from an error (e.g. failure to find the matching >).
- if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_FunctionLBrace,
- TT_ImplicitStringLiteral, TT_RegexLiteral,
- TT_TrailingReturnArrow))
+ if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
+ TT_FunctionLBrace, TT_ImplicitStringLiteral,
+ TT_RegexLiteral, TT_TrailingReturnArrow))
CurrentToken->Type = TT_Unknown;
CurrentToken->Role.reset();
CurrentToken->MatchingParen = nullptr;
return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
(Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
- tok::kw_switch, tok::kw_case) ||
+ tok::kw_switch, tok::kw_case, TT_ForEachMacro) ||
(Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
- (!Left.Previous || Left.Previous->isNot(tok::period))) ||
- Left.IsForEachMacro)) ||
+ (!Left.Previous || Left.Previous->isNot(tok::period))))) ||
(Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
(Left.is(tok::identifier) || Left.isFunctionLikeKeyword()) &&
Line.Type != LT_PreprocessorDirective);
}
break;
case tok::identifier:
- if (FormatTok->IsForEachMacro) {
+ if (FormatTok->is(TT_ForEachMacro)) {
parseForOrWhileLoop();
return;
}
}
void UnwrappedLineParser::parseForOrWhileLoop() {
- assert((FormatTok->Tok.is(tok::kw_for) || FormatTok->Tok.is(tok::kw_while) ||
- FormatTok->IsForEachMacro) &&
+ assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
"'for', 'while' or foreach macro expected");
nextToken();
if (FormatTok->Tok.is(tok::l_paren))