tags:

views:

279

answers:

1

Hello,

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

+1  A: 

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.
Martin v. Löwis