How to get the namespace name from a clang::CXXRecordDecl?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the namespace name from a clang::CXXRecordDecl?

Keane, Erich via cfe-dev
I'm using an AST matcher to get some `clang::CXXRecordDecl`s, and now I want to get the namespace of that record, but I searched all the apis and cannot find one.

P.S. I dumped the record and found that there's no information about namespaces, does that mean I have to handle finding namespaces as well? If that's the case, an AST matcher seems not very helpful since I have to go through the source code anyway.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to get the namespace name from a clang::CXXRecordDecl?

Keane, Erich via cfe-dev
On 31/07/2020 10:25, Yafei Liu via cfe-dev wrote:
> I'm using an AST matcher to get some `clang::CXXRecordDecl`s, and now I
> want to get the namespace of that record, but I searched all the apis
> and cannot find one.

such information is recorded in the DeclContext chain, reachable via
Decl::getDeclContext

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to get the namespace name from a clang::CXXRecordDecl?

Keane, Erich via cfe-dev
Hi Stephan, I'm sorry I tried some combinations of APIs in getDeclContext, which are related to namespace, but failed, can you show me some examples or related documents?

On Fri, Jul 31, 2020 at 4:32 PM Stephan Bergmann <[hidden email]> wrote:
On 31/07/2020 10:25, Yafei Liu via cfe-dev wrote:
> I'm using an AST matcher to get some `clang::CXXRecordDecl`s, and now I
> want to get the namespace of that record, but I searched all the apis
> and cannot find one.

such information is recorded in the DeclContext chain, reachable via
Decl::getDeclContext


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to get the namespace name from a clang::CXXRecordDecl?

Keane, Erich via cfe-dev
On 31/07/2020 10:49, Yafei Liu wrote:
> Hi Stephan, I'm sorry I tried some combinations of APIs in
> getDeclContext, which are related to namespace, but failed, can you show
> me some examples or related documents?

Take for example the definition of Decl::isInAnonymousNamespace in
clang/lib/AST/DeclBase.cpp.  That should give you an idea.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to get the namespace name from a clang::CXXRecordDecl?

Keane, Erich via cfe-dev
It works, thanks so much!

On Fri, Jul 31, 2020 at 5:04 PM Stephan Bergmann <[hidden email]> wrote:
On 31/07/2020 10:49, Yafei Liu wrote:
> Hi Stephan, I'm sorry I tried some combinations of APIs in
> getDeclContext, which are related to namespace, but failed, can you show
> me some examples or related documents?

Take for example the definition of Decl::isInAnonymousNamespace in
clang/lib/AST/DeclBase.cpp.  That should give you an idea.


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev