[PATCH] D120905: [demangler] Add operator precedence

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 06:46:37 PST 2022


urnathan created this revision.
urnathan added reviewers: bruno, ChuanqiXu, iains.
Herald added a project: All.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The demangler had no concept of operator precendence, and would parenthesize many more subexpressions than necessary.  In particular it would parenthesize primary-expressions, such as '4', which just looks strange.  It would also parenthesize '>' expressions, just in case they were inside a template parameter list.

This patch fixes both issues.

- Add operator precedence to the OpInfo structure, and add a subexpression helper that will parenthesize a lower precedence subexpression.

- Add a 'greater-than is greater-than' indicator to the output buffer, so the expression printer knows whether it is immediately inside a template parameter list (and must therefore parenthesize 'expr > expr').  This is a counter, so that ...

- Add open and close printers to the output buffer, that increment and decrement the gt-is-gt indicator.

- Parenthesize comma operators inside comma-separated lists. (probably a rare case, but still).

This dramatically reduces the extraneous parentheses being printed.


https://reviews.llvm.org/D120905

Files:
  libcxxabi/src/demangle/ItaniumDemangle.h
  libcxxabi/src/demangle/Utility.h
  libcxxabi/test/test_demangle.pass.cpp
  llvm/include/llvm/Demangle/ItaniumDemangle.h
  llvm/include/llvm/Demangle/Utility.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120905.412705.patch
Type: text/x-patch
Size: 205803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220303/7e64e983/attachment-0001.bin>


More information about the llvm-commits mailing list