I'm looking to write a clang plugin that enables me to do some basic introspection in C. Specifically, I want to be able to get a struct's name, and iterate over the fields of a struct to get the field's name and value. I was thinking of adding a "meta" field to every struct during compilation which would look something like the following:<div>

<br><div>typedef struct {</div><div>  const char *name;</div><div>  size_t nfields;</div><div>  struct {</div><div>    const char *name;</div><div>    off_t offset;</div><div>    size_t size;</div><div>  } fields[nfields];</div>

<div>} struct_meta_t;</div><div><br></div><div>After having dug through some of clang's sources and doxygen docs, I had originally thought I could add an ASTConsumer which adds the struct, but from what I can tell, Sema generates the errors for invalid struct member access... which is run during AST generation. So I figure I'd need to plug into Sema somehow. Unfortunately, your parser library documentation (<a href="http://clang.llvm.org/docs/InternalsManual.html#libparse">http://clang.llvm.org/docs/InternalsManual.html#libparse</a>).</div>

<div><br></div><div>With that said, my question to you all is this. Is this the right way to go about it? And if so, can someone give me a parser library primer / tips on how to get started learning it?</div><div><div>--<br>

Russell Harmon<br>
</div></div>
</div>