Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Clang AST Match调用使_与特定类唯一_C++_Clang_Abstract Syntax Tree_Clang Ast Matchers - Fatal编程技术网

C++ Clang AST Match调用使_与特定类唯一

C++ Clang AST Match调用使_与特定类唯一,c++,clang,abstract-syntax-tree,clang-ast-matchers,C++,Clang,Abstract Syntax Tree,Clang Ast Matchers,我正试图使用clang的AST匹配器来针对如下代码: #包括 名称空间演示{ 类控件{}; } int main(){ 自动w=std::使_唯一(); } 在clang query中,我尝试了以下方法: callExpr(被调用方(functionDecl( //仅包含此参数将提供匹配项 hasName(“使_独一无二”), //添加第二个参数将产生零个匹配项 hasTemplateArgument(0,referestotype(asString(“Demo::Widget”)) )))

我正试图使用clang的AST匹配器来针对如下代码:

#包括
名称空间演示{
类控件{};
}
int main(){
自动w=std::使_唯一();
}
在clang query中,我尝试了以下方法:

callExpr(被调用方(functionDecl(
//仅包含此参数将提供匹配项
hasName(“使_独一无二”),
//添加第二个参数将产生零个匹配项
hasTemplateArgument(0,referestotype(asString(“Demo::Widget”))
)))
我还尝试将
refrestotype(…)
替换为

referestodeclaration(cxxRecordDecl(isSameOrDerivedFrom(“Demo::Widget”))

这也给出了零匹配。我可以使用什么来定位对特定类型上模板化的
std::make_unique
的调用?

通过模板参数的实际类型使用clang-10.0.0

clang-query> match callExpr(callee(functionDecl(hasName("make_unique"),
                             hasAnyTemplateArgument(refersToType(hasDeclaration(
                                 namedDecl(hasName("Demo::Widget"))))))))

Match #1:

/tmp/test.cpp:8:18: note: "root" binds here
        auto w = std::make_unique<Demo::Widget>();
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 match.
clangquery>match callExpr(被调用方(functionDecl(hasName)(“make_unique”),
hasAnyTemplateArgument(引用类型)(hasDeclaration(
namedDecl(hasName(“演示::小部件”()()())())()))
匹配#1:
/tmp/test.cpp:8:18:注意:“root”在这里绑定
自动w=std::使_唯一();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1场比赛。

通过模板参数的实际类型使用clang-10.0.0

clang-query> match callExpr(callee(functionDecl(hasName("make_unique"),
                             hasAnyTemplateArgument(refersToType(hasDeclaration(
                                 namedDecl(hasName("Demo::Widget"))))))))

Match #1:

/tmp/test.cpp:8:18: note: "root" binds here
        auto w = std::make_unique<Demo::Widget>();
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 match.
clangquery>match callExpr(被调用方(functionDecl(hasName)(“make_unique”),
hasAnyTemplateArgument(引用类型)(hasDeclaration(
namedDecl(hasName(“演示::小部件”()()())())()))
匹配#1:
/tmp/test.cpp:8:18:注意:“root”在这里绑定
自动w=std::使_唯一();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1场比赛。

您需要
引用类型(asString(“class Demo::Widget”))


不幸的是,这不是很容易发现。我在这里展示了一些工具,可以发现这个问题:但目前还没有普遍可用。

您需要
referestotype(asString(“class Demo::Widget”))

不幸的是,这不是很容易发现。我在这里展示了一些工具来发现这个问题:但目前还没有普遍可用