提取头文件中的功能列表 [英] extract list of functions in header file
问题描述
我正在寻找一种提取在C ++头文件中找到的所有函数的方法,包括位于函数定义顶部的有关该函数的注释.
I am looking for a way to extract all functions found in a C++ header file including comments for that respective function which sit on top of the function definition.
这个想法是生成文件中所有功能的列表,以便将其转换为CSV或Excel文件.我希望每一行都有
The idea is to produce a list of all functions in the file in order to get it into a CSV or Excel file. I would like to have on each line:
头文件名;仅函数名称;完整的函数签名;该函数的代码注释
Header file name;Function name only;Complete function signature;Comments in code for that function
示例(来自文件someHeader.h):
Example (from file someHeader.h):
// This is the multi-line
// comment for the DoSomething function.
void DoSomething (int CleverParameter);
变成
someHeader.h;DoSomething;void DoSomething (int CleverParameter);This is the multi-line comment for the DoSomething function.
我不需要聪明的解析和类型/依赖关系解析之类的东西.我手上有VisualStudio 2010和2012.也不要害怕Linux或Windows命令行工具.如果在此过程中清除了空白,那就太好了.
I don't need clever parsing and type/dependency resolution or such things. I have VisualStudio 2010 and 2012 at my hands. Also not afraid of Linux or Windows command-line tools. If whitespace gets cleaned up in the process, that would be great.
推荐答案
编写像样的C ++解析器绝非易事.
Writing a decent C++ parser won't be an easy task.
一种可能的解决方案是使用文档生成器,例如 doxygen's ,它不包含完整的C ++解析器,但对于您的目的应该足够了:
A possible solution would be to use a documentation generator such as doxygen's, it doesn't include a complete C++ parser but it should be sufficient for your purpose:
- 使用doxygen生成包含所有函数定义和注释的XML输出
- 使用XSLT样式表或XML解析器生成CSV文件
这不是完美的解决方案,但是它肯定比正则表达式方法更强大,并且不需要很多代码即可使其工作.
It's not the perfect solution, but it would definitely be more robust than a regex approach and won't require a lot of code to get it working.
这篇关于提取头文件中的功能列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!