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 expected:
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 expected:
clang-query> match callExpr(hasAncestor(functionDecl().bind(“contextFuncDef”)).bind(“someFuncCall”)
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 implemented?
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.