[PATCH] D139211: [clang-format] Properly handle the C11 _Generic keyword.

Emilia Dreamer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 23 01:00:01 PST 2022


rymiel updated this revision to Diff 485062.
rymiel marked an inline comment as done.
rymiel retitled this revision from "[WIP][clang-format] Properly handle the C11 _Generic keyword." to "[clang-format] Properly handle the C11 _Generic keyword.".
rymiel added a comment.
This revision is now accepted and ready to land.

Change indenting behaviour

I'm still not sure what I'm doing regarding ContinuationIndenter, since I don't fully understand its mechanisms, so I just followed my usual method of "stick a very specific check in a random spot that makes the correct fields have the correct value", which feels like a hack here. There is probably a much better way to do this, perhaps something with fake parens or something, to actually treat the "controlling expression" and the actual selectors differently, but right now I've just put in a specific check to dedent the selectors to be relative to the _Generic keyword, and not aligned to the opening paren.

It is also no surprise that I don't know how to write tests; I included organic examples of cases that are semi-realistic use cases of _Generic, but there are definitely edge cases I don't have listed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139211/new/

https://reviews.llvm.org/D139211

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139211.485062.patch
Type: text/x-patch
Size: 7055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221223/129ac54e/attachment.bin>


More information about the cfe-commits mailing list