This revision was not accepted when it landed; it landed in state "Needs Review". This revision was automatically updated to reflect the committed changes. Closed by commit rL335449: [clang-format] Fix end-of-file comments text proto formatting (authored by krasimir, committed by ). Herald added a subscriber: llvm-commits.
Repository: rL LLVM https://reviews.llvm.org/D48539 Files: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/unittests/Format/FormatTestTextProto.cpp Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp =================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp @@ -303,6 +303,18 @@ else parseLevel(/*HasOpeningBrace=*/false); // Make sure to format the remaining tokens. + // + // LK_TextProto is special since its top-level is parsed as the body of a + // braced list, which does not necessarily have natural line separators such + // as a semicolon. Comments after the last entry that have been determined to + // not belong to that line, as in: + // key: value + // // endfile comment + // do not have a chance to be put on a line of their own until this point. + // Here we add this newline before end-of-file comments. + if (Style.Language == FormatStyle::LK_TextProto && + !CommentsBeforeNextToken.empty()) + addUnwrappedLine(); flushComments(true); addUnwrappedLine(); } Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestTextProto.cpp +++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp @@ -700,5 +700,22 @@ "}"); } +TEST_F(FormatTestTextProto, FormatsCommentsAtEndOfFile) { + verifyFormat("key: value\n" + "# endfile comment"); + verifyFormat("key: value\n" + "// endfile comment"); + verifyFormat("key: value\n" + "// endfile comment 1\n" + "// endfile comment 2"); + verifyFormat("submessage { key: value }\n" + "# endfile comment"); + verifyFormat("submessage <\n" + " key: value\n" + " item {}\n" + ">\n" + "# endfile comment"); +} + } // end namespace tooling } // end namespace clang
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp =================================================================== --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp @@ -303,6 +303,18 @@ else parseLevel(/*HasOpeningBrace=*/false); // Make sure to format the remaining tokens. + // + // LK_TextProto is special since its top-level is parsed as the body of a + // braced list, which does not necessarily have natural line separators such + // as a semicolon. Comments after the last entry that have been determined to + // not belong to that line, as in: + // key: value + // // endfile comment + // do not have a chance to be put on a line of their own until this point. + // Here we add this newline before end-of-file comments. + if (Style.Language == FormatStyle::LK_TextProto && + !CommentsBeforeNextToken.empty()) + addUnwrappedLine(); flushComments(true); addUnwrappedLine(); } Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestTextProto.cpp +++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp @@ -700,5 +700,22 @@ "}"); } +TEST_F(FormatTestTextProto, FormatsCommentsAtEndOfFile) { + verifyFormat("key: value\n" + "# endfile comment"); + verifyFormat("key: value\n" + "// endfile comment"); + verifyFormat("key: value\n" + "// endfile comment 1\n" + "// endfile comment 2"); + verifyFormat("submessage { key: value }\n" + "# endfile comment"); + verifyFormat("submessage <\n" + " key: value\n" + " item {}\n" + ">\n" + "# endfile comment"); +} + } // end namespace tooling } // end namespace clang
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits