Skip to content

Code implementing SpacesInParensOptions.ExceptDoubleParentheses logic #93439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

owenca
Copy link
Contributor

@owenca owenca commented May 27, 2024

A simpler (and catch-all) alternative to #77522.

@llvmbot
Copy link
Member

llvmbot commented May 27, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

…ogic


Full diff: https://github.com/llvm/llvm-project/pull/93439.diff

1 Files Affected:

  • (modified) clang/lib/Format/TokenAnnotator.cpp (+8)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 7c4c76a91f2c5..c204d107b12b7 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4346,6 +4346,14 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
        Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
     return Style.SpacesInParensOptions.InEmptyParentheses;
   }
+  if (Style.SpacesInParens == FormatStyle::SIPO_Custom &&
+      Style.SpacesInParensOptions.ExceptDoubleParentheses &&
+      ((Left.is(tok::l_paren) && Right.is(tok::l_paren)) ||
+       (Left.is(tok::r_paren) && Right.is(tok::r_paren)))) {
+    const auto *Tok = Left.MatchingParen;
+    if (Tok && Tok->Previous == Right.MatchingParen)
+      return false;
+  }
   if (Style.SpacesInParensOptions.InConditionalStatements) {
     const FormatToken *LeftParen = nullptr;
     if (Left.is(tok::l_paren))

@owenca owenca marked this pull request as draft May 27, 2024 05:09
@owenca owenca changed the title Code implementing the SpacesInParensOptions.ExceptDoubleParentheses l… Code implementing SpacesInParensOptions.ExceptDoubleParentheses logic May 27, 2024
@gedare
Copy link
Contributor

gedare commented May 28, 2024

I'll try this out in the next few days.

@owenca owenca closed this Jul 2, 2024
@owenca owenca deleted the exceptDoubleParens branch July 2, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants