[cfe-dev] AST Matcher matches InitListExpr child twice
Manuel Klimek via cfe-dev
cfe-dev at lists.llvm.org
Tue Jun 13 00:17:25 PDT 2017
On Mon, Jun 12, 2017 at 7:54 PM Ben Liblit via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> Stephan Bergmann <sbergman at redhat.com> wrote:
> > That looks to be by design, cf. DEF_TRAVERSE_STMT(InitListExpr,...) in
> > include/clang/AST/RecursiveASTVisitor.h calling into
> > TraverseSynOrSemInitListExpr twice (for "syntactic" and "semantic"
> > InitListExpr).
>
> Nutty! But clearly by design, as you point out. There seems to be no
> way to detect this duplication short of maintaining my own "nodes I have
> already seen" set, and no way to prevent double visits short of defining
> my own RecursiveASTVisitor.
>
> > In some of our LibreOffice RecursiveASTVisitor implementations we use
> > [...] to traverse only once
>
> Thank you for this example code, Stephan. Unfortunately I see no way to
> tell the AST Matcher system to use an alternate visitor of this sort.
> Am I missing some API that would let me do this? Or is the recursive
> visit outside of my control if I'm using MatchFinder to drive my tool?
>
Generally, there are many reasons you might visit the same node twice -
after all, the AST is not a tree, but a graph :) When you write tools that
need to run on multiple TUs, you'll have to do some form of deduplication
anyway.
Generally, use the fact that many nodes have pointer identity (you can
deduplicate with a simple set on the pointers).
>
> -- Ben
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170613/7349923f/attachment.html>
More information about the cfe-dev
mailing list