c++ - 如何从 C# 解析/简单分析 C/C++ 代码以获取方法列表

标签 c++ parsing clang

我需要浏览一个 C/C++ 文件并提取类和方法的列表以及它们在文件中的位置。

libclang 是最佳选择吗?还是任务“太多”了?

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

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

谢谢!

最佳答案

你可以考虑ctags ,可在许多平台上使用。输出很容易解析,并且包含您需要的全部信息。

更多信息 对于您的问题,我不得不查看许多可用的选项,过了一会儿我找到了。例如:

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只是为了方便用户检查)

关于c++ - 如何从 C# 解析/简单分析 C/C++ 代码以获取方法列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8817712/

相关文章:

c++ - 从文本文件中读取行并显示在屏幕上

c++ - 错误 : C2065: 'DBL_MAX' : undeclared identifier (in VS2008 but not in VS2010)

c - 使用 libxml2 解析 xml 文件

c# - 非标准时区字符串的 DateTime.ParseExact 问题

c++ - 为什么在 XCode 中默认情况下循环展开?

c++ - g++5 中 std::unordered_set 的不完整类型编译错误,在 clang++ 中编译

c++ - C++中的延迟循环输出

c++ - Objective-C 中的非规范化 float ?

c++ - 灵气 : Completely ignoring output of some rules

objective-c - block 保留命名约定的循环?