From: Daniel Jasper Date: Mon, 4 May 2015 09:22:29 +0000 (+0000) Subject: clang-format: NFC: Delete FormatToken::IsForEachMacro. Use a TokenType instead. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de174e609c774ae0c4905471d9f784d35a026068;p=clang clang-format: NFC: Delete FormatToken::IsForEachMacro. Use a TokenType instead. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236415 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index eabdaca5f3..9aad4f7d0e 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1115,9 +1115,9 @@ private: 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; } diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index 70e2362351..b6a7dcd81b 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -41,6 +41,7 @@ enum TokenType { TT_CtorInitializerComma, TT_DesignatedInitializerPeriod, TT_DictLiteral, + TT_ForEachMacro, TT_FunctionDeclarationName, TT_FunctionLBrace, TT_FunctionTypeLParen, @@ -252,10 +253,6 @@ struct FormatToken { /// 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; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 15f9fba04c..aa415a5b92 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -134,7 +134,7 @@ private: 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; @@ -718,9 +718,9 @@ private: // 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; @@ -1754,11 +1754,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, 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); diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 2aa4414d67..46e59f9227 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -744,7 +744,7 @@ void UnwrappedLineParser::parseStructuralElement() { } break; case tok::identifier: - if (FormatTok->IsForEachMacro) { + if (FormatTok->is(TT_ForEachMacro)) { parseForOrWhileLoop(); return; } @@ -1323,8 +1323,7 @@ void UnwrappedLineParser::parseNew() { } 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))