在不使用编译器的情况下,我可以使用clang获取C / C ++代码的XML AST转储吗? [英] Can I get an XML AST dump of C/C++ code with clang without using the compiler?

查看:560
本文介绍了在不使用编译器的情况下,我可以使用clang获取C / C ++代码的XML AST转储吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法使用cmake和visual studio 10为Windows编译成功clang。我想获得一个XML文件作为源代码的AST表示。有一个选项可以在linux(ubuntu)下使用gcc提供结果,但不能在窗口框中工作:

I managed to compile successfully clang for windows with cmake and visual studio 10. I would like to get an XML file as AST representation of the source code. There is one option that provides the result with clang with gcc under linux (ubuntu) but doesn't work on the windows box:

clang -cc1 -ast-print-xml source.c

但是,这是调用编译阶段(我想避免)。挖掘源代码并没有帮助我,因为我是相当新的ang。我可以使用以下命令生成AST的二进制版本:

However, this is invoking the compilation stage (which I would like to avoid). Digging in the source code didn't help me so far as I am quite new to clang. I could manage to generate the binary version of the AST by using:

clang -emit-ast source.c

不幸的是,此格式无法直接用于解析。是否有一些现有的方法直接生成XML树而不是clang中的二进制树?

Unfortunately, this format is unusable directly for parsing. Is there some existing method to directly generate the XML tree instead of a binary one in clang?

目标是在.NET环境中的其他工具中使用XML表示所以我需要做一些环绕本地clang lib访问二进制AST。也许有第三个选项,如果有人已经为.NET编写了一些二进制clang AST解析器?

The goal is to use the XML representation in other tools in the .NET environment so I would need to make some wrapping around the native clang lib to access the binary AST. Maybe there is a third option if someone already wrote some binary clang AST parser for .NET?

这可能是我缺少的东西,如果蠢产生的AST

Is it possible that I am missing something like if the AST generated by the clang front end is not equivalent to the one generated in the compilation stage.

推荐答案

对于您的信息,XML打印机已从2.9版本由Douglas Gregor负责(负责CLang FrontEnd)。

For you information, the XML printer has been removed from the 2.9 version by Douglas Gregor (responsible of CLang FrontEnd).

问题是缺少XML打印机。许多AST节点从未在打印机中实现,以及一些节点的许多属性,这导致源代码的不准确表示。

The issue was that the XML printer was lacking. A number of the AST nodes had never been implemented in the printer, as well as a number of the properties of some nodes, which led to an inaccurate representation of the source code.

Douglas提出的另一点是,输出应该适合不用于调试CLang本身(这是 -emit-ast 是关于),但是适用于外部工具。这要求输出从一个版本到另一个版本是稳定的。值得注意的是,它不应该是CLang内部的1对1映射,而是将源代码翻译成 standardese 语言。

Another point raised by Douglas was that the output should be suitable not for debugging CLang itself (which is what the -emit-ast is about) but for consumption by external tools. This requires the output to be stable from one version to another. Notably it should not be a 1-on-1 mapping of CLang internal, but rather translate the source code into standardese language.

是打印机上的重要工作(需要志愿者),它不会被集成回...

Unless there is significant work on the printer (which requires volunteers) it will not be integrated back...

这篇关于在不使用编译器的情况下,我可以使用clang获取C / C ++代码的XML AST转储吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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