[cfe-dev] Ghetto Introspection

Russell Harmon russ at eatnumber1.com
Fri Oct 14 16:49:27 PDT 2011


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:

typedef struct {
  const char *name;
  size_t nfields;
  struct {
    const char *name;
    off_t offset;
    size_t size;
  } fields[nfields];
} struct_meta_t;

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 (
http://clang.llvm.org/docs/InternalsManual.html#libparse).

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?
--
Russell Harmon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111014/d4d9d666/attachment.html>


More information about the cfe-dev mailing list