【发布时间】:2018-06-20 13:32:33
【问题描述】:
我正在使用 clang ast 匹配器从源文件中提取一些信息。现在,我还想知道源文件正在使用的标头和依赖标头的列表。例如,源文件 abc.c 的头文件如下:
#include <def.h>
//#include <def_private.h>
在 clang matcher 期间,我需要确保 clang 知道 def.h,它位于同一目录中。 def.h 包含以下标头:
#include <iostream.h>
#include <string.h>
#include <float.h>
#include <math.h>
/*#include <boost>
* #inclde <fstream>*/
我使用 ast matcher 从 abc.c 中提取或识别信息。现在,我想提取所有标题或包含。这应该包括所有这些:
#include <def.h>
#include <iostream.h>
#include <string.h>
#include <float.h>
#include <math.h>
为此我做了一些在线研究,不幸的是,所有这些都涉及正则表达式 (Regular expression to extract header name from c file) 或如何在 Visual Studio 中执行 (Displaying the #include hierarchy for a C++ file in Visual Studio)。
我想知道是否可以使用clang。另外,请告诉我是否有任何其他方法可以以编程方式提取标题,而不仅仅是使用正则表达式。
【问题讨论】:
-
“任何其他方式”是指“使用 clang”,还是任何其他可以让您获得正确答案的方式,无论是否是 clang?
-
以编程方式提取标题的任何其他方法不仅仅是使用正则表达式。换句话说,方法(没有clang也可以,但是程序应该理解header tree)应该能够理解header是什么意思,并且能够区分cmets内部的headers。
-
"区分 cmets 中的标头"??评论可能包含看起来像#include 但它不是的文本,它只是评论文本。您只是指出不应考虑评论内容,对吗?同样的字符串文字内容。 (这对正则表达式来说充其量是尴尬的,同意)。
-
@IraBaxter 你是对的,我只是指出不应考虑评论内容。我将在我的问题中更新这一点,感谢您的澄清。
标签: c++ clang header-files llvm-clang