[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros
Noah Goldstein via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 18 20:33:54 PST 2022
goldstein.w.n marked an inline comment as done.
goldstein.w.n added a comment.
In D137181#3938771 <https://reviews.llvm.org/D137181#3938771>, @owenpan wrote:
> In D137181#3935951 <https://reviews.llvm.org/D137181#3935951>, @owenpan wrote:
>
>> In D137181#3935856 <https://reviews.llvm.org/D137181#3935856>, @goldstein.w.n wrote:
>>
>>> I could remove either the `PPDIS_BeforeHash` or `PPDIS_AfterHash` though as the they really no independent logic in this commit.
>>
>> Yes, please. Or better yet, alternate a little bit between the two.
>
> My bad. I meant splitting the test cases between the two. Can you regroup them (lines 5137-5258) as follows?
>
> style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
> style.IndentWidth = 4;
> style.PPIndentWidth = 1;
> verifyFormat("#ifdef foo\n"
> "# define bar() \\\n"
> " if (A) { \\\n"
> " B(); \\\n"
> " } \\\n"
> " C();\n"
> "#endif",
> style);
> verifyFormat("#if abc\n"
> "# ifdef foo\n"
> "# define bar() \\\n"
> " if (A) { \\\n"
> " if (B) { \\\n"
> " C(); \\\n"
> " } \\\n"
> " } \\\n"
> " D();\n"
> "# endif\n"
> "#endif",
> style);
> verifyFormat("#ifndef foo\n"
> "#define foo\n"
> "if (emacs) {\n"
> "#ifdef is\n"
> "# define lit \\\n"
> " if (af) { \\\n"
> " return duh(); \\\n"
> " }\n"
> "#endif\n"
> "}\n"
> "#endif",
> style);
> verifyFormat("#define X \\\n"
> " { \\\n"
> " x; \\\n"
> " x; \\\n"
> " }",
> style);
>
> style.IndentWidth = 8;
> style.PPIndentWidth = 2;
> verifyFormat("#ifdef foo\n"
> "# define bar() \\\n"
> " if (A) { \\\n"
> " B(); \\\n"
> " } \\\n"
> " C();\n"
> "#endif",
> style);
>
> style.IndentWidth = 1;
> style.PPIndentWidth = 4;
> verifyFormat("#define X \\\n"
> " { \\\n"
> " x; \\\n"
> " x; \\\n"
> " }",
> style);
>
> style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash;
> style.IndentWidth = 4;
> style.PPIndentWidth = 1;
> verifyFormat("if (emacs) {\n"
> "#ifdef is\n"
> " #define lit \\\n"
> " if (af) { \\\n"
> " return duh(); \\\n"
> " }\n"
> "#endif\n"
> "}",
> style);
> verifyFormat("#if abc\n"
> " #ifdef foo\n"
> " #define bar() \\\n"
> " if (A) { \\\n"
> " B(); \\\n"
> " } \\\n"
> " C();\n"
> " #endif\n"
> "#endif",
> style);
> verifyFormat("#if 1\n"
> " #define X \\\n"
> " { \\\n"
> " x; \\\n"
> " x; \\\n"
> " }\n"
> "#endif",
> style);
>
> style.PPIndentWidth = 2;
> verifyFormat("#ifdef foo\n"
> " #define bar() \\\n"
> " if (A) { \\\n"
> " B(); \\\n"
> " } \\\n"
> " C();\n"
> "#endif",
> style);
>
> style.IndentWidth = 1;
> style.PPIndentWidth = 4;
> verifyFormat("#if 1\n"
> " #define X \\\n"
> " { \\\n"
> " x; \\\n"
> " x; \\\n"
> " }\n"
> "#endif",
> style);
Yes done.
================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1281
+ Line->PPLevel = PPBranchLevel + (IncludeGuard == IG_Defined ? 0 : 1);
Line->InMacroBody = true;
----------------
owenpan wrote:
> In case `PPLevel` is negative.
Done.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137181/new/
https://reviews.llvm.org/D137181
More information about the cfe-commits
mailing list