Skip to content

Commit e9e4e92

Browse files
author
Ivan Rymarchyk
committed
PR-134337: fixed PR comments
1 parent df25a8b commit e9e4e92

File tree

7 files changed

+30
-21
lines changed

7 files changed

+30
-21
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,28 +1994,31 @@ the configuration (without a prefix: ``Auto``).
19941994
Inline: true
19951995
All: false
19961996

1997-
* ``bool Empty`` Only merge empty functions.
1997+
* ``bool Empty`` Merge top-level empty functions.
19981998

19991999
.. code-block:: c++
20002000

20012001
void f() {}
20022002
void f2() {
20032003
bar2();
20042004
}
2005+
void f3() { /* comment */ }
20052006
2006-
* ``bool Inline`` Only merge functions defined inside a class.
2007+
* ``bool Inline`` Merge functions defined inside a class.
20072008

20082009
.. code-block:: c++
20092010

20102011
class Foo {
20112012
void f() { foo(); }
2013+
void g() {}
20122014
};
20132015
void f() {
20142016
foo();
20152017
}
2016-
void f() {}
2018+
void f() {
2019+
}
20172020

2018-
* ``bool All`` Merge all functions fitting on a single line.
2021+
* ``bool Other`` Merge all functions fitting on a single line.
20192022

20202023
.. code-block:: c++
20212024

