aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2025-07-13 14:29:51 -0700
committerGitHub <noreply@github.com>2025-07-13 14:29:51 -0700
commitc384ec431dd7f771c9dd7c462cec5301ac0f32bb (patch)
treea2a0cbab11398735e199b7aaa482e7c52ee29bd9 /clang/lib/Format/UnwrappedLineParser.cpp
parent1fbfa333f64bf714efa84db6b1075fc864d53bf8 (diff)
downloadllvm-c384ec431dd7f771c9dd7c462cec5301ac0f32bb.zip
llvm-c384ec431dd7f771c9dd7c462cec5301ac0f32bb.tar.gz
llvm-c384ec431dd7f771c9dd7c462cec5301ac0f32bb.tar.bz2
[clang-format] Add MacrosSkippedByRemoveParentheses option (#148345)
This allows RemoveParentheses to skip the invocations of function-like macros. Fixes #68354. Fixes #147780.
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 7e8634a..91b8fdc 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2579,30 +2579,34 @@ bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) {
/// double ampersands. This applies for all nested scopes as well.
///
/// Returns whether there is a `=` token between the parentheses.
-bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
+bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType,
+ bool InMacroCall) {
assert(FormatTok->is(tok::l_paren) && "'(' expected.");
auto *LParen = FormatTok;
+ auto *Prev = FormatTok->Previous;
bool SeenComma = false;
bool SeenEqual = false;
bool MightBeFoldExpr = false;
nextToken();
const bool MightBeStmtExpr = FormatTok->is(tok::l_brace);
+ if (!InMacroCall && Prev && Prev->is(TT_FunctionLikeMacro))
+ InMacroCall = true;
do {
switch (FormatTok->Tok.getKind()) {
case tok::l_paren:
- if (parseParens(AmpAmpTokenType))
+ if (parseParens(AmpAmpTokenType, InMacroCall))
SeenEqual = true;
if (Style.isJava() && FormatTok->is(tok::l_brace))
parseChildBlock();
break;
case tok::r_paren: {
- auto *Prev = LParen->Previous;
auto *RParen = FormatTok;
nextToken();
if (Prev) {
auto OptionalParens = [&] {
- if (MightBeStmtExpr || MightBeFoldExpr || Line->InMacroBody ||
- SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave ||
+ if (MightBeStmtExpr || MightBeFoldExpr || SeenComma || InMacroCall ||
+ Line->InMacroBody ||
+ Style.RemoveParentheses == FormatStyle::RPS_Leave ||
RParen->getPreviousNonComment() == LParen) {
return false;
}