curdeius updated this revision to Diff 427566. curdeius added a comment. Simplify. Address comments.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D123676/new/ https://reviews.llvm.org/D123676 Files: clang/lib/Format/FormatTokenLexer.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23606,6 +23606,11 @@ // Don't use the helpers here, since 'mess up' will change the whitespace // and these are all whitespace sensitive by definition + + // Newlines are important here. + EXPECT_EQ("FOO(1+2 );\n", format("FOO(1+2 );\n", Style)); + EXPECT_EQ("FOO(1+2 )\n", format("FOO(1+2 )\n", Style)); + EXPECT_EQ("FOO(String-ized&Messy+But(: :Still)=Intentional);", format("FOO(String-ized&Messy+But(: :Still)=Intentional);", Style)); EXPECT_EQ( Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1787,7 +1787,8 @@ : CommentsBeforeNextToken.front()->NewlinesBefore > 0; if (FollowedByNewline && (Text.size() >= 5 || FunctionLike) && - tokenCanStartNewLine(*FormatTok) && Text == Text.upper()) { + tokenCanStartNewLine(*FormatTok) && Text == Text.upper() && + !PreviousToken->isTypeFinalized()) { PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro); addUnwrappedLine(); return; Index: clang/lib/Format/FormatTokenLexer.cpp =================================================================== --- clang/lib/Format/FormatTokenLexer.cpp +++ clang/lib/Format/FormatTokenLexer.cpp @@ -1027,7 +1027,10 @@ Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() == tok::pp_define) && it != Macros.end()) { - FormatTok->setType(it->second); + if (it->second == TT_UntouchableMacroFunc) + FormatTok->setFinalizedType(TT_UntouchableMacroFunc); + else + FormatTok->setType(it->second); if (it->second == TT_IfMacro) { // The lexer token currently has type tok::kw_unknown. However, for this // substitution to be treated correctly in the TokenAnnotator, faking
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23606,6 +23606,11 @@ // Don't use the helpers here, since 'mess up' will change the whitespace // and these are all whitespace sensitive by definition + + // Newlines are important here. + EXPECT_EQ("FOO(1+2 );\n", format("FOO(1+2 );\n", Style)); + EXPECT_EQ("FOO(1+2 )\n", format("FOO(1+2 )\n", Style)); + EXPECT_EQ("FOO(String-ized&Messy+But(: :Still)=Intentional);", format("FOO(String-ized&Messy+But(: :Still)=Intentional);", Style)); EXPECT_EQ( Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1787,7 +1787,8 @@ : CommentsBeforeNextToken.front()->NewlinesBefore > 0; if (FollowedByNewline && (Text.size() >= 5 || FunctionLike) && - tokenCanStartNewLine(*FormatTok) && Text == Text.upper()) { + tokenCanStartNewLine(*FormatTok) && Text == Text.upper() && + !PreviousToken->isTypeFinalized()) { PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro); addUnwrappedLine(); return; Index: clang/lib/Format/FormatTokenLexer.cpp =================================================================== --- clang/lib/Format/FormatTokenLexer.cpp +++ clang/lib/Format/FormatTokenLexer.cpp @@ -1027,7 +1027,10 @@ Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() == tok::pp_define) && it != Macros.end()) { - FormatTok->setType(it->second); + if (it->second == TT_UntouchableMacroFunc) + FormatTok->setFinalizedType(TT_UntouchableMacroFunc); + else + FormatTok->setType(it->second); if (it->second == TT_IfMacro) { // The lexer token currently has type tok::kw_unknown. However, for this // substitution to be treated correctly in the TokenAnnotator, faking
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits