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

Manuel Klimek klimek at google.com
Mon Sep 2 01:34:22 PDT 2013


On Mon, Sep 2, 2013 at 10:26 AM, Daniel Jasper <djasper at google.com> wrote:

> 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)))
>

I don't really understand why:
a) level == 1 (instead of 0); I assume Level always starts with 1 in
PPDirectives?
b) why we want to additionally indent only if we're on the outermost level

A comment would be great :)


> +        ++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"
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130902/8912fa79/attachment.html>


More information about the cfe-commits mailing list