HazardyKnusperkeks created this revision. HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius. HazardyKnusperkeks added a project: clang-format. Herald added a project: All. HazardyKnusperkeks requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/54349 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D121559 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -577,6 +577,15 @@ << I; } +TEST_F(TokenAnnotatorTest, UnderstandsAsm) { + auto Tokens = annotate("__asm{\n" + "a:\n" + "};"); + ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace); +} } // namespace } // namespace format } // namespace clang Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -824,8 +824,10 @@ Previous->is(tok::string_literal)) Previous->setType(TT_SelectorName); } - if (CurrentToken->is(tok::colon) || Style.isJavaScript()) + if (CurrentToken->is(tok::colon) && OpeningBrace.is(TT_Unknown)) OpeningBrace.setType(TT_DictLiteral); + if (Style.isJavaScript()) + OpeningBrace.overwriteFixedType(TT_DictLiteral); } if (CurrentToken->is(tok::comma)) { if (Style.isJavaScript())
Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -577,6 +577,15 @@ << I; } +TEST_F(TokenAnnotatorTest, UnderstandsAsm) { + auto Tokens = annotate("__asm{\n" + "a:\n" + "};"); + ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace); +} } // namespace } // namespace format } // namespace clang Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -824,8 +824,10 @@ Previous->is(tok::string_literal)) Previous->setType(TT_SelectorName); } - if (CurrentToken->is(tok::colon) || Style.isJavaScript()) + if (CurrentToken->is(tok::colon) && OpeningBrace.is(TT_Unknown)) OpeningBrace.setType(TT_DictLiteral); + if (Style.isJavaScript()) + OpeningBrace.overwriteFixedType(TT_DictLiteral); } if (CurrentToken->is(tok::comma)) { if (Style.isJavaScript())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits