This revision was automatically updated to reflect the committed changes. Closed by commit rC325159: [clang-format] Recognize percents as format specifiers in protos (authored by krasimir, committed by ).
Changed prior to commit: https://reviews.llvm.org/D43294?vs=134232&id=134286#toc Repository: rC Clang https://reviews.llvm.org/D43294 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTestProto.cpp unittests/Format/FormatTestTextProto.cpp Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2425,6 +2425,9 @@ if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) && Right.isOneOf(tok::l_brace, tok::less)) return !Style.Cpp11BracedListStyle; + // A percent is probably part of a formatting specification, such as %lld. + if (Left.is(tok::percent)) + return false; } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; Index: unittests/Format/FormatTestTextProto.cpp =================================================================== --- unittests/Format/FormatTestTextProto.cpp +++ unittests/Format/FormatTestTextProto.cpp @@ -386,5 +386,9 @@ " }\n" "}"); } + +TEST_F(FormatTestTextProto, NoSpaceAfterPercent) { + verifyFormat("key: %d"); +} } // end namespace tooling } // end namespace clang Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -432,5 +432,11 @@ "};"); } +TEST_F(FormatTestProto, NoSpaceAfterPercent) { + verifyFormat("option (MyProto.options) = {\n" + " key: %lld\n" + "};"); +} + } // end namespace tooling } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2425,6 +2425,9 @@ if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) && Right.isOneOf(tok::l_brace, tok::less)) return !Style.Cpp11BracedListStyle; + // A percent is probably part of a formatting specification, such as %lld. + if (Left.is(tok::percent)) + return false; } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; Index: unittests/Format/FormatTestTextProto.cpp =================================================================== --- unittests/Format/FormatTestTextProto.cpp +++ unittests/Format/FormatTestTextProto.cpp @@ -386,5 +386,9 @@ " }\n" "}"); } + +TEST_F(FormatTestTextProto, NoSpaceAfterPercent) { + verifyFormat("key: %d"); +} } // end namespace tooling } // end namespace clang Index: unittests/Format/FormatTestProto.cpp =================================================================== --- unittests/Format/FormatTestProto.cpp +++ unittests/Format/FormatTestProto.cpp @@ -432,5 +432,11 @@ "};"); } +TEST_F(FormatTestProto, NoSpaceAfterPercent) { + verifyFormat("option (MyProto.options) = {\n" + " key: %lld\n" + "};"); +} + } // 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