r189743 - clang-format: Fix case-indentation in macros.

Daniel Jasper djasper at google.com
Mon Sep 2 01:26:30 PDT 2013


Author: djasper
Date: Mon Sep  2 03:26:29 2013
New Revision: 189743

URL: http://llvm.org/viewvc/llvm-project?rev=189743&view=rev
Log:
clang-format: Fix case-indentation in macros.

Before:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
    return operations::Operation##name

After:
  #define OPERATION_CASE(name)           \
    case OP_name:                        \
      return operations::Operation##name

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=189743&r1=189742&r2=189743&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Sep  2 03:26:29 2013
@@ -235,8 +235,9 @@ void UnwrappedLineParser::parseLevel(boo
       break;
     case tok::kw_default:
     case tok::kw_case:
-      if (!SwitchLabelEncountered)
-        Line->Level += Style.IndentCaseLabels;
+      if (!SwitchLabelEncountered &&
+          (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 1)))
+        ++Line->Level;
       SwitchLabelEncountered = true;
       parseStructuralElement();
       break;
@@ -864,8 +865,6 @@ void UnwrappedLineParser::parseDoWhile()
 }
 
 void UnwrappedLineParser::parseLabel() {
-  if (FormatTok->Tok.isNot(tok::colon))
-    return;
   nextToken();
   unsigned OldLineLevel = Line->Level;
   if (Line->Level > 1 || (!Line->InPPDirective && Line->Level > 0))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=189743&r1=189742&r2=189743&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Sep  2 03:26:29 2013
@@ -525,6 +525,10 @@ TEST_F(FormatTest, FormatsSwitchStatemen
                "  case a:          \\\n"
                "    foo = b;       \\\n"
                "  }", getLLVMStyleWithColumns(20));
+  verifyFormat("#define OPERATION_CASE(name)           \\\n"
+               "  case OP_name:                        \\\n"
+               "    return operations::Operation##name\n",
+               getLLVMStyleWithColumns(40));
 
   verifyGoogleFormat("switch (x) {\n"
                      "  case 1:\n"





More information about the cfe-commits mailing list