[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-09-13 Thread tetra via Phabricator via cfe-commits
tetraxile added a comment.

Just bumping this patch, I'd like if it could get reviewed before Phabricator 
becomes read-only.


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

https://reviews.llvm.org/D157205

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


[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-08-06 Thread tetra via Phabricator via cfe-commits
tetraxile updated this revision to Diff 547595.
tetraxile added a comment.

Thanks for the suggestion SR_team, I've just added that.


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

https://reviews.llvm.org/D157205

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3383,7 +3383,7 @@
 Type: type (aka can_type)
 Value = value
 Offset: 12 (0xc) bytes
-Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 (0x4) bytes and 3 (0x3) bits
-Size: 25 (0x19) bits (+4 (0x4) bits padding)
+Offset: 4 bytes and 3 bits
+Size: 25 (0x19) bits (+4 bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,8 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : 
"s")
-  .str();
+  const char *Fmt = Value >= 10 ? "{0} ({0:x}) {1}{2}" : "{0} {1}{2}";
+  return llvm::formatv(Fmt, Value, Unit, Value == 1 ? "" : "s").str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3383,7 +3383,7 @@
 Type: type (aka can_type)
 Value = value
 Offset: 12 (0xc) bytes
-Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 (0x4) bytes and 3 (0x3) bits
-Size: 25 (0x19) bits (+4 (0x4) bits padding)
+Offset: 4 bytes and 3 bits
+Size: 25 (0x19) bits (+4 bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,8 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : "s")
-  .str();
+  const char *Fmt = Value >= 10 ? "{0} ({0:x}) {1}{2}" : "{0} {1}{2}";
+  return llvm::formatv(Fmt, Value, Unit, Value == 1 ? "" : "s").str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-08-06 Thread SR_team via Phabricator via cfe-commits
SR_team added a comment.

Until a 10, we don't have difference between DEC and HEX, may be print only DEC 
in these cases?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157205

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


[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-08-06 Thread tetra via Phabricator via cfe-commits
tetraxile created this revision.
tetraxile added a reviewer: sammccall.
tetraxile added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
tetraxile requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

This changes the formatting of class/struct member variable byte offsets and 
sizes, as well as class sizes, from just the decimal value, e.g. "Offset: 12 
bytes", to both decimal and hexadecimal, e.g. "Offset: 12 (0xc) bytes".

I'm open to adding a config file option to disable this feature if users want 
to reduce clutter, but I think it'd be unnecessary, as the other lines in the 
hover popup (declaration, type, comment) are already quite a bit longer than 
the offset and size lines.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157205

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3331,7 +3331,7 @@
   },
   R"(class foo
 
-Size: 10 bytes
+Size: 10 (0xa) bytes
 documentation
 
 template  class Foo {})",
@@ -3382,8 +3382,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 12 bytes
-Size: 4 bytes (+4 bytes padding)
+Offset: 12 (0xc) bytes
+Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 bytes and 3 bits
-Size: 25 bits (+4 bits padding)
+Offset: 4 (0x4) bytes and 3 (0x3) bits
+Size: 25 (0x19) bits (+4 (0x4) bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,7 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} {1}{2}", Value, Unit, Value == 1 ? "" : "s").str();
+  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : 
"s")
+  .str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3331,7 +3331,7 @@
   },
   R"(class foo
 
-Size: 10 bytes
+Size: 10 (0xa) bytes
 documentation
 
 template  class Foo {})",
@@ -3382,8 +3382,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 12 bytes
-Size: 4 bytes (+4 bytes padding)
+Offset: 12 (0xc) bytes
+Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 bytes and 3 bits
-Size: 25 bits (+4 bits padding)
+Offset: 4 (0x4) bytes and 3 (0x3) bits
+Size: 25 (0x19) bits (+4 (0x4) bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,7 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} {1}{2}", Value, Unit, Value == 1 ? "" : "s").str();
+  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : "s")
+  .str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits