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

发布于 2024-10-07 09:11:35 字数 208 浏览 7 评论 0原文

我需要从 SWIG 使用的 .i 文件中解析函数头,该文件除了函数头之外还包含各种垃圾。 (最终输出将是函数声明列表)
对我来说最好的选择是使用 GNU 工具链(GCC、Binutils 等)来执行此操作,但我可能缺少使用 SWIG 执行此操作的简单方法。如果我是请告诉我!
谢谢:]

编辑:我也不知道如何使用 GCC 工具链来做到这一点,如果你有一个想法那就太好了。

I need to parse function headers from a .i file used by SWIG which contains all sorts of garbage beside the function headers. (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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以可爱出名 2024-10-14 09:11:35

我会尝试从 clanggccxml。从那里您可以轻松提取您感兴趣的函数声明。

I would try getting an XML dump of the abstract syntax tree either from clang or from gccxml. From there you can easily extract the function declarations you are interested in.

夜声 2024-10-14 09:11:35

我们的 DMS 软件重组工具包提供通用程序解析、分析和转换功能。它具有多种语言的前端,包括 C++。

它已被用来分析和转换非常复杂的 C++ 程序及其头文件。

您不清楚“解析函数头”后要做什么;通常人们想要提取一些信息或产生另一个工件。 DMS 及其 C++ 前端可以进行解析;您可以配置 DMS 来执行自定义操作。

实际上,这通常不是一个下午的练习;而是一个下午的练习。 DMS 是一个复杂的野兽,因为它必须处理诸如 C++ 之类的复杂野兽。我预计对于任何可以处理 C++ 的工具,您都会面临同样的复杂性。 GCC 工>你想要的。

您的“输出函数声明”目标尚不清楚。您只想要函数名称吗?你想要一个函数签名吗?您想要该函数所依赖的所有类型声明吗?您想要该函数所依赖的所有类型声明(如果它们尚未存在于您打算使用的现有包含文件中)?

Our DMS Software Reengineering Toolkit provides general purpose program parsing, analysis, and transformation capability. It has front ends for a wide variety of languages, including C++.

It has been used to analyze and transforms very complex C++ programs and their header files.

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; you can configure DMS to do the custom stuff.

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++. And I'd expect you to face the same kind of complexity for any tool that can handle 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.

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?

糖粟与秋泊 2024-10-14 09:11:35

从垃圾(即 C 头文件)中提取函数 decls 的最佳方法是替换最臭的垃圾:宏。您可以通过以下方式做到这一点:

   cpp - The C Preprocessor

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. You can do that with:

   cpp - The C Preprocessor
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文