简体   繁体   English

使用GNU工具链从文件解析c ++函数头

[英]Parsing c++ function headers from a file using GNU toolchain

I need to parse function headers from a .i file used by SWIG which contains all sorts of garbage beside the function headers. 我需要解析SWIG使用的.i文件中的函数头,其中包含函数头旁边的各种垃圾。 (final output would be a list of function declarations) (最终输出将是函数声明列表)
The best option for me would be using the GNU toolchain (GCC, Binutils, etc..) to do so, but i might be missing an easy way of doing it with SWIG. 对我来说最好的选择是使用GNU工具链(GCC,Binutils等)这样做,但我可能会错过一个简单的方法来使用SWIG。 If I am please tell me! 如果我请告诉我!
Thanks :] 谢谢 :]

edit: I also don't know how to do that with GCC toolchain, if you have an idea it will be great. 编辑:我也不知道如何使用GCC工具链,如果你有一个想法它会很棒。

I would try getting an XML dump of the abstract syntax tree either from clang or from gccxml . 我会尝试从clanggccxml获取抽象语法树的XML转储。 From there you can easily extract the function declarations you are interested in. 从那里,您可以轻松提取您感兴趣的函数声明。

Our DMS Software Reengineering Toolkit provides general purpose program parsing, analysis, and transformation capability. 我们的DMS软件再造工具包提供通用程序解析,分析和转换功能。 It has front ends for a wide variety of languages, including C++. 它有各种语言的前端,包括C ++。

It has been used to analyze and transforms very complex C++ programs and their header files. 它已被用于分析和转换非常复杂的C ++程序及其头文件。

You aren't clear as to what you will do after you "parse the function headers"; 在“解析函数头”之后,您不清楚将要执行的操作; normally people want to extract some information or produce another artifact. 通常人们想要提取一些信息或制作另一件神器。 DMS with its C++ front end can do the parsing; DMS及其C ++前端可以进行解析; you can configure DMS to do the custom stuff. 您可以配置DMS来执行自定义操作。

As a practical matter, this isn't usually an afternoon's exercise; 实际上,这通常不是下午的练习; DMS is a complex beast, because it has to deal with complex beasts such as C++. DMS是一个复杂的野兽,因为它必须处理复杂的野兽,如C ++。 And I'd expect you to face the same kind of complexity for any tool that can handle C++. 而且我希望你能为任何可以处理C ++的工具面对同样的复杂性。 The GCC toolchain can clearly handle C++, so you might be able to do it with that (at that same level of complexity) but GCC is designed to be a compiler, and IMHO you will find it a fight to get it do what you want. GCC工具链可以清楚地处理C ++,所以你可以用它来做(在相同的复杂程度)但GCC被设计成一个编译器,恕我直言你会觉得它是一个让它做想做的事情的斗争。

Your "output function declarations" goal isn't clear. 您的“输出函数声明”目标尚不清楚。 You want just the function names? 你只想要功能名称? You want a function signature? 你想要一个功能签名? You want all the type declarations on which the function depends? 您想要函数所依赖的所有类型声明吗? You want all the type declarations on which the function depends, if they are not already present in an existing include file you intend to use? 您想要函数所依赖的所有类型声明,如果它们尚未存在于您打算使用的现有包含文件中?

The best way to extract function decls from the garbage which is C header files is to substitute out what constitutes the most smelly garbage: macros. 从作为C头文件的垃圾中提取函数的最佳方法是替换掉构成最臭的垃圾:宏。 You can do that with: 你可以这样做:

   cpp - The C Preprocessor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM