diff options
author | Pavel Labath <pavel@labath.sk> | 2019-04-12 07:19:00 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-04-12 07:19:00 +0000 |
commit | 85ce053d7e2614d65b3506b3a32748c8454f3810 (patch) | |
tree | 39c072811d989f2b92c95bf098b66d76e50a9285 /lldb/packages/Python/lldbsuite/test/python_api | |
parent | b6926bdcff6d4fb9ef9daf53dc4c308f8f2ebf78 (diff) | |
download | bcm5719-llvm-85ce053d7e2614d65b3506b3a32748c8454f3810.tar.gz bcm5719-llvm-85ce053d7e2614d65b3506b3a32748c8454f3810.zip |
PDBFPO: Improvements to the AST visitor
Summary:
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 solve both problems by making the visitor use a type switch
instead of going through double dispatch on the visited object. 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 allows us to make the AST nodes
trivially destructible, which is a good thing, since we were not
destroying them anyway.
Reviewers: aleksandr.urakov, amccarth
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D60410
llvm-svn: 358261
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/python_api')
0 files changed, 0 insertions, 0 deletions