简体   繁体   English

使用C#解析* .c / *。h文件的最佳方法,以进行声明和数据类型定义

[英]Best approach to parsing a *.c/*.h files using C# for declarations and data type definitions

I need to parse .c/ .h files for the data declaration and extract the type declarations. 我需要解析.c / .h文件以获取数据声明并提取类型声明。 For example, I might need to extract the variable declaration and it corresponding data type that might look like: 例如,我可能需要提取变量声明及其对应的数据类型,如下所示:

typedef union 
{
  struct
  {
    unsigned char   OG15 : 1,
                    ...
                    OG0  : 1;
  } Bits;
  unsigned short Packed;

} OUTPUT_DESCRIPTOR;


OUTPUT_DESCRIPTOR DiscreteWord1;

So my questions would be (using C#): 所以我的问题是(使用C#):

  1. What would be the best way to store the data type information? 存储数据类型信息的最佳方法是什么?
  2. What is the best approach to parse to source files to extract the declarations and data types? 解析源文件以提取声明和数据类型的最佳方法是什么?

Thx 谢谢

Mark 标记

Not sure whether any of this is the best approach, but I can propose two working approaches: 不知道这是否是最好的方法,但是我可以提出两种可行的方法:

  1. Use the Phoenix SDK to write a compiler pass that records this information. 使用Phoenix SDK编写记录此信息的编译器通道。
  2. Compile the code with the regular C compiler, ask for PDB file, then use the DIA API to read the data structure definitions from the PDB files. 使用常规C编译器编译代码,索取PDB文件,然后使用DIA API从PDB文件读取数据结构定义。

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

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