Matching a function in global namespace

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

Matching a function in global namespace

Manuel Klimek via cfe-dev
Hi all,

I know how to match a function by its name, but how is it possible to check that it's in the global namespace or namespace Foo? 

Regards 

Matthieu Brucher 

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

Re: Matching a function in global namespace

Manuel Klimek via cfe-dev
Hi,

On Thu, Mar 29, 2018 at 03:58:36PM +0000, Matthieu Brucher via cfe-dev <[hidden email]> wrote:
> I know how to match a function by its name, but how is it possible to check
> that it's in the global namespace or namespace Foo?

Let's say you have:

----
int foo();

namespace n
{
    int foo();
}
----

If you load this into clang-query, then just functionDecl() matches both
function declarations, but
functionDecl(hasParent(translationUnitDecl())) only matches the one in
the global namespace.

HTH,

Miklos

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

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Matching a function in global namespace

Manuel Klimek via cfe-dev


Le ven. 30 mars 2018 à 00:22, Miklos Vajna <[hidden email]> a écrit :
Hi,

On Thu, Mar 29, 2018 at 03:58:36PM +0000, Matthieu Brucher via cfe-dev <[hidden email]> wrote:
> I know how to match a function by its name, but how is it possible to check
> that it's in the global namespace or namespace Foo?

Let's say you have:

----
int foo();

namespace n
{
    int foo();
}
----

If you load this into clang-query, then just functionDecl() matches both
function declarations, but
functionDecl(hasParent(translationUnitDecl())) only matches the one in
the global namespace.

HTH,

Miklos

That was my missing piece, thanks a lot! With allOf, I can combine this with what I want to create and I suppose that even I could use namespaceDecl for hasParent as well. 

Thanks, I will end up figuring this by myself... 

Regards 

Matthieu Brucher 

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