clang/include/clang/Format/Format.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -890,23 +890,26 @@ struct FormatStyle {
890890
/// All: false
891891
/// \endcode
892892
struct ShortFunctionMergeFlags {
893-
/// Only merge empty functions.
893+
/// Merge top-level empty functions.
894894
/// \code
895895
/// void f() {}
896896
/// void f2() {
897897
/// bar2();
898898
/// }
899+
/// void f3() { /* comment */ }
899900
/// \endcode
900901
bool Empty;
901-
/// Only merge functions defined inside a class.
902+
/// Merge functions defined inside a class.
902903
/// \code
903904
/// class Foo {
904905
/// void f() { foo(); }
906+
/// void g() {}
905907
/// };
906908
/// void f() {
907909
/// foo();
908910
/// }
909-
/// void f() {}
911+
/// void f() {
912+
/// }
910913
/// \endcode
911914
bool Inline;
912915
/// Merge all functions fitting on a single line.
@@ -916,15 +919,15 @@ struct FormatStyle {
916919
/// };
917920
/// void f() { bar(); }
918921
/// \endcode
919-
bool All;
922+
bool Other;
920923

921-
ShortFunctionMergeFlags() : Empty(false), Inline(false), All(false) {}
924+
ShortFunctionMergeFlags() : Empty(false), Inline(false), Other(false) {}
922925

923926
ShortFunctionMergeFlags(bool Empty, bool Inline, bool All)
924-
: Empty(Empty), Inline(Inline), All(All) {}
927+
: Empty(Empty), Inline(Inline), Other(All) {}
925928

926929
bool operator==(const ShortFunctionMergeFlags &R) const {
927-
return Empty == R.Empty && Inline == R.Inline && All == R.All;
930+
return Empty == R.Empty && Inline == R.Inline && Other == R.Other;
928931
}
929932
bool operator!=(const ShortFunctionMergeFlags &R) const {
930933
return !(*this == R);

clang/lib/Format/Format.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ template <> struct MappingTraits<FormatStyle::ShortFunctionMergeFlags> {
630630
static void mapping(IO &IO, FormatStyle::ShortFunctionMergeFlags &Value) {
631631
IO.mapOptional("Empty", Value.Empty);
632632
IO.mapOptional("Inline", Value.Inline);
633-
IO.mapOptional("All", Value.All);
633+
IO.mapOptional("Other", Value.Other);
634634
}
635635
};
636636

@@ -1504,7 +1504,7 @@ static void expandPresetsShortFunctionsOnSingleLine(FormatStyle &Expanded) {
15041504
}
15051505

15061506
if (Expanded.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All)
1507-
Expanded.AllowShortFunctionsOnASingleLineOptions.All = true;
1507+
Expanded.AllowShortFunctionsOnASingleLineOptions.Other = true;
15081508
}
15091509

15101510
FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
@@ -1537,7 +1537,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
15371537
LLVMStyle.AllowShortEnumsOnASingleLine = true;
15381538
LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
15391539
LLVMStyle.AllowShortFunctionsOnASingleLineOptions = {};
1540-
LLVMStyle.AllowShortFunctionsOnASingleLineOptions.All = true;
1540+
LLVMStyle.AllowShortFunctionsOnASingleLineOptions.Other = true;
15411541
LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
15421542
LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All;
15431543
LLVMStyle.AllowShortLoopsOnASingleLine = false;

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5688,7 +5688,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
56885688
!Left.Children.empty()) {
56895689
// Support AllowShortFunctionsOnASingleLine for JavaScript.
56905690
return (!Style.AllowShortFunctionsOnASingleLineOptions.Inline &&
5691-
!Style.AllowShortFunctionsOnASingleLineOptions.All) ||
5691+
!Style.AllowShortFunctionsOnASingleLineOptions.Other) ||
56925692
(Left.NestingLevel == 0 && Line.Level == 0 &&
56935693
Style.AllowShortFunctionsOnASingleLineOptions.Inline);
56945694
}

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class LineJoiner {
293293

294294
auto ShouldMergeShortFunctions = [this, &I, &NextLine, PreviousLine,
295295
TheLine]() {
296-
if (Style.AllowShortFunctionsOnASingleLineOptions.All)
296+
if (Style.AllowShortFunctionsOnASingleLineOptions.Other)
297297
return true;
298298
if (Style.AllowShortFunctionsOnASingleLineOptions.Empty &&
299299
NextLine.First->is(tok::r_brace)) {

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
258258
CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, Other);
259259
CHECK_PARSE_NESTED_BOOL(AllowShortFunctionsOnASingleLineOptions, Empty);
260260
CHECK_PARSE_NESTED_BOOL(AllowShortFunctionsOnASingleLineOptions, Inline);
261-
CHECK_PARSE_NESTED_BOOL(AllowShortFunctionsOnASingleLineOptions, All);
261+
CHECK_PARSE_NESTED_BOOL(AllowShortFunctionsOnASingleLineOptions, Other);
262262
}
263263

264264
#undef CHECK_PARSE_BOOL

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15125,7 +15125,7 @@ TEST_F(FormatTest, CustomShortFunctionOptions) {
1512515125
CustomEmpty.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Custom;
1512615126
CustomEmpty.AllowShortFunctionsOnASingleLineOptions.Empty = true;
1512715127
CustomEmpty.AllowShortFunctionsOnASingleLineOptions.Inline = false;
15128-
CustomEmpty.AllowShortFunctionsOnASingleLineOptions.All = false;
15128+
CustomEmpty.AllowShortFunctionsOnASingleLineOptions.Other = false;
1512915129

1513015130
// Empty functions should be on a single line
1513115131
verifyFormat("int f() {}", CustomEmpty);
@@ -15146,6 +15146,9 @@ TEST_F(FormatTest, CustomShortFunctionOptions) {
1514615146
"};",
1514715147
CustomEmpty);
1514815148

15149+
// test with comment
15150+
verifyFormat("void f3() { /* comment */ }", CustomEmpty);
15151+
1514915152
// Test with AfterFunction = true
1515015153
CustomEmpty.BreakBeforeBraces = FormatStyle::BS_Custom;
1515115154
CustomEmpty.BraceWrapping.AfterFunction = true;
@@ -15161,7 +15164,7 @@ TEST_F(FormatTest, CustomShortFunctionOptions) {
1516115164
CustomInline.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Custom;
1516215165
CustomInline.AllowShortFunctionsOnASingleLineOptions.Empty = false;
1516315166
CustomInline.AllowShortFunctionsOnASingleLineOptions.Inline = true;
15164-
CustomInline.AllowShortFunctionsOnASingleLineOptions.All = false;
15167+
CustomInline.AllowShortFunctionsOnASingleLineOptions.Other = false;
1516515168

1516615169
verifyFormat("class C {\n"
1516715170
" int f() {}\n"
@@ -15188,7 +15191,7 @@ TEST_F(FormatTest, CustomShortFunctionOptions) {
1518815191
CustomAll.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Custom;
1518915192
CustomAll.AllowShortFunctionsOnASingleLineOptions.Empty = false;
1519015193
CustomAll.AllowShortFunctionsOnASingleLineOptions.Inline = false;
15191-
CustomAll.AllowShortFunctionsOnASingleLineOptions.All = true;
15194+
CustomAll.AllowShortFunctionsOnASingleLineOptions.Other = true;
1519215195

1519315196
// All functions should be on a single line if they fit
1519415197
verifyFormat("int f() { return 42; }", CustomAll);
@@ -15209,7 +15212,7 @@ TEST_F(FormatTest, CustomShortFunctionOptions) {
1520915212
CustomMixed.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Custom;
1521015213
CustomMixed.AllowShortFunctionsOnASingleLineOptions.Empty = true;
1521115214
CustomMixed.AllowShortFunctionsOnASingleLineOptions.Inline = true;
15212-
CustomMixed.AllowShortFunctionsOnASingleLineOptions.All = false;
15215+
CustomMixed.AllowShortFunctionsOnASingleLineOptions.Other = false;
1521315216

1521415217
// Empty functions should be on a single line
1521515218
verifyFormat("int f() {}", CustomMixed);

0 commit comments

Comments
 (0)