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

Paweł Żukowski via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 10 10:02:05 PDT 2016


idlecode created this revision.
idlecode added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

During clang-format source lexing >> and << operators are split and
treated as two less/greater operators but column position of following
tokens was not adjusted accordingly.


https://reviews.llvm.org/D25439

Files:
  lib/Format/FormatTokenLexer.cpp
  test/Format/bitshift-operator-width.cpp


Index: test/Format/bitshift-operator-width.cpp
===================================================================
--- /dev/null
+++ test/Format/bitshift-operator-width.cpp
@@ -0,0 +1,13 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style=LLVM \
+// RUN:   | FileCheck -strict-whitespace %s
+
+// CHECK: {{^int a = 1 << 2; /\* foo$}}
+// CHECK: {{^                   bar \*/$}}
+int a = 1 << 2; /* foo
+                   bar */
+
+// CHECK: {{^int b = 256 >> 2; /\* foo$}}
+// CHECK: {{^                     bar \*/$}}
+int b = 256 >> 2; /* foo
+                     bar */
+
Index: lib/Format/FormatTokenLexer.cpp
===================================================================
--- lib/Format/FormatTokenLexer.cpp
+++ 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 += 1;
     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 += 1;
     StateStack.push(LexerState::TOKEN_STASHED);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25439.74143.patch
Type: text/x-patch
Size: 1243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161010/2b910628/attachment.bin>


More information about the cfe-commits mailing list