[cfe-dev] AST Matcher question -- hasAncestor
Manuel Klimek via cfe-dev
cfe-dev at lists.llvm.org
Sun Sep 25 23:41:30 PDT 2016
On Wed, Sep 21, 2016 at 8:19 PM Riyaz Puthiyapurayil via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> I am new to both clang AST Matchers. From an AST Matcher in a clang tidy
> check, what is the fastest way to get the enclosing function or method
> scope (if any) from a matching CallExpr node?
> I tried something like this in clang-query and it seems to work as
> clang-query> match
> But how does it work internally? Specifically, will it traverse up the AST
> to bind contextFuncDef every time callExpr is matched? That may be too
> expensive for my use. Or alternatively, does it save the matching ancestor
> in contextFuncDef as it descends down the AST?
Both. It memoizes the results of hasAncestor on every level.
> Or the more general question would be: are matchers evaluated inside-out
> or outside-in or in some other way depending on the type of matcher. Is
> there any documentation outside of source code describing how matchers are
The behavior is "as-if" you just run over the AST and match every node. The
implementation detail to make this fast is that it uses memoization.
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev