0

我正在尝试使用 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”文件或其他(系统)头文件中删除所有这些内置/系统函数?

提前致谢!!!

4

1 回答 1

2

当您访问一个函数时,使用 SourceManagers api 'isInSystemHeader(loc)' 检查它的位置(startLoc 或 endLoc)是否在系统标头中

例如:

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

谢谢,赫曼特

于 2017-07-11T01:19:14.287 回答