[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 2 21:06:50 PDT 2025
owenca wrote:
> > > IMO, a boolean option, e.g. `AllowBreakBeforeQPropertyKeyword` should suffice.
> >
> >
> > I don't like to hardcode neither the macro name nor the keywords, which depend on Qt version. Implementation would not differ save for the source we fetch keywords from.
>
> I support going a generic way, even if it currently seems to be only used by Qt.
This is very Qt-specific with a peculiar syntax, and there's no published style guide for breaking the property "keywords" (a confusing Qt term IMO), so there's little utility in making it generic now. Besides, we usually start a new option as a boolean and then extend it to an `enum` or `struct` when needed.
As to the implementation, it can be simplified and probably made less brittle. I would do something like the following instead:
- Name the option as `AllowBreakBeforeQtProperty`.
- Use `Q_PROPERTY` for a new context `Context::QtProperty`. (See `_Generic` and `Context::C11GenericSelection`.)
- Either use all-uppercase identifiers as the criterion or binary-search in a sorted table of all Qt property keywords (`READ`, `WRITE`, etc.) similar to `CppNonKeywordTypes` in FormatToken.cpp.
- Set the token type of those keywords to `TT_QtProperty`.
https://github.com/llvm/llvm-project/pull/131605
More information about the cfe-commits
mailing list