简体   繁体   English

clang 3.8-如何阻止clang创建系统标头的AST?

[英]clang 3.8 - How to stop clang from creating AST of system headers?

I recently started using using Clang 3.8 on Fedora 22 machine to make a tool which parses the clang AST and extracts some information from AST nodes. 我最近开始在Fedora 22机器上使用Clang 3.8制作一个工具,该工具可以解析clang AST并从AST节点中提取一些信息。 The tool is expected to read in C,C++, and SystemC files. 该工具有望在C,C ++和SystemC文件中读取。

When I read a file and dump the AST using my tool, it shows me the AST for the system headers as well. 当我读取文件并使用工具转储AST时,它也向我显示了系统标头的AST。

Hence my question: How can I ask my tool not to display the AST of system headers? 因此,我的问题是:我该如何要求我的工具不显示系统标头的AST? Because i will be modifying the files and I am afraid that system headers will create an overhead. 因为我将要修改文件,而且恐怕系统头会产生开销。

PS. PS。 I have already tried isInSystemHeader() function, but it is not helpful. 我已经尝试过isInSystemHeader()函数,但是它没有帮助。 Because the parser just keeps digging in the system headers and at some point generates the error. 因为解析器只是不断挖掘系统头文件,并且在某些时候会产生错误。 The error is 错误是

"/llvm/tools/clang/lib/Basic/SourceLocation.cpp:117: bool clang::FullSourceLoc::isInSystemHeader() const: Assertion `isValid()' failed.

Aborted (core dumped)" 中止(核心已弃用)”

Pointers to solution, or solutions will be highly appreciated :) Thanks. 解决方案或解决方案的指针将不胜感激:)谢谢。

try: 尝试:

FullSourceLoc fullSourceLoc(decl->getLocation(), astContext.getSourceManager());
if (fullSourceLoc.isValid() && !fullSourceLoc.isInSystemHeader()) {
     // system header excluded here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM