r174737 - Fix indentation-detection at indent level 0.

Manuel Klimek klimek at google.com
Fri Feb 8 11:53:33 PST 2013


Author: klimek
Date: Fri Feb  8 13:53:32 2013
New Revision: 174737

URL: http://llvm.org/viewvc/llvm-project?rev=174737&view=rev
Log:
Fix indentation-detection at indent level 0.

This correctly formats:
  {
    a;
  }
where { is incorrectly indented by 2, but is at level 0, when
reformatting only 'a;'.

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=174737&r1=174736&r2=174737&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Feb  8 13:53:32 2013
@@ -977,10 +977,10 @@ private:
   /// that level is unknown.
   unsigned GetIndent(const std::vector<int> IndentForLevel,
                      unsigned Level) {
-    if (Level == 0)
-      return 0;
     if (IndentForLevel[Level] != -1)
       return IndentForLevel[Level];
+    if (Level == 0)
+      return 0;
     return GetIndent(IndentForLevel, Level - 1) + 2;
   }
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174737&r1=174736&r2=174737&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Feb  8 13:53:32 2013
@@ -2593,7 +2593,12 @@ TEST_F(FormatTest, ReformatRegionAdjusts
                         "           b;\n"
                         "}\n"
                         "}", 22, 2, getLLVMStyle()));
-} 
+  EXPECT_EQ("  {\n"
+            "    a;\n"
+            "  }", format("  {\n"
+                          "a;\n"
+                          "  }", 4, 2, getLLVMStyle()));
+}
 
 } // end namespace tooling
 } // end namespace clang





More information about the cfe-commits mailing list