lordhog
lordhog

Reputation: 3707

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. 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#):

  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

Upvotes: 1

Views: 446

Answers (1)

Martin v. Löwis
Martin v. Löwis

Reputation: 127467

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.
  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.

Upvotes: 1

Related Questions