Skip to content

Commit 31a8ccc

Browse files
committed
Rename the option
1 parent 3affefb commit 31a8ccc

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4073,12 +4073,6 @@ the configuration (without a prefix: ``Auto``).
40734073
40744074
For example: BOOST_FOREACH.
40754075

4076-
.. _FunctionLikeMacros:
4077-
4078-
**FunctionLikeMacros** (``List of Strings``) :versionbadge:`clang-format 21` :ref:`<FunctionLikeMacros>`
4079-
A vector of function-like macros whose invocations should be skipped by
4080-
``RemoveParentheses``.
4081-
40824076
.. _IfMacros:
40834077

40844078
**IfMacros** (``List of Strings``) :versionbadge:`clang-format 13` :ref:`<IfMacros>`
@@ -4981,6 +4975,12 @@ the configuration (without a prefix: ``Auto``).
49814975
A(z); -> z;
49824976
A(a, b); // will not be expanded.
49834977

4978+
.. _MacrosSkippedByRemoveParentheses:
4979+
4980+
**MacrosSkippedByRemoveParentheses** (``List of Strings``) :versionbadge:`clang-format 21` :ref:`<MacrosSkippedByRemoveParentheses>`
4981+
A vector of function-like macros whose invocations should be skipped by
4982+
``RemoveParentheses``.
4983+
49844984
.. _MainIncludeChar:
49854985

49864986
**MainIncludeChar** (``MainIncludeCharDiscriminator``) :versionbadge:`clang-format 19` :ref:`<MainIncludeChar>`

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,8 @@ clang-format
11321132
``enum`` enumerator lists.
11331133
- Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
11341134
- Add ``SpaceAfterOperatorKeyword`` option.
1135-
- Add ``FunctionLikeMacros`` option so that their invocations are skipped by
1136-
``RemoveParentheses``.
1135+
- Add ``MacrosSkippedByRemoveParentheses`` option so that their invocations are
1136+
skipped by ``RemoveParentheses``.
11371137

11381138
clang-refactor
11391139
--------------

