[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 5 12:00:15 PDT 2025
================
@@ -1472,6 +1483,30 @@ static void expandPresetsSpacesInParens(FormatStyle &Expanded) {
Expanded.SpacesInParensOptions = {};
}
+static void expandPresetsShortFunctionsOnSingleLine(FormatStyle &Expanded) {
+ if (Expanded.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Custom)
+ return;
+ // Reset all flags
+ Expanded.AllowShortFunctionsOnASingleLineOptions = {};
+
+ if (Expanded.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None)
+ return;
+
+ if (Expanded.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty ||
+ Expanded.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline) {
+ Expanded.AllowShortFunctionsOnASingleLineOptions.Empty = true;
+ }
+
+ if (Expanded.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline ||
+ Expanded.AllowShortFunctionsOnASingleLine ==
+ FormatStyle::SFS_InlineOnly) {
+ Expanded.AllowShortFunctionsOnASingleLineOptions.Inline = true;
+ }
+
+ if (Expanded.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All)
+ Expanded.AllowShortFunctionsOnASingleLineOptions.Other = true;
----------------
owenca wrote:
```suggestion
switch (Expanded.AllowShortFunctionsOnASingleLine) {
case FormatStyle::SFS_All:
Expanded.AllowShortFunctionsOnASingleLineOptions.Inline = true;
Expanded.AllowShortFunctionsOnASingleLineOptions.Other = true;
[[fallthrough]];
case FormatStyle::SFS_Empty:
Expanded.AllowShortFunctionsOnASingleLineOptions.Empty = true;
break;
case FormatStyle::SFS_Inline:
Expanded.AllowShortFunctionsOnASingleLineOptions.Empty = true;
[[fallthrough]];
case FormatStyle::SFS_InlineOnly:
Expanded.AllowShortFunctionsOnASingleLineOptions.Inline = true;
}
break;
default:
break;
```
Use `switch` like other expansions.
https://github.com/llvm/llvm-project/pull/134337
More information about the cfe-commits
mailing list