我正在使用 pycparser 解析 C 源代码的项目。
因此,当我运行预处理器时,使用https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html我在我的预处理翻译单元中有 #linenum filename flags linemarkers。
但是,当我解析gcc -E
使用 pycparser 的输出时,标记嵌入了坐标(文件、行、列),但它们似乎不包含来自 linemarkers 标志的任何对我非常有用的信息。
在我的 AST 中包含线标记或将信息嵌入 AST 令牌中的任何解决方案或建议?
更新 我需要的是通过我的令牌并了解它们所属的文件(这已经在 pycparser 中)以及如何包含该文件。
此信息位于预处理器引入的留置权标记的标志字段中。确实,如果我有:
<tokens of file1.h>
<tokens of file2.h>
<tokens of main.c>
file2.h 的包含可能在 file1.h 或 main.c 中。我需要使用 pycparser 提取此信息。我知道我可以使用 gcc -H 并进行大量分析和处理等来摆脱它。但是,线标记的标志元素会报告我是打开文件还是从文件返回,因此它包含有关嵌套包含的信息。这个信息在pycparser的某个地方吗?可以以某种方式简单地添加吗?