[PATCH] D25439: Fixed column shift when formatting line containing bit shift operators

Malcolm Parsons via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 3 10:07:12 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL285934: Fixed column shift when formatting line containing bit shift operators (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D25439?vs=75635&id=76869#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25439

Files:
  cfe/trunk/lib/Format/FormatTokenLexer.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/FormatTokenLexer.cpp
===================================================================
--- cfe/trunk/lib/Format/FormatTokenLexer.cpp
+++ cfe/trunk/lib/Format/FormatTokenLexer.cpp
@@ -525,10 +525,12 @@
   } else if (FormatTok->Tok.is(tok::greatergreater)) {
     FormatTok->Tok.setKind(tok::greater);
     FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
+    ++Column;
     StateStack.push(LexerState::TOKEN_STASHED);
   } else if (FormatTok->Tok.is(tok::lessless)) {
     FormatTok->Tok.setKind(tok::less);
     FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
+    ++Column;
     StateStack.push(LexerState::TOKEN_STASHED);
   }
 
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -5501,6 +5501,18 @@
   verifyFormat("< < < < < < < < < < < < < < < < < < < < < < < < < < < < < <");
 }
 
+TEST_F(FormatTest, BitshiftOperatorWidth) {
+  EXPECT_EQ("int a = 1 << 2; /* foo\n"
+            "                   bar */",
+            format("int    a=1<<2;  /* foo\n"
+                   "                   bar */"));
+
+  EXPECT_EQ("int b = 256 >> 1; /* foo\n"
+            "                     bar */",
+            format("int  b  =256>>1 ;  /* foo\n"
+                   "                      bar */"));
+}
+
 TEST_F(FormatTest, UnderstandsBinaryOperators) {
   verifyFormat("COMPARE(a, ==, b);");
   verifyFormat("auto s = sizeof...(Ts) - 1;");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25439.76869.patch
Type: text/x-patch
Size: 1557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161103/3dc8fd19/attachment.bin>


More information about the cfe-commits mailing list