This is an archive of the discontinued LLVM Phabricator instance.

[demangler] Improve ->* & .* demangling
ClosedPublic

Authored by urnathan on Jan 28 2022, 9:39 AM.

Details

Summary

The demangler treats ->* as a BinaryExpr, but .* as a MemberExpr. That's inconsistent. This makes the former a MemberExpr too. However, in order to not regress the paren output, MemberExpr::print is modified to parenthesize the MemberExpr if the operator ends with '*'. Printing is affected thusly:

Before:

obj.member
obj->member
obj.*member
(obj) ->* (member)

After:

obj.member   # Unchanged
obj->member  # Unchanged
obj.*(member)  # Added paren member operand
obj->*(member) # Removed paren on object operand, less whitespace

The right solution to the paren problem is to add some notion of precedence (and associativity) to Nodes, but that's a larger change that would become simpler once the refactoring I'm doing is completed.

FWIW, binutils' demangler's paren algorithm has a small idea of precedence, and will generally not emit parens when the operand is unary.

Diff Detail

Event Timeline

urnathan requested review of this revision.Jan 28 2022, 9:39 AM
urnathan created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 28 2022, 9:39 AM
ChuanqiXu added inline comments.Feb 6 2022, 7:29 PM
libcxxabi/src/demangle/ItaniumDemangle.h
1804

Should we add a comment here? It is confusing for reader who don't have a background.

urnathan updated this revision to Diff 406477.Feb 7 2022, 8:25 AM

clarifying comment

urnathan marked an inline comment as done.Feb 7 2022, 8:25 AM
bruno accepted this revision.Feb 7 2022, 2:42 PM

The right solution to the paren problem is to add some notion of precedence (and associativity) to Nodes, but that's a larger change that would become simpler once the refactoring I'm doing is completed.

Is this worth putting in a FIXME somewhere as part of this patch? Or is this being tracked elsewhere?

Other than that, LGTM.

This revision is now accepted and ready to land.Feb 7 2022, 2:42 PM

The right solution to the paren problem is to add some notion of precedence (and associativity) to Nodes, but that's a larger change that would become simpler once the refactoring I'm doing is completed.

Is this worth putting in a FIXME somewhere as part of this patch? Or is this being tracked elsewhere?

I'm actively working on it right now :)

This revision was landed with ongoing or failed builds.Feb 8 2022, 6:29 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2022, 6:29 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript