[cfe-commits] r172400 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Mon Jan 14 04:18:19 PST 2013


Author: djasper
Date: Mon Jan 14 06:18:19 2013
New Revision: 172400

URL: http://llvm.org/viewvc/llvm-project?rev=172400&view=rev
Log:
Improve understanding post increment and decrement.

Before: (a->f()) ++;
        a[42] ++;
After:  (a->f())++;
        a[42]++;

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172400&r1=172399&r2=172400&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Jan 14 06:18:19 2013
@@ -1060,7 +1060,10 @@
 
   /// \brief Determine whether ++/-- are pre- or post-increments/-decrements.
   TokenType determineIncrementUsage(const AnnotatedToken &Tok) {
-    if (Tok.Parent != NULL && Tok.Parent->is(tok::identifier))
+    if (Tok.Parent == NULL)
+      return TT_UnaryOperator;
+    if (Tok.Parent->is(tok::r_paren) || Tok.Parent->is(tok::r_square) ||
+        Tok.Parent->is(tok::identifier))
       return TT_TrailingUnaryOperator;
 
     return TT_UnaryOperator;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172400&r1=172399&r2=172400&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 14 06:18:19 2013
@@ -978,6 +978,8 @@
   verifyFormat("if (i < -1) {}");
   verifyFormat("++(a->f());");
   verifyFormat("--(a->f());");
+  verifyFormat("(a->f())++;");
+  verifyFormat("a[42]++;");
   verifyFormat("if (!(a->f())) {}");
 
   verifyFormat("a-- > b;");





More information about the cfe-commits mailing list