[PATCH] D127054: [clang-format] Handle attributes for for/while loops

2022-06-06 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

nice!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127054/new/

https://reviews.llvm.org/D127054

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


[PATCH] D127054: [clang-format] Handle attributes for for/while loops

2022-06-05 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc1c160f7330: [clang-format] Handle attributes for for/while 
loops (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127054/new/

https://reviews.llvm.org/D127054

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23846,6 +23846,22 @@
"  return 29;\n",
Style);
 
+  verifyFormat("while (limit > 0) [[unlikely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("for (auto &limit : limits) [[likely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("for (auto &limit : limits) [[unlikely]]\n"
+   "  --limit;",
+   Style);
+  verifyFormat("while (limit > 0) [[likely]]\n"
+   "  --limit;",
+   Style);
+
   Style.AttributeMacros.push_back("UNLIKELY");
   Style.AttributeMacros.push_back("LIKELY");
   verifyFormat("if (argc > 5) UNLIKELY\n"
@@ -23874,6 +23890,22 @@
"  return 42;\n"
"}\n",
Style);
+
+  verifyFormat("for (auto &limit : limits) UNLIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("while (limit > 0) LIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("while (limit > 0) UNLIKELY\n"
+   "  --limit;",
+   Style);
+  verifyFormat("for (auto &limit : limits) LIKELY\n"
+   "  --limit;",
+   Style);
 }
 
 TEST_F(FormatTest, PenaltyIndentedWhitespace) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2889,6 +2889,7 @@
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
+  handleAttributes();
   parseLoopBody(KeepBraces, /*WrapRightBrace=*/true);
 }
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23846,6 +23846,22 @@
"  return 29;\n",
Style);
 
+  verifyFormat("while (limit > 0) [[unlikely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("for (auto &limit : limits) [[likely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("for (auto &limit : limits) [[unlikely]]\n"
+   "  --limit;",
+   Style);
+  verifyFormat("while (limit > 0) [[likely]]\n"
+   "  --limit;",
+   Style);
+
   Style.AttributeMacros.push_back("UNLIKELY");
   Style.AttributeMacros.push_back("LIKELY");
   verifyFormat("if (argc > 5) UNLIKELY\n"
@@ -23874,6 +23890,22 @@
"  return 42;\n"
"}\n",
Style);
+
+  verifyFormat("for (auto &limit : limits) UNLIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("while (limit > 0) LIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("while (limit > 0) UNLIKELY\n"
+   "  --limit;",
+   Style);
+  verifyFormat("for (auto &limit : limits) LIKELY\n"
+   "  --limit;",
+   Style);
 }
 
 TEST_F(FormatTest, PenaltyIndentedWhitespace) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2889,6 +2889,7 @@
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
+  handleAttributes();
   parseLoopBody(KeepBraces, /*WrapRightBrace=*/true);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127054: [clang-format] Handle attributes for for/while loops

2022-06-05 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Great!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127054/new/

https://reviews.llvm.org/D127054

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


[PATCH] D127054: [clang-format] Handle attributes for for/while loops

2022-06-04 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/55853.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127054

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23846,6 +23846,22 @@
"  return 29;\n",
Style);
 
+  verifyFormat("while (limit > 0) [[unlikely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("for (auto &limit : limits) [[likely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("for (auto &limit : limits) [[unlikely]]\n"
+   "  --limit;",
+   Style);
+  verifyFormat("while (limit > 0) [[likely]]\n"
+   "  --limit;",
+   Style);
+
   Style.AttributeMacros.push_back("UNLIKELY");
   Style.AttributeMacros.push_back("LIKELY");
   verifyFormat("if (argc > 5) UNLIKELY\n"
@@ -23874,6 +23890,22 @@
"  return 42;\n"
"}\n",
Style);
+
+  verifyFormat("for (auto &limit : limits) UNLIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("while (limit > 0) LIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("while (limit > 0) UNLIKELY\n"
+   "  --limit;",
+   Style);
+  verifyFormat("for (auto &limit : limits) LIKELY\n"
+   "  --limit;",
+   Style);
 }
 
 TEST_F(FormatTest, PenaltyIndentedWhitespace) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2889,6 +2889,7 @@
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
+  handleAttributes();
   parseLoopBody(KeepBraces, /*WrapRightBrace=*/true);
 }
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23846,6 +23846,22 @@
"  return 29;\n",
Style);
 
+  verifyFormat("while (limit > 0) [[unlikely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("for (auto &limit : limits) [[likely]] {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("for (auto &limit : limits) [[unlikely]]\n"
+   "  --limit;",
+   Style);
+  verifyFormat("while (limit > 0) [[likely]]\n"
+   "  --limit;",
+   Style);
+
   Style.AttributeMacros.push_back("UNLIKELY");
   Style.AttributeMacros.push_back("LIKELY");
   verifyFormat("if (argc > 5) UNLIKELY\n"
@@ -23874,6 +23890,22 @@
"  return 42;\n"
"}\n",
Style);
+
+  verifyFormat("for (auto &limit : limits) UNLIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+  verifyFormat("while (limit > 0) LIKELY {\n"
+   "  --limit;\n"
+   "}",
+   Style);
+
+  verifyFormat("while (limit > 0) UNLIKELY\n"
+   "  --limit;",
+   Style);
+  verifyFormat("for (auto &limit : limits) LIKELY\n"
+   "  --limit;",
+   Style);
 }
 
 TEST_F(FormatTest, PenaltyIndentedWhitespace) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2889,6 +2889,7 @@
   if (FormatTok->is(tok::l_paren))
 parseParens();
 
+  handleAttributes();
   parseLoopBody(KeepBraces, /*WrapRightBrace=*/true);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits