[clang] [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (PR #87868)

2024-04-07 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/87868
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (PR #87868)

2024-04-07 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/87868
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (PR #87868)

2024-04-06 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/87868

>From 5c614fec2b54c146841a9ef3089dee1a63f72543 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 5 Apr 2024 22:45:47 -0700
Subject: [PATCH 1/2] [clang-format][NFC] Add getNextNonComment() to
 FormatTokenSource

---
 clang/lib/Format/FormatTokenSource.h |  9 +
 clang/lib/Format/UnwrappedLineParser.cpp | 11 ++-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index cce19f527a9236..1b7d2820e2c3b8 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -72,6 +72,15 @@ class FormatTokenSource {
   // getNextToken() -> a1
   // getNextToken() -> a2
   virtual FormatToken *insertTokens(ArrayRef Tokens) = 0;
+
+  FormatToken *getNextNonComment() {
+FormatToken *Tok;
+do {
+  Tok = getNextToken();
+  assert(Tok);
+} while (Tok->is(tok::comment));
+return Tok;
+  }
 };
 
 class IndexedTokenSource : public FormatTokenSource {
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 57d8dbcf3b4c77..33be39f2f77b0b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -427,11 +427,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   break;
 case tok::kw_default: {
   unsigned StoredPosition = Tokens->getPosition();
-  FormatToken *Next;
-  do {
-Next = Tokens->getNextToken();
-assert(Next);
-  } while (Next->is(tok::comment));
+  auto *Next = Tokens->getNextNonComment();
   FormatTok = Tokens->setPosition(StoredPosition);
   if (Next->isNot(tok::colon)) {
 // default not followed by ':' is not a case label; treat it like
@@ -497,10 +493,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   assert(Tok->is(tok::l_brace));
 
   do {
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+auto *NextTok = Tokens->getNextNonComment();
 
 if (!Line->InMacroBody && !Style.isTableGen()) {
   // Skip PPDirective lines and comments.

>From a7675f4a362ffc52a19c49bdc8016335d36127b6 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 6 Apr 2024 01:38:10 -0700
Subject: [PATCH 2/2] Update FormatTokenSource.h

Add `[[nodiscard]]`.
---
 clang/lib/Format/FormatTokenSource.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index 1b7d2820e2c3b8..2b93f302d36034 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -73,7 +73,7 @@ class FormatTokenSource {
   // getNextToken() -> a2
   virtual FormatToken *insertTokens(ArrayRef Tokens) = 0;
 
-  FormatToken *getNextNonComment() {
+  [[nodiscard]] FormatToken *getNextNonComment() {
 FormatToken *Tok;
 do {
   Tok = getNextToken();

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (PR #87868)

2024-04-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes



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


2 Files Affected:

- (modified) clang/lib/Format/FormatTokenSource.h (+9) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+2-9) 


``diff
diff --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index cce19f527a9236..1b7d2820e2c3b8 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -72,6 +72,15 @@ class FormatTokenSource {
   // getNextToken() -> a1
   // getNextToken() -> a2
   virtual FormatToken *insertTokens(ArrayRef Tokens) = 0;
+
+  FormatToken *getNextNonComment() {
+FormatToken *Tok;
+do {
+  Tok = getNextToken();
+  assert(Tok);
+} while (Tok->is(tok::comment));
+return Tok;
+  }
 };
 
 class IndexedTokenSource : public FormatTokenSource {
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 57d8dbcf3b4c77..33be39f2f77b0b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -427,11 +427,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   break;
 case tok::kw_default: {
   unsigned StoredPosition = Tokens->getPosition();
-  FormatToken *Next;
-  do {
-Next = Tokens->getNextToken();
-assert(Next);
-  } while (Next->is(tok::comment));
+  auto *Next = Tokens->getNextNonComment();
   FormatTok = Tokens->setPosition(StoredPosition);
   if (Next->isNot(tok::colon)) {
 // default not followed by ':' is not a case label; treat it like
@@ -497,10 +493,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   assert(Tok->is(tok::l_brace));
 
   do {
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+auto *NextTok = Tokens->getNextNonComment();
 
 if (!Line->InMacroBody && !Style.isTableGen()) {
   // Skip PPDirective lines and comments.

``




https://github.com/llvm/llvm-project/pull/87868
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (PR #87868)

2024-04-05 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/87868

None

>From 5c614fec2b54c146841a9ef3089dee1a63f72543 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 5 Apr 2024 22:45:47 -0700
Subject: [PATCH] [clang-format][NFC] Add getNextNonComment() to
 FormatTokenSource

---
 clang/lib/Format/FormatTokenSource.h |  9 +
 clang/lib/Format/UnwrappedLineParser.cpp | 11 ++-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/FormatTokenSource.h 
b/clang/lib/Format/FormatTokenSource.h
index cce19f527a9236..1b7d2820e2c3b8 100644
--- a/clang/lib/Format/FormatTokenSource.h
+++ b/clang/lib/Format/FormatTokenSource.h
@@ -72,6 +72,15 @@ class FormatTokenSource {
   // getNextToken() -> a1
   // getNextToken() -> a2
   virtual FormatToken *insertTokens(ArrayRef Tokens) = 0;
+
+  FormatToken *getNextNonComment() {
+FormatToken *Tok;
+do {
+  Tok = getNextToken();
+  assert(Tok);
+} while (Tok->is(tok::comment));
+return Tok;
+  }
 };
 
 class IndexedTokenSource : public FormatTokenSource {
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 57d8dbcf3b4c77..33be39f2f77b0b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -427,11 +427,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
   break;
 case tok::kw_default: {
   unsigned StoredPosition = Tokens->getPosition();
-  FormatToken *Next;
-  do {
-Next = Tokens->getNextToken();
-assert(Next);
-  } while (Next->is(tok::comment));
+  auto *Next = Tokens->getNextNonComment();
   FormatTok = Tokens->setPosition(StoredPosition);
   if (Next->isNot(tok::colon)) {
 // default not followed by ':' is not a case label; treat it like
@@ -497,10 +493,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   assert(Tok->is(tok::l_brace));
 
   do {
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+auto *NextTok = Tokens->getNextNonComment();
 
 if (!Line->InMacroBody && !Style.isTableGen()) {
   // Skip PPDirective lines and comments.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits