[all-commits] [llvm/llvm-project] 51ba66: [clang-format] Inherit RightAlign options across s...

Emilia Dreamer via All-commits all-commits at lists.llvm.org
Tue Jan 10 20:02:41 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 51ba660a0700e659e1a97f3ca5879b8617ec5c26
      https://github.com/llvm/llvm-project/commit/51ba660a0700e659e1a97f3ca5879b8617ec5c26
  Author: Emilia Dreamer <emilia at rymiel.space>
  Date:   2023-01-11 (Wed, 11 Jan 2023)

  Changed paths:
    M clang/lib/Format/WhitespaceManager.cpp
    M clang/unittests/Format/FormatTest.cpp

  Log Message:
  -----------
  [clang-format] Inherit RightAlign options across scopes

D119599 added the ability to align compound assignments, right aligning
them in order to line up at the equals sign.
However, that patch didn't account for AlignTokens being called
recursively across scopes, which reset the right justification to be
false in any scope besides the top scope. This meant the compound
assignments were aligned, just not at the right place.
(No tests also ever introduced any scopes)

This patch makes sure to inherit the right justification value, just as
every other parameter is passed on.

Fixes https://github.com/llvm/llvm-project/issues/58029

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D141288


  Commit: 0904e0bac8314249ee7c1b0658f1a1cc92ccd050
      https://github.com/llvm/llvm-project/commit/0904e0bac8314249ee7c1b0658f1a1cc92ccd050
  Author: Emilia Dreamer <emilia at rymiel.space>
  Date:   2023-01-11 (Wed, 11 Jan 2023)

  Changed paths:
    M clang/lib/Format/ContinuationIndenter.cpp
    M clang/lib/Format/FormatToken.h
    M clang/lib/Format/TokenAnnotator.cpp
    M clang/unittests/Format/FormatTest.cpp
    M clang/unittests/Format/TokenAnnotatorTest.cpp

  Log Message:
  -----------
  [clang-format] Properly handle the C11 _Generic keyword.

This patch properly recognizes the generic selection expression
introduced in C11, by adding an additional token type for the colons
present in such expressions.

Previously, they would be recognized as
"inline ASM colons" purely by the fact that those are the last thing
checked for.

I tried to avoid adding an addition token type, but since colons by
default like having spaces around them, I chose to add a new type so
that no space is added after the type selector.

Currently, no aspect of the formatting of these expressions in able to
be configured, as I'm not sure what could even be configured here.

One notable thing is that association list is always formatted as
either entirely on one line, if it can fit, or with line breaks
after every comma in the expression (also after the controlling expr.)

This visually makes them more similar to switch statements when long,
matching the behaviour of the selection expression, being that of a sort
of switch on types, but also allows for terseness when only selecting
for a few things.

Fixes https://github.com/llvm/llvm-project/issues/18080

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D139211


Compare: https://github.com/llvm/llvm-project/compare/57a366be1e77...0904e0bac831


More information about the All-commits mailing list