clang/include/clang/Format/Format.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,11 +2786,6 @@ struct FormatStyle {
27862786
/// \version 3.7
27872787
std::vector<std::string> ForEachMacros;
27882788

2789-
/// A vector of function-like macros whose invocations should be skipped by
2790-
/// ``RemoveParentheses``.
2791-
/// \version 21
2792-
std::vector<std::string> FunctionLikeMacros;
2793-
27942789
tooling::IncludeStyle IncludeStyle;
27952790

27962791
/// A vector of macros that should be interpreted as conditionals
@@ -3493,6 +3488,11 @@ struct FormatStyle {
34933488
/// \version 17
34943489
std::vector<std::string> Macros;
34953490

3491+
/// A vector of function-like macros whose invocations should be skipped by
3492+
/// ``RemoveParentheses``.
3493+
/// \version 21
3494+
std::vector<std::string> MacrosSkippedByRemoveParentheses;
3495+
34963496
/// The maximum number of consecutive empty lines to keep.
34973497
/// \code
34983498
/// MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0
@@ -5387,7 +5387,6 @@ struct FormatStyle {
53875387
R.ExperimentalAutoDetectBinPacking &&
53885388
FixNamespaceComments == R.FixNamespaceComments &&
53895389
ForEachMacros == R.ForEachMacros &&
5390-
FunctionLikeMacros == R.FunctionLikeMacros &&
53915390
IncludeStyle.IncludeBlocks == R.IncludeStyle.IncludeBlocks &&
53925391
IncludeStyle.IncludeCategories == R.IncludeStyle.IncludeCategories &&
53935392
IncludeStyle.IncludeIsMainRegex ==
@@ -5416,6 +5415,8 @@ struct FormatStyle {
54165415
LambdaBodyIndentation == R.LambdaBodyIndentation &&
54175416
LineEnding == R.LineEnding && MacroBlockBegin == R.MacroBlockBegin &&
54185417
MacroBlockEnd == R.MacroBlockEnd && Macros == R.Macros &&
5418+
MacrosSkippedByRemoveParentheses ==
5419+
R.MacrosSkippedByRemoveParentheses &&
54195420
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
54205421
NamespaceIndentation == R.NamespaceIndentation &&
54215422
NamespaceMacros == R.NamespaceMacros &&

clang/lib/Format/Format.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,6 @@ template <> struct MappingTraits<FormatStyle> {
10681068
Style.ExperimentalAutoDetectBinPacking);
10691069
IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
10701070
IO.mapOptional("ForEachMacros", Style.ForEachMacros);
1071-
IO.mapOptional("FunctionLikeMacros", Style.FunctionLikeMacros);
10721071
IO.mapOptional("IfMacros", Style.IfMacros);
10731072
IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
10741073
IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
@@ -1100,6 +1099,8 @@ template <> struct MappingTraits<FormatStyle> {
11001099
IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
11011100
IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
11021101
IO.mapOptional("Macros", Style.Macros);
1102+
IO.mapOptional("MacrosSkippedByRemoveParentheses",
1103+
Style.MacrosSkippedByRemoveParentheses);
11031104
IO.mapOptional("MainIncludeChar", Style.IncludeStyle.MainIncludeChar);
11041105
IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
11051106
IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ FormatTokenLexer::FormatTokenLexer(
4343
auto Identifier = &IdentTable.get(ForEachMacro);
4444
Macros.insert({Identifier, TT_ForEachMacro});
4545
}
46-
for (const std::string &FunctionLikeMacro : Style.FunctionLikeMacros) {
47-
auto Identifier = &IdentTable.get(FunctionLikeMacro);
48-
Macros.insert({Identifier, TT_FunctionLikeMacro});
49-
}
5046
for (const std::string &IfMacro : Style.IfMacros) {
5147
auto Identifier = &IdentTable.get(IfMacro);
5248
Macros.insert({Identifier, TT_IfMacro});
@@ -78,6 +74,8 @@ FormatTokenLexer::FormatTokenLexer(
7874
Macros.insert({Identifier, TT_StatementAttributeLikeMacro});
7975
}
8076

77+
for (const auto &Macro : Style.MacrosSkippedByRemoveParentheses)
78+
MacrosSkippedByRemoveParentheses.insert(&IdentTable.get(Macro));
8179
for (const auto &TemplateName : Style.TemplateNames)
8280
TemplateNames.insert(&IdentTable.get(TemplateName));
8381
for (const auto &TypeName : Style.TypeNames)
@@ -1477,6 +1475,8 @@ FormatToken *FormatTokenLexer::getNextToken() {
14771475
FormatTok->setType(TT_MacroBlockBegin);
14781476
else if (MacroBlockEndRegex.match(Text))
14791477
FormatTok->setType(TT_MacroBlockEnd);
1478+
else if (MacrosSkippedByRemoveParentheses.contains(Identifier))
1479+
FormatTok->setFinalizedType(TT_FunctionLikeMacro);
14801480
else if (TemplateNames.contains(Identifier))
14811481
FormatTok->setFinalizedType(TT_TemplateName);
14821482
else if (TypeNames.contains(Identifier))

clang/lib/Format/FormatTokenLexer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ class FormatTokenLexer {
132132

133133
llvm::SmallMapVector<IdentifierInfo *, TokenType, 8> Macros;
134134

135-
llvm::SmallPtrSet<IdentifierInfo *, 8> TemplateNames, TypeNames,
136-
VariableTemplates;
135+
llvm::SmallPtrSet<IdentifierInfo *, 8> MacrosSkippedByRemoveParentheses,
136+
TemplateNames, TypeNames, VariableTemplates;
137137

138138
bool FormattingDisabled;
139139
llvm::Regex FormatOffRegex; // For one line.

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,9 @@ TEST(ConfigParseTest, ParsesConfiguration) {
940940
CHECK_PARSE("StatementMacros: [QUNUSED, QT_REQUIRE_VERSION]", StatementMacros,
941941
std::vector<std::string>({"QUNUSED", "QT_REQUIRE_VERSION"}));
942942

943-
CHECK_PARSE_LIST(FunctionLikeMacros);
944943
CHECK_PARSE_LIST(JavaImportGroups);
945944
CHECK_PARSE_LIST(Macros);
945+
CHECK_PARSE_LIST(MacrosSkippedByRemoveParentheses);
946946
CHECK_PARSE_LIST(NamespaceMacros);
947947
CHECK_PARSE_LIST(ObjCPropertyAttributeOrder);
948948
CHECK_PARSE_LIST(TableGenBreakingDAGArgOperators);

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28479,9 +28479,9 @@ TEST_F(FormatTest, RemoveParentheses) {
2847928479
verifyFormat("MOCK_METHOD(void, Function, (), override);",
2848028480
"MOCK_METHOD(void, Function, (), (override));", Style);
2848128481

28482-
Style.FunctionLikeMacros.push_back("MOCK_METHOD");
28483-
verifyFormat("MOCK_METHOD((int), func, ((std::map<int, int>)), (override));",
28484-
Style);
28482+
Style.MacrosSkippedByRemoveParentheses.push_back("FOO");
28483+
verifyFormat("FOO((a && b));", Style);
28484+
verifyFormat("FOO((int), func, ((std::map<int, int>)), (override));", Style);
2848528485

2848628486
Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
2848728487
verifyFormat("#define Return0 return (0);", Style);

0 commit comments

Comments
 (0)