如何从C#解析/简单分析C/C ++代码以获取方法列表 [英] How to parse/simple analyze C/C++ code from C# to get a list of methods

查看:91
本文介绍了如何从C#解析/简单分析C/C ++代码以获取方法列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要遍历C/C ++文件并提取类和方法的列表以及它们在文件中的位置.

I need to go through a C/C++ file and extract the list of classes and methods and where they're located on the file.

libclang是最好的选择吗?还是该任务太多"了?

Is libclang the best option? Or is it "too much" for the task?

只寻找配对括号会更好吗?

Would it be better to just look for pairing brackets?

如果选择libclang:有没有办法从c#调用它?

In case libclang is the choice: is there a way to invoke it from c#?

谢谢!

推荐答案

您可以考虑使用 ctags .许多平台.输出易于解析,并包含您所需的全部信息.

You could consider ctags, available on many platforms. The output is easily parsable, and full of info you required.

更多信息 对于您的问题,我不得不寻找许多可用的选项,然后我找到了.例如:

more info For your question, I had to look to the many options available, and after a little I found it. For example:

ctags -N -x --c-kinds=+p crowd.*

产生此输出

CrowdSim         class        44 crowd.h          class CrowdSim
CrowdSim         function     47 crowd.h          CrowdSim( const std::string& contentDir ) : _contentDir( contentDir ) {}
Particle         function     35 crowd.h          Particle()
Particle         struct       25 crowd.h          struct Particle
_contentDir      member       56 crowd.h          std::string _contentDir;
_crowd_H_        macro        18 crowd.h          #define _crowd_H_
_particles       member       57 crowd.h          std::vector< Particle > _particles;
animTime         member       32 crowd.h          float animTime;
chooseDestination function     24 crowd.cpp        void CrowdSim::chooseDestination( Particle &p )
chooseDestination prototype    53 crowd.h          void chooseDestination( Particle &p );
dx               member       28 crowd.h          float dx, dz; // Destination position
dz               member       28 crowd.h          float dx, dz; // Destination position
fx               member       29 crowd.h          float fx, fz; // Force on particle
fz               member       29 crowd.h          float fx, fz; // Force on particle
init             function     35 crowd.cpp        void CrowdSim::init()
init             prototype    49 crowd.h          void init();
node             member       31 crowd.h          H3DNode node;
ox               member       30 crowd.h          float ox, oz; // Orientation vector
oz               member       30 crowd.h          float ox, oz; // Orientation vector
px               member       27 crowd.h          float px, pz; // Current postition
pz               member       27 crowd.h          float px, pz; // Current postition
update           function     68 crowd.cpp        void CrowdSim::update( float fps )
update           prototype    50 crowd.h          void update( float fps );

(注意:-x仅用于方便用户检查)

(note: -x is only for easy user inspection)

这篇关于如何从C#解析/简单分析C/C ++代码以获取方法列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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