如何从clang中排除头文件? [英] How to exclude headers from AST in clang?
问题描述
我使用clang生成AST。我有以下文件(lambda.cpp)来解析:
I'm generating AST using clang. I've got following file (lambda.cpp) to parse:
#include <iostream>
void my_lambda()
{
auto lambda = [](auto x, auto y) {return x + y;};
std::cout << "fabricati diem";
}
我使用以下命令解析此命令:
I'm parsing this using following command:
clang -Xclang -ast-dump -fsyntax-only lambda.cpp
问题是,clang也解析头部内容。结果,我有相当大(〜3000行)文件与无用的(为我的)内容。
The problem is that clang parses also headers content. As a result, I've got quite big (~3000 lines) file with useless (for me) content.
如何在生成AST时排除标题?
How to exclude headers when generating AST?
推荐答案
clang-check
c $ c> clang-check 具有 -ast-dump-filter =< string>
选项
clang-check
might be useful on the matter, clang-check
has option -ast-dump-filter=<string>
documented as follow
-ast-dump-filter =&string; - 与-ast-dump或-ast-print一起使用,只转储/打印在
限定名中具有某个子字符串的AST声明节点。当clang-check时,使用-ast-list列出所有可过滤的声明节点
名称。
-ast-dump-filter=<string> - Use with -ast-dump or -ast-print to dump/print only AST declaration nodes having a certain substring in a qualified name. Use -ast-list to list all filterable declaration node names.
使用示例代码(lambda.cpp)上的 -ast-dump-filter = my_lambda
运行
#include <iostream>
void my_lambda()
{
auto lambda = [](auto x, auto y) {return x + y;};
std::cout << "fabricati diem";
}
它只转储匹配的声明节点 FunctionDecl my_lambda'void (void)'
It dumps only matched declaration node FunctionDecl my_lambda 'void (void)'
这是命令行参数和输出中的几行。
Here is the command line arguments and few lines from output.
$ clang-check -extra-arg=-std=c++1y -ast-dump -ast-dump-filter=my_lambda lambda.cpp --
FunctionDecl 0x2ddf630 <lambda.cpp:3:1, line:7:1> line:3:6 my_lambda 'void (void)'
`-CompoundStmt 0x2de1558 <line:4:1, line:7:1>
|-DeclStmt 0x2de0960 <line:5:9, col:57>
这篇关于如何从clang中排除头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!