This is an archive of the discontinued LLVM Phabricator instance.

[lldb/libc++] Simplify the libc++ string formatter
ClosedPublic

Authored by labath on Jul 11 2022, 8:10 AM.

Details

Summary

Precise string layout has changed a lot recently, but a long of these
changes did not have any effect on the usages of its fields -- e.g.
introduction/removal of an anonymous struct or union does not change the
way one can access the field in C++. Our name-based variable lookup
rules (deliberately) copy the C++ semantics, which means these changes
would have been invisible to the them, if only we were using name-based
lookup.

This patch replaces the opaque child index accesses with name-based
lookups, which allows us to greatly simplify the data formatter code.
The formatter continues to support all the string layouts that it
previously supported.

It is unclear why the formatter was not using this approach from the
beginning. I would speculate that the original version was working
around some (now fixed) issue with anonymous members or base classes,
and the subsequent revisions stuck with that approach out of inertia.

Diff Detail

Event Timeline

labath created this revision.Jul 11 2022, 8:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 8:10 AM
labath requested review of this revision.Jul 11 2022, 8:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 8:10 AM
mib accepted this revision.Jul 11 2022, 1:44 PM

This is great! Thanks for taking care of this! LGTM!

lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
608–609

Nit: In the if statement it's called size_mode but it the other branch (line 603) it's called size_member. Would be nice to make it more consistent.

This revision is now accepted and ready to land.Jul 11 2022, 1:44 PM
labath marked an inline comment as done.Jul 12 2022, 12:58 AM
labath added inline comments.
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
608–609

Done. I've also moved the common statement before the branch.

This revision was automatically updated to reflect the committed changes.
labath marked an inline comment as done.

Thanks. I can see the problem. rGa72306e202e ought to fix it.