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
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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits