[PATCH] D50930: Move Itanium demangler implementation into a header file and add visitation support.

Richard Smith - zygoloid via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 17 15:58:59 PDT 2018


rsmith created this revision.
rsmith added reviewers: erik.pilkington, zturner, chandlerc, dlj.
Herald added subscribers: llvm-commits, aheejin.

This transforms the Itanium demangler into a generic reusable library that can
be used to build, traverse, and transform Itanium mangled name trees.

This is in preparation for adding a canonicalizing demangler, which
cannot live in the Demangle library for layering reasons. In order to
keep the diffs simpler, this patch moves more code to the new header
than is strictly necessary: in particular, all of the printLeft /
printRight implementations can be moved to the implementation file.
(And indeed we could make them non-virtual now if we wished, and remove
the vptr from Node.)

All nodes are now included in the Kind enumeration, rather than omitting
some of the Expr nodes, and the three different floating-point literal
node types now have distinct Kind values.

As a proof of concept for the visitation / matching mechanism, this
patch implements a Node dumping facility on top of it, replacing the
prior mechanism that produced the pretty-printed output rather than a
tree dump. Sample dump output:

FunctionEncoding(

  NameType("int"),
  NameWithTemplateArgs(
    NestedName(
      NameWithTemplateArgs(
        NameType("A"),
        TemplateArgs(
          {NameType("B")})),
      NameType("f")),
    TemplateArgs(
      {NameType("int")})),
  {},
  <null>,
  QualConst, FunctionRefQual::FrefQualLValue)

As a next step, it would make sense to move the LLVM high-level interface to
the demangler (the itaniumDemangler function and ItaniumPartialDemangler class)
into the Support library, and implement them in terms of the Demangle library.
This would allow the libc++abi demangler implementation to be an identical copy
of the llvm Demangle library, and would allow the LLVM implementation to reuse
LLVM components such as llvm::BumpPtrAllocator, but we'll need to decide how to
coordinate that with the MS ABI demangler, so I'm not doing that in this patch.

No functionality change intended other than the behavior of dump().


Repository:
  rL LLVM

https://reviews.llvm.org/D50930

Files:
  include/llvm/Demangle/Compiler.h
  include/llvm/Demangle/ItaniumDemangle.h
  include/llvm/Demangle/StringView.h
  include/llvm/Demangle/Utility.h
  lib/Demangle/Compiler.h
  lib/Demangle/ItaniumDemangle.cpp
  lib/Demangle/MicrosoftDemangle.cpp
  lib/Demangle/StringView.h
  lib/Demangle/Utility.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50930.161353.patch
Type: text/x-patch
Size: 219268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180817/f20d61df/attachment-0001.bin>


More information about the llvm-commits mailing list