[all-commits] [llvm/llvm-project] 28669b: [demangler] Improve ->* & .* demangling

Nathan Sidwell via All-commits all-commits at lists.llvm.org
Tue Feb 8 06:28:58 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 28669bd091e1542d8318bec4cb2219d65cb73b07
      https://github.com/llvm/llvm-project/commit/28669bd091e1542d8318bec4cb2219d65cb73b07
  Author: Nathan Sidwell <nathan at acm.org>
  Date:   2022-02-08 (Tue, 08 Feb 2022)

  Changed paths:
    M libcxxabi/src/demangle/ItaniumDemangle.h
    M libcxxabi/test/test_demangle.pass.cpp
    M llvm/include/llvm/Demangle/ItaniumDemangle.h
    M llvm/include/llvm/Demangle/StringView.h
    M llvm/include/llvm/Demangle/Utility.h

  Log Message:
  -----------
  [demangler] Improve ->* & .* demangling

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.

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D118486




More information about the All-commits mailing list