rymiel updated this revision to Diff 534220. rymiel added a comment. Add annotator test cases involving a lambda
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D153641/new/ https://reviews.llvm.org/D153641 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -906,6 +906,26 @@ annotate("auto bar() -> Template<type> requires(is_integral_v<T>) {}"); ASSERT_EQ(Tokens.size(), 19u) << Tokens; EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause); + + Tokens = annotate("void foo() requires((A<T>) && C) {}"); + ASSERT_EQ(Tokens.size(), 18u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("void foo() requires(((A<T>) && C)) {}"); + ASSERT_EQ(Tokens.size(), 20u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("void foo() requires([](T&&){}(t)) {}"); + ASSERT_EQ(Tokens.size(), 21u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference); + + Tokens = annotate("void foo() requires([](T&& u){}(t)) {}"); + ASSERT_EQ(Tokens.size(), 22u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference); } TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2431,14 +2431,14 @@ /// \brief Parses a pair of parentheses (and everything between them). /// \param AmpAmpTokenType If different than TT_Unknown sets this type for all -/// double ampersands. This only counts for the current parens scope. +/// double ampersands. This applies for all nested scopes as well. void UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { assert(FormatTok->is(tok::l_paren) && "'(' expected."); nextToken(); do { switch (FormatTok->Tok.getKind()) { case tok::l_paren: - parseParens(); + parseParens(AmpAmpTokenType); if (Style.Language == FormatStyle::LK_Java && FormatTok->is(tok::l_brace)) parseChildBlock(); break;
Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -906,6 +906,26 @@ annotate("auto bar() -> Template<type> requires(is_integral_v<T>) {}"); ASSERT_EQ(Tokens.size(), 19u) << Tokens; EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause); + + Tokens = annotate("void foo() requires((A<T>) && C) {}"); + ASSERT_EQ(Tokens.size(), 18u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("void foo() requires(((A<T>) && C)) {}"); + ASSERT_EQ(Tokens.size(), 20u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator); + + Tokens = annotate("void foo() requires([](T&&){}(t)) {}"); + ASSERT_EQ(Tokens.size(), 21u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference); + + Tokens = annotate("void foo() requires([](T&& u){}(t)) {}"); + ASSERT_EQ(Tokens.size(), 22u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause); + EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference); } TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) { Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2431,14 +2431,14 @@ /// \brief Parses a pair of parentheses (and everything between them). /// \param AmpAmpTokenType If different than TT_Unknown sets this type for all -/// double ampersands. This only counts for the current parens scope. +/// double ampersands. This applies for all nested scopes as well. void UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { assert(FormatTok->is(tok::l_paren) && "'(' expected."); nextToken(); do { switch (FormatTok->Tok.getKind()) { case tok::l_paren: - parseParens(); + parseParens(AmpAmpTokenType); if (Style.Language == FormatStyle::LK_Java && FormatTok->is(tok::l_brace)) parseChildBlock(); break;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits