使用CAST AST解析器忽略丢失的标头 [英] Ignore missing headers with clang AST parser

查看:134
本文介绍了使用CAST AST解析器忽略丢失的标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上,使用MSVC编译我的项目,但我需要使用clang进行整洁的AST解析器,这使我可以编写一些代码生成器。

问题是,clang无法解析MSVC标头(一个众所周知的和可以理解的问题)。

I'm on Windows, using MSVC to compile my project, but I need clang for its neat AST parser, which allow me to write a little code generator.
Problem is, clang cannot parse MSVC headers (a very-well known and understandable problem).

我尝试了两种选择:


  1. 我包括MSVC标头文件夹,解析代码中包含的内置标头将最终导致致命错误,从而使我无法正确解析我想要的部分。

  2. 我之前所做的只是不提供任何内置标头,而是向前声明我需要的类型。它运行良好,并且以某种方式在最新的Clang中不再可用。我真的不知道丢失标头的解析器策略是否已更改,但是每次包含< string> 之类的东西而导致解析失败时,它都会导致完全失败。

  1. I include MSVC header folder, parsing the built-in headers included in my code will end-up leading to a fatal error at some point, preventing me from parsing the parts I want correctly.
  2. What I did before is simply not provide any built-in headers and forward declare the types I needed. It worked fine and somehow it doesn't anymore with latest Clang. I don't really know if the parser policy on missing header changed, but it is causing complete failure every time something like <string> is included and not much get parsed.

我正在使用python绑定(libclang),但如果有解决方案,我会考虑切换到C / C ++ API

I am using the python bindings (libclang), but I would consider switching to C/C++ API if there would be a solution there.

无论如何,我是否可以更改此行为,并使clang继续解析,即使未找到某些标头?

Is there anyway I can alter this behavior and make clang continue parsing even when some headers are not found ?

推荐答案

使用SetSuppressIncludeNotFoundError。花了我一个小时才找到!您可以想象我能多么高兴找到它!

Use SetSuppressIncludeNotFoundError. Took me an hour to find! You can imagine how glad I was to find it!

https:// clang .llvm.org / doxygen / classclang_1_1Preprocessor.html#ac7bafe67fc32e41460855b39d20ff6af

这篇关于使用CAST AST解析器忽略丢失的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