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

tetra via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 6 01:59:22 PDT 2023


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 <typename T, typename C = bool> 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157205.547532.patch
Type: text/x-patch
Size: 1525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230806/a1d68d8c/attachment.bin>


More information about the cfe-commits mailing list