[PATCH] D31652: [clang-format] Recognize Java logical shift assignment operator
Richard Bradfield via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 6 14:22:49 PDT 2017
bradfier updated this revision to Diff 94438.
bradfier edited the summary of this revision.
bradfier added a comment.
Switch to a more appropriate (and much simpler) method of identifying these Java-specific operators.
Also removed any references to fictitious "logical left shifts", I think I made those up while tired...
Repository:
rL LLVM
https://reviews.llvm.org/D31652
Files:
lib/Format/FormatTokenLexer.cpp
unittests/Format/FormatTestJava.cpp
Index: unittests/Format/FormatTestJava.cpp
===================================================================
--- unittests/Format/FormatTestJava.cpp
+++ unittests/Format/FormatTestJava.cpp
@@ -522,5 +522,17 @@
" void f() {}"));
}
+TEST_F(FormatTestJava, RetainsLogicalShifts) {
+ verifyFormat("void f() {\n"
+ " int a = 1;\n"
+ " a >>>= 1;\n"
+ "}");
+ verifyFormat("void f() {\n"
+ " int a = 1;\n"
+ " a = a >>> 1;\n"
+ "}");
+}
+
+
} // end namespace tooling
} // end namespace clang
Index: lib/Format/FormatTokenLexer.cpp
===================================================================
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -82,6 +82,19 @@
if (tryMergeTokens(JSRightArrow, TT_JsFatArrow))
return;
}
+
+ if (Style.Language == FormatStyle::LK_Java) {
+ static const tok::TokenKind JavaRightLogicalShift[] = {tok::greater,
+ tok::greater,
+ tok::greater};
+ static const tok::TokenKind JavaRightLogicalShiftAssign[] = {tok::greater,
+ tok::greater,
+ tok::greaterequal};
+ if (tryMergeTokens(JavaRightLogicalShift, TT_BinaryOperator))
+ return;
+ if (tryMergeTokens(JavaRightLogicalShiftAssign, TT_BinaryOperator))
+ return;
+ }
}
bool FormatTokenLexer::tryMergeLessLess() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31652.94438.patch
Type: text/x-patch
Size: 1637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170406/9dda80c3/attachment.bin>
More information about the cfe-commits
mailing list