[PATCH] D150539: [clang-format] Handle ud suffixes in IntegerLiteralSeparator

2023-05-16 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa72b064acf95: [clang-format] Handle chrono ud 
suffixes in IntegerLiteralSeparator (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150539

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -60,6 +60,24 @@
"hil = 0xABCil;",
Style);
 
+  verifyFormat("bd = 0b1'd;\n"
+   "dh = 1'234h;\n"
+   "dmin = 1'234min;\n"
+   "dns = 1'234ns;\n"
+   "ds = 1'234s;\n"
+   "dus = 1'234us;\n"
+   "hy = 0xA'BCy;",
+   "bd = 0b1d;\n"
+   "dh = 1234h;\n"
+   "dmin = 1234min;\n"
+   "dns = 1234ns;\n"
+   "ds = 1234s;\n"
+   "dus = 1234us;\n"
+   "hy = 0xABCy;",
+   Style);
+
+  verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
+
   verifyFormat("d = 5'678_km;\n"
"h = 0xD'EF_u16;",
"d = 5678_km;\n"
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,11 @@
   continue;
 }
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // Hex alpha digits a-f/A-F must be at the end of the string literal.
+  StringRef Suffixes = "_himnsuyd";
+  if (const auto Pos =
+  Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
+  Pos != StringRef::npos) {
 Text = Text.substr(0, Pos);
 Length = Pos;
   }


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -60,6 +60,24 @@
"hil = 0xABCil;",
Style);
 
+  verifyFormat("bd = 0b1'd;\n"
+   "dh = 1'234h;\n"
+   "dmin = 1'234min;\n"
+   "dns = 1'234ns;\n"
+   "ds = 1'234s;\n"
+   "dus = 1'234us;\n"
+   "hy = 0xA'BCy;",
+   "bd = 0b1d;\n"
+   "dh = 1234h;\n"
+   "dmin = 1234min;\n"
+   "dns = 1234ns;\n"
+   "ds = 1234s;\n"
+   "dus = 1234us;\n"
+   "hy = 0xABCy;",
+   Style);
+
+  verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
+
   verifyFormat("d = 5'678_km;\n"
"h = 0xD'EF_u16;",
"d = 5678_km;\n"
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,11 @@
   continue;
 }
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // Hex alpha digits a-f/A-F must be at the end of the string literal.
+  StringRef Suffixes = "_himnsuyd";
+  if (const auto Pos =
+  Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
+  Pos != StringRef::npos) {
 Text = Text.substr(0, Pos);
 Length = Pos;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150539: [clang-format] Handle ud suffixes in IntegerLiteralSeparator

2023-05-15 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 522397.
owenpan added a comment.

Addressed the review comment.


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

https://reviews.llvm.org/D150539

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -60,6 +60,24 @@
"hil = 0xABCil;",
Style);
 
+  verifyFormat("bd = 0b1'd;\n"
+   "dh = 1'234h;\n"
+   "dmin = 1'234min;\n"
+   "dns = 1'234ns;\n"
+   "ds = 1'234s;\n"
+   "dus = 1'234us;\n"
+   "hy = 0xA'BCy;",
+   "bd = 0b1d;\n"
+   "dh = 1234h;\n"
+   "dmin = 1234min;\n"
+   "dns = 1234ns;\n"
+   "ds = 1234s;\n"
+   "dus = 1234us;\n"
+   "hy = 0xABCy;",
+   Style);
+
+  verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
+
   verifyFormat("d = 5'678_km;\n"
"h = 0xD'EF_u16;",
"d = 5678_km;\n"
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,11 @@
   continue;
 }
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // Hex alpha digits a-f/A-F must be at the end of the string literal.
+  StringRef Suffixes = "_himnsuyd";
+  if (const auto Pos =
+  Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
+  Pos != StringRef::npos) {
 Text = Text.substr(0, Pos);
 Length = Pos;
   }


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -60,6 +60,24 @@
"hil = 0xABCil;",
Style);
 
