Matching DeclRefExpr of type T (clang-tidy)

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

Matching DeclRefExpr of type T (clang-tidy)

Nat! via cfe-dev

Hi,

 

I’m trying to match certain expressions with clang-tidy, see code:

 

template<typename T>

using Addr32 = T;

 

Addr32<int>* p32 = nullptr;

int* p64 = p32;                      // I want to match this

int* pTestNative = p64;              // I don't want to match this

 

int main()

{

}

 

So I want to match any DeclRefExpr whose type is Addr32<T>, but I can’t figure out how.

The closest I’ve gotten using clang-query is match declRefExpr(hasType( asString("Addr32<int> *") )), but I don’t want to have the specify the type int. I want to match all possible types Addr32<T>.

Any ideas?

Patrik Eklöf
Programmer
[hidden email]

cid:BE4BF572-C003-4AAA-B3E1-F94F88D12D24@netgear.local


VMS Software, inc.

Skeppsgatan 19, SE-211 11 Malmö Sweden
http://vmssoftware.com/

 

 

 


_______________________________________________
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 DeclRefExpr of type T (clang-tidy)

Nat! via cfe-dev
Hello!

Apologies for the late reply, but in case it's helpful, it looks like the following may be a good (though moderately verbose) starting point :)

declRefExpr(hasType(pointsTo(templateSpecializationType(hasDeclaration(
  typeAliasTemplateDecl(hasName("Addr32")))))))


George

On Tue, Apr 25, 2017 at 3:54 AM, Patrik Eklöf via cfe-dev <[hidden email]> wrote:

Hi,

 

I’m trying to match certain expressions with clang-tidy, see code:

 

template<typename T>

using Addr32 = T;

 

Addr32<int>* p32 = nullptr;

int* p64 = p32;                      // I want to match this

int* pTestNative = p64;              // I don't want to match this

 

int main()

{

}

 

So I want to match any DeclRefExpr whose type is Addr32<T>, but I can’t figure out how.

The closest I’ve gotten using clang-query is match declRefExpr(hasType( asString("Addr32<int> *") )), but I don’t want to have the specify the type int. I want to match all possible types Addr32<T>.

Any ideas?

Patrik Eklöf
Programmer
[hidden email]

cid:BE4BF572-C003-4AAA-B3E1-F94F88D12D24@netgear.local


VMS Software, inc.

Skeppsgatan 19, SE-211 11 Malmö Sweden
http://vmssoftware.com/

 

 

 


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



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