clang-query:检查函数参数类型的模板参数的名称 [英] clang-query: Examining name of template parameter of a function argument's type

查看:29
本文介绍了clang-query:检查函数参数类型的模板参数的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大项目,以及大量的 C++ 类成员函数:

I have a big project, and a slew of C++ class member functions of the form:

Return CClass::MemberFunction(
   Arg1 arg1,
   //...
   std::weak_ptr<IMemberFunctionListenerInterface> listener) {
//...
}

我正在尝试编写一个匹配器来查找此类函数,这些函数的参数类型为字符串Listener";以他们的名义.

I'm trying to write a matcher that finds functions like these, which have arguments whose types have the string "Listener" in their name.

我可以找到参数类型为weak_ptr"的函数;以他们的名义:

I can find functions with arguments whose types have "weak_ptr" in their name:

clang-query> m cxxMethodDecl(hasAnyParameter(hasType(cxxRecordDecl(matchesName("weak_ptr")))))

这和上面的函数匹配得很好.但是,如果我将 "weak_ptr" 更改为 "Listener",则该函数不再匹配.我猜这是因为它是 std::weak_ptr 类模板的模板参数的名称.

This matches the above function just fine. But if I change "weak_ptr" to "Listener", the function is no longer matched. I'm guessing this is because it is the name of a template parameter to the std::weak_ptr class template.

我已经尝试了这个查询的许多不同变体,但我没有找到与我感兴趣的函数相匹配的那个.

I've tried a lot of different variations of this query, but I haven't hit on the one that matches the functions I'm interested in.

有什么指点吗?

推荐答案

一行:

clang-query> m cxxMethodDecl(hasAnyParameter(hasType(allOf(cxxRecordDecl(matchesName("weak_ptr")), classTemplateSpecializationDecl(hasTemplateArgument(0, templateArgument(refersToType(hasDeclaration(cxxRecordDecl(matchesName(".*Listener")))))))))))

clang 格式:

cxxMethodDecl(hasAnyParameter(
    hasType(allOf(cxxRecordDecl(matchesName("weak_ptr")),
                  classTemplateSpecializationDecl(hasTemplateArgument(
                      0, templateArgument(refersToType(hasDeclaration(
                             cxxRecordDecl(matchesName(".*Listener")))))))))))

这篇关于clang-query:检查函数参数类型的模板参数的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