[Lldb-commits] [PATCH] D60410: PDBFPO: Improvements to the AST visitor

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 8 08:48:25 PDT 2019


labath created this revision.
labath added reviewers: aleksandr.urakov, amccarth.

This patch attempts to solve two issues made this code hard to follow
for me.

The first issue was that a lot of what these visitors do is mutate the
AST. The visitor pattern is not particularly good for that because by
the time you have performed the dynamic type dispatch, it's too late to
go back to the parent node, and change its pointer. The previous code
dealt with that relatively elegantly, but it still meant that one had to
perform manual type checks, which is what the visitor pattern is
supposed to avoid.

The second issue was not being able to return values from the Visit
functions, which meant that one had to store function results in member
variables (a common problem with visitor patterns).

Here, I try to solve both problems by making the visitor a CRTP
template. This allows one to parameterize the visitor based on the
return type and pass function results as function results. The mutation
is fascilitated by having each Visit function take two arguments -- a
reference to the object itself (with the correct dynamic type), and a
reference to the parent's pointer to this object.

Although this wasn't my explicit goal here, the fact that we're not
using virtual dispatch anymore (not possible due to return type
templatization) allows us to make the AST nodes trivially destructible,
which is a good thing, since we were not destroying them anyway.


https://reviews.llvm.org/D60410

Files:
  source/Plugins/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpression.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60410.194155.patch
Type: text/x-patch
Size: 14403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190408/85be58d0/attachment.bin>


More information about the lldb-commits mailing list