[cfe-dev] How do I retrieve all non-local variables a function has access to?
Artem Dergachev via cfe-dev
cfe-dev at lists.llvm.org
Sun Jul 21 08:04:12 PDT 2019
Note that match() doesn't automatically recursively descend into the
node. So it should be either matchAST(varDecl()) or
match(translationUnitDecl(forEachDescendant(varDecl()))).
Generally, though, i'd recommend taking a look at DeclContext's methods
to see if you have anything readily available. Or, at least, you should
probably take a look how DeclContext::lookup() is implemented.
On 7/21/19 3:42 AM, Kristóf Umann via cfe-dev wrote:
> Hi!
>
> I'm trying to implement a primitive reaching definitions algorithm for
> C++, but am struggling a bit. I'd like to make all function calls be
> definitions of global/static variables, but I can't seem to retrieve
> them.
>
> I tried using AST matchers (match() to be precise) on a
> TranslationUnitDecl, but I can't seem to be able to match varDecl()s
> at all. Is there a reason for this? When I use clang-query, "m
> varDecl()" works like a charm, but match() doesn't seem to.
>
> In any case, I can retrieve local variables by matching declStmt() and
> some non-local ones when inspecting the LHS of assignments (I need to
> do this anyways to find all definitions), but I feel like I'm not the
> first person trying to recover all accessible variables to a function.
> Could anyone give me some guidance please? :)
>
> Cheers!
> Kristóf
>
> P.S. This is the patch I'm working on: https://reviews.llvm.org/D64991
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list