+  verifyFormat("bd = 0b1'd;\n"
+   "dh = 1'234h;\n"
+   "dmin = 1'234min;\n"
+   "dns = 1'234ns;\n"
+   "ds = 1'234s;\n"
+   "dus = 1'234us;\n"
+   "hy = 0xA'BCy;",
+   "bd = 0b1d;\n"
+   "dh = 1234h;\n"
+   "dmin = 1234min;\n"
+   "dns = 1234ns;\n"
+   "ds = 1234s;\n"
+   "dus = 1234us;\n"
+   "hy = 0xABCy;",
+   Style);
+
+  verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
+
   verifyFormat("d = 5'678_km;\n"
"h = 0xD'EF_u16;",
"d = 5678_km;\n"
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,11 @@
   continue;
 }
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // Hex alpha digits a-f/A-F must be at the end of the string literal.
+  StringRef Suffixes = "_himnsuyd";
+  if (const auto Pos =
+  Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
+  Pos != StringRef::npos) {
 Text = Text.substr(0, Pos);
 Length = Pos;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150539: [clang-format] Handle ud suffixes in IntegerLiteralSeparator

2023-05-15 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp:116-117
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // FIXME: This doesn't work for ud-suffix d from std::chrono::day.
+  if (const auto Pos = Text.find_first_of("_himnsuy");
+  Pos != StringRef::npos) {

HazardyKnusperkeks wrote:
> What about this?
Good idea!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150539

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


[PATCH] D150539: [clang-format] Handle ud suffixes in IntegerLiteralSeparator

2023-05-15 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp:116-117
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // FIXME: This doesn't work for ud-suffix d from std::chrono::day.
+  if (const auto Pos = Text.find_first_of("_himnsuy");
+  Pos != StringRef::npos) {

What about this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150539

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


[PATCH] D150539: [clang-format] Handle ud suffixes in IntegerLiteralSeparator

2023-05-15 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150539

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -60,6 +60,20 @@
"hil = 0xABCil;",
Style);
 
+  verifyFormat("bh = 0b1'h;\n"
+   "dmin = 1'234min;\n"
+   "dns = 1'234ns;\n"
+   "ds = 1'234s;\n"
+   "dus = 1'234us;\n"
+   "hy = 0xA'BCy;",
+   "bh = 0b1h;\n"
+   "dmin = 1234min;\n"
+   "dns = 1234ns;\n"
+   "ds = 1234s;\n"
+   "dus = 1234us;\n"
+   "hy = 0xABCy;",
+   Style);
+
   verifyFormat("d = 5'678_km;\n"
"h = 0xD'EF_u16;",
"d = 5678_km;\n"
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,9 @@
   continue;
 }
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // FIXME: This doesn't work for ud-suffix d from std::chrono::day.
+  if (const auto Pos = Text.find_first_of("_himnsuy");
+  Pos != StringRef::npos) {
 Text = Text.substr(0, Pos);
 Length = Pos;
   }


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -60,6 +60,20 @@
"hil = 0xABCil;",
Style);
 
+  verifyFormat("bh = 0b1'h;\n"
+   "dmin = 1'234min;\n"
+   "dns = 1'234ns;\n"
+   "ds = 1'234s;\n"
+   "dus = 1'234us;\n"
+   "hy = 0xA'BCy;",
+   "bh = 0b1h;\n"
+   "dmin = 1234min;\n"
+   "dns = 1234ns;\n"
+   "ds = 1234s;\n"
+   "dus = 1234us;\n"
+   "hy = 0xABCy;",
+   Style);
+
   verifyFormat("d = 5'678_km;\n"
"h = 0xD'EF_u16;",
"d = 5678_km;\n"
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,9 @@
   continue;
 }
 if (Style.isCpp()) {
-  if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+  // FIXME: This doesn't work for ud-suffix d from std::chrono::day.
+  if (const auto Pos = Text.find_first_of("_himnsuy");
+  Pos != StringRef::npos) {
 Text = Text.substr(0, Pos);
 Length = Pos;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits