如何在clang libtooling的功能分析中排除内置/系统功能

时间:2017-07-08 21:47:29

标签: clang llvm llvm-clang libtooling

我正在尝试使用clang libtooling来分析函数。 以下是我要分析的源代码:

#include <stdio.h>

int main(){
    int a = 100;
    printf("a==%d", a);
}

当我运行我的工具以获取上述文件中的所有函数decl时,我发现有很多内置/系统函数,例如:

decls: 
_IO_cookie_init
 __underflow
 __uflow
 __overflow
 _IO_getc
 _IO_putc
 _IO_feof
 _IO_ferror
 _IO_peekc_locked
 _IO_flockfile
 _IO_funlockfile
 _IO_ftrylockfile
 _IO_vfscanf
 _IO_vfprintf
 _IO_padn
 _IO_sgetn
 _IO_seekoff
 _IO_seekpos
 _IO_free_backup_area
 remove
 rename
 renameat
 tmpfile
 tmpfile64
 tmpnam
 tmpnam_r
 tempnam
 fclose
 fflush
 fflush_unlocked
 fcloseall
 fopen

(我认为它们是由头文件“stdio.h”引入的)

我的问题是: 如何从“stdio.h”文件或其他(系统)头文件中删除所有这些内置/系统函数?

提前致谢!!!

1 个答案:

答案 0 :(得分:2)

访问函数时,使用SourceManagers api'isInSystemHeader(loc)'检查其位置(startLoc或endLoc)是否在系统头中

e.g:

Bool VisitFunctionDecl(FunctionDecl * D)
{
    If(sourceManager.isInSystemHeader(D->getLocStart()))
        return true;
}

谢谢, 与Hemant

相关问题