r358275 - [clang-format] Use SpacesBeforeTrailingComments for "option" directive
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 12 03:11:34 PDT 2019
Author: krasimir
Date: Fri Apr 12 03:11:34 2019
New Revision: 358275
URL: http://llvm.org/viewvc/llvm-project?rev=358275&view=rev
Log:
[clang-format] Use SpacesBeforeTrailingComments for "option" directive
Summary:
AnnotatingParser::next() is needed to implicitly set TT_BlockComment
versus TT_LineComment. On most other paths through
AnnotatingParser::parseLine(), all tokens are consumed to achieve that.
This change updates one place where this wasn't done.
Contributed by @dchai!
Reviewers: krasimir
Reviewed By: krasimir
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D60541
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=358275&r1=358274&r2=358275&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Apr 12 03:11:34 2019
@@ -1124,8 +1124,11 @@ public:
if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
CurrentToken->is(Keywords.kw_option)) {
next();
- if (CurrentToken && CurrentToken->is(tok::identifier))
+ if (CurrentToken && CurrentToken->is(tok::identifier)) {
+ while (CurrentToken)
+ next();
return LT_ImportStatement;
+ }
}
bool KeywordVirtualFound = false;
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=358275&r1=358274&r2=358275&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Fri Apr 12 03:11:34 2019
@@ -193,6 +193,10 @@ TEST_F(FormatTestProto, DoesntWrapFileOp
"\"some.really.long.package.that.exceeds.the.column.limit\";"));
}
+TEST_F(FormatTestProto, TrailingCommentAfterFileOption) {
+ verifyFormat("option java_package = \"foo.pkg\"; // comment\n");
+}
+
TEST_F(FormatTestProto, FormatsOptions) {
verifyFormat("option (MyProto.options) = {\n"
" field_a: OK\n"
More information about the cfe-commits
mailing list