[cfe-users] finding in which function/method/scope a Decl is in, the parent so to say

Richard Trieu via cfe-users cfe-users at lists.llvm.org
Fri Nov 11 10:54:09 PST 2016


It sounds like you want the DeclContext.  Use the function
Decl::getDeclContext() to get a DeclContext pointer.  See
http://clang.llvm.org/doxygen/classclang_1_1DeclContext.html for details
about DeclContext.  DeclContext::isTranslationUnit() for globals and
DeclContext::isFunctionOrMethod() for function/method scope.  DeclContext
can also be cast to other Decl types, so for example you could use
dyn_cast<FunctionDecl> to get the function scope.

On Fri, Nov 11, 2016 at 4:06 AM, folkert via cfe-users <
cfe-users at lists.llvm.org> wrote:

> Hi,
>
> How can I find the parent of a VarDecl? The scope it is in. E.g.
> function/method or a global.
>
>
> Folkert van Heusden
> _______________________________________________
> cfe-users mailing list
> cfe-users at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20161111/293689b6/attachment.html>


More information about the cfe-users mailing list